clean up code

This commit is contained in:
Siwat Sirichai 2024-02-03 15:41:31 +07:00
parent f0bdfe0d03
commit 3345cf6ae1

View file

@ -2,30 +2,10 @@
ISEDisplay::ISEDisplay(HardwareSerial *adapter) : ESPMegaDisplay(adapter) ISEDisplay::ISEDisplay(HardwareSerial *adapter) : ESPMegaDisplay(adapter)
{ {
} }
void ISEDisplay::begin(DigitalInputCard *inputCard, DigitalOutputCard *outputCard, ClimateCard *climateCard) void ISEDisplay::begin(DigitalInputCard *inputCard, DigitalOutputCard *outputCard, ClimateCard *climateCard)
{ {
/*
ISEDisplay(HardwareSerial* adapter);
void begin(DigitalInputCard* inputCard, DigitalOutputCard* outputCard, ClimateCard* climateCard);
void updateDateTimeText(rtctime_t time);
void updateWeather(uint8_t weather_code, float outside_temp);
void updatePMoutside(float pm25_outside);
void updatePMinside(float pm25_inside);
private:
void handleTouch(uint8_t page, uint8_t component, uint8_t touch_type);
void handlePWMChange(uint8_t pin, bool state, uint16_t value);
void setPMstate(bool is_pm_on, uint8_t pm_fan_speed);
void setACstate(uint8_t ac_fan_speed, uint8_t ac_mode, uint8_t ac_temperature);
void setLightLevel(uint8_t row, uint8_t level);
*/
this->inputCard = inputCard; this->inputCard = inputCard;
this->outputCard = outputCard; this->outputCard = outputCard;
this->climateCard = climateCard; this->climateCard = climateCard;
@ -43,12 +23,12 @@ ISEDisplay(HardwareSerial* adapter);
this->updateLightGroupState(); this->updateLightGroupState();
this->updateAirPurifierState(); this->updateAirPurifierState();
this->updateACState(); this->updateACState();
} }
void ISEDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t touch_type){ void ISEDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t touch_type)
if (page == PAGE_STANDBY){ {
if (page == PAGE_STANDBY)
{
switch (component) switch (component)
{ {
case COMPONENT_STANDBY_OPEN_ALL_TOGGLE: case COMPONENT_STANDBY_OPEN_ALL_TOGGLE:
@ -77,7 +57,8 @@ void ISEDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t touch_type
} }
} }
else if (page == PAGE_DASHBOARD){ else if (page == PAGE_DASHBOARD)
{
switch (component) switch (component)
{ {
case COMPONENT_LIGHT_MASTER_BUTTON: case COMPONENT_LIGHT_MASTER_BUTTON:
@ -215,15 +196,16 @@ void ISEDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t touch_type
default: default:
break; break;
} }
} }
else{ else
{
return; return;
} }
} }
void ISEDisplay::handlePWMChange(uint8_t pin, bool state, uint16_t value){ void ISEDisplay::handlePWMChange(uint8_t pin, bool state, uint16_t value)
{
if (pin >= 1 && pin <= 4) if (pin >= 1 && pin <= 4)
{ {
// Light // Light
@ -236,7 +218,8 @@ void ISEDisplay::handlePWMChange(uint8_t pin, bool state, uint16_t value){
updateAirPurifierState(); updateAirPurifierState();
} }
} }
void ISEDisplay::updateDateTimeText(rtctime_t time){ void ISEDisplay::updateDateTimeText(rtctime_t time)
{
this->takeSerialMutex(); this->takeSerialMutex();
// Send the time to the display // Send the time to the display
@ -254,32 +237,36 @@ void ISEDisplay::updateDateTimeText(rtctime_t time){
this->giveSerialMutex(); this->giveSerialMutex();
} }
void ISEDisplay::updateWeather(uint8_t weather_code, float outside_temp){ void ISEDisplay::updateWeather(uint8_t weather_code, float outside_temp)
{
} }
void ISEDisplay::updatePMoutside(float pm25_outside){ void ISEDisplay::updatePMoutside(float pm25_outside)
{
} }
void ISEDisplay::updatePMinside(float pm25_inside){ void ISEDisplay::updatePMinside(float pm25_inside)
{
} }
void ISEDisplay::setPMstate(bool is_pm_on, uint8_t pm_fan_speed){ 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){ void ISEDisplay::setACstate(uint8_t ac_fan_speed, uint8_t ac_mode, uint8_t ac_temperature)
{
updateACState(); updateACState();
} }
void ISEDisplay::setLightLevel(uint8_t row, uint8_t level){ void ISEDisplay::setLightLevel(uint8_t row, uint8_t level)
for (uint8_t i = 1; i <= 4; i++) { {
for (uint8_t i = 1; i <= 4; i++)
{
if (row == i) if (row == i)
this->outputCard->setState(row, level); this->outputCard->setState(row, level);
} }
} }
void ISEDisplay::updateLightGroupStatePageStandby(){ void ISEDisplay::updateLightGroupStatePageStandby()
{
// Calculate the state // Calculate the state
bool state = calculateLightGroupState(); bool state = calculateLightGroupState();
// Send the state to the display // Send the state to the display
@ -295,7 +282,8 @@ void ISEDisplay::updateLightGroupStatePageStandby(){
this->giveSerialMutex(); this->giveSerialMutex();
} }
void ISEDisplay::updateLightGroupStatePageDashboard(){ void ISEDisplay::updateLightGroupStatePageDashboard()
{
// Calculate the state // Calculate the state
bool state = calculateLightGroupState(); bool state = calculateLightGroupState();
// Send the state to the display // Send the state to the display
@ -309,7 +297,8 @@ void ISEDisplay::updateLightGroupStatePageDashboard(){
this->displayAdapter->print(state ? COMPONENT_LIGHT_MASTER_ON_PRESSED : COMPONENT_LIGHT_MASTER_OFF_PRESSED); this->displayAdapter->print(state ? COMPONENT_LIGHT_MASTER_ON_PRESSED : COMPONENT_LIGHT_MASTER_OFF_PRESSED);
this->sendStopBytes(); this->sendStopBytes();
for (uint8_t i = 1; i <= 4; i++) { for (uint8_t i = 1; i <= 4; i++)
{
u_int8_t state = this->outputCard->getState(i); u_int8_t state = this->outputCard->getState(i);
switch (state) switch (state)
{ {
@ -348,18 +337,22 @@ void ISEDisplay::updateLightGroupStatePageDashboard(){
this->giveSerialMutex(); this->giveSerialMutex();
} }
bool ISEDisplay::calculateLightGroupState() { bool ISEDisplay::calculateLightGroupState()
{
// Check if all lights are on // Check if all lights are on
bool lightOn = false; bool lightOn = false;
for (uint8_t i = 1; i <= 4; i++) { for (uint8_t i = 1; i <= 4; i++)
if (this->outputCard->getState(i) != 0) { {
if (this->outputCard->getState(i) != 0)
{
lightOn = true; lightOn = true;
break; break;
} }
} }
return lightOn; return lightOn;
} }
void ISEDisplay::updateAirPurifierState(){ void ISEDisplay::updateAirPurifierState()
{
// Get the state // Get the state
bool state = this->outputCard->getState(5); bool state = this->outputCard->getState(5);
uint8_t fan_speed = this->outputCard->getState(5); uint8_t fan_speed = this->outputCard->getState(5);
@ -386,12 +379,13 @@ void ISEDisplay::updateAirPurifierState(){
this->giveSerialMutex(); this->giveSerialMutex();
} }
void ISEDisplay::updateACState(){ void ISEDisplay::updateACState()
{
// Get the state // Get the state
uint8_t mode = this->climateCard->getMode(); uint8_t mode = this->climateCard->getMode();
if(mode == 0){ if (mode == 0)
{
} }
uint8_t fan_speed = this->climateCard->getFanSpeed(); uint8_t fan_speed = this->climateCard->getFanSpeed();
uint8_t temperature = this->climateCard->getTemperature(); uint8_t temperature = this->climateCard->getTemperature();
@ -399,8 +393,8 @@ void ISEDisplay::updateACState(){
this->takeSerialMutex(); this->takeSerialMutex();
// Send the state to the display // Send the state to the display
if (mode == 0 ){ if (mode == 0)
{
this->displayAdapter->print("ac_temp.pco="); this->displayAdapter->print("ac_temp.pco=");
this->displayAdapter->print(33841); this->displayAdapter->print(33841);
@ -409,9 +403,9 @@ void ISEDisplay::updateACState(){
this->displayAdapter->print("ac_temp.pic="); this->displayAdapter->print("ac_temp.pic=");
this->displayAdapter->print(COMPONENT_AC_STATUS_OFF); this->displayAdapter->print(COMPONENT_AC_STATUS_OFF);
this->sendStopBytes(); this->sendStopBytes();
} }
else{ else
{
this->displayAdapter->print("ac_temp.pco="); this->displayAdapter->print("ac_temp.pco=");
this->displayAdapter->print(34486); this->displayAdapter->print(34486);
this->sendStopBytes(); this->sendStopBytes();
@ -494,4 +488,3 @@ void ISEDisplay::updateACState(){
this->giveSerialMutex(); this->giveSerialMutex();
} }