From c718750c45296f6db2b32a7efc5e096e4bad1fa7 Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Thu, 11 Jan 2024 21:29:49 +0700 Subject: [PATCH] update ids --- platformio.ini | 3 +- src/cud_display.cpp | 51 +++++++++++++++++++++++-------- src/cud_display.hpp | 74 ++++++++++++++++++++++++--------------------- src/main.cpp | 5 +-- 4 files changed, 84 insertions(+), 49 deletions(-) diff --git a/platformio.ini b/platformio.ini index d5cb6f5..1e2820e 100644 --- a/platformio.ini +++ b/platformio.ini @@ -12,4 +12,5 @@ platform = espressif32 board = wt32-eth01 framework = arduino -lib_deps = siwats/ESPMegaProR3@^2.0.1 +lib_deps = siwats/ESPMegaProR3@^2.0.2 +monitor_speed = 115200 \ No newline at end of file diff --git a/src/cud_display.cpp b/src/cud_display.cpp index 651f093..2f8190c 100644 --- a/src/cud_display.cpp +++ b/src/cud_display.cpp @@ -8,7 +8,6 @@ void CUDDisplay::begin(std::function getTime, HardwareSerial *seria DigitalInputCard *inputCard, DigitalOutputCard *outputCard, ClimateCard *climateCard) { - ESPMegaDisplay::begin(); this->getTime = getTime; this->sendClock(); this->inputCard = inputCard; @@ -16,12 +15,20 @@ void CUDDisplay::begin(std::function getTime, HardwareSerial *seria this->climateCard = climateCard; auto bindedHandlePWMChange = std::bind(&CUDDisplay::handlePWMChange, this, std::placeholders::_1, std::placeholders::_2); auto bindedHandleACChange = std::bind(&CUDDisplay::handleACChange, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3); + auto bindedHandleTouch = std::bind(&CUDDisplay::handleTouch, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3); this->outputCallbackHandle = this->outputCard->registerChangeCallback(bindedHandlePWMChange); this->climateCallbackHandle = this->climateCard->registerChangeCallback(bindedHandleACChange); + this->registerTouchCallback(bindedHandleTouch); + this->reset(); + delay(500); + this->jumpToPage(1); + delay(100); + this->setACControlEnabled(true); } void CUDDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t event) { + Serial.printf("Touch Event on Page %d, Component %d, Event %d\n", page, component, event); if (page != PAGE_DASHBOARD) return; switch (component) @@ -42,46 +49,55 @@ void CUDDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t event) this->outputCard->setState(7, !this->outputCard->getState(7)); break; case COMPONENT_AC_TEMP_UP_BUTTON: + if (!ac_control_enabled) break; if (event != TOUCH_TYPE_RELEASE) break; this->climateCard->setTemperature(this->climateCard->getTemperature() + 1); break; case COMPONENT_AC_TEMP_DOWN_BUTTON: + if (!ac_control_enabled) break; if (event != TOUCH_TYPE_RELEASE) break; this->climateCard->setTemperature(this->climateCard->getTemperature() - 1); break; case COMPONENT_AC_MODE_OFF_BUTTON: + if (!ac_control_enabled) break; if (event != TOUCH_TYPE_RELEASE) break; this->climateCard->setMode(0); break; case COMPONENT_AC_MODE_FAN_ONLY_BUTTON: + if (!ac_control_enabled) break; if (event != TOUCH_TYPE_RELEASE) break; this->climateCard->setMode(1); break; case COMPONENT_AC_MODE_COOL_BUTTON: + if (!ac_control_enabled) break; if (event != TOUCH_TYPE_RELEASE) break; this->climateCard->setMode(2); break; case COMPONENT_AC_FAN_MODE_AUTO_BUTTON: + if (!ac_control_enabled) break; if (event != TOUCH_TYPE_RELEASE) break; this->climateCard->setFanSpeed(0); break; case COMPONENT_AC_FAN_MODE_LOW_BUTTON: + if (!ac_control_enabled) break; if (event != TOUCH_TYPE_RELEASE) break; this->climateCard->setFanSpeed(1); break; case COMPONENT_AC_FAN_MODE_MEDIUM_BUTTON: + if (!ac_control_enabled) break; if (event != TOUCH_TYPE_RELEASE) break; this->climateCard->setFanSpeed(2); break; case COMPONENT_AC_FAN_MODE_HIGH_BUTTON: + if (!ac_control_enabled) break; if (event != TOUCH_TYPE_RELEASE) break; this->climateCard->setFanSpeed(3); @@ -185,7 +201,7 @@ void CUDDisplay::updateLightGroupState() { // Calculate the state bool state = calculateLightGroupState(); // Send the state to the display - this->displayAdapter->print("LT_BT.pic="); + this->displayAdapter->print("lt_bt.pic="); this->displayAdapter->println(state ? COMPONENT_LIGHT_TOGGLE_PIC_ON : COMPONENT_LIGHT_TOGGLE_PIC_OFF); this->sendStopBytes(); } @@ -193,7 +209,7 @@ void CUDDisplay::updateFanGroupState() { // Calculate the state bool state = calculateFanGroupState(); // Send the state to the display - this->displayAdapter->print("FAN_BT.pic="); + this->displayAdapter->print("fan_bt.pic="); this->displayAdapter->println(state ? COMPONENT_FAN_TOGGLE_PIC_ON : COMPONENT_FAN_TOGGLE_PIC_OFF); this->sendStopBytes(); } @@ -201,7 +217,7 @@ void CUDDisplay::updateAirPurifierState() { // Get the state bool state = this->outputCard->getState(7); // Send the state to the display - this->displayAdapter->print("AIR_BT.pic="); + this->displayAdapter->print("puri_bt.pic="); this->displayAdapter->println(state ? COMPONENT_AIR_PURIFIER_TOGGLE_PIC_ON : COMPONENT_AIR_PURIFIER_TOGGLE_PIC_OFF); this->sendStopBytes(); } @@ -211,28 +227,39 @@ void CUDDisplay::updateACState() { uint8_t fan_speed = this->climateCard->getFanSpeed(); uint8_t temperature = this->climateCard->getTemperature(); // Send the state to the display - this->displayAdapter->print("AC_MODE_OFF.pic="); + this->displayAdapter->print("mode_off_btn.pic="); this->displayAdapter->println(mode == 0 ? COMPONENT_AC_MODE_OFF_PIC_ACTIVE : COMPONENT_AC_MODE_OFF_PIC_INACTIVE); this->sendStopBytes(); - this->displayAdapter->print("AC_MODE_FAN_ONLY.pic="); + this->displayAdapter->print("mode_fan_btn.pic="); this->displayAdapter->println(mode == 1 ? COMPONENT_AC_MODE_FAN_ONLY_PIC_ACTIVE : COMPONENT_AC_MODE_FAN_ONLY_PIC_INACTIVE); this->sendStopBytes(); - this->displayAdapter->print("AC_MODE_COOL.pic="); + this->displayAdapter->print("mode_cool_btn.pic="); this->displayAdapter->println(mode == 2 ? COMPONENT_AC_MODE_COOL_PIC_ACTIVE : COMPONENT_AC_MODE_COOL_PIC_INACTIVE); this->sendStopBytes(); - this->displayAdapter->print("AC_FAN_MODE_AUTO.pic="); + this->displayAdapter->print("fan_auto_btn.pic="); this->displayAdapter->println(fan_speed == 0 ? COMPONENT_AC_FAN_MODE_AUTO_PIC_ACTIVE : COMPONENT_AC_FAN_MODE_AUTO_PIC_INACTIVE); this->sendStopBytes(); - this->displayAdapter->print("AC_FAN_MODE_HIGH.pic="); + this->displayAdapter->print("fan_1_btn.pic="); this->displayAdapter->println(fan_speed == 1 ? COMPONENT_AC_FAN_MODE_HIGH_PIC_ACTIVE : COMPONENT_AC_FAN_MODE_HIGH_PIC_INACTIVE); this->sendStopBytes(); - this->displayAdapter->print("AC_FAN_MODE_MEDIUM.pic="); + this->displayAdapter->print("fan_2_btn.pic="); this->displayAdapter->println(fan_speed == 2 ? COMPONENT_AC_FAN_MODE_MEDIUM_PIC_ACTIVE : COMPONENT_AC_FAN_MODE_MEDIUM_PIC_INACTIVE); this->sendStopBytes(); - this->displayAdapter->print("AC_FAN_MODE_LOW.pic="); + this->displayAdapter->print("fan_3_btn.pic="); this->displayAdapter->println(fan_speed == 3 ? COMPONENT_AC_FAN_MODE_LOW_PIC_ACTIVE : COMPONENT_AC_FAN_MODE_LOW_PIC_INACTIVE); this->sendStopBytes(); - this->displayAdapter->print("AC_TEMP.val="); + this->displayAdapter->print("temp_txt.txt="); this->displayAdapter->println(temperature); + this->displayAdapter->print("C"); this->sendStopBytes(); } + +void CUDDisplay::setACControlEnabled(bool enabled) { + ac_control_enabled = enabled; + this->displayAdapter->print("dashboard.pic="); + this->displayAdapter->print(enabled ? COMPONENT_BACKGROUND_AC_UNLOCK : COMPONENT_BACKGROUND_AC_LOCK); + this->sendStopBytes(); +} +bool CUDDisplay::getACControlEnabled() { + return ac_control_enabled; +} \ No newline at end of file diff --git a/src/cud_display.hpp b/src/cud_display.hpp index c7a140c..1e1588e 100644 --- a/src/cud_display.hpp +++ b/src/cud_display.hpp @@ -13,48 +13,51 @@ Pin Mapping */ // Touch Types -#define TOUCH_TYPE_PRESS 0 -#define TOUCH_TYPE_RELEASE 1 +#define TOUCH_TYPE_PRESS 1 +#define TOUCH_TYPE_RELEASE 0 // Page IDs #define PAGE_BOOT 0 #define PAGE_DASHBOARD 1 // Dashboard Toggle Buttons -#define COMPONENT_LIGHT_TOGGLE_BUTTON 1 -#define COMPONENT_LIGHT_TOGGLE_PIC_ON 11 -#define COMPONENT_LIGHT_TOGGLE_PIC_OFF 12 -#define COMPONENT_FAN_TOGGLE_BUTTON 2 -#define COMPONENT_FAN_TOGGLE_PIC_ON 21 -#define COMPONENT_FAN_TOGGLE_PIC_OFF 22 -#define COMPONENT_AIR_PURIFIER_TOGGLE_BUTTON 3 -#define COMPONENT_AIR_PURIFIER_TOGGLE_PIC_ON 31 -#define COMPONENT_AIR_PURIFIER_TOGGLE_PIC_OFF 32 +#define COMPONENT_LIGHT_TOGGLE_BUTTON 11 +#define COMPONENT_LIGHT_TOGGLE_PIC_ON 4 +#define COMPONENT_LIGHT_TOGGLE_PIC_OFF 3 +#define COMPONENT_FAN_TOGGLE_BUTTON 12 +#define COMPONENT_FAN_TOGGLE_PIC_ON 6 +#define COMPONENT_FAN_TOGGLE_PIC_OFF 5 +#define COMPONENT_AIR_PURIFIER_TOGGLE_BUTTON 13 +#define COMPONENT_AIR_PURIFIER_TOGGLE_PIC_ON 8 +#define COMPONENT_AIR_PURIFIER_TOGGLE_PIC_OFF 7 // Dashboard AC Controls -#define COMPONENT_AC_TEMP_UP_BUTTON 4 -#define COMPONENT_AC_TEMP_DOWN_BUTTON 5 -#define COMPONENT_AC_MODE_OFF_BUTTON 6 -#define COMPONENT_AC_MODE_OFF_PIC_ACTIVE 61 -#define COMPONENT_AC_MODE_OFF_PIC_INACTIVE 62 -#define COMPONENT_AC_MODE_FAN_ONLY_BUTTON 7 -#define COMPONENT_AC_MODE_FAN_ONLY_PIC_ACTIVE 71 -#define COMPONENT_AC_MODE_FAN_ONLY_PIC_INACTIVE 72 -#define COMPONENT_AC_MODE_COOL_BUTTON 8 -#define COMPONENT_AC_MODE_COOL_PIC_ACTIVE 81 -#define COMPONENT_AC_MODE_COOL_PIC_INACTIVE 82 -#define COMPONENT_AC_FAN_MODE_AUTO_BUTTON 9 -#define COMPONENT_AC_FAN_MODE_AUTO_PIC_ACTIVE 91 -#define COMPONENT_AC_FAN_MODE_AUTO_PIC_INACTIVE 92 -#define COMPONENT_AC_FAN_MODE_LOW_BUTTON 10 -#define COMPONENT_AC_FAN_MODE_LOW_PIC_ACTIVE 101 -#define COMPONENT_AC_FAN_MODE_LOW_PIC_INACTIVE 102 -#define COMPONENT_AC_FAN_MODE_MEDIUM_BUTTON 11 -#define COMPONENT_AC_FAN_MODE_MEDIUM_PIC_ACTIVE 111 -#define COMPONENT_AC_FAN_MODE_MEDIUM_PIC_INACTIVE 112 -#define COMPONENT_AC_FAN_MODE_HIGH_BUTTON 12 -#define COMPONENT_AC_FAN_MODE_HIGH_PIC_ACTIVE 121 -#define COMPONENT_AC_FAN_MODE_HIGH_PIC_INACTIVE 122 +#define COMPONENT_AC_TEMP_UP_BUTTON 2 +#define COMPONENT_AC_TEMP_DOWN_BUTTON 3 +#define COMPONENT_AC_MODE_OFF_BUTTON 4 +#define COMPONENT_AC_MODE_OFF_PIC_ACTIVE 14 +#define COMPONENT_AC_MODE_OFF_PIC_INACTIVE 13 +#define COMPONENT_AC_MODE_FAN_ONLY_BUTTON 5 +#define COMPONENT_AC_MODE_FAN_ONLY_PIC_ACTIVE 16 +#define COMPONENT_AC_MODE_FAN_ONLY_PIC_INACTIVE 15 +#define COMPONENT_AC_MODE_COOL_BUTTON 6 +#define COMPONENT_AC_MODE_COOL_PIC_ACTIVE 18 +#define COMPONENT_AC_MODE_COOL_PIC_INACTIVE 17 +#define COMPONENT_AC_FAN_MODE_AUTO_BUTTON 7 +#define COMPONENT_AC_FAN_MODE_AUTO_PIC_ACTIVE 20 +#define COMPONENT_AC_FAN_MODE_AUTO_PIC_INACTIVE 19 +#define COMPONENT_AC_FAN_MODE_LOW_BUTTON 8 +#define COMPONENT_AC_FAN_MODE_LOW_PIC_ACTIVE 22 +#define COMPONENT_AC_FAN_MODE_LOW_PIC_INACTIVE 21 +#define COMPONENT_AC_FAN_MODE_MEDIUM_BUTTON 9 +#define COMPONENT_AC_FAN_MODE_MEDIUM_PIC_ACTIVE 24 +#define COMPONENT_AC_FAN_MODE_MEDIUM_PIC_INACTIVE 23 +#define COMPONENT_AC_FAN_MODE_HIGH_BUTTON 10 +#define COMPONENT_AC_FAN_MODE_HIGH_PIC_ACTIVE 26 +#define COMPONENT_AC_FAN_MODE_HIGH_PIC_INACTIVE 25 + +#define COMPONENT_BACKGROUND_AC_LOCK 2 +#define COMPONENT_BACKGROUND_AC_UNLOCK 1 /** * @brief A class for controlling the ESPMegaDisplay. @@ -69,7 +72,10 @@ class CUDDisplay : public ESPMegaDisplay { void handlePWMChange(uint8_t pin, uint8_t value); void handleACChange(uint8_t mode, uint8_t fan_speed, uint8_t temperature); void sendClock(); + void setACControlEnabled(bool enabled); + bool getACControlEnabled(); private: + bool ac_control_enabled = true; std::function getTime; DigitalInputCard* inputCard; DigitalOutputCard* outputCard; diff --git a/src/main.cpp b/src/main.cpp index 019bff5..aa08eba 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,12 +8,12 @@ // Display Configuration #define cudDisplayAdapter Serial2 #define CUD_DISPLAY_BAUD_RATE 115200 -#define CUD_DISPLAY_TX_PIN 16 +#define CUD_DISPLAY_TX_PIN 4 #define CUD_DISPLAY_RX_PIN 17 //Air Conditioner Configuration #define AIR_CONDITIONER_SENSOR_TYPE AC_SENSOR_TYPE_DHT22 -#define AIR_CONDITIONER_SENSOR_PIN 4 +#define AIR_CONDITIONER_SENSOR_PIN 32 #define AIR_CONDITIONER_IR_PIN 5 #define AIR_CONDITIONER_RMT_CHANNEL RMT_CHANNEL_0 @@ -58,6 +58,7 @@ void setup() { climateCard.bindFRAM(&espmega.fram, 5000); climateCard.loadStateFromFRAM(); climateCard.setFRAMAutoSave(true); + espmega.display->bindClimateCard(&climateCard); espmega.iot->registerCard(3); cudDisplayAdapter.begin(CUD_DISPLAY_BAUD_RATE, SERIAL_8N1, CUD_DISPLAY_RX_PIN, CUD_DISPLAY_TX_PIN); auto bindedGetTime = std::bind(&ESPMegaPRO::getTime, &espmega);