diff --git a/Core/Inc/bubble.h b/Core/Inc/bubble.h new file mode 100644 index 0000000..3985546 --- /dev/null +++ b/Core/Inc/bubble.h @@ -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 \ No newline at end of file diff --git a/Core/Src/bubble.c b/Core/Src/bubble.c new file mode 100644 index 0000000..28b9bf2 --- /dev/null +++ b/Core/Src/bubble.c @@ -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; + } +}