process.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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; //异常,主要指IIC 通信
  16. uint8_t close_count =0;
  17. uint8_t open_count=0;
  18. static void update_state()
  19. {
  20. // //判定阀开状态
  21. // if(config->valvecolse_base <= 0){
  22. //
  23. // if(getHalldiff() > (config->valvecolse_base + config->threshold)){
  24. // //g_state = STATUS_OPEN;
  25. // if(open_count < 0xFF) open_count++;
  26. // close_count=0;
  27. // }else{
  28. // //g_state = STATUS_CLOSE;
  29. // open_count=0;
  30. // if(close_count < 0xFF) close_count++;
  31. // }
  32. //
  33. // }else{
  34. // if(getHalldiff() >= (config->valvecolse_base + config->threshold)){
  35. // //g_state = STATUS_CLOSE;
  36. // open_count=0;
  37. // if(close_count < 0xFF) close_count++;
  38. // }else{
  39. // //g_state = STATUS_OPEN;
  40. // if(open_count < 0xFF) open_count++;
  41. // close_count=0;
  42. // }
  43. // }
  44. if(close_count >= 10){
  45. g_state = STATUS_CLOSE;
  46. }else if(open_count >= 10){
  47. g_state = STATUS_OPEN;
  48. }
  49. if(STATUS_OPEN == g_state){
  50. g_runstate = STATUS_OPEN;
  51. }else if(STATUS_CLOSE == g_state){
  52. g_runstate = STATUS_CLOSE;
  53. }
  54. if(1 == g_exception){
  55. g_runstate = STATUS_EXCEPTION;
  56. }
  57. }
  58. void Process_Init(void)
  59. {
  60. /*初始化控制变量.*/
  61. g_blinkLedTime = 0;
  62. g_blinkLedTgtTime = BLINK_LED_DFTT;
  63. g_mr_Interval = 0;
  64. g_exception = 0;
  65. g_state = STATUS_CLOSE;
  66. update_state();
  67. //printf("process init \r\n");
  68. }
  69. void Process_RunPeriod(void)
  70. {
  71. /*周期性地检查LED闪烁,LED2和LED3同时闪烁.*/
  72. if (g_blinkLedTime >= g_blinkLedTgtTime)
  73. {
  74. g_blinkLedTime = 0;
  75. switch(g_runstate){
  76. case STATUS_CLOSE:
  77. REDLED_OFF;
  78. GREENLED_TOGGLE;
  79. break;
  80. case STATUS_OPEN:
  81. GREENLED_OFF;
  82. REDLED_TOGGLE;
  83. break;
  84. case STATUS_UNKNOW:
  85. REDLED_OFF;
  86. GREENLED_ON;
  87. break;
  88. default:
  89. GREENLED_OFF;
  90. REDLED_ON;
  91. break;
  92. };
  93. }
  94. //压力传感器测量请求
  95. if(g_mr_Interval >= 50){
  96. g_mr_Interval=0;
  97. //g_exception = PressureSensor_MR();
  98. Imu_MR();
  99. Radar_CheckResponse();
  100. update_state();
  101. }
  102. if(g_print_interval >= 500){
  103. g_print_interval=0;
  104. Radar_SendRequest();
  105. //Imu_MR();
  106. //printTempPress();
  107. //PressureSensor_Print();
  108. //printf("the NTC temperature: %f \r\n",getTemperature());
  109. //printf("the DIFF ADC1-ADC2: %d \r\n", getHalldiff());
  110. }
  111. }
  112. uint8_t Process_GetValveStatus(void)
  113. {
  114. return g_state;
  115. }
  116. float Process_GetTemperature(void)
  117. {
  118. return getTemperature();
  119. }
  120. float Process_GetPressure(void)
  121. {
  122. return getPressure();
  123. }
  124. uint8_t Process_GetAirHeight(float* pHeight)
  125. {
  126. return Radar_GetHeight(pHeight);
  127. }
  128. uint8_t Process_GetAngle(float* pRoll, float* pPitch, float* pYaw)
  129. {
  130. return Imu_GetAngle(pRoll, pPitch, pYaw);
  131. }
  132. uint8_t Process_WRadarTransData(uint8_t *pdata, uint8_t len)
  133. {
  134. Radar_SendData(pdata, len);
  135. return 0;
  136. }
  137. uint8_t Process_RRadarTransData(uint8_t *pBuf, uint8_t read_len)
  138. {
  139. Radar_ReadData(pBuf, read_len);
  140. return 0;
  141. }