add bubble detect

This commit is contained in:
CSSC-WORK\murmur 2024-12-17 15:57:50 +08:00
parent ef9e4bb589
commit 437210b6de
2 changed files with 96 additions and 0 deletions

22
Core/Inc/bubble.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef __BUBBLE_H
#define __BUBBLE_H
#ifdef __cplusplus
extern "C" {
#endif
#include "main.h"
#include "stdint.h"
extern uint8_t getPWMDutyCycle(void);
uint8_t bubble_init(void);
uint8_t bubble_set_mode(uint8_t mode);
uint8_t bubbleGetSize(void);
uint8_t bubbleGetStatus(void);
#ifdef __cplusplus
}
#endif
#endif

74
Core/Src/bubble.c Normal file
View File

@ -0,0 +1,74 @@
// Interface Mode 6 / 7
// The output is configured as PWM output, the input is configured as test input.
/*
+----------------------------+----------+--------------------------------------------+
| mode | Priority | ABD-OUT |
+----------------------------+----------+--------------------------------------------+
| Liquid/small-bubbles | Low | PWM-signal:20-<80%,represents-bubble-size |
+----------------------------+----------+--------------------------------------------+
| Air/Bubble | Medium | 80% |
+----------------------------+----------+--------------------------------------------+
| Internal-error(self-test) | High | 90% |
+----------------------------+----------+--------------------------------------------+
| Serious-fault(watchdog) | Highest | Static-H |
+----------------------------+----------+--------------------------------------------+
| Start-Mode | -- | H |
+----------------------------+----------+--------------------------------------------+
| Boot-mode | -- | UART-Tx |
+----------------------------+----------+--------------------------------------------+
*/
#include "bubble.h"
#define DELTA 1
/**
*
*
* @return 0: :
*/
uint8_t bubble_init(void)
{
return 0;
}
/**
*
*
* @param mode
* @return 0: :
*/
uint8_t bubble_set_mode(uint8_t mode)
{
return 0;
}
/**
*
*
* @return ,20-80%/80-90%/90%/
*/
uint8_t bubbleGetSize(void)
{
return getPWMDutyCycle();
}
/**
*
*
* @return ,0:,1:,2:
*/
uint8_t bubbleGetStatus(void)
{
uint8_t size = bubbleGetSize();
if (size < (80 - DELTA))
{
return 0;
}
else if (size >= (80 - DELTA) && size < (90 + DELTA))
{
return 1;
}
else if (size <= (90 + DELTA) && size >= (90 - DELTA))
{
return 2;
}
}