add bubble detect
This commit is contained in:
parent
ef9e4bb589
commit
437210b6de
22
Core/Inc/bubble.h
Normal file
22
Core/Inc/bubble.h
Normal 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
74
Core/Src/bubble.c
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user