You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

209 lines
7.0 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. #include <stdbool.h>
  2. //
  3. #include "camera.h"
  4. extern "C"
  5. {
  6. #include "ble_spp_server_demo.h"
  7. #include "light.h"
  8. #include "key.h"
  9. #include "wifi.h"
  10. #include "heating_plate.h"
  11. #include "temp.h"
  12. #include "port.h"
  13. #include "cover.h"
  14. #include "beep.h"
  15. }
  16. #define REACTION_TIME_MS 10 * 60 * 1000
  17. typedef struct
  18. {
  19. bool reaction_start_flag;
  20. uint32_t reaction_start_time;
  21. } reaction_structer_t;
  22. typedef struct
  23. {
  24. bool device_standby_start_flag;
  25. uint32_t device_standby_start_time;
  26. } this_device_standby_t;
  27. /***********************************************************************************************************************
  28. * *******************************************************light******************************************************* *
  29. ***********************************************************************************************************************/
  30. power_state_light_structer_t power_state_light_structer = {
  31. .state = ShutDown,
  32. .change_flag = false,
  33. };
  34. heating_plate_state_light_structer_t heating_plate_state_light_structer = {
  35. .state = NoHeat,
  36. .change_flag = false,
  37. };
  38. reaction_state_light_structer_t reaction_state_light_structer = {
  39. .state = NoReaction,
  40. .change_flag = false,
  41. };
  42. wifi_state_light_structer_t wifi_state_light_structer = {
  43. .state = NotConnected,
  44. .change_flag = false,
  45. };
  46. /***********************************************************************************************************************
  47. * ********************************************************key******************************************************** *
  48. ***********************************************************************************************************************/
  49. T_key_structer_t T_key_structer = {
  50. .key_before_state = false,
  51. .key_now_state = false,
  52. .key_start_time = 0,
  53. };
  54. /***********************************************************************************************************************
  55. * ***************************************************heating_plate*************************************************** *
  56. ***********************************************************************************************************************/
  57. heating_plate_structer_t heating_plate_structer = {
  58. .heating_plate_preheat_start_flag = false,
  59. .heating_plate_preheat_finished_flag = false,
  60. };
  61. /***********************************************************************************************************************
  62. * *****************************************************reaction****************************************************** *
  63. ***********************************************************************************************************************/
  64. reaction_structer_t reaction_structer = {
  65. .reaction_start_flag = false,
  66. .reaction_start_time = 0,
  67. };
  68. /***********************************************************************************************************************
  69. * *******************************************************wifi******************************************************** *
  70. ***********************************************************************************************************************/
  71. wifi_structer_t wifi_structer = {
  72. .wifi_connect_flag = false,
  73. .wifi_distribution_network_flag = false,
  74. .wifi_max_connect_num = 10,
  75. };
  76. /***********************************************************************************************************************
  77. * ****************************************************this_device**************************************************** *
  78. ***********************************************************************************************************************/
  79. this_device_standby_t this_device_standby_structer = {
  80. .device_standby_start_flag = false,
  81. .device_standby_start_time = 0,
  82. };
  83. static void T_all_light_init(void)
  84. {
  85. T_power_light_init(&power_state_light_structer);
  86. T_heating_plate_state_light_init(&heating_plate_state_light_structer);
  87. T_reaction_state_light_init(&reaction_state_light_structer);
  88. T_wifi_state_light_init(&wifi_state_light_structer);
  89. }
  90. void process_short_key_event(void)
  91. {
  92. /* 加热完成 */
  93. if (heating_plate_structer.heating_plate_preheat_finished_flag)
  94. {
  95. /* 识别有反应板放入 */
  96. if (camera_recognition_reaction_plate())
  97. {
  98. /* 未开始反应 */
  99. if (!reaction_structer.reaction_start_flag)
  100. {
  101. reaction_structer.reaction_start_flag = true;
  102. reaction_structer.reaction_start_time = port_get_ticket();
  103. }
  104. /* 反应中 */
  105. else
  106. {
  107. }
  108. }
  109. /* 识别没有反应板放入 */
  110. else
  111. {
  112. }
  113. }
  114. /* 加热未完成 */
  115. else
  116. {
  117. T_heating_plate_start();
  118. T_heating_plate_light_set_rgb_by_state(Heating);
  119. }
  120. }
  121. void process_key_long_press_event(void)
  122. {
  123. /* 配网 */
  124. if (!wifi_structer.wifi_distribution_network_flag)
  125. {
  126. T_wifi_light_change_state(Connecting);
  127. if (T_wifi_distribution_network())
  128. {
  129. wifi_structer.wifi_distribution_network_flag = true;
  130. T_wifi_light_change_state(ConnectionComplete);
  131. }
  132. }
  133. }
  134. void T_reaction_schedule(void)
  135. {
  136. if (reaction_structer.reaction_start_flag)
  137. {
  138. /* 反应完成 */
  139. if ((port_get_ticket() - reaction_structer.reaction_start_time) >= REACTION_TIME_MS)
  140. {
  141. beep_set_level(true);
  142. reaction_structer.reaction_start_flag = false;
  143. }
  144. }
  145. if ((heating_plate_structer.heating_plate_preheat_finished_flag == true) && //
  146. (!camera_recognition_reaction_plate()) && !this_device_standby_structer.device_standby_start_flag)
  147. {
  148. this_device_standby_structer.device_standby_start_flag = true;
  149. this_device_standby_structer.device_standby_start_time = port_get_ticket();
  150. }
  151. else
  152. {
  153. this_device_standby_structer.device_standby_start_flag = false;
  154. }
  155. }
  156. void T_this_device_standby_schedule(void)
  157. {
  158. if (this_device_standby_structer.device_standby_start_flag)
  159. {
  160. if ((port_get_ticket() - this_device_standby_structer.device_standby_start_time) >= 600000)
  161. {
  162. T_heating_plate_stop();
  163. T_heating_plate_light_set_rgb_by_state(NoHeat);
  164. this_device_standby_structer.device_standby_start_flag = false;
  165. }
  166. }
  167. }
  168. extern "C" void app_main(void)
  169. {
  170. T_debug_light_init();
  171. T_all_light_init();
  172. ble_spp_server_init();
  173. camera_init();
  174. T_key_init(&T_key_structer);
  175. T_wifi_init(&wifi_structer);
  176. T_temp_init();
  177. T_heating_plate_init(&heating_plate_structer);
  178. cover_init();
  179. beep_init();
  180. T_key_registered_cb(process_short_key_event, process_key_long_press_event);
  181. T_wifi_registered_cb();
  182. T_heating_plate_registered_cb(T_temp_get_data);
  183. while (true)
  184. {
  185. T_debug_light_schedule();
  186. T_light_schedule();
  187. T_key_schedule();
  188. T_heating_plate_schedule();
  189. T_reaction_schedule();
  190. T_this_device_standby_schedule();
  191. }
  192. }