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.

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