address some TODO and modify standby behavior

This commit is contained in:
reaw55 2024-02-04 05:19:26 +07:00
parent ee230bb3be
commit ab759ef08e
5 changed files with 466 additions and 303 deletions

View file

@ -1,9 +1,20 @@
#include <ise_display.hpp>
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);

View file

@ -1,210 +1,12 @@
#pragma once
#include "ise_display_definitions.hpp"
#include <ESPMegaDisplay.hpp>
#include <TimeStructure.hpp>
#include <DigitalInputCard.hpp>
#include <DigitalOutputCard.hpp>
#include <ClimateCard.hpp>
// 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();
};

View file

@ -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();