cud lcd implementation
This commit is contained in:
parent
97eb56d256
commit
1d775584db
Binary file not shown.
|
@ -314,11 +314,6 @@ bool NexButton::Set_background_image_pic(uint32_t number)
|
||||||
cmd += ".pic=";
|
cmd += ".pic=";
|
||||||
cmd += buf;
|
cmd += buf;
|
||||||
sendCommand(cmd.c_str());
|
sendCommand(cmd.c_str());
|
||||||
|
|
||||||
cmd = "";
|
|
||||||
cmd += "ref ";
|
|
||||||
cmd += getObjName();
|
|
||||||
sendCommand(cmd.c_str());
|
|
||||||
return recvRetCommandFinished();
|
return recvRetCommandFinished();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ char PWM_SET_VALUE_TOPIC[70];
|
||||||
|
|
||||||
// Infrared Transciever
|
// Infrared Transciever
|
||||||
#define IR_RECIEVE_PIN 35
|
#define IR_RECIEVE_PIN 35
|
||||||
#define IR_SEND_PIN 17
|
#define IR_SEND_PIN 12
|
||||||
#define MARK_EXCESS_MICROS 20
|
#define MARK_EXCESS_MICROS 20
|
||||||
#define RAW_BUFFER_LENGTH 750
|
#define RAW_BUFFER_LENGTH 750
|
||||||
|
|
||||||
|
|
|
@ -2,24 +2,24 @@
|
||||||
|
|
||||||
// AC Control Locking
|
// AC Control Locking
|
||||||
char AC_LOCK_TOPIC[75];
|
char AC_LOCK_TOPIC[75];
|
||||||
|
char AC_LOCK_REPORT_TOPIC[75];
|
||||||
#define AC_LOCK_ADDRESS 15002
|
#define AC_LOCK_ADDRESS 15002
|
||||||
bool ac_lock = false;
|
bool ac_lock = false;
|
||||||
|
|
||||||
// Display Componets
|
// Display Componets
|
||||||
NexText clock_txt = NexText(1, 2, "clock");
|
NexButton up_bt = NexButton(1, 2, "up_bt");
|
||||||
NexDSButton lt_bt = NexDSButton(1, 3, "lt_bt");
|
NexButton down_bt = NexButton(1, 3, "down_bt");
|
||||||
NexDSButton fan_bt = NexDSButton(1, 4, "fan_bt");
|
NexButton mode_off_btn = NexButton(1, 4, "mode_off_btn");
|
||||||
NexDSButton puri_bt = NexDSButton(1, 5, "puri_bt");
|
NexButton mode_fan_btn = NexButton(1, 5, "mode_fan_btn");
|
||||||
NexButton up_bt = NexButton(1, 6, "up_bt");
|
NexButton mode_cool_btn = NexButton(1, 6, "mode_cool_btn");
|
||||||
NexButton down_bt = NexButton(1, 7, "down_bt");
|
NexButton fan_auto_btn = NexButton(1, 7, "fan_auto_btn");
|
||||||
NexButton mode_off_btn = NexButton(1, 8, "mode_off_btn");
|
NexButton fan_1_btn = NexButton(1, 8, "fan_1_btn");
|
||||||
NexButton mode_fan_btn = NexButton(1, 9, "mode_fan_btn");
|
NexButton fan_2_btn = NexButton(1, 9, "fan_2_btn");
|
||||||
NexButton mode_cool_btn = NexButton(1, 10, "mode_cool_btn");
|
NexButton fan_3_btn = NexButton(1, 10, "fan_3_btn");
|
||||||
NexButton fan_auto_btn = NexButton(1, 11, "fan_auto_btn");
|
NexButton lt_bt = NexButton(1, 11, "lt_bt");
|
||||||
NexButton fan_1_btn = NexButton(1, 12, "fan_1_btn");
|
NexButton fan_bt = NexButton(1, 12, "fan_bt");
|
||||||
NexButton fan_2_btn = NexButton(1, 13, "fan_2_btn");
|
NexButton puri_bt = NexButton(1, 13, "puri_bt");
|
||||||
NexButton fan_3_btn = NexButton(1, 14, "fan_3_btn");
|
|
||||||
NexText temp_txt = NexText(1, 15, "temp_txt");
|
|
||||||
|
|
||||||
// List of Component ID Message to listen to
|
// List of Component ID Message to listen to
|
||||||
NexTouch *nex_listen_list[] =
|
NexTouch *nex_listen_list[] =
|
||||||
|
@ -52,19 +52,17 @@ This code will run after every component is initialized
|
||||||
*/
|
*/
|
||||||
void user_init()
|
void user_init()
|
||||||
{
|
{
|
||||||
ESPMega_EXTLCD.print("page dashboard");
|
elcd.print("page dashboard");
|
||||||
ESPMega_EXTLCD.write(0xFF);
|
elcd_sendstop();
|
||||||
ESPMega_EXTLCD.write(0xFF);
|
|
||||||
ESPMega_EXTLCD.write(0xFF);
|
|
||||||
memcpy(AC_LOCK_TOPIC, MQTT_BASE_TOPIC, 20);
|
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 = ESPMega_FRAM.read8(AC_LOCK_ADDRESS);
|
||||||
ac_lock = ac_lock > 1 ? 0 : ac_lock;
|
ac_lock = ac_lock > 1 ? 0 : ac_lock;
|
||||||
ESPMega_EXTLCD.print("dashboard.pic=");
|
elcd.print("dashboard.pic=");
|
||||||
ESPMega_EXTLCD.print(ac_lock ? "2" : "1");
|
elcd.print(ac_lock ? "2" : "1");
|
||||||
ESPMega_EXTLCD.write(0xFF);
|
elcd_sendstop();
|
||||||
ESPMega_EXTLCD.write(0xFF);
|
|
||||||
ESPMega_EXTLCD.write(0xFF);
|
|
||||||
mqtt.subscribe(AC_LOCK_TOPIC, ac_lock_callback);
|
mqtt.subscribe(AC_LOCK_TOPIC, ac_lock_callback);
|
||||||
lt_bt.attachPop(lt_btn_cb, <_bt);
|
lt_bt.attachPop(lt_btn_cb, <_bt);
|
||||||
fan_bt.attachPop(fan_btn_cb, &fan_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_1_btn.attachPop(fan_1_btn_cb, &fan_1_btn);
|
||||||
fan_2_btn.attachPop(fan_2_btn_cb, &fan_2_btn);
|
fan_2_btn.attachPop(fan_2_btn_cb, &fan_2_btn);
|
||||||
fan_3_btn.attachPop(fan_3_btn_cb, &fan_3_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)
|
void pwm_changed_user_callback(int pin)
|
||||||
{
|
{
|
||||||
if ((pin == LIGHT1_PIN) || (pin == LIGHT2_PIN) || (pin == LIGHT3_PIN) || (pin = LIGHT4_PIN))
|
pwm_update_lcd();
|
||||||
{
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -120,10 +110,9 @@ This code will run every 15 seconds
|
||||||
*/
|
*/
|
||||||
void timer_tick_callback()
|
void timer_tick_callback()
|
||||||
{
|
{
|
||||||
char time_buffer[15];
|
|
||||||
rtctime_t time = ESPMega_getTime();
|
rtctime_t time = ESPMega_getTime();
|
||||||
sprintf(time_buffer, "%02d:%02d", time.hours, time.minutes);
|
elcd.printf("clock.txt=\"%02d:%02d\"", time.hours, time.minutes);
|
||||||
clock_txt.setText(time_buffer);
|
elcd_sendstop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void lt_btn_cb(void *comp)
|
void lt_btn_cb(void *comp)
|
||||||
|
@ -140,19 +129,21 @@ void puri_btn_cb(void *comp)
|
||||||
}
|
}
|
||||||
void temp_up_btn_cb(void *comp)
|
void temp_up_btn_cb(void *comp)
|
||||||
{
|
{
|
||||||
|
Serial.println("UPCB");
|
||||||
if (!ac_lock)
|
if (!ac_lock)
|
||||||
{
|
{
|
||||||
uint8_t new_temp = ac_get_temperature();
|
|
||||||
ac_set_state(ac_get_mode(), ac_get_temperature() + 1, ac_get_fan_speed());
|
ac_set_state(ac_get_mode(), ac_get_temperature() + 1, ac_get_fan_speed());
|
||||||
}
|
}
|
||||||
|
Serial.println("UPCBEND");
|
||||||
}
|
}
|
||||||
void temp_down_btn_cb(void *comp)
|
void temp_down_btn_cb(void *comp)
|
||||||
{
|
{
|
||||||
|
Serial.println("DOWNCB");
|
||||||
if (!ac_lock)
|
if (!ac_lock)
|
||||||
{
|
{
|
||||||
uint8_t new_temp = ac_get_temperature();
|
|
||||||
ac_set_state(ac_get_mode(), ac_get_temperature() - 1, ac_get_fan_speed());
|
ac_set_state(ac_get_mode(), ac_get_temperature() - 1, ac_get_fan_speed());
|
||||||
}
|
}
|
||||||
|
Serial.println("DOWNCBEND");
|
||||||
}
|
}
|
||||||
void mode_cool_btn_cb(void *comp)
|
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);
|
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];
|
ac_update_lcd();
|
||||||
sprintf(temp_text, "%dC", temperature);
|
}
|
||||||
temp_txt.setText(temp_text);
|
|
||||||
mode_off_btn.Set_background_image_pic(mode == 0 ? 14 : 13);
|
void ac_update_lcd() {
|
||||||
mode_fan_btn.Set_background_image_pic(mode == 2 ? 16 : 15);
|
uint8_t temperature = ac_get_temperature();
|
||||||
mode_cool_btn.Set_background_image_pic(mode == 1 ? 18 : 17);
|
uint8_t mode = ac_get_mode();
|
||||||
fan_auto_btn.Set_background_image_pic(fan_speed == 0 ? 20 : 19);
|
uint8_t fan_speed = ac_get_fan_speed();
|
||||||
fan_1_btn.Set_background_image_pic(fan_speed == 3 ? 22 : 21);
|
elcd_sendstop();
|
||||||
fan_2_btn.Set_background_image_pic(fan_speed == 2 ? 24 : 23);
|
elcd.print("temp_txt.txt=\"");
|
||||||
fan_3_btn.Set_background_image_pic(fan_speed == 1 ? 26 : 25);
|
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)
|
void ac_lock_callback(String topic, String payload)
|
||||||
|
@ -243,20 +257,39 @@ void ac_lock_callback(String topic, String payload)
|
||||||
{
|
{
|
||||||
ac_lock = true;
|
ac_lock = true;
|
||||||
ESPMega_FRAM.write8(AC_LOCK_ADDRESS, ac_lock);
|
ESPMega_FRAM.write8(AC_LOCK_ADDRESS, ac_lock);
|
||||||
ESPMega_EXTLCD.print("dashboard.pic=");
|
elcd.print("dashboard.pic=");
|
||||||
ESPMega_EXTLCD.print(ac_lock ? "2" : "1");
|
elcd.print(ac_lock ? "2" : "1");
|
||||||
ESPMega_EXTLCD.write(0xFF);
|
elcd_sendstop();
|
||||||
ESPMega_EXTLCD.write(0xFF);
|
|
||||||
ESPMega_EXTLCD.write(0xFF);
|
|
||||||
}
|
}
|
||||||
else if (payload.equals("unlock"))
|
else if (payload.equals("unlock"))
|
||||||
{
|
{
|
||||||
ac_lock = false;
|
ac_lock = false;
|
||||||
ESPMega_FRAM.write8(AC_LOCK_ADDRESS, ac_lock);
|
ESPMega_FRAM.write8(AC_LOCK_ADDRESS, ac_lock);
|
||||||
ESPMega_EXTLCD.print("dashboard.pic=");
|
elcd.print("dashboard.pic=");
|
||||||
ESPMega_EXTLCD.print(ac_lock ? "2" : "1");
|
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);
|
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();
|
||||||
}
|
}
|
|
@ -39,6 +39,7 @@ I0-I2: Fan Switch
|
||||||
|
|
||||||
#ifdef ENABLE_EXTERNAL_LCD
|
#ifdef ENABLE_EXTERNAL_LCD
|
||||||
#define ESPMega_EXTLCD Serial2
|
#define ESPMega_EXTLCD Serial2
|
||||||
|
#define elcd ESPMega_EXTLCD
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// User Defined Functions
|
// User Defined Functions
|
||||||
|
@ -47,7 +48,7 @@ void user_init();
|
||||||
void user_loop();
|
void user_loop();
|
||||||
void virtual_interrupt_user_callback(int pin, int state);
|
void virtual_interrupt_user_callback(int pin, int state);
|
||||||
void pwm_changed_user_callback(int pin);
|
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 timer_tick_callback();
|
||||||
void lt_btn_cb(void *comp);
|
void lt_btn_cb(void *comp);
|
||||||
void fan_btn_cb(void *comp);
|
void fan_btn_cb(void *comp);
|
||||||
|
@ -66,7 +67,9 @@ bool cud_light_group_state();
|
||||||
void cud_fan_toggle();
|
void cud_fan_toggle();
|
||||||
bool cud_fan_group_state();
|
bool cud_fan_group_state();
|
||||||
void ac_lock_callback(String topic, String payload);
|
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
|
// ESPMega IoT Core Build-in Functions
|
||||||
extern void pwm_set_state(int id, int state);
|
extern void pwm_set_state(int id, int state);
|
||||||
|
|
Loading…
Reference in New Issue