lcd pwm adjust functionality

This commit is contained in:
Siwat Sirichai 2023-09-03 17:41:31 +07:00
parent edbb9280e1
commit 4e9b98b4d7
2 changed files with 59 additions and 3 deletions

11
.vscode/settings.json vendored
View File

@ -1,6 +1,15 @@
{
"C_Cpp.errorSquiggles": "enabled",
"files.associations": {
"string": "cpp"
"string": "cpp",
"optional": "cpp",
"istream": "cpp",
"ostream": "cpp",
"system_error": "cpp",
"array": "cpp",
"functional": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp"
}
}

View File

@ -55,6 +55,7 @@ char PWM_SET_VALUE_TOPIC[75] = MQTT_BASE_TOPIC "/pwm/00/set/value";
// LCD
int lcd_current_page = 1;
int lcd_pwmAdj_id = 0;
EasyNex panel(Serial);
// Air Conditioner Control
@ -113,6 +114,10 @@ void lcd_loop();
void lcd_refresh();
void lcd_refresh_pd();
void lcd_top_bar_update();
void trigger0();
void trigger1();
void trigger2();
void trigger4();
char PWM_STATE_TOPIC[75] = MQTT_BASE_TOPIC "/pwm/00/state";
char PWM_VALUE_TOPIC[75] = MQTT_BASE_TOPIC "/pwm/00/value";
@ -326,6 +331,8 @@ void publish_pwm_state(int id)
int value = pwm_values[id];
PWM_STATE_TOPIC[sizeof(MQTT_BASE_TOPIC) + 4] = ((id - id % 10) / 10) + '0';
PWM_STATE_TOPIC[sizeof(MQTT_BASE_TOPIC) + 5] = (id % 10) + '0';
PWM_VALUE_TOPIC[sizeof(MQTT_BASE_TOPIC) + 4] = ((id - id % 10) / 10) + '0';
PWM_VALUE_TOPIC[sizeof(MQTT_BASE_TOPIC) + 5] = (id % 10) + '0';
if (state == 1)
{
mqtt_client.publish(PWM_STATE_TOPIC, "on");
@ -345,7 +352,9 @@ void pwm_set_state(int id, int state)
int pwm_value = pwm_values[id];
ESPMega_analogWrite(pwm_pins[id], state * (int)(pwm_linear_scaling_m[id] * pwm_value + pwm_linear_scaling_c[id]));
if (lcd_current_page == 3)
panel.writeNum("j" + String(id) + ".pco", state?47829:12710);
panel.writeNum("j" + String(id) + ".pco", state ? 47829 : 12710);
else if (lcd_current_page == 5 && id == lcd_pwmAdj_id)
panel.writeStr("pwm_state.txt", pwm_states[lcd_pwmAdj_id] ? "ON" : "OFF");
publish_pwm_state(id);
}
}
@ -357,6 +366,8 @@ void pwm_set_value(int id, int value)
ESPMega_analogWrite(pwm_pins[id], pwm_state * (int)(pwm_linear_scaling_m[id] * value + pwm_linear_scaling_c[id]));
if (lcd_current_page == 3)
panel.writeNum("j" + String(id) + ".val", int(value / 4095.0 * 100.0));
else if (lcd_current_page == 5 && id == lcd_pwmAdj_id)
panel.writeNum("pwm_value.val", pwm_values[lcd_pwmAdj_id]);
publish_pwm_state(id);
}
@ -627,9 +638,14 @@ void lcd_refresh()
for (int i = 0; i <= 15; i++)
{
panel.writeNum("j" + String(i) + ".val", int(pwm_values[i] / 4095.0 * 100.0));
panel.writeNum("j" + String(i) + ".pco", pwm_states[i]?47829:12710);
panel.writeNum("j" + String(i) + ".pco", pwm_states[i] ? 47829 : 12710);
}
break;
case 5:
panel.writeStr("pwm_id.txt", String("P") + String(lcd_pwmAdj_id));
panel.writeStr("pwm_state.txt", pwm_states[lcd_pwmAdj_id] ? "ON" : "OFF");
panel.writeNum("pwm_value.val", pwm_values[lcd_pwmAdj_id]);
break;
default:
break;
}
@ -639,4 +655,35 @@ void lcd_top_bar_update()
panel.writeStr("time.txt", "NO RTC!");
panel.writeNum("server.pic", standalone ? 4 : 5);
panel.writeNum("lan.pic", ETH.linkUp() ? 3 : 2);
}
void trigger0()
{
if (lcd_pwmAdj_id >= 15)
lcd_pwmAdj_id = 0;
else
lcd_pwmAdj_id++;
lcd_refresh();
}
void trigger1()
{
if (lcd_pwmAdj_id <= 0)
lcd_pwmAdj_id = 15;
else
lcd_pwmAdj_id--;
lcd_refresh();
}
void trigger2()
{
pwm_toggle(lcd_pwmAdj_id);
}
void trigger3()
{
int value = panel.readNumber("pwm_value.val");
Serial.println(value);
lcd_send_stop_bit();
pwm_set_value(lcd_pwmAdj_id,value);
}