From c12a909f66a2b39f2fbe4615c6ce2f3c6d9ca5fd Mon Sep 17 00:00:00 2001 From: reaw55 <58457329+reaw55@users.noreply.github.com> Date: Wed, 27 Dec 2023 00:28:41 +0700 Subject: [PATCH] band aid fix on light toggle --- src/user_code.cpp | 12 +++++++++++- src/user_code.hpp | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/user_code.cpp b/src/user_code.cpp index ee2d0b4..431db5b 100644 --- a/src/user_code.cpp +++ b/src/user_code.cpp @@ -49,6 +49,10 @@ bool row_is_on(int light1_pin, int light2_pin) { return pwm_get_state(light1_pin) && pwm_get_state(light2_pin); } +bool row_is_on_or(int light1_pin, int light2_pin) { + return pwm_get_state(light1_pin) || pwm_get_state(light2_pin); +} + void light_toggle_pop_callback(void *ptr) { bool new_state = !row_is_on(ROW1_LIGHT1,ROW1_LIGHT2) && !row_is_on(ROW2_LIGHT1,ROW2_LIGHT2) && !row_is_on(ROW3_LIGHT1,ROW3_LIGHT2) && !row_is_on(ROW4_LIGHT1,ROW4_LIGHT2); @@ -210,6 +214,12 @@ void user_init() fan.attachPop(fan_pop_callback, &fan); mode.attachPop(mode_pop_callback, &mode); ac_toggle.attachPop(ac_toggle_pop_callback, &ac_toggle); + update_lcd_row1(); + update_lcd_row2(); + update_lcd_row3(); + update_lcd_row4(); + update_toggle_button(); + update_lcd_ac(); } /* This code will run once every event loop @@ -313,7 +323,7 @@ void update_lcd_row4() { void update_toggle_button() { //calcuate the current state of the toggle button - bool current_state = row_is_on(ROW1_LIGHT1,ROW1_LIGHT2) || row_is_on(ROW2_LIGHT1,ROW2_LIGHT2) || row_is_on(ROW3_LIGHT1,ROW3_LIGHT2) || row_is_on(ROW4_LIGHT1,ROW4_LIGHT2); + bool current_state = row_is_on_or(ROW1_LIGHT1,ROW1_LIGHT2) || row_is_on_or(ROW2_LIGHT1,ROW2_LIGHT2) || row_is_on_or(ROW3_LIGHT1,ROW3_LIGHT2) || row_is_on_or(ROW4_LIGHT1,ROW4_LIGHT2); //light_toggle.Set_background_image_pic(current_state?3:4); elcd_send_stop_bit(); elcd.print("light_toggle.pic="); diff --git a/src/user_code.hpp b/src/user_code.hpp index bb0b3b7..101ce22 100644 --- a/src/user_code.hpp +++ b/src/user_code.hpp @@ -66,6 +66,7 @@ #define elcd ESPMega_EXTLCD void elcd_send_stop_bit(); bool row_is_on(int light1_pin, int light2_pin); +bool row_is_on_or(int light1_pin, int light2_pin); void update_lcd_row1(); void update_lcd_row2(); void update_lcd_row3();