diff --git a/libraries/ui/src/CMakeLists.txt b/libraries/ui/src/CMakeLists.txt index 985fbf3..3330f39 100644 --- a/libraries/ui/src/CMakeLists.txt +++ b/libraries/ui/src/CMakeLists.txt @@ -1,9 +1,10 @@ SET(SOURCES ui_Screen1.c - ui_Screen2.c ui_Screen3.c ui_Screen4.c ui_Screen5.c ui_Screen6.c + ui_Screen7.c + ui_Screen2.c ui.c ui_comp_hook.c ui_helpers.c @@ -13,8 +14,8 @@ SET(SOURCES ui_Screen1.c ui_img_light_png.c ui_img_fan_png.c ui_img_settings_png.c - ui_img_up_png.c ui_img_down_png.c + ui_img_up_png.c ui_img_home_png.c ui_img_wifi_png.c ui_temporary_image.c) diff --git a/libraries/ui/src/filelist.txt b/libraries/ui/src/filelist.txt index e1df2b9..08aca30 100644 --- a/libraries/ui/src/filelist.txt +++ b/libraries/ui/src/filelist.txt @@ -1,9 +1,10 @@ ui_Screen1.c -ui_Screen2.c ui_Screen3.c ui_Screen4.c ui_Screen5.c ui_Screen6.c +ui_Screen7.c +ui_Screen2.c ui.c ui_comp_hook.c ui_helpers.c @@ -13,8 +14,8 @@ ui_img_florist_png.c ui_img_light_png.c ui_img_fan_png.c ui_img_settings_png.c -ui_img_up_png.c ui_img_down_png.c +ui_img_up_png.c ui_img_home_png.c ui_img_wifi_png.c ui_temporary_image.c diff --git a/libraries/ui/src/ui.c b/libraries/ui/src/ui.c index 01aa5a3..5280d47 100644 --- a/libraries/ui/src/ui.c +++ b/libraries/ui/src/ui.c @@ -29,26 +29,6 @@ lv_obj_t * ui_settings; lv_obj_t * ui_growmode; -// SCREEN: ui_Screen2 -void ui_Screen2_screen_init(void); -lv_obj_t * ui_Screen2; -lv_obj_t * ui_Image3; -lv_obj_t * ui_Image4; -void ui_event_Label1(lv_event_t * e); -lv_obj_t * ui_Label1; -lv_obj_t * ui_Label2; -lv_obj_t * ui_light2statuslbl; -lv_obj_t * ui_light1statuslbl; -lv_obj_t * ui_light1switch; -lv_obj_t * ui_light2switch; -lv_obj_t * ui_light2percent; -lv_obj_t * ui_light1percent; -lv_obj_t * ui_light1up; -lv_obj_t * ui_light1down; -lv_obj_t * ui_light2up; -lv_obj_t * ui_light2down; - - // SCREEN: ui_Screen3 void ui_Screen3_screen_init(void); lv_obj_t * ui_Screen3; @@ -63,7 +43,6 @@ lv_obj_t * ui_Image6; void ui_event_btnfanhome(lv_event_t * e); lv_obj_t * ui_btnfanhome; lv_obj_t * ui_switchfanstatus; -lv_obj_t * ui_lblfanstatus; // SCREEN: ui_Screen4 @@ -109,6 +88,42 @@ lv_obj_t * ui_savemode; lv_obj_t * ui_lblsavemode; void ui_event_homebtngrow(lv_event_t * e); lv_obj_t * ui_homebtngrow; +lv_obj_t * ui_led1check; +lv_obj_t * ui_led3check; +lv_obj_t * ui_led2check; + + +// SCREEN: ui_Screen7 +void ui_Screen7_screen_init(void); +lv_obj_t * ui_Screen7; +lv_obj_t * ui_Label10; +lv_obj_t * ui_light3switch; +lv_obj_t * ui_light2switch; +lv_obj_t * ui_light1switch; +lv_obj_t * ui_light3percent; +lv_obj_t * ui_Label9; +lv_obj_t * ui_Label12; +lv_obj_t * ui_led3; +lv_obj_t * ui_led1; +lv_obj_t * ui_led2; +lv_obj_t * ui_light1percent; +lv_obj_t * ui_light2percent; +lv_obj_t * ui_lightup; +lv_obj_t * ui_lightdown; +void ui_event_ledhome(lv_event_t * e); +lv_obj_t * ui_ledhome; + + +// SCREEN: ui_Screen2 +void ui_Screen2_screen_init(void); +lv_obj_t * ui_Screen2; +lv_obj_t * ui_sunsimspin; +lv_obj_t * ui_lblsunsim; +lv_obj_t * ui_endtime; +lv_obj_t * ui_starttime; +lv_obj_t * ui_clock; +void ui_event_simhome(lv_event_t * e); +lv_obj_t * ui_simhome; lv_obj_t * ui____initial_actions0; ///////////////////// TEST LVGL SETTINGS //////////////////// @@ -124,7 +139,7 @@ void ui_event_btnlight(lv_event_t * e) lv_event_code_t event_code = lv_event_get_code(e); lv_obj_t * target = lv_event_get_target(e); if(event_code == LV_EVENT_CLICKED) { - _ui_screen_change(&ui_Screen2, LV_SCR_LOAD_ANIM_FADE_ON, 500, 0, &ui_Screen2_screen_init); + _ui_screen_change(&ui_Screen7, LV_SCR_LOAD_ANIM_FADE_ON, 500, 0, &ui_Screen7_screen_init); } } void ui_event_btnfan(lv_event_t * e) @@ -143,14 +158,6 @@ void ui_event_settings(lv_event_t * e) _ui_screen_change(&ui_Screen4, LV_SCR_LOAD_ANIM_FADE_ON, 500, 0, &ui_Screen4_screen_init); } } -void ui_event_Label1(lv_event_t * e) -{ - lv_event_code_t event_code = lv_event_get_code(e); - lv_obj_t * target = lv_event_get_target(e); - if(event_code == LV_EVENT_CLICKED) { - _ui_screen_change(&ui_Screen1, LV_SCR_LOAD_ANIM_FADE_ON, 500, 0, &ui_Screen1_screen_init); - } -} void ui_event_btnfanhome(lv_event_t * e) { lv_event_code_t event_code = lv_event_get_code(e); @@ -210,6 +217,23 @@ void ui_event_homebtngrow(lv_event_t * e) _ui_screen_change(&ui_Screen1, LV_SCR_LOAD_ANIM_FADE_ON, 500, 0, &ui_Screen1_screen_init); } } +void ui_event_ledhome(lv_event_t * e) +{ + lv_event_code_t event_code = lv_event_get_code(e); + lv_obj_t * target = lv_event_get_target(e); + if(event_code == LV_EVENT_CLICKED) { + _ui_screen_change(&ui_Screen1, LV_SCR_LOAD_ANIM_FADE_ON, 500, 0, &ui_Screen1_screen_init); + _ui_state_modify(ui_led1check, LV_STATE_CHECKED, _UI_MODIFY_STATE_REMOVE); + } +} +void ui_event_simhome(lv_event_t * e) +{ + lv_event_code_t event_code = lv_event_get_code(e); + lv_obj_t * target = lv_event_get_target(e); + if(event_code == LV_EVENT_CLICKED) { + _ui_screen_change(&ui_Screen1, LV_SCR_LOAD_ANIM_FADE_ON, 500, 0, &ui_Screen1_screen_init); + } +} ///////////////////// SCREENS //////////////////// @@ -220,11 +244,12 @@ void ui_init(void) false, LV_FONT_DEFAULT); lv_disp_set_theme(dispp, theme); ui_Screen1_screen_init(); - ui_Screen2_screen_init(); ui_Screen3_screen_init(); ui_Screen4_screen_init(); ui_Screen5_screen_init(); ui_Screen6_screen_init(); + ui_Screen7_screen_init(); + ui_Screen2_screen_init(); ui____initial_actions0 = lv_obj_create(NULL); lv_disp_load_scr(ui_Screen1); } diff --git a/libraries/ui/src/ui.h b/libraries/ui/src/ui.h index 94e6f4f..d783a3f 100644 --- a/libraries/ui/src/ui.h +++ b/libraries/ui/src/ui.h @@ -43,24 +43,6 @@ extern lv_obj_t * ui_lblfanspeed; void ui_event_settings(lv_event_t * e); extern lv_obj_t * ui_settings; extern lv_obj_t * ui_growmode; -// SCREEN: ui_Screen2 -void ui_Screen2_screen_init(void); -extern lv_obj_t * ui_Screen2; -extern lv_obj_t * ui_Image3; -extern lv_obj_t * ui_Image4; -void ui_event_Label1(lv_event_t * e); -extern lv_obj_t * ui_Label1; -extern lv_obj_t * ui_Label2; -extern lv_obj_t * ui_light2statuslbl; -extern lv_obj_t * ui_light1statuslbl; -extern lv_obj_t * ui_light1switch; -extern lv_obj_t * ui_light2switch; -extern lv_obj_t * ui_light2percent; -extern lv_obj_t * ui_light1percent; -extern lv_obj_t * ui_light1up; -extern lv_obj_t * ui_light1down; -extern lv_obj_t * ui_light2up; -extern lv_obj_t * ui_light2down; // SCREEN: ui_Screen3 void ui_Screen3_screen_init(void); extern lv_obj_t * ui_Screen3; @@ -75,7 +57,6 @@ extern lv_obj_t * ui_Image6; void ui_event_btnfanhome(lv_event_t * e); extern lv_obj_t * ui_btnfanhome; extern lv_obj_t * ui_switchfanstatus; -extern lv_obj_t * ui_lblfanstatus; // SCREEN: ui_Screen4 void ui_Screen4_screen_init(void); extern lv_obj_t * ui_Screen4; @@ -115,6 +96,38 @@ extern lv_obj_t * ui_savemode; extern lv_obj_t * ui_lblsavemode; void ui_event_homebtngrow(lv_event_t * e); extern lv_obj_t * ui_homebtngrow; +extern lv_obj_t * ui_led1check; +extern lv_obj_t * ui_led3check; +extern lv_obj_t * ui_led2check; +// SCREEN: ui_Screen7 +void ui_Screen7_screen_init(void); +extern lv_obj_t * ui_Screen7; +extern lv_obj_t * ui_Label10; +extern lv_obj_t * ui_light3switch; +extern lv_obj_t * ui_light2switch; +extern lv_obj_t * ui_light1switch; +extern lv_obj_t * ui_light3percent; +extern lv_obj_t * ui_Label9; +extern lv_obj_t * ui_Label12; +extern lv_obj_t * ui_led3; +extern lv_obj_t * ui_led1; +extern lv_obj_t * ui_led2; +extern lv_obj_t * ui_light1percent; +extern lv_obj_t * ui_light2percent; +extern lv_obj_t * ui_lightup; +extern lv_obj_t * ui_lightdown; +void ui_event_ledhome(lv_event_t * e); +extern lv_obj_t * ui_ledhome; +// SCREEN: ui_Screen2 +void ui_Screen2_screen_init(void); +extern lv_obj_t * ui_Screen2; +extern lv_obj_t * ui_sunsimspin; +extern lv_obj_t * ui_lblsunsim; +extern lv_obj_t * ui_endtime; +extern lv_obj_t * ui_starttime; +extern lv_obj_t * ui_clock; +void ui_event_simhome(lv_event_t * e); +extern lv_obj_t * ui_simhome; extern lv_obj_t * ui____initial_actions0; LV_IMG_DECLARE(ui__temporary_image); @@ -124,8 +137,8 @@ LV_IMG_DECLARE(ui_img_florist_png); // assets/florist.png LV_IMG_DECLARE(ui_img_light_png); // assets/light.png LV_IMG_DECLARE(ui_img_fan_png); // assets/fan.png LV_IMG_DECLARE(ui_img_settings_png); // assets/settings.png -LV_IMG_DECLARE(ui_img_up_png); // assets/up.png LV_IMG_DECLARE(ui_img_down_png); // assets/down.png +LV_IMG_DECLARE(ui_img_up_png); // assets/up.png LV_IMG_DECLARE(ui_img_home_png); // assets/home.png LV_IMG_DECLARE(ui_img_wifi_png); // assets/wifi.png diff --git a/libraries/ui/src/ui_Screen2.c b/libraries/ui/src/ui_Screen2.c index 573b1fb..f3826f7 100644 --- a/libraries/ui/src/ui_Screen2.c +++ b/libraries/ui/src/ui_Screen2.c @@ -10,155 +10,58 @@ void ui_Screen2_screen_init(void) ui_Screen2 = lv_obj_create(NULL); lv_obj_remove_flag(ui_Screen2, LV_OBJ_FLAG_SCROLLABLE); /// Flags - ui_Image3 = lv_image_create(ui_Screen2); - lv_image_set_src(ui_Image3, &ui_img_light_png); - lv_obj_set_width(ui_Image3, LV_SIZE_CONTENT); /// 64 - lv_obj_set_height(ui_Image3, LV_SIZE_CONTENT); /// 64 - lv_obj_set_x(ui_Image3, 30); - lv_obj_set_y(ui_Image3, -40); - lv_obj_set_align(ui_Image3, LV_ALIGN_CENTER); - lv_obj_add_flag(ui_Image3, LV_OBJ_FLAG_CLICKABLE); /// Flags - lv_obj_remove_flag(ui_Image3, LV_OBJ_FLAG_SCROLLABLE); /// Flags + ui_sunsimspin = lv_spinner_create(ui_Screen2); + //lv_spinner_set_anim_params(ui_sunsimspin, 1000, 90); + lv_obj_set_width(ui_sunsimspin, 95); + lv_obj_set_height(ui_sunsimspin, 97); + lv_obj_set_x(ui_sunsimspin, 0); + lv_obj_set_y(ui_sunsimspin, -10); + lv_obj_set_align(ui_sunsimspin, LV_ALIGN_CENTER); + lv_obj_remove_flag(ui_sunsimspin, LV_OBJ_FLAG_CLICKABLE); /// Flags - ui_Image4 = lv_image_create(ui_Screen2); - lv_image_set_src(ui_Image4, &ui_img_light_png); - lv_obj_set_width(ui_Image4, LV_SIZE_CONTENT); /// 64 - lv_obj_set_height(ui_Image4, LV_SIZE_CONTENT); /// 64 - lv_obj_set_x(ui_Image4, -120); - lv_obj_set_y(ui_Image4, -40); - lv_obj_set_align(ui_Image4, LV_ALIGN_CENTER); - lv_obj_add_flag(ui_Image4, LV_OBJ_FLAG_CLICKABLE); /// Flags - lv_obj_remove_flag(ui_Image4, LV_OBJ_FLAG_SCROLLABLE); /// Flags + ui_lblsunsim = lv_label_create(ui_Screen2); + lv_obj_set_width(ui_lblsunsim, LV_SIZE_CONTENT); /// 1 + lv_obj_set_height(ui_lblsunsim, LV_SIZE_CONTENT); /// 1 + lv_obj_set_x(ui_lblsunsim, 0); + lv_obj_set_y(ui_lblsunsim, -90); + lv_obj_set_align(ui_lblsunsim, LV_ALIGN_CENTER); + lv_label_set_text(ui_lblsunsim, "Sonnensimulation"); + lv_obj_set_style_text_font(ui_lblsunsim, &lv_font_montserrat_22, LV_PART_MAIN | LV_STATE_DEFAULT); - ui_Label1 = lv_label_create(ui_Screen2); - lv_obj_set_width(ui_Label1, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_Label1, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_Label1, -85); - lv_obj_set_y(ui_Label1, -90); - lv_obj_set_align(ui_Label1, LV_ALIGN_CENTER); - lv_label_set_text(ui_Label1, "First"); - lv_obj_add_flag(ui_Label1, LV_OBJ_FLAG_CLICKABLE); /// Flags - lv_obj_set_style_text_font(ui_Label1, &lv_font_montserrat_22, LV_PART_MAIN | LV_STATE_DEFAULT); + ui_endtime = lv_label_create(ui_Screen2); + lv_obj_set_width(ui_endtime, LV_SIZE_CONTENT); /// 1 + lv_obj_set_height(ui_endtime, LV_SIZE_CONTENT); /// 1 + lv_obj_set_x(ui_endtime, 0); + lv_obj_set_y(ui_endtime, 80); + lv_obj_set_align(ui_endtime, LV_ALIGN_CENTER); + lv_label_set_text(ui_endtime, "Sonnenuntergang: 12:00 Uhr"); - ui_Label2 = lv_label_create(ui_Screen2); - lv_obj_set_width(ui_Label2, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_Label2, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_Label2, 75); - lv_obj_set_y(ui_Label2, -90); - lv_obj_set_align(ui_Label2, LV_ALIGN_CENTER); - lv_label_set_text(ui_Label2, "Second"); - lv_obj_set_style_text_font(ui_Label2, &lv_font_montserrat_22, LV_PART_MAIN | LV_STATE_DEFAULT); + ui_starttime = lv_label_create(ui_Screen2); + lv_obj_set_width(ui_starttime, LV_SIZE_CONTENT); /// 1 + lv_obj_set_height(ui_starttime, LV_SIZE_CONTENT); /// 1 + lv_obj_set_x(ui_starttime, 0); + lv_obj_set_y(ui_starttime, 60); + lv_obj_set_align(ui_starttime, LV_ALIGN_CENTER); + lv_label_set_text(ui_starttime, "Sonnenaufgang: 18:00 Uhr"); - ui_light2statuslbl = lv_label_create(ui_Screen2); - lv_obj_set_width(ui_light2statuslbl, 60); - lv_obj_set_height(ui_light2statuslbl, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_light2statuslbl, 30); - lv_obj_set_y(ui_light2statuslbl, 15); - lv_obj_set_align(ui_light2statuslbl, LV_ALIGN_CENTER); - lv_label_set_text(ui_light2statuslbl, "ON"); - lv_obj_set_style_text_align(ui_light2statuslbl, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_font(ui_light2statuslbl, &lv_font_montserrat_22, LV_PART_MAIN | LV_STATE_DEFAULT); + ui_clock = lv_label_create(ui_Screen2); + lv_obj_set_width(ui_clock, LV_SIZE_CONTENT); /// 1 + lv_obj_set_height(ui_clock, LV_SIZE_CONTENT); /// 1 + lv_obj_set_x(ui_clock, 0); + lv_obj_set_y(ui_clock, 101); + lv_obj_set_align(ui_clock, LV_ALIGN_CENTER); + lv_label_set_text(ui_clock, "Uhrzeit: "); - ui_light1statuslbl = lv_label_create(ui_Screen2); - lv_obj_set_width(ui_light1statuslbl, 60); - lv_obj_set_height(ui_light1statuslbl, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_light1statuslbl, -120); - lv_obj_set_y(ui_light1statuslbl, 15); - lv_obj_set_align(ui_light1statuslbl, LV_ALIGN_CENTER); - lv_label_set_text(ui_light1statuslbl, "ON"); - lv_obj_set_style_text_align(ui_light1statuslbl, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_font(ui_light1statuslbl, &lv_font_montserrat_22, LV_PART_MAIN | LV_STATE_DEFAULT); + ui_simhome = lv_image_create(ui_Screen2); + lv_image_set_src(ui_simhome, &ui_img_home_png); + lv_obj_set_width(ui_simhome, LV_SIZE_CONTENT); /// 64 + lv_obj_set_height(ui_simhome, LV_SIZE_CONTENT); /// 64 + lv_obj_set_x(ui_simhome, -120); + lv_obj_set_y(ui_simhome, -11); + lv_obj_set_align(ui_simhome, LV_ALIGN_CENTER); + lv_obj_add_flag(ui_simhome, LV_OBJ_FLAG_CLICKABLE); /// Flags + lv_obj_remove_flag(ui_simhome, LV_OBJ_FLAG_SCROLLABLE); /// Flags - ui_light1switch = lv_switch_create(ui_Screen2); - lv_obj_set_width(ui_light1switch, 50); - lv_obj_set_height(ui_light1switch, 25); - lv_obj_set_x(ui_light1switch, -45); - lv_obj_set_y(ui_light1switch, 15); - lv_obj_set_align(ui_light1switch, LV_ALIGN_CENTER); - - - ui_light2switch = lv_switch_create(ui_Screen2); - lv_obj_set_width(ui_light2switch, 50); - lv_obj_set_height(ui_light2switch, 25); - lv_obj_set_x(ui_light2switch, 105); - lv_obj_set_y(ui_light2switch, 15); - lv_obj_set_align(ui_light2switch, LV_ALIGN_CENTER); - - - ui_light2percent = lv_label_create(ui_Screen2); - lv_obj_set_width(ui_light2percent, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_light2percent, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_light2percent, 105); - lv_obj_set_y(ui_light2percent, -40); - lv_obj_set_align(ui_light2percent, LV_ALIGN_CENTER); - lv_label_set_text(ui_light2percent, "0 %"); - lv_obj_set_style_text_align(ui_light2percent, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_font(ui_light2percent, &lv_font_montserrat_22, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_light1percent = lv_label_create(ui_Screen2); - lv_obj_set_width(ui_light1percent, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_light1percent, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_light1percent, -45); - lv_obj_set_y(ui_light1percent, -40); - lv_obj_set_align(ui_light1percent, LV_ALIGN_CENTER); - lv_label_set_text(ui_light1percent, "0 %"); - lv_obj_set_style_text_align(ui_light1percent, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_font(ui_light1percent, &lv_font_montserrat_22, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_light1up = lv_imagebutton_create(ui_Screen2); - lv_imagebutton_set_src(ui_light1up, LV_IMAGEBUTTON_STATE_RELEASED, NULL, &ui_img_up_png, NULL); - lv_imagebutton_set_src(ui_light1up, LV_IMAGEBUTTON_STATE_PRESSED, NULL, &ui_img_up_png, NULL); - lv_imagebutton_set_src(ui_light1up, LV_IMAGEBUTTON_STATE_DISABLED, NULL, &ui__temporary_image, NULL); - lv_imagebutton_set_src(ui_light1up, LV_IMAGEBUTTON_STATE_CHECKED_PRESSED, NULL, &ui__temporary_image, NULL); - lv_imagebutton_set_src(ui_light1up, LV_IMAGEBUTTON_STATE_CHECKED_RELEASED, NULL, &ui__temporary_image, NULL); - lv_imagebutton_set_src(ui_light1up, LV_IMAGEBUTTON_STATE_CHECKED_DISABLED, NULL, &ui__temporary_image, NULL); - lv_obj_set_height(ui_light1up, 64); - lv_obj_set_width(ui_light1up, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_light1up, -120); - lv_obj_set_y(ui_light1up, 75); - lv_obj_set_align(ui_light1up, LV_ALIGN_CENTER); - lv_obj_set_style_bg_color(ui_light1up, lv_color_hex(0x82ADF0), LV_PART_MAIN | LV_STATE_PRESSED); - lv_obj_set_style_bg_opa(ui_light1up, 255, LV_PART_MAIN | LV_STATE_PRESSED); - - ui_light1down = lv_imagebutton_create(ui_Screen2); - lv_imagebutton_set_src(ui_light1down, LV_IMAGEBUTTON_STATE_RELEASED, NULL, &ui_img_down_png, NULL); - lv_imagebutton_set_src(ui_light1down, LV_IMAGEBUTTON_STATE_PRESSED, NULL, &ui_img_down_png, NULL); - lv_imagebutton_set_src(ui_light1down, LV_IMAGEBUTTON_STATE_DISABLED, NULL, &ui__temporary_image, NULL); - lv_imagebutton_set_src(ui_light1down, LV_IMAGEBUTTON_STATE_CHECKED_PRESSED, NULL, &ui__temporary_image, NULL); - lv_imagebutton_set_src(ui_light1down, LV_IMAGEBUTTON_STATE_CHECKED_RELEASED, NULL, &ui__temporary_image, NULL); - lv_imagebutton_set_src(ui_light1down, LV_IMAGEBUTTON_STATE_CHECKED_DISABLED, NULL, &ui__temporary_image, NULL); - lv_obj_set_height(ui_light1down, 64); - lv_obj_set_width(ui_light1down, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_light1down, -45); - lv_obj_set_y(ui_light1down, 75); - lv_obj_set_align(ui_light1down, LV_ALIGN_CENTER); - - ui_light2up = lv_imagebutton_create(ui_Screen2); - lv_imagebutton_set_src(ui_light2up, LV_IMAGEBUTTON_STATE_RELEASED, NULL, &ui_img_up_png, NULL); - lv_imagebutton_set_src(ui_light2up, LV_IMAGEBUTTON_STATE_PRESSED, NULL, &ui_img_up_png, NULL); - lv_imagebutton_set_src(ui_light2up, LV_IMAGEBUTTON_STATE_DISABLED, NULL, &ui__temporary_image, NULL); - lv_imagebutton_set_src(ui_light2up, LV_IMAGEBUTTON_STATE_CHECKED_PRESSED, NULL, &ui__temporary_image, NULL); - lv_imagebutton_set_src(ui_light2up, LV_IMAGEBUTTON_STATE_CHECKED_RELEASED, NULL, &ui__temporary_image, NULL); - lv_imagebutton_set_src(ui_light2up, LV_IMAGEBUTTON_STATE_CHECKED_DISABLED, NULL, &ui__temporary_image, NULL); - lv_obj_set_height(ui_light2up, 64); - lv_obj_set_width(ui_light2up, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_light2up, 30); - lv_obj_set_y(ui_light2up, 75); - lv_obj_set_align(ui_light2up, LV_ALIGN_CENTER); - - ui_light2down = lv_imagebutton_create(ui_Screen2); - lv_imagebutton_set_src(ui_light2down, LV_IMAGEBUTTON_STATE_RELEASED, NULL, &ui_img_down_png, NULL); - lv_imagebutton_set_src(ui_light2down, LV_IMAGEBUTTON_STATE_PRESSED, NULL, &ui_img_down_png, NULL); - lv_imagebutton_set_src(ui_light2down, LV_IMAGEBUTTON_STATE_DISABLED, NULL, &ui__temporary_image, NULL); - lv_imagebutton_set_src(ui_light2down, LV_IMAGEBUTTON_STATE_CHECKED_PRESSED, NULL, &ui__temporary_image, NULL); - lv_imagebutton_set_src(ui_light2down, LV_IMAGEBUTTON_STATE_CHECKED_RELEASED, NULL, &ui__temporary_image, NULL); - lv_imagebutton_set_src(ui_light2down, LV_IMAGEBUTTON_STATE_CHECKED_DISABLED, NULL, &ui__temporary_image, NULL); - lv_obj_set_height(ui_light2down, 64); - lv_obj_set_width(ui_light2down, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_light2down, 105); - lv_obj_set_y(ui_light2down, 75); - lv_obj_set_align(ui_light2down, LV_ALIGN_CENTER); - - lv_obj_add_event_cb(ui_Label1, ui_event_Label1, LV_EVENT_ALL, NULL); + lv_obj_add_event_cb(ui_simhome, ui_event_simhome, LV_EVENT_ALL, NULL); } diff --git a/libraries/ui/src/ui_Screen3.c b/libraries/ui/src/ui_Screen3.c index ef355ab..18c6d8d 100644 --- a/libraries/ui/src/ui_Screen3.c +++ b/libraries/ui/src/ui_Screen3.c @@ -115,20 +115,11 @@ void ui_Screen3_screen_init(void) ui_switchfanstatus = lv_switch_create(ui_Screen3); lv_obj_set_width(ui_switchfanstatus, 50); lv_obj_set_height(ui_switchfanstatus, 25); - lv_obj_set_x(ui_switchfanstatus, 100); + lv_obj_set_x(ui_switchfanstatus, 40); lv_obj_set_y(ui_switchfanstatus, 5); lv_obj_set_align(ui_switchfanstatus, LV_ALIGN_CENTER); - ui_lblfanstatus = lv_label_create(ui_Screen3); - lv_obj_set_width(ui_lblfanstatus, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_lblfanstatus, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_lblfanstatus, 30); - lv_obj_set_y(ui_lblfanstatus, 5); - lv_obj_set_align(ui_lblfanstatus, LV_ALIGN_CENTER); - lv_label_set_text(ui_lblfanstatus, "ON"); - lv_obj_set_style_text_font(ui_lblfanstatus, &lv_font_montserrat_22, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_add_event_cb(ui_btnfanhome, ui_event_btnfanhome, LV_EVENT_ALL, NULL); } diff --git a/libraries/ui/src/ui_Screen6.c b/libraries/ui/src/ui_Screen6.c index ac41a8e..8c91f6f 100644 --- a/libraries/ui/src/ui_Screen6.c +++ b/libraries/ui/src/ui_Screen6.c @@ -100,14 +100,14 @@ void ui_Screen6_screen_init(void) lv_label_set_text(ui_Label8, "Grow Mode"); ui_sunsetcheck = lv_checkbox_create(ui_Screen6); - lv_checkbox_set_text(ui_sunsetcheck, "Sonne simulieren"); + lv_checkbox_set_text(ui_sunsetcheck, "SIM"); lv_obj_set_width(ui_sunsetcheck, LV_SIZE_CONTENT); /// 1 lv_obj_set_height(ui_sunsetcheck, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_sunsetcheck, -35); - lv_obj_set_y(ui_sunsetcheck, 40); + lv_obj_set_x(ui_sunsetcheck, 103); + lv_obj_set_y(ui_sunsetcheck, 50); lv_obj_set_align(ui_sunsetcheck, LV_ALIGN_CENTER); lv_obj_add_flag(ui_sunsetcheck, LV_OBJ_FLAG_SCROLL_ON_FOCUS); /// Flags - lv_obj_set_style_text_font(ui_sunsetcheck, &lv_font_montserrat_22, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_text_font(ui_sunsetcheck, &lv_font_montserrat_14, LV_PART_MAIN | LV_STATE_DEFAULT); ui_setmode = lv_dropdown_create(ui_Screen6); lv_dropdown_set_options(ui_setmode, "Veggie\nFlower"); @@ -133,7 +133,7 @@ void ui_Screen6_screen_init(void) lv_obj_set_width(ui_lblsavemode, LV_SIZE_CONTENT); /// 1 lv_obj_set_height(ui_lblsavemode, LV_SIZE_CONTENT); /// 1 lv_obj_set_x(ui_lblsavemode, 61); - lv_obj_set_y(ui_lblsavemode, 90); + lv_obj_set_y(ui_lblsavemode, 91); lv_obj_set_align(ui_lblsavemode, LV_ALIGN_CENTER); lv_label_set_text(ui_lblsavemode, "Speichern"); lv_obj_add_flag(ui_lblsavemode, LV_OBJ_FLAG_IGNORE_LAYOUT); /// Flags @@ -151,6 +151,35 @@ void ui_Screen6_screen_init(void) lv_obj_set_y(ui_homebtngrow, -83); lv_obj_set_align(ui_homebtngrow, LV_ALIGN_CENTER); + ui_led1check = lv_checkbox_create(ui_Screen6); + lv_checkbox_set_text(ui_led1check, "LED1"); + lv_obj_set_width(ui_led1check, LV_SIZE_CONTENT); /// 1 + lv_obj_set_height(ui_led1check, LV_SIZE_CONTENT); /// 1 + lv_obj_set_x(ui_led1check, -120); + lv_obj_set_y(ui_led1check, 50); + lv_obj_set_align(ui_led1check, LV_ALIGN_CENTER); + lv_obj_add_flag(ui_led1check, LV_OBJ_FLAG_SCROLL_ON_FOCUS); /// Flags + lv_obj_set_style_text_font(ui_led1check, &lv_font_montserrat_14, LV_PART_MAIN | LV_STATE_DEFAULT); + + ui_led3check = lv_checkbox_create(ui_Screen6); + lv_checkbox_set_text(ui_led3check, "LED3"); + lv_obj_set_width(ui_led3check, LV_SIZE_CONTENT); /// 1 + lv_obj_set_height(ui_led3check, LV_SIZE_CONTENT); /// 1 + lv_obj_set_x(ui_led3check, 30); + lv_obj_set_y(ui_led3check, 50); + lv_obj_set_align(ui_led3check, LV_ALIGN_CENTER); + lv_obj_add_flag(ui_led3check, LV_OBJ_FLAG_SCROLL_ON_FOCUS); /// Flags + + ui_led2check = lv_checkbox_create(ui_Screen6); + lv_checkbox_set_text(ui_led2check, "LED2"); + lv_obj_set_width(ui_led2check, LV_SIZE_CONTENT); /// 1 + lv_obj_set_height(ui_led2check, LV_SIZE_CONTENT); /// 1 + lv_obj_set_x(ui_led2check, -45); + lv_obj_set_y(ui_led2check, 50); + lv_obj_set_align(ui_led2check, LV_ALIGN_CENTER); + lv_obj_add_flag(ui_led2check, LV_OBJ_FLAG_SCROLL_ON_FOCUS); /// Flags + lv_obj_set_style_text_font(ui_led2check, &lv_font_montserrat_14, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_add_event_cb(ui_homebtngrow, ui_event_homebtngrow, LV_EVENT_ALL, NULL); } diff --git a/libraries/ui/src/ui_Screen7.c b/libraries/ui/src/ui_Screen7.c new file mode 100644 index 0000000..fc2c971 --- /dev/null +++ b/libraries/ui/src/ui_Screen7.c @@ -0,0 +1,159 @@ +// This file was generated by SquareLine Studio +// SquareLine Studio version: SquareLine Studio 1.4.2 +// LVGL version: 9.1.0 +// Project name: SmartGrow + +#include "ui.h" + +void ui_Screen7_screen_init(void) +{ + ui_Screen7 = lv_obj_create(NULL); + lv_obj_remove_flag(ui_Screen7, LV_OBJ_FLAG_SCROLLABLE); /// Flags + + ui_Label10 = lv_label_create(ui_Screen7); + lv_obj_set_width(ui_Label10, LV_SIZE_CONTENT); /// 1 + lv_obj_set_height(ui_Label10, LV_SIZE_CONTENT); /// 1 + lv_obj_set_x(ui_Label10, -145); + lv_obj_set_y(ui_Label10, -80); + lv_obj_set_align(ui_Label10, LV_ALIGN_CENTER); + lv_label_set_text(ui_Label10, "1"); + lv_obj_set_style_text_font(ui_Label10, &lv_font_montserrat_22, LV_PART_MAIN | LV_STATE_DEFAULT); + + ui_light3switch = lv_switch_create(ui_Screen7); + lv_obj_set_width(ui_light3switch, 50); + lv_obj_set_height(ui_light3switch, 25); + lv_obj_set_x(ui_light3switch, -50); + lv_obj_set_y(ui_light3switch, 60); + lv_obj_set_align(ui_light3switch, LV_ALIGN_CENTER); + + + ui_light2switch = lv_switch_create(ui_Screen7); + lv_obj_set_width(ui_light2switch, 50); + lv_obj_set_height(ui_light2switch, 25); + lv_obj_set_x(ui_light2switch, -50); + lv_obj_set_y(ui_light2switch, -10); + lv_obj_set_align(ui_light2switch, LV_ALIGN_CENTER); + + + ui_light1switch = lv_switch_create(ui_Screen7); + lv_obj_set_width(ui_light1switch, 50); + lv_obj_set_height(ui_light1switch, 25); + lv_obj_set_x(ui_light1switch, -50); + lv_obj_set_y(ui_light1switch, -80); + lv_obj_set_align(ui_light1switch, LV_ALIGN_CENTER); + + + ui_light3percent = lv_label_create(ui_Screen7); + lv_obj_set_width(ui_light3percent, LV_SIZE_CONTENT); /// 1 + lv_obj_set_height(ui_light3percent, LV_SIZE_CONTENT); /// 1 + lv_obj_set_x(ui_light3percent, 10); + lv_obj_set_y(ui_light3percent, 60); + lv_obj_set_align(ui_light3percent, LV_ALIGN_CENTER); + lv_label_set_text(ui_light3percent, "0 %"); + lv_obj_set_style_text_font(ui_light3percent, &lv_font_montserrat_22, LV_PART_MAIN | LV_STATE_DEFAULT); + + ui_Label9 = lv_label_create(ui_Screen7); + lv_obj_set_width(ui_Label9, LV_SIZE_CONTENT); /// 1 + lv_obj_set_height(ui_Label9, LV_SIZE_CONTENT); /// 1 + lv_obj_set_x(ui_Label9, -145); + lv_obj_set_y(ui_Label9, -10); + lv_obj_set_align(ui_Label9, LV_ALIGN_CENTER); + lv_label_set_text(ui_Label9, "2"); + lv_obj_set_style_text_font(ui_Label9, &lv_font_montserrat_22, LV_PART_MAIN | LV_STATE_DEFAULT); + + ui_Label12 = lv_label_create(ui_Screen7); + lv_obj_set_width(ui_Label12, LV_SIZE_CONTENT); /// 1 + lv_obj_set_height(ui_Label12, LV_SIZE_CONTENT); /// 1 + lv_obj_set_x(ui_Label12, -145); + lv_obj_set_y(ui_Label12, 60); + lv_obj_set_align(ui_Label12, LV_ALIGN_CENTER); + lv_label_set_text(ui_Label12, "3"); + lv_obj_set_style_text_font(ui_Label12, &lv_font_montserrat_22, LV_PART_MAIN | LV_STATE_DEFAULT); + + ui_led3 = lv_image_create(ui_Screen7); + lv_image_set_src(ui_led3, &ui_img_light_png); + lv_obj_set_width(ui_led3, 56); + lv_obj_set_height(ui_led3, 56); + lv_obj_set_x(ui_led3, -110); + lv_obj_set_y(ui_led3, 60); + lv_obj_set_align(ui_led3, LV_ALIGN_CENTER); + lv_obj_add_flag(ui_led3, LV_OBJ_FLAG_CLICKABLE | LV_OBJ_FLAG_CHECKABLE); /// Flags + lv_obj_remove_flag(ui_led3, LV_OBJ_FLAG_SCROLLABLE); /// Flags + lv_obj_set_style_bg_color(ui_led3, lv_color_hex(0xEFF623), LV_PART_MAIN | LV_STATE_CHECKED); + lv_obj_set_style_bg_opa(ui_led3, 255, LV_PART_MAIN | LV_STATE_CHECKED); + + ui_led1 = lv_image_create(ui_Screen7); + lv_image_set_src(ui_led1, &ui_img_light_png); + lv_obj_set_width(ui_led1, 56); + lv_obj_set_height(ui_led1, 56); + lv_obj_set_x(ui_led1, -110); + lv_obj_set_y(ui_led1, -80); + lv_obj_set_align(ui_led1, LV_ALIGN_CENTER); + lv_obj_add_flag(ui_led1, LV_OBJ_FLAG_CLICKABLE | LV_OBJ_FLAG_CHECKABLE); /// Flags + lv_obj_remove_flag(ui_led1, LV_OBJ_FLAG_SCROLLABLE); /// Flags + lv_obj_set_style_bg_color(ui_led1, lv_color_hex(0xEFF623), LV_PART_MAIN | LV_STATE_CHECKED); + lv_obj_set_style_bg_opa(ui_led1, 255, LV_PART_MAIN | LV_STATE_CHECKED); + + ui_led2 = lv_image_create(ui_Screen7); + lv_image_set_src(ui_led2, &ui_img_light_png); + lv_obj_set_width(ui_led2, 56); + lv_obj_set_height(ui_led2, 56); + lv_obj_set_x(ui_led2, -110); + lv_obj_set_y(ui_led2, -10); + lv_obj_set_align(ui_led2, LV_ALIGN_CENTER); + lv_obj_add_flag(ui_led2, LV_OBJ_FLAG_CLICKABLE | LV_OBJ_FLAG_CHECKABLE); /// Flags + lv_obj_remove_flag(ui_led2, LV_OBJ_FLAG_SCROLLABLE); /// Flags + lv_obj_set_style_bg_color(ui_led2, lv_color_hex(0xEFF623), LV_PART_MAIN | LV_STATE_CHECKED); + lv_obj_set_style_bg_opa(ui_led2, 255, LV_PART_MAIN | LV_STATE_CHECKED); + + ui_light1percent = lv_label_create(ui_Screen7); + lv_obj_set_width(ui_light1percent, LV_SIZE_CONTENT); /// 1 + lv_obj_set_height(ui_light1percent, LV_SIZE_CONTENT); /// 1 + lv_obj_set_x(ui_light1percent, 10); + lv_obj_set_y(ui_light1percent, -80); + lv_obj_set_align(ui_light1percent, LV_ALIGN_CENTER); + lv_label_set_text(ui_light1percent, "0 %"); + lv_obj_set_style_text_font(ui_light1percent, &lv_font_montserrat_22, LV_PART_MAIN | LV_STATE_DEFAULT); + + ui_light2percent = lv_label_create(ui_Screen7); + lv_obj_set_width(ui_light2percent, LV_SIZE_CONTENT); /// 1 + lv_obj_set_height(ui_light2percent, LV_SIZE_CONTENT); /// 1 + lv_obj_set_x(ui_light2percent, 10); + lv_obj_set_y(ui_light2percent, -10); + lv_obj_set_align(ui_light2percent, LV_ALIGN_CENTER); + lv_label_set_text(ui_light2percent, "0 %"); + lv_obj_set_style_text_font(ui_light2percent, &lv_font_montserrat_22, LV_PART_MAIN | LV_STATE_DEFAULT); + + ui_lightup = lv_image_create(ui_Screen7); + lv_image_set_src(ui_lightup, &ui_img_up_png); + lv_obj_set_width(ui_lightup, 56); + lv_obj_set_height(ui_lightup, 56); + lv_obj_set_x(ui_lightup, 125); + lv_obj_set_y(ui_lightup, 75); + lv_obj_set_align(ui_lightup, LV_ALIGN_CENTER); + lv_obj_add_flag(ui_lightup, LV_OBJ_FLAG_CLICKABLE); /// Flags + lv_obj_remove_flag(ui_lightup, LV_OBJ_FLAG_SCROLLABLE); /// Flags + + ui_lightdown = lv_image_create(ui_Screen7); + lv_image_set_src(ui_lightdown, &ui_img_down_png); + lv_obj_set_width(ui_lightdown, 56); + lv_obj_set_height(ui_lightdown, 56); + lv_obj_set_x(ui_lightdown, 60); + lv_obj_set_y(ui_lightdown, 75); + lv_obj_set_align(ui_lightdown, LV_ALIGN_CENTER); + lv_obj_add_flag(ui_lightdown, LV_OBJ_FLAG_CLICKABLE); /// Flags + lv_obj_remove_flag(ui_lightdown, LV_OBJ_FLAG_SCROLLABLE); /// Flags + + ui_ledhome = lv_image_create(ui_Screen7); + lv_image_set_src(ui_ledhome, &ui_img_home_png); + lv_obj_set_width(ui_ledhome, LV_SIZE_CONTENT); /// 64 + lv_obj_set_height(ui_ledhome, LV_SIZE_CONTENT); /// 64 + lv_obj_set_x(ui_ledhome, 125); + lv_obj_set_y(ui_ledhome, -80); + lv_obj_set_align(ui_ledhome, LV_ALIGN_CENTER); + lv_obj_add_flag(ui_ledhome, LV_OBJ_FLAG_CLICKABLE); /// Flags + lv_obj_remove_flag(ui_ledhome, LV_OBJ_FLAG_SCROLLABLE); /// Flags + + lv_obj_add_event_cb(ui_ledhome, ui_event_ledhome, LV_EVENT_ALL, NULL); + +} diff --git a/ui/ui.ino b/ui/ui.ino index 35510e1..1902a42 100644 --- a/ui/ui.ino +++ b/ui/ui.ino @@ -23,8 +23,10 @@ Preferences preferences; Adafruit_BME280 bme; // I2C const char* ntp = "fritz.box"; +//const char* ntp = "pool.ntp.org"; + const int gmt_offset_sec = 3600; -const int daylight_offset_sec = 7200; +const int daylight_offset_sec = 0; //Variablen für PWM int pwm_freq = 5000; @@ -44,8 +46,8 @@ int led2_pwm_channel = 2; int led2_pwm_pin = 27; //Variabke PWM LED2 -int led3_pwm_channel = 2; -int led3_pwm_pin = 13; +int led3_pwm_channel = 3; +int led3_pwm_pin = 33; char led1cycle[5] = "led1"; char led2cycle[5] = "led2"; @@ -58,6 +60,25 @@ bool led1active = false; bool led2active = false; bool led3active = false; +struct tm timeinfo; +struct tm targettime = {0}; +time_t realtime; +time_t target_sec; +time_t endtime; +time_t diff_time; +int updateVeggieMode = 5000; + +bool sunrise = false; +bool sunset = false; +bool start_sim = false; +int sim_duty_cycle; +int led1_pref; +int led2_pref; +int led3_pref; +int updateSimMode = 24 * 60 * 60 * 1000; +int updateSimLbl = 24 * 60 * 60 * 1000 - 2000; + + /* Ändern Sie dies auf die Auflösung Ihres Bildschirms */ static const uint16_t screenWidth = 320; static const uint16_t screenHeight = 240; @@ -134,17 +155,17 @@ void switchEventHandler(lv_event_t * e) if (lv_obj_has_state(obj, LV_STATE_CHECKED)) { preferences.begin("g_phase", true); - led1_duty_cycle = preferences.getInt(user_data, 860); + led1_duty_cycle = preferences.getInt(user_data, 920); preferences.end(); led1active = true; - turnOn(led1_pwm_pin, led1_duty_cycle, ui_light1statuslbl, ui_lbllightstatus, ui_light1percent); + turnOn(led1_pwm_pin, led1_duty_cycle, ui_lbllightstatus, ui_light1percent); } else { led1active = false; - turnOff(led1_pwm_pin, light_off_duty_cycle, ui_light1statuslbl, ui_lbllightstatus, ui_light1percent); + turnOff(led1_pwm_pin, light_off_duty_cycle, ui_lbllightstatus, ui_light1percent); } } if(obj == ui_light2switch) @@ -152,31 +173,31 @@ void switchEventHandler(lv_event_t * e) if (lv_obj_has_state(obj, LV_STATE_CHECKED)) { preferences.begin("g_phase", true); - led2_duty_cycle = preferences.getInt(user_data, 860); + led2_duty_cycle = preferences.getInt(user_data, 920); preferences.end(); led2active = true; - turnOn(led2_pwm_pin, led2_duty_cycle, ui_light2statuslbl, ui_lbllightstatus, ui_light2percent); + turnOn(led2_pwm_pin, led2_duty_cycle, ui_lbllightstatus, ui_light2percent); } else { led2active = false; - turnOff(led2_pwm_pin, light_off_duty_cycle, ui_light2statuslbl, ui_lbllightstatus, ui_light2percent); + turnOff(led2_pwm_pin, light_off_duty_cycle, ui_lbllightstatus, ui_light2percent); } } - if(obj == ui_light2switch) + if(obj == ui_light3switch) { if (lv_obj_has_state(obj, LV_STATE_CHECKED)) { preferences.begin("g_phase", true); - led3_duty_cycle = preferences.getInt(user_data, 860); + led3_duty_cycle = preferences.getInt(user_data, 920); preferences.end(); led3active = true; - turnOn(led3_pwm_pin, led2_duty_cycle, ui_light2statuslbl, ui_lbllightstatus, ui_light2percent); + turnOn(led3_pwm_pin, led3_duty_cycle, ui_lbllightstatus, ui_light3percent); } else { - led2active = false; - turnOff(led2_pwm_pin, light_off_duty_cycle, ui_light2statuslbl, ui_lbllightstatus, ui_light2percent); + led3active = false; + turnOff(led3_pwm_pin, light_off_duty_cycle, ui_lbllightstatus, ui_light3percent); } } if(obj == ui_switchfanstatus) @@ -188,24 +209,24 @@ void switchEventHandler(lv_event_t * e) preferences.end(); fan_active = true; - turnOn(fan_pwm_pin, fan_duty_cycle, ui_lblfanstatus, ui_lblfanspeed, ui_lblfanfanspeed); + turnOn(fan_pwm_pin, fan_duty_cycle, ui_lblfanspeed, ui_lblfanfanspeed); } else { int off_duty_cycle = 0; fan_active = false; - turnOff(fan_pwm_pin, off_duty_cycle, ui_lblfanstatus, ui_lblfanspeed, ui_lblfanfanspeed); + turnOff(fan_pwm_pin, off_duty_cycle, ui_lblfanspeed, ui_lblfanfanspeed); } } } -void turnOn(int pin, int duty_cycle, lv_obj_t * statuslbl, lv_obj_t * statusmainlbl, lv_obj_t * percent) +void turnOn(int pin, int duty_cycle, lv_obj_t * statusmainlbl, lv_obj_t * percent) { ledcWrite(pin, duty_cycle); int percentage; if (statusmainlbl == ui_lblfanspeed) { - percentage = round((duty_cycle * 100.0) / 1024.0); + percentage = round((duty_cycle * 100.0) / 1023.0); lv_label_set_text_fmt(statusmainlbl, "%d%%", percentage); lv_label_set_text_fmt(percent, "%d%%", percentage); } @@ -219,20 +240,19 @@ void turnOn(int pin, int duty_cycle, lv_obj_t * statuslbl, lv_obj_t * statusmain preferences.putBool("light", true); preferences.end(); } - - - lv_label_set_text(statuslbl, "ON"); } -void turnOff(int pin, int duty_cycle, lv_obj_t * statuslbl, lv_obj_t * statusmainlbl, lv_obj_t * percent) +void turnOff(int pin, int duty_cycle, lv_obj_t * statusmainlbl, lv_obj_t * percent) { ledcWrite(pin, duty_cycle); - if (statusmainlbl == ui_lblfanspeed) lv_label_set_text(statusmainlbl, "0%"); - lv_label_set_text(statuslbl, "OFF"); - lv_label_set_text_fmt(percent, "0%%"); + if (statusmainlbl == ui_lblfanspeed) + { + lv_label_set_text(statusmainlbl, "0%"); + lv_label_set_text_fmt(percent, "0%%"); + } - if (led1active == false && led2active == false) + if (led1active == false && led2active == false && led3active == false) { preferences.begin("g_phase", false); preferences.putBool("light", false); @@ -242,67 +262,94 @@ void turnOff(int pin, int duty_cycle, lv_obj_t * statuslbl, lv_obj_t * statusmai + + } - -void dimm(int pin, int duty_cycle, lv_obj_t * percent, lv_obj_t * percent2 = NULL) +void changeLightLbl(int duty_cycle, lv_obj_t * percent, lv_obj_t * percent2 = NULL) { - int percentage = 0; - ledcWrite(pin, duty_cycle); + int percentage; if (percent == ui_lblfanspeed) { percentage = round((duty_cycle * 100.0) / 1024.0); - lv_label_set_text_fmt(percent2, "%d%%", percentage); + } else { percentage = round(100.0 - (duty_cycle * 100.0) / 1024.0); } lv_label_set_text_fmt(percent, "%d%%", percentage); +} + +void dimm(int pin, int duty_cycle, lv_obj_t * percent, lv_obj_t * percent2 = NULL) +{ + + Serial.println("DIMM wird ausgeführt"); + ledcWrite(pin, duty_cycle); + + + + + changeLightLbl(duty_cycle, percent, percent2); + } + + static void dimmUpBtnEventHandler(lv_event_t * e) { int fan_duty_cycle = 10; int led1_duty_cycle = -10; int led2_duty_cycle = -10; + int led3_duty_cycle = -10; lv_obj_t *obj = (lv_obj_t *)lv_event_get_target(e); char* user_data = (char*)lv_event_get_user_data(e); - - if (obj == ui_light1up) + if (lv_obj_has_state(ui_led1, LV_STATE_CHECKED)) { if (led1active) { preferences.begin("g_phase", false); - led1_duty_cycle += preferences.getInt(user_data, 860); + led1_duty_cycle += preferences.getInt(led1cycle, 920); if (led1_duty_cycle <= 0) led1_duty_cycle = 0; - preferences.putInt(user_data, led1_duty_cycle); + preferences.putInt(led1cycle, led1_duty_cycle); preferences.end(); dimm(led1_pwm_pin, led1_duty_cycle, ui_light1percent); - } } - if (obj == ui_light2up) + + if (lv_obj_has_state(ui_led2, LV_STATE_CHECKED)) { if (led2active) { preferences.begin("g_phase", false); - led2_duty_cycle += preferences.getInt(user_data, 860); + led2_duty_cycle += preferences.getInt(led2cycle, 920); if (led2_duty_cycle <= 0) led2_duty_cycle = 0; - preferences.putInt(user_data, led2_duty_cycle); + preferences.putInt(led2cycle, led2_duty_cycle); preferences.end(); dimm(led2_pwm_pin, led2_duty_cycle, ui_light2percent); } } + if (lv_obj_has_state(ui_led3, LV_STATE_CHECKED)) + { + if (led3active) + { + preferences.begin("g_phase", false); + led3_duty_cycle += preferences.getInt(led3cycle, 920); + if (led3_duty_cycle <= 0) led3_duty_cycle = 0; + preferences.putInt(led3cycle, led3_duty_cycle); + preferences.end(); + dimm(led3_pwm_pin, led3_duty_cycle, ui_light3percent); + } + } if (obj == ui_btnfanup) { if (fan_active) { preferences.begin("g_phase", false); fan_duty_cycle += preferences.getInt(user_data, 0); - if (fan_duty_cycle >= 1024) fan_duty_cycle = 1024; + if (fan_duty_cycle >= 1023) fan_duty_cycle = 1023; preferences.putInt(user_data, fan_duty_cycle); preferences.end(); dimm(fan_pwm_pin, fan_duty_cycle, ui_lblfanspeed, ui_lblfanfanspeed); @@ -318,31 +365,44 @@ static void dimmDownBtnEventHandler(lv_event_t * e) int fan_duty_cycle = -10; int led1_duty_cycle = 10; int led2_duty_cycle = 10; + int led3_duty_cycle = 10; - if (obj == ui_light1down) + if (lv_obj_has_state(ui_led1, LV_STATE_CHECKED)) { if (led1active) { preferences.begin("g_phase", false); - led1_duty_cycle += preferences.getInt(user_data); - if (led1_duty_cycle >= 860) led1_duty_cycle = 860; - preferences.putInt(user_data, led1_duty_cycle); + led1_duty_cycle += preferences.getInt(led1cycle); + if (led1_duty_cycle >= 920) led1_duty_cycle = 920; + preferences.putInt(led1cycle, led1_duty_cycle); preferences.end(); dimm(led1_pwm_pin, led1_duty_cycle, ui_light1percent); } } - if (obj == ui_light2down) + if (lv_obj_has_state(ui_led2, LV_STATE_CHECKED)) { if (led2active) { preferences.begin("g_phase", false); - led2_duty_cycle += preferences.getInt(user_data); - if (led2_duty_cycle >= 920) led2_duty_cycle = 860; - preferences.putInt(user_data, led2_duty_cycle); + led2_duty_cycle += preferences.getInt(led2cycle); + if (led2_duty_cycle >= 920) led2_duty_cycle = 920; + preferences.putInt(led2cycle, led2_duty_cycle); preferences.end(); dimm(led2_pwm_pin, led2_duty_cycle, ui_light2percent); } } + if (lv_obj_has_state(ui_led3, LV_STATE_CHECKED)) + { + if (led3active) + { + preferences.begin("g_phase", false); + led3_duty_cycle += preferences.getInt(led3cycle); + if (led3_duty_cycle >= 920) led3_duty_cycle = 920; + preferences.putInt(led3cycle, led3_duty_cycle); + preferences.end(); + dimm(led3_pwm_pin, led3_duty_cycle, ui_light3percent); + } + } if (obj == ui_btnfandown) { if (fan_active) @@ -420,35 +480,16 @@ void initPreferences() preferences.begin("g_phase", false); preferences.putBool("light", false); - preferences.putInt(led1cycle, 860); - preferences.putInt(led2cycle, 860); - preferences.putInt(fancycle, 510); + preferences.putInt(led1cycle, 920); + preferences.putInt(led2cycle, 920); + preferences.putInt(led3cycle, 920); + preferences.putInt(fancycle, 150); preferences.putBool("veggie", false); preferences.putBool("flowering", false); preferences.putBool("sun", false); preferences.end(); } - - - -struct tm timeinfo; -struct tm targettime = {0}; -time_t realtime; -time_t target_sec; -time_t endtime; -time_t diff_time; -int updateVeggieMode = 5000; -bool sunrise = false; -bool sunset = false; -int sim_duty_cycle; -int led1_pref; -int led2_pref; -int updateSimMode = 24 * 60 * 60 * 1000; -int updateSimLbl = 24 * 60 * 60 * 1000; - - - void setup () { Serial.begin( 115200 ); /* Vorbereitung für mögliches serielles Debugging */ @@ -478,6 +519,7 @@ void setup () ledcAttachChannel(fan_pwm_pin, pwm_freq, pwm_resolution, fan_pwm_channel); ledcAttachChannel(led1_pwm_pin, pwm_freq, pwm_resolution, led1_pwm_channel); ledcAttachChannel(led2_pwm_pin, pwm_freq, pwm_resolution, led2_pwm_channel); + ledcAttachChannel(led3_pwm_pin, pwm_freq, pwm_resolution, led3_pwm_channel); @@ -501,25 +543,25 @@ void setup () lv_obj_add_event_cb(ui_btnfandown, dimmDownBtnEventHandler, LV_EVENT_CLICKED, fancycle); lv_obj_add_event_cb(ui_light1switch, switchEventHandler, LV_EVENT_VALUE_CHANGED, led1cycle); lv_obj_add_event_cb(ui_light2switch, switchEventHandler, LV_EVENT_VALUE_CHANGED, led2cycle); - lv_obj_add_event_cb(ui_light1up, dimmUpBtnEventHandler, LV_EVENT_CLICKED, led1cycle); - lv_obj_add_event_cb(ui_light2up, dimmUpBtnEventHandler, LV_EVENT_CLICKED, led2cycle); - lv_obj_add_event_cb(ui_light1down, dimmDownBtnEventHandler, LV_EVENT_CLICKED, led1cycle); - lv_obj_add_event_cb(ui_light2down, dimmDownBtnEventHandler, LV_EVENT_CLICKED, led2cycle); + lv_obj_add_event_cb(ui_light3switch, switchEventHandler, LV_EVENT_VALUE_CHANGED, led3cycle); lv_obj_add_event_cb(ui_wifibtn, scanWifi, LV_EVENT_CLICKED, NULL); lv_obj_add_event_cb(ui_wifikeyboard, setWifi, LV_EVENT_READY, NULL); lv_obj_add_event_cb(ui_savemode, saveModeSettings, LV_EVENT_CLICKED, NULL); lv_obj_add_event_cb(ui_growmodebtn, setGrowModeLbl, LV_EVENT_CLICKED, NULL); + // lv_obj_add_event_cb(ui_setmode, setGrowModeLbl, LV_EVENT_VALUE_CHANGED, NULL); + lv_obj_add_event_cb(ui_lightup, dimmUpBtnEventHandler, LV_EVENT_CLICKED, NULL); + lv_obj_add_event_cb(ui_lightdown, dimmDownBtnEventHandler, LV_EVENT_CLICKED, NULL); // Setze initial den Lüfter auf "Off" und den Schalter auf unchecked - lv_label_set_text(ui_lblfanstatus, "OFF"); + lv_label_set_text(ui_lblfanfanspeed, "0%"); lv_label_set_text(ui_lblfanspeed, "0%"); lv_label_set_text(ui_lbllightstatus, "OFF"); - lv_label_set_text(ui_light1statuslbl, "OFF"); - lv_label_set_text(ui_light2statuslbl, "OFF"); + lv_spinner_set_anim_params(ui_sunsimspin, 3600000, 360); + //Speichern der var von DutyCycle led1, led2, fan lv_dropdown_clear_options(ui_wifinetlist); @@ -594,18 +636,31 @@ void setup () configTime(gmt_offset_sec, daylight_offset_sec, ntp); printTime(); targettime = timeinfo; + Serial.println(&timeinfo, "#############SETUP############"); + Serial.println(&timeinfo, "Realtime: %A, %B %d %Y %H:%M:%S"); + Serial.println(&targettime, "Realtime: %A, %B %d %Y %H:%M:%S"); + Serial.println(&timeinfo, "#############SETUP############"); lv_obj_add_event_cb(ui_growmode, setMode, LV_EVENT_VALUE_CHANGED, NULL); - xTaskCreatePinnedToCore( - loopC2, /* Task function. */ - "Task1", /* name of task. */ - 1000, /* Stack size of task */ - NULL, /* parameter of the task */ - 1, /* priority of the task */ - &Task1, /* Task handle to keep track of created task */ - 0); + // xTaskCreatePinnedToCore( + // loopC2, /* Task function. */ + // "Task1", /* name of task. */ + // 1000, /* Stack size of task */ + // NULL, /* parameter of the task */ + // 1, /* priority of the task */ + // &Task1, /* Task handle to keep track of created task */ + // 0); + + // xTaskCreatePinnedToCore( + // loopC1, /* Task function. */ + // "Task1", /* name of task. */ + // 1000, /* Stack size of task */ + // NULL, /* parameter of the task */ + // 1, /* priority of the task */ + // &Task1, /* Task handle to keep track of created task */ + // 0); WiFi.disconnect(); @@ -613,41 +668,56 @@ void setup () // default settings // (you can also pass in a Wire library object like &Wire2) - status = bme.begin(0x76); - if (!status) - { - lv_label_set_text(ui_lblhum, "NA"); - lv_label_set_text(ui_fanhum, "NA"); - lv_label_set_text(ui_lbltemp, "NA"); - lv_label_set_text(ui_fantemp, "NA"); - } + // status = bme.begin(0x76); + // if (!status) + // { + // lv_label_set_text(ui_lblhum, "NA"); + // lv_label_set_text(ui_fanhum, "NA"); + // lv_label_set_text(ui_lbltemp, "NA"); + // lv_label_set_text(ui_fantemp, "NA"); + // } } -void loopC2(void* pvParameters) -{ - static unsigned int lastUpdate = 0; - for (;;) - { +// void loopC2(void* pvParameters) +// { +// static unsigned int lastUpdate = 0; +// for (;;) +// { - unsigned long currentMillis = millis(); +// unsigned long currentMillis = millis(); - if (currentMillis - lastUpdate >= updateSimMode) - { - vTaskDelay(1000); - Serial.println("sunSim running "); - sunSim(); +// if (currentMillis - lastUpdate >= updateSimMode) +// { +// vTaskDelay(1000); +// sunSim(); - lastUpdate = currentMillis; - } +// lastUpdate = currentMillis; +// } - vTaskDelay(1); - } -} +// vTaskDelay(1); +// } +// } + +// void loopC1(void* pvParameters) +// { +// static unsigned int lastUpdate = 0; +// for (;;) +// { + +// + +// vTaskDelay(1); +// } +// } void loop () { + lv_timer_handler(); /* Lässt die GUI ihre Arbeit verrichten */ + + static unsigned int lastUpdate = 0; static unsigned int lastUpdate2 = 0; + static unsigned int lastUpdate3 = 0; const unsigned int updateInterval = 1000; //60 sekunden unsigned long currentMillis = millis(); @@ -655,7 +725,7 @@ void loop () if (currentMillis - lastUpdate >= updateInterval) { printTime(); - printValues(); + // printValues(); lastUpdate = currentMillis; } @@ -666,6 +736,25 @@ void loop () growMode(); lastUpdate2 = currentMillis; } + if (currentMillis - lastUpdate3 >= updateSimMode) + { + vTaskDelay(1000); + sunSim(); + + lastUpdate3 = currentMillis; + } + + + // if (currentMillis - lastUpdate3 >= updateSimLbl) + // { + // Serial.print("Refresh Label"); + // if (sunrise || sunset) + // { + // changeLightLbl() + // } + + // lastUpdate2 = currentMillis; + // } } @@ -695,12 +784,26 @@ void saveModeSettings(lv_event_t * e) { preferences.putInt("veggie_start_h", start_hour); preferences.putInt("veggie_start_m", start_min); + preferences.putInt("veggie_end_m", end_min); + if (lv_obj_has_state(ui_sunsetcheck, LV_STATE_CHECKED)) { - Serial.println("CHECKBOX SUN ACTIVATED"); - preferences.putBool("ve_sun", true); - preferences.putInt("veggie_end_h", (end_hour - 1)); + Serial.print("ENDHOUR: "); + Serial.println(end_hour); + if (end_hour <= 0) + { + Serial.println("ENDHOUR < 0"); + preferences.putBool("ve_sun", true); + preferences.putInt("veggie_end_h", (23)); + } + else + { + Serial.println("ENDHOUR > 0"); + preferences.putBool("ve_sun", true); + preferences.putInt("veggie_end_h", (end_hour - 1)); + } + } else @@ -708,7 +811,10 @@ void saveModeSettings(lv_event_t * e) preferences.putBool("ve_sun", false); preferences.putInt("veggie_end_h", end_hour); } + } + + else if (!strncmp(mode, "Flower", 6)) { preferences.putInt("flower_start_h", start_hour); @@ -718,9 +824,18 @@ void saveModeSettings(lv_event_t * e) if (lv_obj_has_state(ui_sunsetcheck, LV_STATE_CHECKED)) { - Serial.println("CHECKBOX SUN ACTIVATED"); - preferences.putBool("fl_sun", true); - preferences.putInt("flower_end_h", (end_hour - 1)); + if (end_hour < 0) + { + Serial.println("ENDHOUR < 0"); + preferences.putBool("fl_sun", true); + preferences.putInt("flower_end_h", (23)); + } + else + { + Serial.println("ENDHOUR > 0"); + preferences.putBool("fl_sun", true); + preferences.putInt("flower_end_h", (end_hour - 1)); + } } else { @@ -729,6 +844,110 @@ void saveModeSettings(lv_event_t * e) } } preferences.end(); + setLed(); +} + +void setLed() +{ + char led1[7]; + char led2[7]; + char led3[7]; + char mode[32]; + lv_dropdown_get_selected_str(ui_setmode, mode, sizeof(mode)); + if (!strncmp(mode, "Veggie", 6)) + { + strcpy(led1, "v_led1"); + strcpy(led2, "v_led2"); + strcpy(led3, "v_led3"); + } + else + { + strcpy(led1, "f_led1"); + strcpy(led2, "f_led2"); + strcpy(led3, "f_led3"); + } + + preferences.begin("g_phase", false); + if (lv_obj_has_state(ui_led1check, LV_STATE_CHECKED)) + { + preferences.putBool(led1, true); + } + else + { + preferences.putBool(led1, false); + } + if (lv_obj_has_state(ui_led2check, LV_STATE_CHECKED)) + { + Serial.println("STATE LED2CHECK TRUE"); + preferences.putBool(led2, true); + bool test = preferences.getBool(led2); + Serial.println(test); + } + else + { + preferences.putBool(led2, false); + } + if (lv_obj_has_state(ui_led3check, LV_STATE_CHECKED)) + { + preferences.putBool(led3, true); + } + else + { + preferences.putBool(led3, false); + } + preferences.end(); +} + +void getLed() +{ + char led1[7]; + char led2[7]; + char led3[7]; + char mode[32]; + lv_dropdown_get_selected_str(ui_setmode, mode, sizeof(mode)); + + if (!strncmp(mode, "Veggie", 6)) + { + strcpy(led1, "v_led1"); + strcpy(led2, "v_led2"); + strcpy(led3, "v_led3"); + } + else + { + strcpy(led1, "f_led1"); + strcpy(led2, "f_led2"); + strcpy(led3, "f_led3"); + } + + preferences.begin("g_phase", false); + + if (preferences.getBool(led1, false)) + { + lv_obj_add_state(ui_led1check, LV_STATE_CHECKED); + } + else + { + lv_obj_remove_state(ui_led1check, LV_STATE_CHECKED); + } + + if (preferences.getBool(led2, false)) + { + lv_obj_add_state(ui_led2check, LV_STATE_CHECKED); + } + else + { + lv_obj_remove_state(ui_led2check, LV_STATE_CHECKED); + } + + if (preferences.getBool(led3, false)) + { + lv_obj_add_state(ui_led3check, LV_STATE_CHECKED); + } + else + { + lv_obj_remove_state(ui_led3check, LV_STATE_CHECKED); + } + preferences.end(); } void setMode(lv_event_t * e) @@ -740,6 +959,9 @@ void setMode(lv_event_t * e) { preferences.putBool("veggie", false); preferences.putBool("flowering", false); + updateSimMode = 24 * 60 * 60 * 1000; + sunset = false; + sunrise = false; } else if (!strncmp(mode, "Veggie", 6)) { @@ -760,68 +982,256 @@ void setMode(lv_event_t * e) void modeOn() { + char mode[8]; + lv_dropdown_get_selected_str(ui_growmode, mode, sizeof(mode)); + char led1[7]; + char led2[7]; + char led3[7]; + if (!strncmp(mode, "Veggie", 6)) + { + strcpy(led1, "v_led1"); + strcpy(led2, "v_led2"); + strcpy(led3, "v_led3"); + } + else + { + strcpy(led1, "f_led1"); + strcpy(led2, "f_led2"); + strcpy(led3, "f_led3"); + } + preferences.begin("g_phase", false); + bool stored_led1 = preferences.getBool(led1); + bool stored_led2 = preferences.getBool(led2); + bool stored_led3 = preferences.getBool(led3); + if (stored_led1) + { lv_obj_add_state(ui_light1switch, LV_STATE_CHECKED); - lv_obj_add_state(ui_light2switch, LV_STATE_CHECKED); lv_obj_send_event(ui_light1switch, LV_EVENT_VALUE_CHANGED, led1cycle); + } + + if (stored_led2) + { + lv_obj_add_state(ui_light2switch, LV_STATE_CHECKED); lv_obj_send_event(ui_light2switch, LV_EVENT_VALUE_CHANGED, led2cycle); + } + + if (stored_led3) + { + lv_obj_add_state(ui_light3switch, LV_STATE_CHECKED); + lv_obj_send_event(ui_light3switch, LV_EVENT_VALUE_CHANGED, led3cycle); + } + preferences.end(); } void modeOff() { + char mode[8]; + lv_dropdown_get_selected_str(ui_growmode, mode, sizeof(mode)); + char led1[7]; + char led2[7]; + char led3[7]; + + if (!strncmp(mode, "Veggie", 6)) + { + strcpy(led1, "v_led1"); + strcpy(led2, "v_led2"); + strcpy(led3, "v_led3"); + } + else + { + strcpy(led1, "f_led1"); + strcpy(led2, "f_led2"); + strcpy(led3, "f_led3"); + } + preferences.begin("g_phase", false); + bool stored_led1 = preferences.getBool(led1); + bool stored_led2 = preferences.getBool(led2); + bool stored_led3 = preferences.getBool(led3); + if (stored_led1) + { lv_obj_remove_state(ui_light1switch, LV_STATE_CHECKED); - lv_obj_remove_state(ui_light2switch, LV_STATE_CHECKED); lv_obj_send_event(ui_light1switch, LV_EVENT_VALUE_CHANGED, led1cycle); + } + if (stored_led2) + { + lv_obj_remove_state(ui_light2switch, LV_STATE_CHECKED); lv_obj_send_event(ui_light2switch, LV_EVENT_VALUE_CHANGED, led2cycle); + } + if (stored_led3) + { + lv_obj_remove_state(ui_light3switch, LV_STATE_CHECKED); + lv_obj_send_event(ui_light3switch, LV_EVENT_VALUE_CHANGED, led3cycle); + } + preferences.end(); } +bool stored_led1; +bool stored_led2; +bool stored_led3; + void sunSim() { - Serial.println("SUNSIM WORKING"); + Serial.println("SUNSIM WORKING"); + Serial.print("SUNSET: "); + Serial.println(sunset); + Serial.println("SUNRISE: "); + Serial.println(sunrise); + char mode[8]; + lv_dropdown_get_selected_str(ui_growmode, mode, sizeof(mode)); + char led1[7]; + char led2[7]; + char led3[7]; + int led_pref; + + if(start_sim) + { + Serial.println("start_sim active"); + if (!strncmp(mode, "Veggie", 6)) + { + strcpy(led1, "v_led1"); + strcpy(led2, "v_led2"); + strcpy(led3, "v_led3"); + } + else + { + strcpy(led1, "f_led1"); + strcpy(led2, "f_led2"); + strcpy(led3, "f_led3"); + } + preferences.begin("g_phase", false); + stored_led1 = preferences.getBool(led1); + stored_led2 = preferences.getBool(led2); + stored_led3 = preferences.getBool(led3); + led1_pref = preferences.getInt(led1cycle, 920); + led1_pref = preferences.getInt(led2cycle, 920); + led3_pref = preferences.getInt(led3cycle, 920); + preferences.end(); + if (led1_pref <= led2_pref && led1_pref <= led3_pref) + { + led_pref = led1_pref; + } + else if (led2_pref <= led1_pref && led2_pref <= led3_pref) + { + led_pref = led2_pref; + } + else if (led3_pref <= led1_pref && led3_pref <= led2_pref) + { + led_pref = led3_pref; + } + + if (stored_led1) + { + lv_obj_add_state(ui_light1switch, LV_STATE_CHECKED); + led1active = true; + turnOn(led1_pwm_pin, 920, ui_lbllightstatus, ui_light1percent); + } + if (stored_led2) + { + lv_obj_add_state(ui_light2switch, LV_STATE_CHECKED); + led2active = false; + + turnOn(led2_pwm_pin, 920, ui_lbllightstatus, ui_light2percent); + } + if (stored_led3) + { + led3active = true; + lv_obj_add_state(ui_light3switch, LV_STATE_CHECKED); + turnOn(led3_pwm_pin, 920, ui_lbllightstatus, ui_light3percent); + } + + + sim_duty_cycle = 920; + Serial.println(led_pref); + Serial.println(sim_duty_cycle); + + } if (sunrise) { - if (sim_duty_cycle == led1_pref) + + if (sim_duty_cycle <= led1_pref && sim_duty_cycle <= led2_pref && sim_duty_cycle <= led3_pref) { updateSimMode = 24 * 60 * 60 * 1000; sunrise = false; + Serial.println("SUNSIM SUNRISE ENDED"); + Serial.println(&timeinfo, "Realtime: %A, %B %d %Y %H:%M:%S"); } - sim_duty_cycle -= 1; + Serial.println("SUNSIM SUNRISE WORKING"); Serial.println(sim_duty_cycle); - dimm(led1_pwm_pin, sim_duty_cycle, ui_light1percent); - dimm(led2_pwm_pin, sim_duty_cycle, ui_light2percent); + if (stored_led1 && sim_duty_cycle >= led1_pref) + { + dimm(led1_pwm_pin, sim_duty_cycle, ui_light1percent); + } + if (stored_led2 && sim_duty_cycle >= led2_pref) + { + dimm(led2_pwm_pin, sim_duty_cycle, ui_light2percent); + } + if (stored_led3 && sim_duty_cycle >= led3_pref) + { + dimm(led3_pwm_pin, sim_duty_cycle, ui_light3percent); + } + + sim_duty_cycle -= 1; + } else if (sunset) { - if (led1_pref == sim_duty_cycle) + + + if (led1_pref >= sim_duty_cycle && led2_pref >= sim_duty_cycle && led3_pref >= sim_duty_cycle) { + Serial.println("SUNSIM SUNSET END"); + Serial.println(&timeinfo, "Realtime: %A, %B %d %Y %H:%M:%S"); updateSimMode = 24 * 60 * 60 * 1000; + led1active = false; + led2active = false; + led3active = false; lv_obj_remove_state(ui_light1switch, LV_STATE_CHECKED); lv_obj_remove_state(ui_light2switch, LV_STATE_CHECKED); - turnOff(led1_pwm_pin, led1_pref, ui_light1statuslbl, ui_lbllightstatus, ui_light1percent); - turnOff(led2_pwm_pin, led2_pref, ui_light2statuslbl, ui_lbllightstatus, ui_light2percent); + lv_obj_remove_state(ui_light3switch, LV_STATE_CHECKED); + turnOff(led1_pwm_pin, led1_pref, ui_lbllightstatus, ui_light1percent); + turnOff(led2_pwm_pin, led2_pref, ui_lbllightstatus, ui_light2percent); + turnOff(led3_pwm_pin, led3_pref, ui_lbllightstatus, ui_light3percent); sunset = false; - } - led1_pref += 1; + + + Serial.println("SUNSIM SUNSET WORKING"); Serial.println(led1_pref); - dimm(led1_pwm_pin, led1_pref, ui_light1percent); - dimm(led2_pwm_pin, led1_pref, ui_light2percent); + if (stored_led1 && led1_pref <= sim_duty_cycle) + { + led1_pref += 1; + dimm(led1_pwm_pin, led1_pref, ui_light1percent); + } + if (stored_led2 && led2_pref <= sim_duty_cycle) + { + led2_pref += 1; + dimm(led2_pwm_pin, led2_pref, ui_light2percent); + } + if (stored_led3 && led3_pref <= sim_duty_cycle) + { + led3_pref += 1; + dimm(led3_pwm_pin, led3_pref, ui_light3percent); + + } + } + if (start_sim) + { + start_sim = false; + updateSimMode = round(3600 / (sim_duty_cycle - led_pref) * 1000); } - } - - - void setGrowModeLbl(lv_event_t * e) { preferences.begin("g_phase", true); bool veggie_state = preferences.getBool("veggie"); bool flower_state = preferences.getBool("flowering"); + bool sun_sim_checked; char* start_h; char* start_m; char* end_h; @@ -834,7 +1244,9 @@ void setGrowModeLbl(lv_event_t * e) start_m = "flower_start_m"; end_h = "flower_end_h"; end_m = "flower_end_m"; + sun_sim_checked = preferences.getBool("fl_sun"); } + else { lv_dropdown_set_selected(ui_setmode, 0); @@ -842,12 +1254,29 @@ void setGrowModeLbl(lv_event_t * e) start_m = "veggie_start_m"; end_h = "veggie_end_h"; end_m = "veggie_end_m"; + sun_sim_checked = preferences.getBool("ve_sun"); } - int s_hour = preferences.getInt(start_h); int s_min = preferences.getInt(start_m); int e_hour = preferences.getInt(end_h); int e_min = preferences.getInt(end_m); + if (sun_sim_checked) + { + lv_obj_add_state(ui_sunsetcheck, LV_STATE_CHECKED); + if (e_hour == 23) + { + e_hour = 0; + } + else + { + e_hour += 1; + } + + } + else + { + lv_obj_remove_state(ui_sunsetcheck, LV_STATE_CHECKED); + } char start_hour = s_hour; char start_min = s_min; char end_hour = e_hour; @@ -857,20 +1286,23 @@ void setGrowModeLbl(lv_event_t * e) lv_roller_set_selected(ui_endhour, end_hour, LV_ANIM_ON); lv_roller_set_selected(ui_endmin, end_min, LV_ANIM_ON); preferences.end(); + getLed(); } +// void sunSimScreen() +// { +// lv_screen_load(ui_Screen2); +// } void growMode() { Serial.println("GROWMODE"); - preferences.begin("g_phase", true); bool lights = preferences.getBool("light"); bool veggie_state = preferences.getBool("veggie"); bool flower_state = preferences.getBool("flowering"); led1_pref = preferences.getInt("led1"); led2_pref = preferences.getInt("led2"); - - + led3_pref = preferences.getInt("led3"); Serial.print("Veggie: "); Serial.println(veggie_state); Serial.print("Flowering: "); @@ -879,6 +1311,7 @@ void growMode() Serial.println(lights); Serial.println("###################"); preferences.end(); + if (veggie_state || flower_state) { preferences.begin("g_phase", true); @@ -888,8 +1321,8 @@ void growMode() int end_h; int end_m; bool sim_sun; - Serial.println("###################"); + if (veggie_state) { Serial.println("IF VEGGIE"); @@ -908,38 +1341,153 @@ void growMode() end_h = preferences.getInt("flower_end_h"); end_m = preferences.getInt("flower_end_m"); sim_sun = preferences.getBool("fl_sun"); -… + Serial.println("###################"); + } + preferences.end(); + time_t diff_start = getDiffTime(start_h, start_m); + Serial.println(&targettime, "STARTTIME: %A, %B %d %Y %H:%M:%S"); + time_t diff_end = getDiffTime(end_h, end_m); Serial.println(&timeinfo, "Realtime: %A, %B %d %Y %H:%M:%S"); - Serial.println(&targettime, "Targettime: %A, %B %d %Y %H:%M:%S"); + Serial.println(&targettime, "ENDTIME: %A, %B %d %Y %H:%M:%S"); - if (diff_start < 0 && diff_end > 0) + + Serial.print("diff_start: "); + Serial.println(diff_start); + Serial.print("diff_end: "); + Serial.println(diff_end); + Serial.println("####################################"); + + if (diff_start < 0 && diff_end < 0 && diff_start > diff_end) { - Serial.println("Diffstart < 0 && Diffstart > Diffend"); - if(sim_sun) + Serial.println("####################################"); + Serial.println("diff_start < 0 && diff_end < 0 && diff_start > diff_end"); + if(sim_sun && diff_start > -300) { Serial.println("SIMSUN TRUE"); diff_time = getDiffTime(end_h, end_m); updateVeggieMode = (diff_time * 1000) + 1000; - lv_obj_add_state(ui_light1switch, LV_STATE_CHECKED); - lv_obj_add_state(ui_light2switch, LV_STATE_CHECKED); - sim_duty_cycle = 860; sunrise = true; - updateSimMode = (5 * 60 * 1000) / (sim_duty_cycle - led1_pref); - Serial.println(updateSimMode); - + start_sim = true; + sim_duty_cycle = 920; + sunSim(); + Serial.print("diff_time: "); + Serial.println(diff_time); + Serial.println(updateVeggieMode); + Serial.println(&timeinfo, "Realtime: %A, %B %d %Y %H:%M:%S"); + Serial.println(&targettime, "Targettime: %A, %B %d %Y %H:%M:%S"); + Serial.println("###################"); } + else { - + Serial.println("SIMSUN FALSE"); modeOn(); - if (diff_start > diff_end) - { - targettime.tm_mday += 1; - } - + targettime.tm_mday += 1; diff_time = getDiffTime(end_h, end_m); updateVeggieMode = (diff_time * 1000) + 1000; + + + + Serial.print("diff_time: "); + Serial.println(diff_time); + Serial.println(updateVeggieMode); + Serial.println(&timeinfo, "Realtime: %A, %B %d %Y %H:%M:%S"); + Serial.println(&targettime, "Targettime: %A, %B %d %Y %H:%M:%S"); + Serial.println("###################"); + } + } + + else if (diff_start < 0 && diff_end < 0 && diff_start < diff_end) + { + Serial.println("####################################"); + Serial.println("diff_start < 0 && diff_end < 0 && diff_start < diff_end"); + // Serial.println("SIMSUN FALSE"); + // getDiffTime(start_h, start_m); + // targettime.tm_mday += 1; + // diff_time = getDiffTime(start_h, start_m); + // updateVeggieMode = (diff_time * 1000) + 1000; + // modeOff(); + + // Serial.print("diff_time: "); + // Serial.println(diff_time); + // Serial.println(updateVeggieMode); + // Serial.println(&timeinfo, "Realtime: %A, %B %d %Y %H:%M:%S"); + // Serial.println(&targettime, "Targettime: %A, %B %d %Y %H:%M:%S"); + // Serial.println("###################"); + if(sim_sun && diff_end > -300) + { + + + Serial.println("SIMSUN TRUE"); + targettime.tm_mday += 1; + diff_time = getDiffTime(start_h, start_m); + updateVeggieMode = (diff_time * 1000) + 1000; + + sunset = true; + start_sim = true; + sim_duty_cycle = 920; + sunSim(); + Serial.print("diff_time: "); + Serial.println(diff_time); + Serial.println(updateVeggieMode); + Serial.println(&timeinfo, "Realtime: %A, %B %d %Y %H:%M:%S"); + Serial.println(&targettime, "Targettime: %A, %B %d %Y %H:%M:%S"); + Serial.println("###################"); + } + + + else + { + Serial.println("SIMSUN FALSE"); + targettime.tm_mday += 1; + diff_time = getDiffTime(start_h, start_m); + updateVeggieMode = (diff_time * 1000) + 1000; + modeOff(); + + Serial.print("diff_time: "); + Serial.println(diff_time); + Serial.println(updateVeggieMode); + Serial.println(&timeinfo, "Realtime: %A, %B %d %Y %H:%M:%S"); + Serial.println(&targettime, "Targettime: %A, %B %d %Y %H:%M:%S"); + Serial.println("###################"); + } + } + + else if (diff_start < 0 && diff_end > 0) + { + Serial.println("####################################"); + Serial.println("diff_start < 0 && diff_end > 0"); + if(sim_sun && diff_start > -300) + { + Serial.println("SIMSUN TRUE"); + targettime.tm_mday += 1; + diff_time = getDiffTime(end_h, end_m); + updateVeggieMode = (diff_time * 1000 ) + 1000; + + sunrise = true; + start_sim = true; + sim_duty_cycle = 920; + sunSim(); + Serial.print("diff_time: "); + Serial.println(diff_time); + Serial.print("updateVeggieMode: "); + Serial.println(updateVeggieMode); + Serial.println(&timeinfo, "Realtime: %A, %B %d %Y %H:%M:%S"); + Serial.println(&targettime, "Targettime: %A, %B %d %Y %H:%M:%S"); + Serial.println("###################"); + } + + else + { + Serial.println("SIMSUN FALSE"); + diff_time = getDiffTime(end_h, end_m); + updateVeggieMode = (diff_time * 1000) + 1000; + + modeOn(); + Serial.print("diff_time: "); + Serial.println(diff_time); + Serial.print("updateVeggieMode: "); Serial.println(updateVeggieMode); Serial.println(&timeinfo, "Realtime: %A, %B %d %Y %H:%M:%S"); Serial.println(&targettime, "Targettime: %A, %B %d %Y %H:%M:%S"); @@ -947,90 +1495,157 @@ void growMode() } } - - else if (diff_start < 0 && diff_start < diff_end) - { - Serial.println("Diffstart < 0 && Diffstart < Diffend"); - targettime.tm_mday += 1; - diff_time = getDiffTime(start_h, start_m); - updateVeggieMode = (diff_time * 1000) + 1000; - - modeOff(); - Serial.print("UPDATE LIGHTS ON: "); - Serial.println(updateVeggieMode); - Serial.println(&timeinfo, "Realtime: %A, %B %d %Y %H:%M:%S"); - Serial.println(&targettime, "Targettime: %A, %B %d %Y %H:%M:%S"); - Serial.println("###################"); - - } - else if (diff_start < 0 && diff_start > diff_end) - { - Serial.println("Diffstart < 0 && Diffstart > Diffend"); - targettime.tm_mday += 1; - diff_time = getDiffTime(end_h, end_m); - updateVeggieMode = (diff_time * 1000) + 1000; - - modeOn(); - - Serial.print("UPDATE LIGHTS ON: "); - Serial.println(updateVeggieMode); - Serial.println(&timeinfo, "Realtime: %A, %B %d %Y %H:%M:%S"); - Serial.println(&targettime, "Targettime: %A, %B %d %Y %H:%M:%S"); - Serial.println("###################"); - - } else if (diff_start > 0 && diff_end < 0) { - Serial.println("Diffstart > 0 && Diffstart < Diffend"); - - diff_time = getDiffTime(start_h, start_m); - updateVeggieMode = (diff_time * 1000) + 1000; - - modeOff(); + Serial.println("####################################"); + Serial.println("diff_start > 0 && diff_end < 0"); + if(sim_sun && diff_end > -300) + { + + Serial.println("SIMSUN TRUE"); + diff_time = getDiffTime(start_h, start_m); + updateVeggieMode = (diff_time * 1000) + 1000; + + sunset = true; + start_sim = true; + sim_duty_cycle = 920; + // sunSimScreen(); + + sunSim(); + Serial.print("diff_time: "); + Serial.println(diff_time); + Serial.print("updateVeggieMode: "); + Serial.println(updateVeggieMode); + Serial.println(&timeinfo, "Realtime: %A, %B %d %Y %H:%M:%S"); + Serial.println(&targettime, "Targettime: %A, %B %d %Y %H:%M:%S"); + Serial.println("###################"); + } - Serial.print("UPDATE LIGHTS ON: "); - Serial.println(updateVeggieMode); - Serial.println(&timeinfo, "Realtime: %A, %B %d %Y %H:%M:%S"); - Serial.println(&targettime, "Targettime: %A, %B %d %Y %H:%M:%S"); - Serial.println("###################"); + else + { + Serial.println("SIMSUN FALSE"); + + diff_time = getDiffTime(start_h, start_m); + updateVeggieMode = (diff_time * 1000) + 1000; + modeOff(); + Serial.print("diff_time: "); + Serial.println(diff_time); + Serial.print("updateVeggieMode: "); + Serial.println(updateVeggieMode); + Serial.println(&timeinfo, "Realtime: %A, %B %d %Y %H:%M:%S"); + Serial.println(&targettime, "Targettime: %A, %B %d %Y %H:%M:%S"); + Serial.println("###################"); + } + } - else if (diff_start > 0 && diff_start > diff_end) + + else if (diff_start > 0 && diff_end > 0 && diff_start > diff_end) { - Serial.println("Diffstart > 0 && Diffstart > Diffend"); - + Serial.println("####################################"); + Serial.println("diff_start > 0 && diff_end > 0 && diff_start > diff_end"); + Serial.println("SIMSUN FALSE"); + modeOn(); diff_time = getDiffTime(end_h, end_m); updateVeggieMode = (diff_time * 1000) + 1000; - modeOn(); - - Serial.print("UPDATE LIGHTS ON: "); + Serial.print("diff_time: "); + Serial.println(diff_time); + Serial.print("updateVeggieMode: "); Serial.println(updateVeggieMode); Serial.println(&timeinfo, "Realtime: %A, %B %d %Y %H:%M:%S"); Serial.println(&targettime, "Targettime: %A, %B %d %Y %H:%M:%S"); Serial.println("###################"); + // if(sim_sun) + // { + // Serial.println("SIMSUN TRUE"); + // modeOn(); + // diff_time = getDiffTime(end_h, end_m); + + // updateVeggieMode = (diff_time* 1000) + 1000; + + + + + // Serial.print("diff_time: "); + // Serial.println(diff_time); + // Serial.print("updateVeggieMode: "); + // Serial.println(updateVeggieMode); + // Serial.println(&timeinfo, "Realtime: %A, %B %d %Y %H:%M:%S"); + // Serial.println(&targettime, "Targettime: %A, %B %d %Y %H:%M:%S"); + // Serial.println("###################"); + // } + + // else + // { + // Serial.println("SIMSUN FALSE"); + // modeOn(); + // diff_time = getDiffTime(end_h, end_m); + // updateVeggieMode = (diff_time * 1000) + 1000; + + // Serial.print("diff_time: "); + // Serial.println(diff_time); + // Serial.print("updateVeggieMode: "); + // Serial.println(updateVeggieMode); + // Serial.println(&timeinfo, "Realtime: %A, %B %d %Y %H:%M:%S"); + // Serial.println(&targettime, "Targettime: %A, %B %d %Y %H:%M:%S"); + // Serial.println("###################"); + // } } - else if (diff_start > 0 && diff_start < diff_end) + else if (diff_start > 0 && diff_end > 0 && diff_start < diff_end) { - Serial.println("Diffstart > 0 && Diffstart < Diffend"); - + Serial.println("####################################"); + Serial.println("diff_start > 0 && diff_end > 0 && diff_start < diff_end"); + diff_time = getDiffTime(start_h, start_m); updateVeggieMode = (diff_time * 1000) + 1000; - modeOff(); - - Serial.print("UPDATE LIGHTS ON: "); + Serial.print("diff_time: "); + Serial.println(diff_time); + Serial.print("updateVeggieMode: "); Serial.println(updateVeggieMode); Serial.println(&timeinfo, "Realtime: %A, %B %d %Y %H:%M:%S"); Serial.println(&targettime, "Targettime: %A, %B %d %Y %H:%M:%S"); Serial.println("###################"); - } + // if(sim_sun && diff_end > -300) + // { + // Serial.println("SIMSUN TRUE"); + // diff_time = getDiffTime(start_h, start_m); + // updateVeggieMode = (diff_time * 1000) + 1000; + + // sunset = true; + // start_sim = true; + // sim_duty_cycle = 920; + // sunSim(); + // Serial.print("diff_time: "); + // Serial.println(diff_time); + // Serial.print("updateVeggieMode: "); + // Serial.println(updateVeggieMode); + // Serial.println(&timeinfo, "Realtime: %A, %B %d %Y %H:%M:%S"); + // Serial.println(&targettime, "Targettime: %A, %B %d %Y %H:%M:%S"); + // Serial.println("###################"); + // } + + // else + // { + // Serial.println("SIMSUN FALSE"); + // diff_time = getDiffTime(start_h, start_m); + // updateVeggieMode = (diff_time * 1000) + 1000; + // modeOff(); + // Serial.print("diff_time: "); + // Serial.println(diff_time); + // Serial.print("updateVeggieMode: "); + // Serial.println(updateVeggieMode); + // Serial.println(&timeinfo, "Realtime: %A, %B %d %Y %H:%M:%S"); + // Serial.println(&targettime, "Targettime: %A, %B %d %Y %H:%M:%S"); + // Serial.println("###################"); + // } - + // } } preferences.end(); @@ -1054,21 +1669,25 @@ void printTime() Serial.println("Failed to obtain time"); return; } + else + { char clock[80]; strftime(clock,80,"Uhrzeit: %H:%M:%S",&timeinfo); - lv_label_set_text(ui_lblclock, clock); + lv_label_set_text(ui_lblclock, clock); + } + } -void printValues() -{ - char hum[20]; - char temp[20]; - sprintf(hum, "%.0f%%",bme.readHumidity()); - sprintf(temp, "%.0f%%",bme.readTemperature()); - lv_label_set_text(ui_lblhum, hum); - lv_label_set_text(ui_fanhum, hum); - lv_label_set_text(ui_lbltemp, temp); - lv_label_set_text(ui_fantemp, temp); -} +// void printValues() +// { +// char hum[20]; +// char temp[20]; +// sprintf(hum, "%.0f%%",bme.readHumidity()); +// sprintf(temp, "%.0f%%",bme.readTemperature()); +// lv_label_set_text(ui_lblhum, hum); +// lv_label_set_text(ui_fanhum, hum); +// lv_label_set_text(ui_lbltemp, temp); +// lv_label_set_text(ui_fantemp, temp); +// }