diff --git a/.vscode/settings.json b/.vscode/settings.json index 0856fb1..c850caf 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -10,6 +10,7 @@ "esp_bt_main.h": "c", "esp_bt_defs.h": "c", "camera.h": "c", - "key.h": "c" + "key.h": "c", + "heating_plate.h": "c" } } \ No newline at end of file diff --git a/main/app_main.cpp b/main/app_main.cpp index 2228d9f..a9fd90c 100644 --- a/main/app_main.cpp +++ b/main/app_main.cpp @@ -41,6 +41,7 @@ T_key_structer_t T_key_structer = { * ***************************************************heating_plate*************************************************** * ***********************************************************************************************************************/ heating_plate_structer_t heating_plate_structer = { + .heating_plate_preheat_start_flag = false, .heating_plate_preheat_finished_flag = false, }; @@ -74,7 +75,8 @@ extern "C" void app_main(void) T_key_init(&T_key_structer); T_wifi_init(); T_temp_init(); - + T_heating_plate_init(&heating_plate_structer); + T_key_registered_cb(process_key_event); T_wifi_registered_cb(); T_heating_plate_registered_cb(T_temp_get_data); diff --git a/main/heating_plate.c b/main/heating_plate.c index 024d554..8234873 100644 --- a/main/heating_plate.c +++ b/main/heating_plate.c @@ -11,9 +11,16 @@ #include "heating_plate.h" +#define heating_plate_target_temp 48.0 +#define heating_plate_variable_temperature_range 0.5 + +static heating_plate_structer_t *heating_plate_structer_s; static get_temp_callback_t get_temp_cb_s; -void T_heating_plate_init(void) {} +void T_heating_plate_init(heating_plate_structer_t *heating_plate_structer) +{ + heating_plate_structer_s = heating_plate_structer; +} void T_heating_plate_registered_cb(get_temp_callback_t cb) { get_temp_cb_s = cb; } @@ -21,4 +28,17 @@ void T_heating_plate_start(void) {} void T_heating_plate_stop(void) {} -void T_heating_plate_schedule(void) { get_temp_cb_s(); } \ No newline at end of file +void T_heating_plate_schedule(void) +{ + if (heating_plate_structer_s->heating_plate_preheat_start_flag) + { + if (get_temp_cb_s() >= heating_plate_target_temp + heating_plate_variable_temperature_range) + { + T_heating_plate_stop(); + } + else if (get_temp_cb_s() <= heating_plate_target_temp - heating_plate_variable_temperature_range) + { + T_heating_plate_start(); + } + } +} \ No newline at end of file diff --git a/main/heating_plate.h b/main/heating_plate.h index ced47c9..aadd374 100644 --- a/main/heating_plate.h +++ b/main/heating_plate.h @@ -3,12 +3,13 @@ typedef struct { + bool heating_plate_preheat_start_flag; bool heating_plate_preheat_finished_flag; } heating_plate_structer_t; -typedef double(*get_temp_callback_t)(void); +typedef double (*get_temp_callback_t)(void); -void T_heating_plate_init(void); +void T_heating_plate_init(heating_plate_structer_t *heating_plate_structer); void T_heating_plate_registered_cb(get_temp_callback_t cb); void T_heating_plate_start(void); void T_heating_plate_stop(void);