process.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. #include "process.h"
  2. #include "gpio.h"
  3. #include "cfg.h"
  4. #include "ac780x_gpio.h"
  5. #include "Radar.h"
  6. #include "Imu.h"
  7. #include "adc.h"
  8. uint16_t g_blinkLedTime; /*LED闪烁频率控制时间*/
  9. uint16_t g_blinkLedTgtTime; /*LED目标闪烁频率*/
  10. uint8_t g_mr_Interval = 0; /* 压力传感器更新周期 */
  11. uint16_t g_print_interval = 0; /* 打印周期 */
  12. #define STATUS_DETECTINTERVAL (40) /*60ms * 8 == 320ms 去抖动 */
  13. uint8_t g_runstate; //状态
  14. uint8_t g_state; //状态
  15. uint8_t g_exception; //异常,主要指雷达
  16. static float radar_airheight = 0;
  17. static uint8_t radar_status = 0;
  18. static void update_state()
  19. {
  20. radar_status = Radar_GetHeight(&radar_airheight);
  21. if((STATUS_NoResponse == radar_status) || (STATUS_DataError == radar_status)){
  22. g_exception = 1;
  23. }else{
  24. g_exception = 0;
  25. }
  26. if(STATUS_OPEN == g_state){
  27. g_runstate = STATUS_OPEN;
  28. }else if(STATUS_CLOSE == g_state){
  29. g_runstate = STATUS_CLOSE;
  30. }
  31. if(1 == g_exception){
  32. g_runstate = STATUS_EXCEPTION;
  33. }
  34. }
  35. void Process_Init(void)
  36. {
  37. /*初始化控制变量.*/
  38. g_blinkLedTime = 0;
  39. g_blinkLedTgtTime = BLINK_LED_DFTT;
  40. g_mr_Interval = 0;
  41. g_exception = 0;
  42. g_state = STATUS_CLOSE;
  43. update_state();
  44. ADCSample_UpdateBias(config->temperature_bias, config->pressure_bias);
  45. //printf("process init \r\n");
  46. }
  47. void Process_RunPeriod(void)
  48. {
  49. /*周期性地检查LED闪烁,LED2和LED3同时闪烁.*/
  50. if (g_blinkLedTime >= g_blinkLedTgtTime)
  51. {
  52. g_blinkLedTime = 0;
  53. switch(g_runstate){
  54. case STATUS_CLOSE:
  55. REDLED_OFF;
  56. GREENLED_TOGGLE;
  57. break;
  58. case STATUS_OPEN:
  59. GREENLED_OFF;
  60. REDLED_TOGGLE;
  61. break;
  62. case STATUS_UNKNOW:
  63. REDLED_OFF;
  64. GREENLED_ON;
  65. break;
  66. default:
  67. GREENLED_OFF;
  68. REDLED_ON;
  69. break;
  70. };
  71. }
  72. //压力传感器测量请求
  73. if(g_mr_Interval >= 50){
  74. g_mr_Interval=0;
  75. //g_exception = PressureSensor_MR();
  76. Imu_MR();
  77. Radar_CheckResponse();
  78. update_state();
  79. }
  80. if(g_print_interval >= 500){
  81. g_print_interval=0;
  82. Radar_SendRequest();
  83. //Imu_MR();
  84. //printTempPress();
  85. //PressureSensor_Print();
  86. //printf("the NTC temperature: %f \r\n",getTemperature());
  87. //printf("the DIFF ADC1-ADC2: %d \r\n", getHalldiff());
  88. }
  89. }
  90. uint8_t Process_GetValveStatus(void)
  91. {
  92. return g_state;
  93. }
  94. float Process_GetTemperature(void)
  95. {
  96. return getTemperature();
  97. }
  98. float Process_GetPressure(void)
  99. {
  100. return getPressure();
  101. }
  102. uint8_t Process_GetAirHeight(float* pHeight)
  103. {
  104. return Radar_GetHeight(pHeight);
  105. }
  106. uint8_t Process_GetAngle(float* pRoll, float* pPitch, float* pYaw)
  107. {
  108. return Imu_GetAngle(pRoll, pPitch, pYaw);
  109. }
  110. uint8_t Process_WRadarTransData(uint8_t *pdata, uint8_t len)
  111. {
  112. Radar_SendData(pdata, len);
  113. return 0;
  114. }
  115. uint8_t Process_RRadarTransData(uint8_t *pBuf, uint8_t read_len)
  116. {
  117. Radar_ReadData(pBuf, read_len);
  118. return 0;
  119. }
  120. uint8_t Process_SetBias(float temp_bias, float press_bias)
  121. {
  122. ADCSample_UpdateBias(temp_bias, press_bias);
  123. return 0;
  124. }