Update user_code.cpp

This commit is contained in:
Siwat Sirichai 2023-12-26 23:22:55 +07:00
parent b6e862d1d2
commit 291782dee4
1 changed files with 18 additions and 0 deletions

View File

@ -51,6 +51,7 @@ bool row_is_on(int light1_pin, int light2_pin) {
void light_toggle_pop_callback(void *ptr) void light_toggle_pop_callback(void *ptr)
{ {
Serial.println("Toggle Button Pressed");
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);
pwm_set_state(ROW1_LIGHT1, new_state); pwm_set_state(ROW1_LIGHT1, new_state);
pwm_set_state(ROW1_LIGHT2, new_state); pwm_set_state(ROW1_LIGHT2, new_state);
@ -64,41 +65,49 @@ void light_toggle_pop_callback(void *ptr)
void row1_lv1_pop_callback(void *ptr) void row1_lv1_pop_callback(void *ptr)
{ {
Serial.println("Row 1 Light 1 Button Pressed");
pwm_toggle(ROW1_LIGHT1); pwm_toggle(ROW1_LIGHT1);
} }
void row1_lv2_pop_callback(void *ptr) void row1_lv2_pop_callback(void *ptr)
{ {
Serial.println("Row 1 Light 2 Button Pressed");
pwm_toggle(ROW1_LIGHT2); pwm_toggle(ROW1_LIGHT2);
} }
void row2_lv1_pop_callback(void *ptr) void row2_lv1_pop_callback(void *ptr)
{ {
Serial.println("Row 2 Light 1 Button Pressed");
pwm_toggle(ROW2_LIGHT1); pwm_toggle(ROW2_LIGHT1);
} }
void row2_lv2_pop_callback(void *ptr) void row2_lv2_pop_callback(void *ptr)
{ {
Serial.println("Row 2 Light 2 Button Pressed");
pwm_toggle(ROW2_LIGHT2); pwm_toggle(ROW2_LIGHT2);
} }
void row3_lv1_pop_callback(void *ptr) void row3_lv1_pop_callback(void *ptr)
{ {
Serial.println("Row 3 Light 1 Button Pressed");
pwm_toggle(ROW3_LIGHT1); pwm_toggle(ROW3_LIGHT1);
} }
void row3_lv2_pop_callback(void *ptr) void row3_lv2_pop_callback(void *ptr)
{ {
Serial.println("Row 3 Light 2 Button Pressed");
pwm_toggle(ROW3_LIGHT2); pwm_toggle(ROW3_LIGHT2);
} }
void row4_lv1_pop_callback(void *ptr) void row4_lv1_pop_callback(void *ptr)
{ {
Serial.println("Row 4 Light 1 Button Pressed");
pwm_toggle(ROW4_LIGHT1); pwm_toggle(ROW4_LIGHT1);
} }
void row4_lv2_pop_callback(void *ptr) void row4_lv2_pop_callback(void *ptr)
{ {
Serial.println("Row 4 Light 2 Button Pressed");
pwm_toggle(ROW4_LIGHT2); pwm_toggle(ROW4_LIGHT2);
} }
@ -114,16 +123,19 @@ void decrease_temp() {
void temp_plus_pop_callback(void *ptr) void temp_plus_pop_callback(void *ptr)
{ {
Serial.println("Temp Plus Button Pressed");
increase_temp(); increase_temp();
} }
void temp_neg_pop_callback(void *ptr) void temp_neg_pop_callback(void *ptr)
{ {
Serial.println("Temp Neg Button Pressed");
decrease_temp(); decrease_temp();
} }
void fan_pop_callback(void *ptr) void fan_pop_callback(void *ptr)
{ {
Serial.println("Fan Button Pressed");
uint8_t current_fan_speed = ac_get_fan_speed(); uint8_t current_fan_speed = ac_get_fan_speed();
uint8_t new_fan_speed = (current_fan_speed + 1) % 4; // Loop back to 0 when reaching 3 uint8_t new_fan_speed = (current_fan_speed + 1) % 4; // Loop back to 0 when reaching 3
ac_set_state(ac_get_mode(), ac_get_temperature(), new_fan_speed); ac_set_state(ac_get_mode(), ac_get_temperature(), new_fan_speed);
@ -131,6 +143,7 @@ void fan_pop_callback(void *ptr)
void mode_pop_callback(void *ptr) void mode_pop_callback(void *ptr)
{ {
Serial.println("Mode Button Pressed");
uint8_t current_mode = ac_get_mode(); uint8_t current_mode = ac_get_mode();
uint8_t new_mode = (current_mode + 1) % 3; // Loop back to 0 when reaching 2 uint8_t new_mode = (current_mode + 1) % 3; // Loop back to 0 when reaching 2
ac_set_state(new_mode, ac_get_temperature(), ac_get_fan_speed()); ac_set_state(new_mode, ac_get_temperature(), ac_get_fan_speed());
@ -138,6 +151,7 @@ void mode_pop_callback(void *ptr)
void ac_toggle_pop_callback(void *ptr) void ac_toggle_pop_callback(void *ptr)
{ {
Serial.println("AC Toggle Button Pressed");
//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
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());
@ -150,6 +164,7 @@ void ac_toggle_pop_callback(void *ptr)
void row1_master_pop_callback(void *ptr) void row1_master_pop_callback(void *ptr)
{ {
Serial.println("Row 1 Master Button Pressed");
bool new_state = !row_is_on(ROW1_LIGHT1,ROW1_LIGHT2); bool new_state = !row_is_on(ROW1_LIGHT1,ROW1_LIGHT2);
pwm_set_state(ROW1_LIGHT1, new_state); pwm_set_state(ROW1_LIGHT1, new_state);
pwm_set_state(ROW1_LIGHT2, new_state); pwm_set_state(ROW1_LIGHT2, new_state);
@ -157,6 +172,7 @@ void row1_master_pop_callback(void *ptr)
void row2_master_pop_callback(void *ptr) void row2_master_pop_callback(void *ptr)
{ {
Serial.println("Row 2 Master Button Pressed");
bool new_state = !row_is_on(ROW2_LIGHT1,ROW2_LIGHT2); bool new_state = !row_is_on(ROW2_LIGHT1,ROW2_LIGHT2);
pwm_set_state(ROW2_LIGHT1, new_state); pwm_set_state(ROW2_LIGHT1, new_state);
pwm_set_state(ROW2_LIGHT2, new_state); pwm_set_state(ROW2_LIGHT2, new_state);
@ -164,6 +180,7 @@ void row2_master_pop_callback(void *ptr)
void row3_master_pop_callback(void *ptr) void row3_master_pop_callback(void *ptr)
{ {
Serial.println("Row 3 Master Button Pressed");
bool new_state = !row_is_on(ROW3_LIGHT1,ROW3_LIGHT2); bool new_state = !row_is_on(ROW3_LIGHT1,ROW3_LIGHT2);
pwm_set_state(ROW3_LIGHT1, new_state); pwm_set_state(ROW3_LIGHT1, new_state);
pwm_set_state(ROW3_LIGHT2, new_state); pwm_set_state(ROW3_LIGHT2, new_state);
@ -171,6 +188,7 @@ void row3_master_pop_callback(void *ptr)
void row4_master_pop_callback(void *ptr) void row4_master_pop_callback(void *ptr)
{ {
Serial.println("Row 4 Master Button Pressed");
bool new_state = !row_is_on(ROW4_LIGHT1,ROW4_LIGHT2); bool new_state = !row_is_on(ROW4_LIGHT1,ROW4_LIGHT2);
pwm_set_state(ROW4_LIGHT1, new_state); pwm_set_state(ROW4_LIGHT1, new_state);
pwm_set_state(ROW4_LIGHT2, new_state); pwm_set_state(ROW4_LIGHT2, new_state);