band aid fix on light toggle

This commit is contained in:
reaw55 2023-12-27 00:28:41 +07:00
parent bda80d340b
commit c12a909f66
2 changed files with 12 additions and 1 deletions

View File

@ -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); 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) 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); 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); fan.attachPop(fan_pop_callback, &fan);
mode.attachPop(mode_pop_callback, &mode); mode.attachPop(mode_pop_callback, &mode);
ac_toggle.attachPop(ac_toggle_pop_callback, &ac_toggle); 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 This code will run once every event loop
@ -313,7 +323,7 @@ void update_lcd_row4() {
void update_toggle_button() { void update_toggle_button() {
//calcuate the current state of the 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); //light_toggle.Set_background_image_pic(current_state?3:4);
elcd_send_stop_bit(); elcd_send_stop_bit();
elcd.print("light_toggle.pic="); elcd.print("light_toggle.pic=");

View File

@ -66,6 +66,7 @@
#define elcd ESPMega_EXTLCD #define elcd ESPMega_EXTLCD
void elcd_send_stop_bit(); void elcd_send_stop_bit();
bool row_is_on(int light1_pin, int light2_pin); 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_row1();
void update_lcd_row2(); void update_lcd_row2();
void update_lcd_row3(); void update_lcd_row3();