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.

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