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.

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