cud lcd implementation

This commit is contained in:
Siwat Sirichai 2023-10-03 02:01:55 +07:00
parent 97eb56d256
commit 1d775584db
5 changed files with 101 additions and 70 deletions

Binary file not shown.

View File

@ -314,11 +314,6 @@ bool NexButton::Set_background_image_pic(uint32_t number)
cmd += ".pic=";
cmd += buf;
sendCommand(cmd.c_str());
cmd = "";
cmd += "ref ";
cmd += getObjName();
sendCommand(cmd.c_str());
return recvRetCommandFinished();
}

View File

@ -49,7 +49,7 @@ char PWM_SET_VALUE_TOPIC[70];
// Infrared Transciever
#define IR_RECIEVE_PIN 35
#define IR_SEND_PIN 17
#define IR_SEND_PIN 12
#define MARK_EXCESS_MICROS 20
#define RAW_BUFFER_LENGTH 750

View File

@ -2,24 +2,24 @@
// AC Control Locking
char AC_LOCK_TOPIC[75];
char AC_LOCK_REPORT_TOPIC[75];
#define AC_LOCK_ADDRESS 15002
bool ac_lock = false;
// Display Componets
NexText clock_txt = NexText(1, 2, "clock");
NexDSButton lt_bt = NexDSButton(1, 3, "lt_bt");
NexDSButton fan_bt = NexDSButton(1, 4, "fan_bt");
NexDSButton puri_bt = NexDSButton(1, 5, "puri_bt");
NexButton up_bt = NexButton(1, 6, "up_bt");
NexButton down_bt = NexButton(1, 7, "down_bt");
NexButton mode_off_btn = NexButton(1, 8, "mode_off_btn");
NexButton mode_fan_btn = NexButton(1, 9, "mode_fan_btn");
NexButton mode_cool_btn = NexButton(1, 10, "mode_cool_btn");
NexButton fan_auto_btn = NexButton(1, 11, "fan_auto_btn");
NexButton fan_1_btn = NexButton(1, 12, "fan_1_btn");
NexButton fan_2_btn = NexButton(1, 13, "fan_2_btn");
NexButton fan_3_btn = NexButton(1, 14, "fan_3_btn");
NexText temp_txt = NexText(1, 15, "temp_txt");
NexButton up_bt = NexButton(1, 2, "up_bt");
NexButton down_bt = NexButton(1, 3, "down_bt");
NexButton mode_off_btn = NexButton(1, 4, "mode_off_btn");
NexButton mode_fan_btn = NexButton(1, 5, "mode_fan_btn");
NexButton mode_cool_btn = NexButton(1, 6, "mode_cool_btn");
NexButton fan_auto_btn = NexButton(1, 7, "fan_auto_btn");
NexButton fan_1_btn = NexButton(1, 8, "fan_1_btn");
NexButton fan_2_btn = NexButton(1, 9, "fan_2_btn");
NexButton fan_3_btn = NexButton(1, 10, "fan_3_btn");
NexButton lt_bt = NexButton(1, 11, "lt_bt");
NexButton fan_bt = NexButton(1, 12, "fan_bt");
NexButton puri_bt = NexButton(1, 13, "puri_bt");
// List of Component ID Message to listen to
NexTouch *nex_listen_list[] =
@ -52,19 +52,17 @@ This code will run after every component is initialized
*/
void user_init()
{
ESPMega_EXTLCD.print("page dashboard");
ESPMega_EXTLCD.write(0xFF);
ESPMega_EXTLCD.write(0xFF);
ESPMega_EXTLCD.write(0xFF);
elcd.print("page dashboard");
elcd_sendstop();
memcpy(AC_LOCK_TOPIC, MQTT_BASE_TOPIC, 20);
strcat(AC_LOCK_TOPIC, "/ac/lock");
strcat(AC_LOCK_TOPIC, "/ac/lock/set");
memcpy(AC_LOCK_REPORT_TOPIC, MQTT_BASE_TOPIC, 20);
strcat(AC_LOCK_REPORT_TOPIC, "/ac/lock");
ac_lock = ESPMega_FRAM.read8(AC_LOCK_ADDRESS);
ac_lock = ac_lock > 1 ? 0 : ac_lock;
ESPMega_EXTLCD.print("dashboard.pic=");
ESPMega_EXTLCD.print(ac_lock ? "2" : "1");
ESPMega_EXTLCD.write(0xFF);
ESPMega_EXTLCD.write(0xFF);
ESPMega_EXTLCD.write(0xFF);
elcd.print("dashboard.pic=");
elcd.print(ac_lock ? "2" : "1");
elcd_sendstop();
mqtt.subscribe(AC_LOCK_TOPIC, ac_lock_callback);
lt_bt.attachPop(lt_btn_cb, &lt_bt);
fan_bt.attachPop(fan_btn_cb, &fan_bt);
@ -78,6 +76,9 @@ void user_init()
fan_1_btn.attachPop(fan_1_btn_cb, &fan_1_btn);
fan_2_btn.attachPop(fan_2_btn_cb, &fan_2_btn);
fan_3_btn.attachPop(fan_3_btn_cb, &fan_3_btn);
ac_update_lcd();
pwm_update_lcd();
timer_tick_callback();
}
/*
@ -101,18 +102,7 @@ void virtual_interrupt_user_callback(int pin, int state)
void pwm_changed_user_callback(int pin)
{
if ((pin == LIGHT1_PIN) || (pin == LIGHT2_PIN) || (pin == LIGHT3_PIN) || (pin = LIGHT4_PIN))
{
lt_bt.setValue(cud_light_group_state());
}
else if (pin == FAN1_PIN || pin == FAN2_PIN || pin == FAN3_PIN)
{
fan_bt.setValue(cud_fan_group_state());
}
else if (pin == AIR_PURIFIER_PIN)
{
puri_bt.setValue(pwm_get_state(pin));
}
pwm_update_lcd();
}
/*
@ -120,10 +110,9 @@ This code will run every 15 seconds
*/
void timer_tick_callback()
{
char time_buffer[15];
rtctime_t time = ESPMega_getTime();
sprintf(time_buffer, "%02d:%02d", time.hours, time.minutes);
clock_txt.setText(time_buffer);
elcd.printf("clock.txt=\"%02d:%02d\"", time.hours, time.minutes);
elcd_sendstop();
}
void lt_btn_cb(void *comp)
@ -140,19 +129,21 @@ void puri_btn_cb(void *comp)
}
void temp_up_btn_cb(void *comp)
{
Serial.println("UPCB");
if (!ac_lock)
{
uint8_t new_temp = ac_get_temperature();
ac_set_state(ac_get_mode(), ac_get_temperature() + 1, ac_get_fan_speed());
}
Serial.println("UPCBEND");
}
void temp_down_btn_cb(void *comp)
{
Serial.println("DOWNCB");
if (!ac_lock)
{
uint8_t new_temp = ac_get_temperature();
ac_set_state(ac_get_mode(), ac_get_temperature() - 1, ac_get_fan_speed());
}
Serial.println("DOWNCBEND");
}
void mode_cool_btn_cb(void *comp)
{
@ -223,18 +214,41 @@ bool cud_fan_group_state()
return pwm_get_state(FAN1_PIN) || pwm_get_state(FAN2_PIN) || pwm_get_state(FAN3_PIN);
}
void ac_changed_user_callback(int mode, int temperature, int fan_speed)
void ac_changed_user_callback(uint8_t mode, uint8_t temperature, uint8_t fan_speed)
{
char temp_text[3];
sprintf(temp_text, "%dC", temperature);
temp_txt.setText(temp_text);
mode_off_btn.Set_background_image_pic(mode == 0 ? 14 : 13);
mode_fan_btn.Set_background_image_pic(mode == 2 ? 16 : 15);
mode_cool_btn.Set_background_image_pic(mode == 1 ? 18 : 17);
fan_auto_btn.Set_background_image_pic(fan_speed == 0 ? 20 : 19);
fan_1_btn.Set_background_image_pic(fan_speed == 3 ? 22 : 21);
fan_2_btn.Set_background_image_pic(fan_speed == 2 ? 24 : 23);
fan_3_btn.Set_background_image_pic(fan_speed == 1 ? 26 : 25);
ac_update_lcd();
}
void ac_update_lcd() {
uint8_t temperature = ac_get_temperature();
uint8_t mode = ac_get_mode();
uint8_t fan_speed = ac_get_fan_speed();
elcd_sendstop();
elcd.print("temp_txt.txt=\"");
elcd.print(temperature);
elcd.print("C\"");
elcd_sendstop();
elcd.print("mode_off_btn.pic=");
elcd.print(mode == 0 ? 14 : 13);
elcd_sendstop();
elcd.print("mode_fan_btn.pic=");
elcd.print(mode == 2 ? 16 : 15);
elcd_sendstop();
elcd.print("mode_cool_btn.pic=");
elcd.print(mode == 1 ? 18 : 17);
elcd_sendstop();
elcd.print("fan_auto_btn.pic=");
elcd.print(fan_speed == 0 ? 20 : 19);
elcd_sendstop();
elcd.print("fan_1_btn.pic=");
elcd.print(fan_speed == 3 ? 22 : 21);
elcd_sendstop();
elcd.print("fan_2_btn.pic=");
elcd.print(fan_speed == 2 ? 24 : 23);
elcd_sendstop();
elcd.print("fan_3_btn.pic=");
elcd.print(fan_speed == 1 ? 26 : 25);
elcd_sendstop();
}
void ac_lock_callback(String topic, String payload)
@ -243,20 +257,39 @@ void ac_lock_callback(String topic, String payload)
{
ac_lock = true;
ESPMega_FRAM.write8(AC_LOCK_ADDRESS, ac_lock);
ESPMega_EXTLCD.print("dashboard.pic=");
ESPMega_EXTLCD.print(ac_lock ? "2" : "1");
ESPMega_EXTLCD.write(0xFF);
ESPMega_EXTLCD.write(0xFF);
ESPMega_EXTLCD.write(0xFF);
elcd.print("dashboard.pic=");
elcd.print(ac_lock ? "2" : "1");
elcd_sendstop();
}
else if (payload.equals("unlock"))
{
ac_lock = false;
ESPMega_FRAM.write8(AC_LOCK_ADDRESS, ac_lock);
ESPMega_EXTLCD.print("dashboard.pic=");
ESPMega_EXTLCD.print(ac_lock ? "2" : "1");
ESPMega_EXTLCD.write(0xFF);
ESPMega_EXTLCD.write(0xFF);
ESPMega_EXTLCD.write(0xFF);
elcd.print("dashboard.pic=");
elcd.print(ac_lock ? "2" : "1");
elcd_sendstop();
}
ac_lock_report();
}
void ac_lock_report() {
mqtt_client.publish(AC_LOCK_REPORT_TOPIC,ac_lock?"lock":"unlock");
}
void elcd_sendstop() {
ESPMega_EXTLCD.write(0xFF);
ESPMega_EXTLCD.write(0xFF);
ESPMega_EXTLCD.write(0xFF);
}
void pwm_update_lcd() {
elcd.print("lt_bt.pic=");
elcd.print(cud_light_group_state()?4:3);
elcd_sendstop();
elcd.print("fan_bt.pic=");
elcd.print(cud_fan_group_state()?6:5);
elcd_sendstop();
elcd.print("puri_bt.pic=");
elcd.print(pwm_get_state(AIR_PURIFIER_PIN)?8:7);
elcd_sendstop();
}

View File

@ -39,6 +39,7 @@ I0-I2: Fan Switch
#ifdef ENABLE_EXTERNAL_LCD
#define ESPMega_EXTLCD Serial2
#define elcd ESPMega_EXTLCD
#endif
// User Defined Functions
@ -47,7 +48,7 @@ void user_init();
void user_loop();
void virtual_interrupt_user_callback(int pin, int state);
void pwm_changed_user_callback(int pin);
void ac_changed_user_callback(int mode, int temperature, int fan_speed);
void ac_changed_user_callback(uint8_t mode, uint8_t temperature, uint8_t fan_speed);
void timer_tick_callback();
void lt_btn_cb(void *comp);
void fan_btn_cb(void *comp);
@ -66,7 +67,9 @@ bool cud_light_group_state();
void cud_fan_toggle();
bool cud_fan_group_state();
void ac_lock_callback(String topic, String payload);
void elcd_sendstop();
void ac_update_lcd();
void pwm_update_lcd();
// ESPMega IoT Core Build-in Functions
extern void pwm_set_state(int id, int state);