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.

146 lines
4.5 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
  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. static void T_all_light_init(void)
  64. {
  65. T_power_light_init(&power_state_light_structer);
  66. T_heating_plate_state_light_init(&heating_plate_state_light_structer);
  67. T_reaction_state_light_init(&reaction_state_light_structer);
  68. T_wifi_state_light_init(&wifi_state_light_structer);
  69. }
  70. void process_key_event(void)
  71. {
  72. if (heating_plate_structer.heating_plate_preheat_finished_flag)
  73. {
  74. /* 加热完成 */
  75. if (camera_recognition_reaction_plate())
  76. {
  77. /* 识别有反应板放入 */
  78. if (!reaction_structer.reaction_start_flag)
  79. {
  80. /* 未开始反应 */
  81. reaction_structer.reaction_start_flag = true;
  82. reaction_structer.reaction_start_time = port_get_ticket();
  83. }
  84. }
  85. else
  86. {
  87. /* 识别没有反应板放入 */
  88. }
  89. }
  90. else
  91. {
  92. /* 加热未完成 */
  93. T_heating_plate_start();
  94. }
  95. }
  96. void process_key_long_press_event(void)
  97. {
  98. }
  99. void T_reaction_schedule(void)
  100. {
  101. if (reaction_structer.reaction_start_flag)
  102. {
  103. if ((port_get_ticket() - reaction_structer.reaction_start_time) >= REACTION_TIME_MS)
  104. {
  105. /* 反应完成 */
  106. reaction_structer.reaction_start_flag = false;
  107. }
  108. }
  109. }
  110. extern "C" void app_main(void)
  111. {
  112. T_debug_light_init();
  113. T_all_light_init();
  114. ble_spp_server_init();
  115. camera_init();
  116. T_key_init(&T_key_structer);
  117. T_wifi_init();
  118. T_temp_init();
  119. T_heating_plate_init(&heating_plate_structer);
  120. cover_init();
  121. beep_init();
  122. T_key_registered_cb(process_key_event, process_key_long_press_event);
  123. T_wifi_registered_cb();
  124. T_heating_plate_registered_cb(T_temp_get_data);
  125. while (true)
  126. {
  127. T_debug_light_schedule();
  128. T_light_flash_schedule();
  129. T_key_schedule();
  130. T_heating_plate_schedule();
  131. T_reaction_schedule();
  132. }
  133. }