123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- #include "process.h"
- #include "gpio.h"
- #include "cfg.h"
- #include "ac780x_gpio.h"
- #include "Radar.h"
- #include "Imu.h"
- #include "adc.h"
- uint16_t g_blinkLedTime; /*LED闪烁频率控制时间*/
- uint16_t g_blinkLedTgtTime; /*LED目标闪烁频率*/
- uint8_t g_mr_Interval = 0; /* 压力传感器更新周期 */
- uint16_t g_print_interval = 0; /* 打印周期 */
- #define STATUS_DETECTINTERVAL (40) /*60ms * 8 == 320ms 去抖动 */
- uint8_t g_runstate; //状态
- uint8_t g_state; //状态
- uint8_t g_exception; //异常,主要指雷达
- static float radar_airheight = 0;
- static uint8_t radar_status = 0;
- static void update_state()
- {
- radar_status = Radar_GetHeight(&radar_airheight);
-
- if((STATUS_NoResponse == radar_status) || (STATUS_DataError == radar_status)){
- g_exception = 1;
- }else{
- g_exception = 0;
- }
-
-
- if(STATUS_OPEN == g_state){
- g_runstate = STATUS_OPEN;
- }else if(STATUS_CLOSE == g_state){
- g_runstate = STATUS_CLOSE;
- }
-
- if(1 == g_exception){
- g_runstate = STATUS_EXCEPTION;
- }
- }
- void Process_Init(void)
- {
- /*初始化控制变量.*/
- g_blinkLedTime = 0;
- g_blinkLedTgtTime = BLINK_LED_DFTT;
-
- g_mr_Interval = 0;
- g_exception = 0;
-
- g_state = STATUS_CLOSE;
- update_state();
-
- ADCSample_UpdateBias(config->temperature_bias, config->pressure_bias);
-
- //printf("process init \r\n");
- }
- void Process_RunPeriod(void)
- {
- /*周期性地检查LED闪烁,LED2和LED3同时闪烁.*/
- if (g_blinkLedTime >= g_blinkLedTgtTime)
- {
- g_blinkLedTime = 0;
-
- switch(g_runstate){
- case STATUS_CLOSE:
- REDLED_OFF;
- GREENLED_TOGGLE;
- break;
- case STATUS_OPEN:
- GREENLED_OFF;
- REDLED_TOGGLE;
- break;
- case STATUS_UNKNOW:
- REDLED_OFF;
- GREENLED_ON;
- break;
- default:
- GREENLED_OFF;
- REDLED_ON;
- break;
-
- };
-
- }
-
-
-
- //压力传感器测量请求
- if(g_mr_Interval >= 50){
- g_mr_Interval=0;
- //g_exception = PressureSensor_MR();
- Imu_MR();
- Radar_CheckResponse();
-
- update_state();
-
- }
-
-
-
- if(g_print_interval >= 500){
- g_print_interval=0;
-
- Radar_SendRequest();
-
- //Imu_MR();
-
- //printTempPress();
-
- //PressureSensor_Print();
-
- //printf("the NTC temperature: %f \r\n",getTemperature());
- //printf("the DIFF ADC1-ADC2: %d \r\n", getHalldiff());
- }
-
-
-
- }
- uint8_t Process_GetValveStatus(void)
- {
- return g_state;
- }
- float Process_GetTemperature(void)
- {
- return getTemperature();
- }
- float Process_GetPressure(void)
- {
- return getPressure();
-
- }
- uint8_t Process_GetAirHeight(float* pHeight)
- {
- return Radar_GetHeight(pHeight);
- }
- uint8_t Process_GetAngle(float* pRoll, float* pPitch, float* pYaw)
- {
- return Imu_GetAngle(pRoll, pPitch, pYaw);
- }
- uint8_t Process_WRadarTransData(uint8_t *pdata, uint8_t len)
- {
- Radar_SendData(pdata, len);
- return 0;
- }
- uint8_t Process_RRadarTransData(uint8_t *pBuf, uint8_t read_len)
- {
- Radar_ReadData(pBuf, read_len);
- return 0;
- }
- uint8_t Process_SetBias(float temp_bias, float press_bias)
- {
- ADCSample_UpdateBias(temp_bias, press_bias);
- return 0;
- }
|