From ab759ef08ed90395565771dc780268095bc2659d Mon Sep 17 00:00:00 2001 From: reaw55 <58457329+reaw55@users.noreply.github.com> Date: Sun, 4 Feb 2024 05:19:26 +0700 Subject: [PATCH] address some TODO and modify standby behavior --- .vscode/settings.json | 50 ++++++- ise-display/ise-display-prod.HMI | Bin 37446253 -> 37446253 bytes src/ise_display.cpp | 250 ++++++++++++++++++++++--------- src/ise_display.hpp | 241 ++--------------------------- src/ise_display_definitions.hpp | 228 ++++++++++++++++++++++++++++ 5 files changed, 466 insertions(+), 303 deletions(-) create mode 100644 src/ise_display_definitions.hpp diff --git a/.vscode/settings.json b/.vscode/settings.json index 08a7dd5..cb0dece 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -287,6 +287,54 @@ "C_Cpp_Runner.msvcSecureNoWarnings": false, "files.associations": { "random": "cpp", - "*.tcc": "cpp" + "*.tcc": "cpp", + "array": "cpp", + "atomic": "cpp", + "bitset": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "map": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "regex": "cpp", + "string": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "istream": "cpp", + "limits": "cpp", + "new": "cpp", + "ostream": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "cinttypes": "cpp", + "typeinfo": "cpp" } } \ No newline at end of file diff --git a/ise-display/ise-display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WCVYa;_!I^B3|sIy zwqhH$qYz)MJUEz?8AP1gKu#F2XP4B;V_Qid;EZ-aN|cD!*QIz zNu0t@IE|n23(nvy&f!;_#|2!(C0xdD_#J=X3jV}ZT*Gzzg&VkuTed8*v;AR*AN&!3 zKm;KeAt;5?2t^r`MLC3_JnlgSgd+kK5s6Buj4G&#C{)9}sE!(_iTiLrYN0mjpf2j6 lJ{q7Q8lf?opedpegJx)sSUi9hXo)zqLcD#mw6-@M_BUDkgT(*< diff --git a/src/ise_display.cpp b/src/ise_display.cpp index a3e33da..9387901 100644 --- a/src/ise_display.cpp +++ b/src/ise_display.cpp @@ -1,9 +1,20 @@ #include - ISEDisplay::ISEDisplay(HardwareSerial *adapter) : ESPMegaDisplay(adapter) { } +// sat->sun +// TODO : Implement +// debug to complie +// standby +// dimable +// sun -> mon +// debug to work +// appdeamon send data / receive data +// sound + +// mon -> tue +// slider void ISEDisplay::begin(DigitalInputCard *inputCard, DigitalOutputCard *outputCard, ClimateCard *climateCard) { this->inputCard = inputCard; @@ -14,16 +25,35 @@ void ISEDisplay::begin(DigitalInputCard *inputCard, DigitalOutputCard *outputCar auto bindedHandleTouch = std::bind(&ISEDisplay::handleTouch, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3); this->outputCallbackHandle = this->outputCard->registerChangeCallback(bindedHandlePWMChange); this->climateCallbackHandle = this->climateCard->registerChangeCallback(bindedHandleACChange); - this->user_mode = 1; // set to cool by default + this->user_mode = 1; // initialized to cool by default + this->time_since_last_screen_update = 0; this->registerTouchCallback(bindedHandleTouch); this->reset(); delay(1000); - //TODO : Will the light be on or off when the system is started?, You need to jump to its respective page - this->jumpToPage(1); + // TODO : Will the light be on or off when the system is started?, You need to jump to its respective page + // first jump to main then if no activity jump to standby + this->jumpToPage(2); delay(100); - this->updateLightGroupState(); this->updateAirPurifierState(); this->updateACState(); + this->updateLightGroupStatePageDashboard(); + this->updateLightGroupStatePageStandby(); +} +void ISEDisplay::loop() +{ + // Check if there is data in the serial buffer + // If there is data, process the data + recieveSerialCommand(); + + // Update the time since the last screen update using millis() + + u_int32_t current_time = millis(); + + if (current_time - this->time_since_last_screen_update > 120000) + { + // jump to standby page if there is no activity for 2 minutes + this->jumpToPage(1); + } } void ISEDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t touch_type) @@ -35,29 +65,31 @@ void ISEDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t touch_type case COMPONENT_STANDBY_OPEN_ALL_TOGGLE: if (touch_type != TOUCH_TYPE_RELEASE) break; - //TODO : Should you really jump to page 2 here? should't page jumping be handled reactivly? - // EX. if atleast one light is on, then jump to active page, else jump to standby page - // This will allow page to change correctly when the system is started and when controlled remotely which won't call handleTouch + // TODO : Should you really jump to page 2 here? should't page jumping be handled reactivly? + // EX. if atleast one light is on, then jump to active page, else jump to standby page + // This will allow page to change correctly when the system is started and when controlled remotely which won't call handleTouch this->jumpToPage(2); + // the function of the button is to open the dashboard from standby break; case COMPONENT_STANDBY_LIGHT_TOGGLE: if (touch_type != TOUCH_TYPE_RELEASE) break; - //TODO : So this does nothing? Shouldn't it turn on the lights? - updateLightGroupStatePageStandby(); + // TODO : So this does nothing? Shouldn't it turn on the lights? + // should turn it on now + toggleLightGroupState(); break; case COMPONENT_STANDBY_AC_TOGGLE: - //TODO : What's the expexted behavior of standby? Does it enter standby when the lights are all off and ignore the AC - // or does it only enter standby when ac is also off and purifier is off, or is it a timed thing? + // TODO : What's the expexted behavior of standby? Does it enter standby when the lights are all off and ignore the AC + // or does it only enter standby when ac is also off and purifier is off, or is it a timed thing? if (touch_type != TOUCH_TYPE_RELEASE) break; - this->climateCard->setMode(this->climateCard->getMode() == 0 ? 1 : 0); - // need fix + toggleAC(); + break; case COMPONENT_STANDBY_PM_TOGGLE: if (touch_type != TOUCH_TYPE_RELEASE) break; - this->outputCard->setState(5, !this->outputCard->getState(5)); + togglePM(); break; default: break; @@ -66,15 +98,18 @@ void ISEDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t touch_type else if (page == PAGE_DASHBOARD) { + u_int8_t pm_fan_speed = 0; + u_int8_t fan_speed = 0; switch (component) { case COMPONENT_LIGHT_MASTER_BUTTON: - //TODO : this only update the display to match the light, it doesn't toggle the light. + // TODO : this only update the display to match the light, it doesn't toggle the light. if (touch_type != TOUCH_TYPE_RELEASE) break; - updateLightGroupStatePageDashboard(); + toggleLightGroupState(); break; - //TODO : can't this be done better with array lookup? + // TODOlater : can't this be done better with array lookup? + case COMPONENT_LIGHT_ROW1_LEVEL0_TOUCHPOINT: if (touch_type != TOUCH_TYPE_RELEASE) break; @@ -159,8 +194,7 @@ void ISEDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t touch_type case COMPONENT_AC_TOGGLE_BUTTON: if (touch_type != TOUCH_TYPE_RELEASE) break; - this->climateCard->setMode(this->climateCard->getMode() == 0 ? 1 : 0); - // need fix + toggleAC(); break; case COMPONENT_AC_MODE: if (touch_type != TOUCH_TYPE_RELEASE) @@ -171,9 +205,10 @@ void ISEDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t touch_type case COMPONENT_AC_FAN_SPEED: if (touch_type != TOUCH_TYPE_RELEASE) break; - uint8_t fan_speed = this->climateCard->getFanSpeed(); + fan_speed = this->climateCard->getFanSpeed(); // TODO : We have auto, low, mid, high right?, that's 0,1,2,3 a modulo operation of 3 only gives 0,1,2 - this->climateCard->setFanSpeed((fan_speed + 1) % 3); + // mod 4 should fixed it + this->climateCard->setFanSpeed((fan_speed + 1) % 4); break; case COMPONENT_AC_TEMP_DOWN_BUTTON: if (touch_type != TOUCH_TYPE_RELEASE) @@ -193,16 +228,16 @@ void ISEDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t touch_type case COMPONENT_PM_FAN_SPEED_DECREASE: if (touch_type != TOUCH_TYPE_RELEASE) break; - uint8_t pm_fan_speed = this->outputCard->getState(6); + pm_fan_speed = this->outputCard->getValue(6); if (pm_fan_speed >= 0 && pm_fan_speed <= 20) - this->outputCard->setState(5, (pm_fan_speed - 1)); + this->outputCard->setValue(5, (pm_fan_speed - 1)); break; case COMPONENT_PM_FAN_SPEED_INCREASE: if (touch_type != TOUCH_TYPE_RELEASE) break; - uint8_t pm_fan_speed = this->outputCard->getState(6); + pm_fan_speed = this->outputCard->getValue(6); if (pm_fan_speed >= 0 && pm_fan_speed <= 20) - this->outputCard->setState(5, (pm_fan_speed + 1)); + this->outputCard->setValue(5, (pm_fan_speed + 1)); break; default: break; @@ -217,16 +252,23 @@ void ISEDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t touch_type void ISEDisplay::handlePWMChange(uint8_t pin, bool state, uint16_t value) { + // NEED to switch case for different page + + // Question: can add another input and placeholder for page differentation + // or that would mean changing the data structure of the callback + if (pin >= 1 && pin <= 4) { // Light updateLightGroupStatePageDashboard(); updateLightGroupStatePageStandby(); + time_since_last_screen_update = millis(); // update time since last activity } - else if (pin == 0) + else if (pin == 4 || pin == 5) { // Air Purifier updateAirPurifierState(); + time_since_last_screen_update = millis(); // update time since last activity } } void ISEDisplay::updateDateTimeText(rtctime_t time) @@ -249,6 +291,8 @@ void ISEDisplay::updateDateTimeText(rtctime_t time) this->giveSerialMutex(); } // TODO : Implement +// user remote var +// appdeamon void ISEDisplay::updateWeather(uint8_t weather_code, float outside_temp) { } @@ -265,9 +309,66 @@ void ISEDisplay::setPMstate(bool is_pm_on, uint8_t pm_fan_speed) void ISEDisplay::setACstate(uint8_t ac_fan_speed, uint8_t ac_mode, uint8_t ac_temperature) { + this->climateCard->setTemperature(ac_temperature); + this->climateCard->setFanSpeed(ac_fan_speed); + this->climateCard->setMode(ac_mode); updateACState(); } - +void ISEDisplay::toggleLightGroupState() +{ + // Get the current group state + bool state = calculateLightGroupState(); + // Toggle light + for (uint8_t i = 1; i <= 4; i++) + { + setLightLevel(i, state ? 0 : 3); + } +} +void ISEDisplay::togglePM() +{ + // Get the current group state + bool state = this->outputCard->getState(5); + // Toggle the state + state = !state; + // Set the state + this->outputCard->setState(5, state); +} +void ISEDisplay::toggleAC() +{ + // Get the current group state + uint8_t mode = this->climateCard->getMode(); + // Toggle the state + if (mode == 0) + { + this->climateCard->setMode(user_mode); + } + else + { + // update user mode to new mode + user_mode = mode; + // change actual mode to off + this->climateCard->setMode(0); + } +} +void ISEDisplay::changeUserACmode() +{ + // Get the current group state + uint8_t mode = this->climateCard->getMode(); + // Toggle the state + // user mode alternate between 1 and 2 + user_mode = (user_mode + 1) % 2 + 1; + if (mode != 0) + { + // update mode to new mode + mode = user_mode; + } + else + { // ie mode is off + // do nothing as the state is keep in user_mode + // the mode will change to user_mode when turn on by toggleAC() + } + updateuserACmode(); // call to update mode part of the display seperately +} void ISEDisplay::setLightLevel(uint8_t row, uint8_t level) { for (uint8_t i = 1; i <= 4; i++) @@ -390,51 +491,8 @@ void ISEDisplay::updateAirPurifierState() this->giveSerialMutex(); } - -void ISEDisplay::updateACState() +void ISEDisplay::updateuserACmode() { - //TODO : The cognitive complexity here is so high, maybe break up the method a bit? - // Get the state - uint8_t mode = this->climateCard->getMode(); - - if (mode == 0) - { - } - uint8_t fan_speed = this->climateCard->getFanSpeed(); - uint8_t temperature = this->climateCard->getTemperature(); - - this->takeSerialMutex(); - - // Send the state to the display - if (mode == 0) - { - - this->displayAdapter->print("ac_temp.pco="); - this->displayAdapter->print(33841); - this->sendStopBytes(); - - this->displayAdapter->print("ac_temp.pic="); - this->displayAdapter->print(COMPONENT_AC_STATUS_OFF); - this->sendStopBytes(); - } - else - { - this->displayAdapter->print("ac_temp.pco="); - this->displayAdapter->print(34486); - this->sendStopBytes(); - - this->displayAdapter->print("ac_temp.pic="); - this->displayAdapter->print(COMPONENT_AC_STATUS_ON); - this->sendStopBytes(); - - user_mode = mode; - } - this->displayAdapter->print("ac_sw.pic="); - this->displayAdapter->print(mode != 0 ? COMPONENT_AC_TOGGLE_PIC_ON : COMPONENT_AC_TOGGLE_PIC_OFF); - this->sendStopBytes(); - this->displayAdapter->print("ac_sw.pic2="); - this->displayAdapter->print(mode != 0 ? COMPONENT_AC_TOGGLE_PIC_ON_PRESSED : COMPONENT_AC_TOGGLE_PIC_OFF_PRESSED); - this->sendStopBytes(); switch (user_mode) { case 1: @@ -456,6 +514,10 @@ void ISEDisplay::updateACState() default: break; } +} +void ISEDisplay::updateACfanSpeed() +{ + uint8_t fan_speed = this->climateCard->getFanSpeed(); switch (fan_speed) { case 0: @@ -493,6 +555,50 @@ void ISEDisplay::updateACState() default: break; } +} +void ISEDisplay::updateACState() +{ + // TODOlater : The cognitive complexity here is so high, maybe break up the method a bit? + + // Get the state + uint8_t mode = this->climateCard->getMode(); + uint8_t temperature = this->climateCard->getTemperature(); + + this->takeSerialMutex(); + + // Send the state to the display + if (mode == 0) + { + this->displayAdapter->print("ac_temp.pco="); + this->displayAdapter->print(33841); + this->sendStopBytes(); + + this->displayAdapter->print("ac_temp.pic="); + this->displayAdapter->print(COMPONENT_AC_STATUS_OFF); + this->sendStopBytes(); + } + else + { + this->displayAdapter->print("ac_temp.pco="); + this->displayAdapter->print(34486); + this->sendStopBytes(); + + this->displayAdapter->print("ac_temp.pic="); + this->displayAdapter->print(COMPONENT_AC_STATUS_ON); + this->sendStopBytes(); + + user_mode = mode; + } + this->displayAdapter->print("ac_sw.pic="); + this->displayAdapter->print(mode != 0 ? COMPONENT_AC_TOGGLE_PIC_ON : COMPONENT_AC_TOGGLE_PIC_OFF); + this->sendStopBytes(); + this->displayAdapter->print("ac_sw.pic2="); + this->displayAdapter->print(mode != 0 ? COMPONENT_AC_TOGGLE_PIC_ON_PRESSED : COMPONENT_AC_TOGGLE_PIC_OFF_PRESSED); + this->sendStopBytes(); + + updateuserACmode(); + + updateACfanSpeed(); this->displayAdapter->print("ac_temp.txt=\""); this->displayAdapter->print(temperature); diff --git a/src/ise_display.hpp b/src/ise_display.hpp index 826283c..001595a 100644 --- a/src/ise_display.hpp +++ b/src/ise_display.hpp @@ -1,210 +1,12 @@ #pragma once +#include "ise_display_definitions.hpp" + #include #include #include #include #include - -// TODO: I cannot review this propperly as I do not know what condtion need to be met for the standbye page to be displayed - -/* -tentetive pin mapping - -1-4 Lights - 1: row 1 - 2: row 2 - 3: row 3 - 4: row 4 - -5: Air Purifier status (on/off) -6: Air Purifier fan speed (0-20) - -lights have 4 states -0: off -1: low -2: mid -3: high - -*/ - - -// Touch Types -#define TOUCH_TYPE_PRESS 1 -#define TOUCH_TYPE_RELEASE 0 - -// Page IDs -#define PAGE_BOOT 0 -#define PAGE_STANDBY 1 -#define PAGE_DASHBOARD 2 - -//boot page - -//logo gmov boot -#define COMPONENT_LOGO_BOOT 1 -#define COMPONENT_LOGO_BOOT_VID 1 - -//boot background -#define COMPONENT_BACKGROUND_BOOT_PIC 43 - - -//standby page object id -#define COMPONENT_LOGO_STANDBY 1 -#define COMPONENT_LOGO_STANDBY_VID 2 - -#define COMPONENT_STANDBY_OPEN_ALL_TOGGLE 2 -#define COMPONENT_STANDBY_LIGHT_TOGGLE 3 -#define COMPONENT_STANDBY_AC_TOGGLE 4 -#define COMPONENT_STANDBY_PM_TOGGLE 5 - -//text -#define COMPONENT_STANDBY_TIME_TXT 6 -#define COMPONENT_STANDBY_DATE_TXT 7 -#define COMPONENT_STANDBY_OUTSIDE_TEMP_TXT 8 - -//standby page picture id -#define COMPONENT_BACKGROUND_PIC 44 -#define COMPONENT_BACKGROUND_REFERENCE_PIC 45 - -#define COMPONENT_STANDBY_OPEN_ALL_TOGGLE_PIC_OFF 46 -#define COMPONENT_STANDBY_OPEN_ALL_TOGGLE_PIC_OFF_PRESSED 47 -#define COMPONENT_STANDBY_OPEN_ALL_TOGGLE_PIC_ON 48 -#define COMPONENT_STANDBY_OPEN_ALL_TOGGLE_PIC_ON_PRESSED 49 - -#define COMPONENT_STANDBY_AC_PIC_OFF 50 -#define COMPONENT_STANDBY_AC_PIC_OFF_PRESSED 51 -#define COMPONENT_STANDBY_AC_PIC_ON 52 -#define COMPONENT_STANDBY_AC_PIC_ON_PRESSED 53 - -#define COMPONENT_STANDBY_LIGHT_PIC_OFF 54 -#define COMPONENT_STANDBY_LIGHT_PIC_OFF_PRESSED 55 -#define COMPONENT_STANDBY_LIGHT_PIC_ON 56 -#define COMPONENT_STANDBY_LIGHT_PIC_ON_PRESSED 57 - -#define COMPONENT_STANDBY_PM_PIC_OFF 58 -#define COMPONENT_STANDBY_PM_PIC_OFF_PRESSED 59 -#define COMPONENT_STANDBY_PM_PIC_ON 60 -#define COMPONENT_STANDBY_PM_PIC_ON_PRESSED 61 - -#define COMPONENT_REFERENCE_BACKGROUND_PIC 62 - - - -//dashboard page - -//dashboard page object id -#define COMPONENT_AC_TOGGLE_BUTTON 3 -#define COMPONENT_AC_MODE 4 -#define COMPONENT_AC_FAN_SPEED 5 -#define COMPONENT_AC_TEMP_DOWN_BUTTON 6 -#define COMPONENT_AC_TEMP_UP_BUTTON 7 - -#define COMPONENT_PM_TOGGLE_BUTTON 8 -#define COMPONENT_PM_FAN_SPEED_DECREASE 9 -#define COMPONENT_PM_FAN_SPEED_INCREASE 10 - -#define COMPONENT_PM_INSIDE_TXT 11 -#define COMPONENT_PM_OUTSIDE_TXT 12 - -#define COMPONENT_LIGHT_MASTER_BUTTON 13 -#define COMPONENT_LIGHT_ROW1_PIC_PLACEHOLDER 14 -#define COMPONENT_LIGHT_ROW2_PIC_PLACEHOLDER 15 -#define COMPONENT_LIGHT_ROW3_PIC_PLACEHOLDER 16 -#define COMPONENT_LIGHT_ROW4_PIC_PLACEHOLDER 17 - -#define COMPONENT_LIGHT_MASTER_LEVEL1_TOUCHPOINT 18 -#define COMPONENT_LIGHT_MASTER_LEVEL2_TOUCHPOINT 19 -#define COMPONENT_LIGHT_MASTER_LEVEL3_TOUCHPOINT 20 - -#define COMPONENT_LIGHT_ROW1_LEVEL0_TOUCHPOINT 21 -#define COMPONENT_LIGHT_ROW1_LEVEL1_TOUCHPOINT 22 -#define COMPONENT_LIGHT_ROW1_LEVEL2_TOUCHPOINT 23 -#define COMPONENT_LIGHT_ROW1_LEVEL3_TOUCHPOINT 24 - -#define COMPONENT_LIGHT_ROW2_LEVEL0_TOUCHPOINT 25 -#define COMPONENT_LIGHT_ROW2_LEVEL1_TOUCHPOINT 26 -#define COMPONENT_LIGHT_ROW2_LEVEL2_TOUCHPOINT 27 -#define COMPONENT_LIGHT_ROW2_LEVEL3_TOUCHPOINT 28 - -#define COMPONENT_LIGHT_ROW3_LEVEL0_TOUCHPOINT 29 -#define COMPONENT_LIGHT_ROW3_LEVEL1_TOUCHPOINT 30 -#define COMPONENT_LIGHT_ROW3_LEVEL2_TOUCHPOINT 31 -#define COMPONENT_LIGHT_ROW3_LEVEL3_TOUCHPOINT 32 - -#define COMPONENT_LIGHT_ROW4_LEVEL0_TOUCHPOINT 33 -#define COMPONENT_LIGHT_ROW4_LEVEL1_TOUCHPOINT 34 -#define COMPONENT_LIGHT_ROW4_LEVEL2_TOUCHPOINT 35 -#define COMPONENT_LIGHT_ROW4_LEVEL3_TOUCHPOINT 36 - -#define COMPONENT_DASHBOARD_TIME_TXT 37 -#define COMPONENT_DASHBOARD_DATE_TXT 38 -#define COMPONENT_DASHBOARD_OUTSIDE_TEMP_TXT 39 - - -//dashboard page picture id - -#define COMPONENT_DASHBOARD_REFERENCE_BACKGROUND_PIC 0 -#define COMPONENT_DASHBOARD_BACKGROUND_PIC 1 -#define COMPONENT_DASHBOARD_BACKGROUND_VARIANT_PIC 2 - -//AC on/off -#define COMPONENT_AC_TOGGLE_PIC_OFF 3 -#define COMPONENT_AC_TOGGLE_PIC_OFF_PRESSED 4 -#define COMPONENT_AC_TOGGLE_PIC_ON 5 -#define COMPONENT_AC_TOGGLE_PIC_ON_PRESSED 6 -#define COMPONENT_AC_TEMP_DOWN_PIC 7 -#define COMPONENT_AC_TEMP_DOWN_PIC_PRESSED 8 -#define COMPONENT_AC_TEMP_UP_PIC 9 -#define COMPONENT_AC_TEMP_UP_PIC_PRESSED 10 - -#define COMPONENT_AC_FAN_MODE_AUTO_PIC 11 -#define COMPONENT_AC_FAN_MODE_AUTO_PIC_PRESSED 12 -#define COMPONENT_AC_FAN_MODE_HIGH_PIC 13 -#define COMPONENT_AC_FAN_MODE_HIGH_PIC_PRESSED 14 -#define COMPONENT_AC_FAN_MODE_MID_PIC 15 -#define COMPONENT_AC_FAN_MODE_MID_PIC_PRESSED 16 -#define COMPONENT_AC_FAN_MODE_LOW_PIC 17 -#define COMPONENT_AC_FAN_MODE_LOW_PIC_PRESSED 18 - -#define COMPONENT_AC_MODE_DRY_PIC 19 -#define COMPONENT_AC_MODE_DRY_PIC_PRESSED 20 -#define COMPONENT_AC_MODE_COOL_PIC 21 -#define COMPONENT_AC_MODE_COOL_PIC_PRESSED 22 -#define COMPONENT_AC_MODE_FAN_PIC 23 -#define COMPONENT_AC_MODE_FAN_PIC_PRESSED 24 - -//pm; air purifier -#define COMPONENT_PM_TOGGLE_PIC_OFF 25 -#define COMPONENT_PM_TOGGLE_PIC_OFF_PRESSED 26 -#define COMPONENT_PM_TOGGLE_PIC_ON 27 -#define COMPONENT_PM_TOGGLE_PIC_ON_PRESSED 28 - -#define COMPONENT_PM_FAN_SPEED_DECREASE_PIC 29 -#define COMPONENT_PM_FAN_SPEED_DECREASE_PIC_PRESSED 30 -#define COMPONENT_PM_FAN_SPEED_INCREASE_PIC 31 -#define COMPONENT_PM_FAN_SPEED_INCREASE_PIC_PRESSED 32 - -//AC status indicator -#define COMPONENT_AC_STATUS_OFF 33 -#define COMPONENT_AC_STATUS_ON 34 - -//light master -#define COMPONENT_LIGHT_MASTER_OFF 35 -#define COMPONENT_LIGHT_MASTER_OFF_PRESSED 36 -#define COMPONENT_LIGHT_MASTER_ON 37 -#define COMPONENT_LIGHT_MASTER_ON_PRESSED 38 - -//light level component -#define COMPONENT_LIGHT_LEVEL_0 39 -#define COMPONENT_LIGHT_LEVEL_1 40 -#define COMPONENT_LIGHT_LEVEL_2 41 -#define COMPONENT_LIGHT_LEVEL_3 42 - - - - - - /** * @brief A class for controlling the ESPMegaDisplay. * @@ -214,36 +16,6 @@ lights have 4 states -//need to toggle 4 row of light independently and have one master switch that can control all - -//need to toggle AC on/off, fan speed, mode, and temperature - -//need to toggle air purifier on/off and fan speed - -//display pm2.5 both outside and inside - -//need to display time, date, and outside temperature for standby and dashbaord page in separate value - - -// Function to update date and time on screen-> void updateDateTimeText(); - -// Function to receieve touch input -> void handleTouch(uint8_t page, uint8_t component, uint8_t touch_type); - -// Touch input will call a function that update the light at its respective row -> void setLightLevel(uint8_t row, uint8_t level); - -// Function to React to change in light, contactor -> void handlePWMChange(uint8_t pin, bool state, uint16_t value); - -// Function to Set AC state -> void setACstate(uint8_t ac_fan_speed, uint8_t ac_mode, uint8_t ac_temperature); - -// Function to Set Air Purifier -> setPMstate(bool is_pm_on, uint8_t pm_fan_speed); - -// Function to update pm2.5 inside on screen -> void updatePMinside(); // get internal info from HA's air purifier sensor -// Function to update pm2.5 outside on screen -> void updatePMoutside(); // call API - -// Function to get weather forcast and outside temperature and update screen -> void handleWeatherCallback(); - - - class ISEDisplay : public ESPMegaDisplay { public: ISEDisplay(HardwareSerial* adapter); @@ -253,6 +25,7 @@ class ISEDisplay : public ESPMegaDisplay { void updateWeather(uint8_t weather_code, float outside_temp); void updatePMoutside(float pm25_outside); void updatePMinside(float pm25_inside); + void loop(); private: @@ -268,10 +41,18 @@ class ISEDisplay : public ESPMegaDisplay { uint8_t outputCallbackHandle; uint8_t climateCallbackHandle; uint8_t user_mode; + uint8_t time_since_last_screen_update; + void updateLightGroupStatePageDashboard(); void updateLightGroupStatePageStandby(); void updateAirPurifierState(); void updateACState(); bool calculateLightGroupState(); + void toggleLightGroupState(); + void togglePM(); + void toggleAC(); + void changeUserACmode(); + void updateuserACmode(); + void updateACfanSpeed(); }; \ No newline at end of file diff --git a/src/ise_display_definitions.hpp b/src/ise_display_definitions.hpp new file mode 100644 index 0000000..4922c1c --- /dev/null +++ b/src/ise_display_definitions.hpp @@ -0,0 +1,228 @@ +#pragma once + +//start definition +/* +tentetive pin mapping + +1-4 Lights + 1: row 1 + 2: row 2 + 3: row 3 + 4: row 4 + +5: Air Purifier status (on/off) +6: Air Purifier fan speed (0-20) + +lights have 4 states +0: off +1: low +2: mid +3: high + +*/ + +// +#define DISPLAY_TIMEOUT 5*60*1000 // 5 minutes + +// Touch Types +#define TOUCH_TYPE_PRESS 1 +#define TOUCH_TYPE_RELEASE 0 + +// Page IDs +#define PAGE_BOOT 0 +#define PAGE_STANDBY 1 +#define PAGE_DASHBOARD 2 + +//boot page + +//logo gmov boot +#define COMPONENT_LOGO_BOOT 1 +#define COMPONENT_LOGO_BOOT_VID 1 + +//boot background +#define COMPONENT_BACKGROUND_BOOT_PIC 43 + + +//standby page object id +#define COMPONENT_LOGO_STANDBY 1 +#define COMPONENT_LOGO_STANDBY_VID 2 + +#define COMPONENT_STANDBY_OPEN_ALL_TOGGLE 2 +#define COMPONENT_STANDBY_LIGHT_TOGGLE 3 +#define COMPONENT_STANDBY_AC_TOGGLE 4 +#define COMPONENT_STANDBY_PM_TOGGLE 5 + +//text +#define COMPONENT_STANDBY_TIME_TXT 6 +#define COMPONENT_STANDBY_DATE_TXT 7 +#define COMPONENT_STANDBY_OUTSIDE_TEMP_TXT 8 + +//standby page picture id +#define COMPONENT_BACKGROUND_PIC 44 +#define COMPONENT_BACKGROUND_REFERENCE_PIC 45 + +#define COMPONENT_STANDBY_OPEN_ALL_TOGGLE_PIC_OFF 46 +#define COMPONENT_STANDBY_OPEN_ALL_TOGGLE_PIC_OFF_PRESSED 47 +#define COMPONENT_STANDBY_OPEN_ALL_TOGGLE_PIC_ON 48 +#define COMPONENT_STANDBY_OPEN_ALL_TOGGLE_PIC_ON_PRESSED 49 + +#define COMPONENT_STANDBY_AC_PIC_OFF 50 +#define COMPONENT_STANDBY_AC_PIC_OFF_PRESSED 51 +#define COMPONENT_STANDBY_AC_PIC_ON 52 +#define COMPONENT_STANDBY_AC_PIC_ON_PRESSED 53 + +#define COMPONENT_STANDBY_LIGHT_PIC_OFF 54 +#define COMPONENT_STANDBY_LIGHT_PIC_OFF_PRESSED 55 +#define COMPONENT_STANDBY_LIGHT_PIC_ON 56 +#define COMPONENT_STANDBY_LIGHT_PIC_ON_PRESSED 57 + +#define COMPONENT_STANDBY_PM_PIC_OFF 58 +#define COMPONENT_STANDBY_PM_PIC_OFF_PRESSED 59 +#define COMPONENT_STANDBY_PM_PIC_ON 60 +#define COMPONENT_STANDBY_PM_PIC_ON_PRESSED 61 + +#define COMPONENT_REFERENCE_BACKGROUND_PIC 62 + + + +//dashboard page + +//dashboard page object id +#define COMPONENT_AC_TOGGLE_BUTTON 3 +#define COMPONENT_AC_MODE 4 +#define COMPONENT_AC_FAN_SPEED 5 +#define COMPONENT_AC_TEMP_DOWN_BUTTON 6 +#define COMPONENT_AC_TEMP_UP_BUTTON 7 + +#define COMPONENT_PM_TOGGLE_BUTTON 8 +#define COMPONENT_PM_FAN_SPEED_DECREASE 9 +#define COMPONENT_PM_FAN_SPEED_INCREASE 10 + +#define COMPONENT_PM_INSIDE_TXT 11 +#define COMPONENT_PM_OUTSIDE_TXT 12 + +#define COMPONENT_LIGHT_MASTER_BUTTON 13 +#define COMPONENT_LIGHT_ROW1_PIC_PLACEHOLDER 14 +#define COMPONENT_LIGHT_ROW2_PIC_PLACEHOLDER 15 +#define COMPONENT_LIGHT_ROW3_PIC_PLACEHOLDER 16 +#define COMPONENT_LIGHT_ROW4_PIC_PLACEHOLDER 17 + +#define COMPONENT_LIGHT_MASTER_LEVEL1_TOUCHPOINT 18 +#define COMPONENT_LIGHT_MASTER_LEVEL2_TOUCHPOINT 19 +#define COMPONENT_LIGHT_MASTER_LEVEL3_TOUCHPOINT 20 + +#define COMPONENT_LIGHT_ROW1_LEVEL0_TOUCHPOINT 21 +#define COMPONENT_LIGHT_ROW1_LEVEL1_TOUCHPOINT 22 +#define COMPONENT_LIGHT_ROW1_LEVEL2_TOUCHPOINT 23 +#define COMPONENT_LIGHT_ROW1_LEVEL3_TOUCHPOINT 24 + +#define COMPONENT_LIGHT_ROW2_LEVEL0_TOUCHPOINT 25 +#define COMPONENT_LIGHT_ROW2_LEVEL1_TOUCHPOINT 26 +#define COMPONENT_LIGHT_ROW2_LEVEL2_TOUCHPOINT 27 +#define COMPONENT_LIGHT_ROW2_LEVEL3_TOUCHPOINT 28 + +#define COMPONENT_LIGHT_ROW3_LEVEL0_TOUCHPOINT 29 +#define COMPONENT_LIGHT_ROW3_LEVEL1_TOUCHPOINT 30 +#define COMPONENT_LIGHT_ROW3_LEVEL2_TOUCHPOINT 31 +#define COMPONENT_LIGHT_ROW3_LEVEL3_TOUCHPOINT 32 + +#define COMPONENT_LIGHT_ROW4_LEVEL0_TOUCHPOINT 33 +#define COMPONENT_LIGHT_ROW4_LEVEL1_TOUCHPOINT 34 +#define COMPONENT_LIGHT_ROW4_LEVEL2_TOUCHPOINT 35 +#define COMPONENT_LIGHT_ROW4_LEVEL3_TOUCHPOINT 36 + +#define COMPONENT_DASHBOARD_TIME_TXT 37 +#define COMPONENT_DASHBOARD_DATE_TXT 38 +#define COMPONENT_DASHBOARD_OUTSIDE_TEMP_TXT 39 + + +//dashboard page picture id + +#define COMPONENT_DASHBOARD_REFERENCE_BACKGROUND_PIC 0 +#define COMPONENT_DASHBOARD_BACKGROUND_PIC 1 +#define COMPONENT_DASHBOARD_BACKGROUND_VARIANT_PIC 2 + +//AC on/off +#define COMPONENT_AC_TOGGLE_PIC_OFF 3 +#define COMPONENT_AC_TOGGLE_PIC_OFF_PRESSED 4 +#define COMPONENT_AC_TOGGLE_PIC_ON 5 +#define COMPONENT_AC_TOGGLE_PIC_ON_PRESSED 6 +#define COMPONENT_AC_TEMP_DOWN_PIC 7 +#define COMPONENT_AC_TEMP_DOWN_PIC_PRESSED 8 +#define COMPONENT_AC_TEMP_UP_PIC 9 +#define COMPONENT_AC_TEMP_UP_PIC_PRESSED 10 + +#define COMPONENT_AC_FAN_MODE_AUTO_PIC 11 +#define COMPONENT_AC_FAN_MODE_AUTO_PIC_PRESSED 12 +#define COMPONENT_AC_FAN_MODE_HIGH_PIC 13 +#define COMPONENT_AC_FAN_MODE_HIGH_PIC_PRESSED 14 +#define COMPONENT_AC_FAN_MODE_MID_PIC 15 +#define COMPONENT_AC_FAN_MODE_MID_PIC_PRESSED 16 +#define COMPONENT_AC_FAN_MODE_LOW_PIC 17 +#define COMPONENT_AC_FAN_MODE_LOW_PIC_PRESSED 18 + +#define COMPONENT_AC_MODE_DRY_PIC 19 +#define COMPONENT_AC_MODE_DRY_PIC_PRESSED 20 +#define COMPONENT_AC_MODE_COOL_PIC 21 +#define COMPONENT_AC_MODE_COOL_PIC_PRESSED 22 +#define COMPONENT_AC_MODE_FAN_PIC 23 +#define COMPONENT_AC_MODE_FAN_PIC_PRESSED 24 + +//pm; air purifier +#define COMPONENT_PM_TOGGLE_PIC_OFF 25 +#define COMPONENT_PM_TOGGLE_PIC_OFF_PRESSED 26 +#define COMPONENT_PM_TOGGLE_PIC_ON 27 +#define COMPONENT_PM_TOGGLE_PIC_ON_PRESSED 28 + +#define COMPONENT_PM_FAN_SPEED_DECREASE_PIC 29 +#define COMPONENT_PM_FAN_SPEED_DECREASE_PIC_PRESSED 30 +#define COMPONENT_PM_FAN_SPEED_INCREASE_PIC 31 +#define COMPONENT_PM_FAN_SPEED_INCREASE_PIC_PRESSED 32 + +//AC status indicator +#define COMPONENT_AC_STATUS_OFF 33 +#define COMPONENT_AC_STATUS_ON 34 + +//light master +#define COMPONENT_LIGHT_MASTER_OFF 35 +#define COMPONENT_LIGHT_MASTER_OFF_PRESSED 36 +#define COMPONENT_LIGHT_MASTER_ON 37 +#define COMPONENT_LIGHT_MASTER_ON_PRESSED 38 + +//light level component +#define COMPONENT_LIGHT_LEVEL_0 39 +#define COMPONENT_LIGHT_LEVEL_1 40 +#define COMPONENT_LIGHT_LEVEL_2 41 +#define COMPONENT_LIGHT_LEVEL_3 42 + + + + + +//need to toggle 4 row of light independently and have one master switch that can control all + +//need to toggle AC on/off, fan speed, mode, and temperature + +//need to toggle air purifier on/off and fan speed + +//display pm2.5 both outside and inside + +//need to display time, date, and outside temperature for standby and dashbaord page in separate value + + +// Function to update date and time on screen-> void updateDateTimeText(); + +// Function to receieve touch input -> void handleTouch(uint8_t page, uint8_t component, uint8_t touch_type); + +// Touch input will call a function that update the light at its respective row -> void setLightLevel(uint8_t row, uint8_t level); + +// Function to React to change in light, contactor -> void handlePWMChange(uint8_t pin, bool state, uint16_t value); + +// Function to Set AC state -> void setACstate(uint8_t ac_fan_speed, uint8_t ac_mode, uint8_t ac_temperature); + +// Function to Set Air Purifier -> setPMstate(bool is_pm_on, uint8_t pm_fan_speed); + +// Function to update pm2.5 inside on screen -> void updatePMinside(); // get internal info from HA's air purifier sensor +// Function to update pm2.5 outside on screen -> void updatePMoutside(); // call API + +// Function to get weather forcast and outside temperature and update screen -> void handleWeatherCallback();