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.

163 lines
5.3 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
  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. /***********************************************************************************************************************
  23. * *******************************************************light******************************************************* *
  24. ***********************************************************************************************************************/
  25. power_state_light_structer_t power_state_light_structer = {
  26. .state = ShutDown,
  27. .change_flag = false,
  28. };
  29. heating_plate_state_light_structer_t heating_plate_state_light_structer = {
  30. .state = NoHeat,
  31. .change_flag = false,
  32. };
  33. reaction_state_light_structer_t reaction_state_light_structer = {
  34. .state = NoReaction,
  35. .change_flag = false,
  36. };
  37. wifi_state_light_structer_t wifi_state_light_structer = {
  38. .state = NotConnected,
  39. .change_flag = false,
  40. };
  41. /***********************************************************************************************************************
  42. * ********************************************************key******************************************************** *
  43. ***********************************************************************************************************************/
  44. T_key_structer_t T_key_structer = {
  45. .key_before_state = false,
  46. .key_now_state = false,
  47. .key_start_time = 0,
  48. };
  49. /***********************************************************************************************************************
  50. * ***************************************************heating_plate*************************************************** *
  51. ***********************************************************************************************************************/
  52. heating_plate_structer_t heating_plate_structer = {
  53. .heating_plate_preheat_start_flag = false,
  54. .heating_plate_preheat_finished_flag = false,
  55. };
  56. /***********************************************************************************************************************
  57. * *****************************************************reaction****************************************************** *
  58. ***********************************************************************************************************************/
  59. reaction_structer_t reaction_structer = {
  60. .reaction_start_flag = false,
  61. .reaction_start_time = 0,
  62. };
  63. /***********************************************************************************************************************
  64. * *******************************************************wifi******************************************************** *
  65. ***********************************************************************************************************************/
  66. wifi_structer_t wifi_structer = {
  67. .wifi_connect_flag = false,
  68. .wifi_distribution_network_flag = false,
  69. .wifi_max_connect_num = 10,
  70. };
  71. static void T_all_light_init(void)
  72. {
  73. T_power_light_init(&power_state_light_structer);
  74. T_heating_plate_state_light_init(&heating_plate_state_light_structer);
  75. T_reaction_state_light_init(&reaction_state_light_structer);
  76. T_wifi_state_light_init(&wifi_state_light_structer);
  77. }
  78. void process_key_event(void)
  79. {
  80. if (heating_plate_structer.heating_plate_preheat_finished_flag)
  81. {
  82. /* 加热完成 */
  83. if (camera_recognition_reaction_plate())
  84. {
  85. /* 识别有反应板放入 */
  86. if (!reaction_structer.reaction_start_flag)
  87. {
  88. /* 未开始反应 */
  89. reaction_structer.reaction_start_flag = true;
  90. reaction_structer.reaction_start_time = port_get_ticket();
  91. }
  92. }
  93. else
  94. {
  95. /* 识别没有反应板放入 */
  96. }
  97. }
  98. else
  99. {
  100. /* 加热未完成 */
  101. T_heating_plate_start();
  102. }
  103. }
  104. void process_key_long_press_event(void)
  105. {
  106. /* 配网 */
  107. if (!wifi_structer.wifi_distribution_network_flag)
  108. {
  109. if (T_wifi_distribution_network())
  110. {
  111. wifi_structer.wifi_distribution_network_flag = true;
  112. }
  113. }
  114. }
  115. void T_reaction_schedule(void)
  116. {
  117. if (reaction_structer.reaction_start_flag)
  118. {
  119. if ((port_get_ticket() - reaction_structer.reaction_start_time) >= REACTION_TIME_MS)
  120. {
  121. /* 反应完成 */
  122. reaction_structer.reaction_start_flag = false;
  123. }
  124. }
  125. }
  126. extern "C" void app_main(void)
  127. {
  128. T_debug_light_init();
  129. T_all_light_init();
  130. ble_spp_server_init();
  131. camera_init();
  132. T_key_init(&T_key_structer);
  133. T_wifi_init(&wifi_structer);
  134. T_temp_init();
  135. T_heating_plate_init(&heating_plate_structer);
  136. cover_init();
  137. beep_init();
  138. T_key_registered_cb(process_key_event, process_key_long_press_event);
  139. T_wifi_registered_cb();
  140. T_heating_plate_registered_cb(T_temp_get_data);
  141. while (true)
  142. {
  143. T_debug_light_schedule();
  144. T_light_flash_schedule();
  145. T_key_schedule();
  146. T_heating_plate_schedule();
  147. T_reaction_schedule();
  148. }
  149. }