From 5887862992d78ab36554739f8f6997f038a411f8 Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Sat, 23 Mar 2024 16:16:33 +0700 Subject: [PATCH] socket contact state display --- src/config.hpp | 3 ++- src/display.cpp | 15 +++++++++++++++ src/display.hpp | 2 ++ src/main.cpp | 3 ++- 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/config.hpp b/src/config.hpp index 0cd93b2..f61d2eb 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -16,7 +16,8 @@ #define AIR_PURIFIER_PIN 7 // There are one power relay for the mosquito zapper #define MOSQUITO_ZAPPER_PIN 8 - +// There are one power relay for the socket +#define SOCKET_CONTACTOR_PIN 9 /*********************************************** * Air Conditioner * ***********************************************/ diff --git a/src/display.cpp b/src/display.cpp index 39680f5..1b68308 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -236,6 +236,13 @@ void CUDDisplay::handle_output_change(uint8_t pin, bool state) return; } + // Check if it's the socket contactor + if (pin == this->conf->socket_contactor_pin) + { + this->refresh_display_socket(); + return; + } + // Loop through each to check if the pin is a light for (int i = 0; i < 4; i++) { @@ -657,6 +664,7 @@ void CUDDisplay::refresh_display() } refresh_display_ac(); refresh_display_allsystem(); + refresh_display_socket(); } void CUDDisplay::refresh_display_ac() @@ -749,6 +757,13 @@ void CUDDisplay::refresh_display_allsystem() this->giveSerialMutex(); } +void CUDDisplay::refresh_display_socket() { + this->takeSerialMutex(); + this->displayAdapter->printf("%s.pic=%d", LCD_DASHBOARD_ELEMENT_NAME_SOCKET_POWER, this->cards.outputCard->getState(this->conf->socket_contactor_pin) ? LCD_DASHBOARD_PIC_SOCKET_POWER_ON: LCD_DASHBOARD_PIC_SOCKET_POWER_OFF); + this->sendStopBytes(); + this->giveSerialMutex(); +} + bool CUDDisplay::get_system_state() { // The system state is defined to be on when any of the lights, fans, air purifier, mosquito zapper or AC is on diff --git a/src/display.hpp b/src/display.hpp index 3e7e50e..88e6c1f 100644 --- a/src/display.hpp +++ b/src/display.hpp @@ -32,6 +32,7 @@ struct cud_display_conf_t uint8_t fan_pins[3]; uint8_t air_purifier_pin; uint8_t mosquito_zapper_pin; + uint8_t socket_contactor_pin; }; struct cud_display_cards_t @@ -98,6 +99,7 @@ private: void refresh_display(); void refresh_display_ac(); void refresh_display_allsystem(); + void refresh_display_socket(); // Helper Functions bool get_system_state(); void system_toggle(); diff --git a/src/main.cpp b/src/main.cpp index 59c1925..5111ecd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -28,7 +28,8 @@ cud_display_conf_t cud_display_conf = { .light_pins = {LIGHT_ROW_1_PIN, LIGHT_ROW_2_PIN, LIGHT_ROW_3_PIN, LIGHT_ROW_4_PIN}, .fan_pins = {FAN_ROW_1_PIN, FAN_ROW_2_PIN, FAN_ROW_3_PIN}, .air_purifier_pin = AIR_PURIFIER_PIN, - .mosquito_zapper_pin = MOSQUITO_ZAPPER_PIN}; + .mosquito_zapper_pin = MOSQUITO_ZAPPER_PIN, + .socket_contactor_pin = SOCKET_CONTACTOR_PIN}; CUDDisplay cudDisplay = CUDDisplay(&cud_display_conf);