#include // #include "camera.h" extern "C" { #include "ble_spp_server_demo.h" #include "light.h" #include "key.h" #include "wifi.h" #include "heating_plate.h" #include "temp.h" #include "port.h" #include "cover.h" #include "beep.h" } #define REACTION_TIME_MS 10 * 60 * 1000 typedef struct { bool reaction_start_flag; uint32_t reaction_start_time; } reaction_structer_t; /*********************************************************************************************************************** * *******************************************************light******************************************************* * ***********************************************************************************************************************/ power_state_light_structer_t power_state_light_structer = { .state = ShutDown, .change_flag = false, }; heating_plate_state_light_structer_t heating_plate_state_light_structer = { .state = NoHeat, .change_flag = false, }; reaction_state_light_structer_t reaction_state_light_structer = { .state = NoReaction, .change_flag = false, }; wifi_state_light_structer_t wifi_state_light_structer = { .state = NotConnected, .change_flag = false, }; /*********************************************************************************************************************** * ********************************************************key******************************************************** * ***********************************************************************************************************************/ T_key_structer_t T_key_structer = { .key_before_state = false, .key_now_state = false, .key_start_time = 0, }; /*********************************************************************************************************************** * ***************************************************heating_plate*************************************************** * ***********************************************************************************************************************/ heating_plate_structer_t heating_plate_structer = { .heating_plate_preheat_start_flag = false, .heating_plate_preheat_finished_flag = false, }; /*********************************************************************************************************************** * *****************************************************reaction****************************************************** * ***********************************************************************************************************************/ reaction_structer_t reaction_structer = { .reaction_start_flag = false, .reaction_start_time = 0, }; /*********************************************************************************************************************** * *******************************************************wifi******************************************************** * ***********************************************************************************************************************/ wifi_structer_t wifi_structer = { .wifi_connect_flag = false, .wifi_distribution_network_flag = false, .wifi_max_connect_num = 10, }; static void T_all_light_init(void) { T_power_light_init(&power_state_light_structer); T_heating_plate_state_light_init(&heating_plate_state_light_structer); T_reaction_state_light_init(&reaction_state_light_structer); T_wifi_state_light_init(&wifi_state_light_structer); } void process_key_event(void) { if (heating_plate_structer.heating_plate_preheat_finished_flag) { /* 加热完成 */ if (camera_recognition_reaction_plate()) { /* 识别有反应板放入 */ if (!reaction_structer.reaction_start_flag) { /* 未开始反应 */ reaction_structer.reaction_start_flag = true; reaction_structer.reaction_start_time = port_get_ticket(); } } else { /* 识别没有反应板放入 */ } } else { /* 加热未完成 */ T_heating_plate_start(); } } void process_key_long_press_event(void) { /* 配网 */ if (!wifi_structer.wifi_distribution_network_flag) { T_wifi_light_change_state(Connecting); if (T_wifi_distribution_network()) { wifi_structer.wifi_distribution_network_flag = true; T_wifi_light_change_state(ConnectionComplete); } } } void T_reaction_schedule(void) { if (reaction_structer.reaction_start_flag) { if ((port_get_ticket() - reaction_structer.reaction_start_time) >= REACTION_TIME_MS) { /* 反应完成 */ beep_set_level(true); reaction_structer.reaction_start_flag = false; } } } extern "C" void app_main(void) { T_debug_light_init(); T_all_light_init(); ble_spp_server_init(); camera_init(); T_key_init(&T_key_structer); T_wifi_init(&wifi_structer); T_temp_init(); T_heating_plate_init(&heating_plate_structer); cover_init(); beep_init(); T_key_registered_cb(process_key_event, process_key_long_press_event); T_wifi_registered_cb(); T_heating_plate_registered_cb(T_temp_get_data); while (true) { T_debug_light_schedule(); T_light_schedule(); T_key_schedule(); T_heating_plate_schedule(); T_reaction_schedule(); } }