fix toggle
This commit is contained in:
parent
595a13a7c1
commit
c4fe483975
|
@ -45,11 +45,13 @@ NexTouch *nex_listen_list[] =
|
||||||
&ac_toggle,
|
&ac_toggle,
|
||||||
NULL};
|
NULL};
|
||||||
|
|
||||||
bool row_is_on(int light1_pin, int light2_pin) {
|
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) {
|
bool row_is_on_or(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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,12 +108,14 @@ void row4_lv2_pop_callback(void *ptr)
|
||||||
pwm_toggle(ROW4_LIGHT2);
|
pwm_toggle(ROW4_LIGHT2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void increase_temp() {
|
void increase_temp()
|
||||||
|
{
|
||||||
uint8_t current_temp = ac_get_temperature();
|
uint8_t current_temp = ac_get_temperature();
|
||||||
ac_set_state(ac_get_mode(), current_temp + 1, ac_get_fan_speed());
|
ac_set_state(ac_get_mode(), current_temp + 1, ac_get_fan_speed());
|
||||||
}
|
}
|
||||||
|
|
||||||
void decrease_temp() {
|
void decrease_temp()
|
||||||
|
{
|
||||||
uint8_t current_temp = ac_get_temperature();
|
uint8_t current_temp = ac_get_temperature();
|
||||||
ac_set_state(ac_get_mode(), current_temp - 1, ac_get_fan_speed());
|
ac_set_state(ac_get_mode(), current_temp - 1, ac_get_fan_speed());
|
||||||
}
|
}
|
||||||
|
@ -135,11 +139,17 @@ void fan_pop_callback(void *ptr)
|
||||||
|
|
||||||
void mode_pop_callback(void *ptr)
|
void mode_pop_callback(void *ptr)
|
||||||
{
|
{
|
||||||
uint8_t current_mode = ac_get_mode();
|
// uint8_t current_mode = ac_get_mode();
|
||||||
|
user_acmode = ac_get_mode();
|
||||||
// uint8_t new_mode = (current_mode + 1) % 3; // Loop back to 1 when reaching 2
|
// uint8_t new_mode = (current_mode + 1) % 3; // Loop back to 1 when reaching 2
|
||||||
if(current_mode == 1) {
|
if (user_acmode == 1)
|
||||||
|
{
|
||||||
|
user_acmode = 2;
|
||||||
ac_set_state(2, ac_get_temperature(), ac_get_fan_speed());
|
ac_set_state(2, ac_get_temperature(), ac_get_fan_speed());
|
||||||
} else if(current_mode == 2) {
|
}
|
||||||
|
else if (user_acmode == 2)
|
||||||
|
{
|
||||||
|
user_acmode = 1;
|
||||||
ac_set_state(1, ac_get_temperature(), ac_get_fan_speed());
|
ac_set_state(1, ac_get_temperature(), ac_get_fan_speed());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,9 +160,12 @@ void ac_toggle_pop_callback(void *ptr)
|
||||||
{
|
{
|
||||||
// this function should set the state of the AC to toggle between off (mode 0) and the same state as before store in variable acmode
|
// this function should set the state of the AC to toggle between off (mode 0) and the same state as before store in variable acmode
|
||||||
// val user_acmode already initialized to 1 (cool mode)
|
// val user_acmode already initialized to 1 (cool mode)
|
||||||
if (ac_get_mode() == 0) {
|
if (ac_get_mode() == 0)
|
||||||
|
{
|
||||||
ac_set_state(user_acmode, ac_get_temperature(), ac_get_fan_speed());
|
ac_set_state(user_acmode, ac_get_temperature(), ac_get_fan_speed());
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
user_acmode = ac_get_mode();
|
user_acmode = ac_get_mode();
|
||||||
ac_set_state(0, ac_get_temperature(), ac_get_fan_speed());
|
ac_set_state(0, ac_get_temperature(), ac_get_fan_speed());
|
||||||
}
|
}
|
||||||
|
@ -249,7 +262,8 @@ void virtual_interrupt_user_callback(int pin, int state)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_lcd_row1() {
|
void update_lcd_row1()
|
||||||
|
{
|
||||||
bool master_state = row_is_on_or(ROW1_LIGHT1, ROW1_LIGHT2);
|
bool master_state = row_is_on_or(ROW1_LIGHT1, ROW1_LIGHT2);
|
||||||
// row1_master.Set_background_image_pic(master_state?10:9);
|
// row1_master.Set_background_image_pic(master_state?10:9);
|
||||||
elcd_send_stop_bit();
|
elcd_send_stop_bit();
|
||||||
|
@ -279,7 +293,8 @@ void update_lcd_row1() {
|
||||||
elcd_send_stop_bit();
|
elcd_send_stop_bit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_lcd_row2() {
|
void update_lcd_row2()
|
||||||
|
{
|
||||||
bool master_state = row_is_on_or(ROW2_LIGHT1, ROW2_LIGHT2);
|
bool master_state = row_is_on_or(ROW2_LIGHT1, ROW2_LIGHT2);
|
||||||
// row2_master.Set_background_image_pic(master_state?12:11);
|
// row2_master.Set_background_image_pic(master_state?12:11);
|
||||||
elcd_send_stop_bit();
|
elcd_send_stop_bit();
|
||||||
|
@ -306,10 +321,10 @@ void update_lcd_row2() {
|
||||||
elcd.print("row2_lv2.pic2=");
|
elcd.print("row2_lv2.pic2=");
|
||||||
elcd.print(lt2_state ? 8 : 7);
|
elcd.print(lt2_state ? 8 : 7);
|
||||||
elcd_send_stop_bit();
|
elcd_send_stop_bit();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_lcd_row3() {
|
void update_lcd_row3()
|
||||||
|
{
|
||||||
bool master_state = row_is_on_or(ROW3_LIGHT1, ROW3_LIGHT2);
|
bool master_state = row_is_on_or(ROW3_LIGHT1, ROW3_LIGHT2);
|
||||||
// row3_master.Set_background_image_pic(master_state?14:13);
|
// row3_master.Set_background_image_pic(master_state?14:13);
|
||||||
elcd_send_stop_bit();
|
elcd_send_stop_bit();
|
||||||
|
@ -338,7 +353,8 @@ void update_lcd_row3() {
|
||||||
elcd_send_stop_bit();
|
elcd_send_stop_bit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_lcd_row4() {
|
void update_lcd_row4()
|
||||||
|
{
|
||||||
bool master_state = row_is_on_or(ROW4_LIGHT1, ROW4_LIGHT2);
|
bool master_state = row_is_on_or(ROW4_LIGHT1, ROW4_LIGHT2);
|
||||||
// row4_master.Set_background_image_pic(master_state?16:15);
|
// row4_master.Set_background_image_pic(master_state?16:15);
|
||||||
elcd_send_stop_bit();
|
elcd_send_stop_bit();
|
||||||
|
@ -365,10 +381,10 @@ void update_lcd_row4() {
|
||||||
elcd.print("row4_lv2.pic2=");
|
elcd.print("row4_lv2.pic2=");
|
||||||
elcd.print(lt2_state ? 8 : 7);
|
elcd.print(lt2_state ? 8 : 7);
|
||||||
elcd_send_stop_bit();
|
elcd_send_stop_bit();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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_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);
|
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?4:3);
|
// light_toggle.Set_background_image_pic(current_state?4:3);
|
||||||
|
@ -381,7 +397,8 @@ void update_toggle_button() {
|
||||||
elcd_send_stop_bit();
|
elcd_send_stop_bit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_lcd_ac() {
|
void update_lcd_ac()
|
||||||
|
{
|
||||||
// update the current temperature
|
// update the current temperature
|
||||||
char temp_str[3];
|
char temp_str[3];
|
||||||
sprintf(temp_str, "%d", ac_get_temperature());
|
sprintf(temp_str, "%d", ac_get_temperature());
|
||||||
|
@ -389,35 +406,44 @@ void update_lcd_ac() {
|
||||||
// update the fan speed auto is 18, high 19, medium 21, low 20
|
// update the fan speed auto is 18, high 19, medium 21, low 20
|
||||||
// Fan Speed 0: Auto, 1: High, 2: Mid, 3: Low
|
// Fan Speed 0: Auto, 1: High, 2: Mid, 3: Low
|
||||||
uint8_t fan_speed = ac_get_fan_speed();
|
uint8_t fan_speed = ac_get_fan_speed();
|
||||||
if(fan_speed == 0) {
|
if (fan_speed == 0)
|
||||||
|
{
|
||||||
// fan.Set_background_image_pic(18);
|
// fan.Set_background_image_pic(18);
|
||||||
elcd_send_stop_bit();
|
elcd_send_stop_bit();
|
||||||
elcd.print("fan.pic=18");
|
elcd.print("fan.pic=18");
|
||||||
elcd_send_stop_bit();
|
elcd_send_stop_bit();
|
||||||
elcd.print("fan.pic2=18");
|
elcd.print("fan.pic2=18");
|
||||||
elcd_send_stop_bit();
|
elcd_send_stop_bit();
|
||||||
} else if(fan_speed == 1) {
|
}
|
||||||
|
else if (fan_speed == 1)
|
||||||
|
{
|
||||||
// fan.Set_background_image_pic(19);
|
// fan.Set_background_image_pic(19);
|
||||||
elcd_send_stop_bit();
|
elcd_send_stop_bit();
|
||||||
elcd.print("fan.pic=19");
|
elcd.print("fan.pic=19");
|
||||||
elcd_send_stop_bit();
|
elcd_send_stop_bit();
|
||||||
elcd.print("fan.pic2=19");
|
elcd.print("fan.pic2=19");
|
||||||
elcd_send_stop_bit();
|
elcd_send_stop_bit();
|
||||||
} else if(fan_speed == 2) {
|
}
|
||||||
|
else if (fan_speed == 2)
|
||||||
|
{
|
||||||
// fan.Set_background_image_pic(21);
|
// fan.Set_background_image_pic(21);
|
||||||
elcd_send_stop_bit();
|
elcd_send_stop_bit();
|
||||||
elcd.print("fan.pic=21");
|
elcd.print("fan.pic=21");
|
||||||
elcd_send_stop_bit();
|
elcd_send_stop_bit();
|
||||||
elcd.print("fan.pic2=21");
|
elcd.print("fan.pic2=21");
|
||||||
elcd_send_stop_bit();
|
elcd_send_stop_bit();
|
||||||
} else if(fan_speed == 3) {
|
}
|
||||||
|
else if (fan_speed == 3)
|
||||||
|
{
|
||||||
// fan.Set_background_image_pic(20);
|
// fan.Set_background_image_pic(20);
|
||||||
elcd_send_stop_bit();
|
elcd_send_stop_bit();
|
||||||
elcd.print("fan.pic=20");
|
elcd.print("fan.pic=20");
|
||||||
elcd_send_stop_bit();
|
elcd_send_stop_bit();
|
||||||
elcd.print("fan.pic2=20");
|
elcd.print("fan.pic2=20");
|
||||||
elcd_send_stop_bit();
|
elcd_send_stop_bit();
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
// fan.Set_background_image_pic(18);
|
// fan.Set_background_image_pic(18);
|
||||||
elcd_send_stop_bit();
|
elcd_send_stop_bit();
|
||||||
elcd.print("fan.pic=18");
|
elcd.print("fan.pic=18");
|
||||||
|
@ -430,7 +456,8 @@ void update_lcd_ac() {
|
||||||
uint8_t mode_state = ac_get_mode();
|
uint8_t mode_state = ac_get_mode();
|
||||||
// mode.Set_background_image_pic(mode_state==1?22:24);
|
// mode.Set_background_image_pic(mode_state==1?22:24);
|
||||||
elcd_send_stop_bit();
|
elcd_send_stop_bit();
|
||||||
if(mode_state==1){
|
if (mode_state == 1)
|
||||||
|
{
|
||||||
elcd_send_stop_bit();
|
elcd_send_stop_bit();
|
||||||
elcd.print("ac_toggle.pic=2");
|
elcd.print("ac_toggle.pic=2");
|
||||||
elcd_send_stop_bit();
|
elcd_send_stop_bit();
|
||||||
|
@ -440,8 +467,9 @@ void update_lcd_ac() {
|
||||||
elcd_send_stop_bit();
|
elcd_send_stop_bit();
|
||||||
elcd.print("mode.pic2=22");
|
elcd.print("mode.pic2=22");
|
||||||
elcd_send_stop_bit();
|
elcd_send_stop_bit();
|
||||||
|
}
|
||||||
} else if(mode_state==2){
|
else if (mode_state == 2)
|
||||||
|
{
|
||||||
elcd_send_stop_bit();
|
elcd_send_stop_bit();
|
||||||
elcd.print("ac_toggle.pic=2");
|
elcd.print("ac_toggle.pic=2");
|
||||||
elcd_send_stop_bit();
|
elcd_send_stop_bit();
|
||||||
|
@ -451,19 +479,23 @@ void update_lcd_ac() {
|
||||||
elcd_send_stop_bit();
|
elcd_send_stop_bit();
|
||||||
elcd.print("mode.pic2=24");
|
elcd.print("mode.pic2=24");
|
||||||
elcd_send_stop_bit();
|
elcd_send_stop_bit();
|
||||||
} else{
|
}
|
||||||
|
else if (mode_state == 0)
|
||||||
|
{
|
||||||
elcd_send_stop_bit();
|
elcd_send_stop_bit();
|
||||||
elcd.print("ac_toggle.pic=1");
|
elcd.print("ac_toggle.pic=1");
|
||||||
elcd_send_stop_bit();
|
elcd_send_stop_bit();
|
||||||
elcd.print("ac_toggle.pic2=1");
|
elcd.print("ac_toggle.pic2=1");
|
||||||
if(user_acmode==1){
|
if (user_acmode == 1)
|
||||||
|
{
|
||||||
elcd_send_stop_bit();
|
elcd_send_stop_bit();
|
||||||
elcd.print("mode.pic=22");
|
elcd.print("mode.pic=22");
|
||||||
elcd_send_stop_bit();
|
elcd_send_stop_bit();
|
||||||
elcd.print("mode.pic2=22");
|
elcd.print("mode.pic2=22");
|
||||||
elcd_send_stop_bit();
|
elcd_send_stop_bit();
|
||||||
}
|
}
|
||||||
else{
|
else
|
||||||
|
{
|
||||||
elcd_send_stop_bit();
|
elcd_send_stop_bit();
|
||||||
elcd.print("mode.pic=24");
|
elcd.print("mode.pic=24");
|
||||||
elcd_send_stop_bit();
|
elcd_send_stop_bit();
|
||||||
|
@ -488,8 +520,6 @@ void update_lcd_ac() {
|
||||||
elcd_send_stop_bit(); */
|
elcd_send_stop_bit(); */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void pwm_changed_user_callback(int pin)
|
void pwm_changed_user_callback(int pin)
|
||||||
{
|
{
|
||||||
switch (pin)
|
switch (pin)
|
||||||
|
@ -529,23 +559,25 @@ void timer_tick_callback()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ac_changed_user_callback(int mode, int temperature, int fan_speed) {
|
void ac_changed_user_callback(int mode, int temperature, int fan_speed)
|
||||||
|
{
|
||||||
update_lcd_ac();
|
update_lcd_ac();
|
||||||
}
|
}
|
||||||
|
|
||||||
void mqtt_connected_user_callback() {
|
void mqtt_connected_user_callback()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void user_state_request_callback() {
|
void user_state_request_callback()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void user_mqtt_callback(char* topic, uint8_t topic_length, char* payload, unsigned int payload_length) {
|
void user_mqtt_callback(char *topic, uint8_t topic_length, char *payload, unsigned int payload_length)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void elcd_send_stop_bit() {
|
void elcd_send_stop_bit()
|
||||||
|
{
|
||||||
elcd.write(0xFF);
|
elcd.write(0xFF);
|
||||||
elcd.write(0xFF);
|
elcd.write(0xFF);
|
||||||
elcd.write(0xFF);
|
elcd.write(0xFF);
|
||||||
|
|
Loading…
Reference in New Issue