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)
{
}
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->outputCard = outputCard;
this->climateCard = climateCard;
@ -43,12 +23,12 @@ ISEDisplay(HardwareSerial* adapter);
this->updateLightGroupState();
this->updateAirPurifierState();
this->updateACState();
}
void ISEDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t touch_type){
if (page == PAGE_STANDBY){
void ISEDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t touch_type)
{
if (page == PAGE_STANDBY)
{
switch (component)
{
case COMPONENT_STANDBY_OPEN_ALL_TOGGLE:
@ -76,8 +56,9 @@ void ISEDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t touch_type
break;
}
}
else if (page == PAGE_DASHBOARD){
else if (page == PAGE_DASHBOARD)
{
switch (component)
{
case COMPONENT_LIGHT_MASTER_BUTTON:
@ -115,7 +96,7 @@ void ISEDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t touch_type
break;
setLightLevel(2, 1);
break;
case COMPONENT_LIGHT_ROW2_LEVEL2_TOUCHPOINT:
case COMPONENT_LIGHT_ROW2_LEVEL2_TOUCHPOINT:
if (touch_type != TOUCH_TYPE_RELEASE)
break;
setLightLevel(2, 2);
@ -135,12 +116,12 @@ void ISEDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t touch_type
break;
setLightLevel(3, 1);
break;
case COMPONENT_LIGHT_ROW3_LEVEL2_TOUCHPOINT:
case COMPONENT_LIGHT_ROW3_LEVEL2_TOUCHPOINT:
if (touch_type != TOUCH_TYPE_RELEASE)
break;
setLightLevel(3, 2);
break;
case COMPONENT_LIGHT_ROW3_LEVEL3_TOUCHPOINT:
case COMPONENT_LIGHT_ROW3_LEVEL3_TOUCHPOINT:
if (touch_type != TOUCH_TYPE_RELEASE)
break;
setLightLevel(3, 3);
@ -155,12 +136,12 @@ void ISEDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t touch_type
break;
setLightLevel(4, 1);
break;
case COMPONENT_LIGHT_ROW4_LEVEL2_TOUCHPOINT:
case COMPONENT_LIGHT_ROW4_LEVEL2_TOUCHPOINT:
if (touch_type != TOUCH_TYPE_RELEASE)
break;
setLightLevel(4, 2);
break;
case COMPONENT_LIGHT_ROW4_LEVEL3_TOUCHPOINT:
case COMPONENT_LIGHT_ROW4_LEVEL3_TOUCHPOINT:
if (touch_type != TOUCH_TYPE_RELEASE)
break;
setLightLevel(4, 3);
@ -181,7 +162,7 @@ void ISEDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t touch_type
if (touch_type != TOUCH_TYPE_RELEASE)
break;
uint8_t fan_speed = this->climateCard->getFanSpeed();
this->climateCard->setFanSpeed((fan_speed + 1)%3);
this->climateCard->setFanSpeed((fan_speed + 1) % 3);
break;
case COMPONENT_AC_TEMP_DOWN_BUTTON:
if (touch_type != TOUCH_TYPE_RELEASE)
@ -215,15 +196,16 @@ void ISEDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t touch_type
default:
break;
}
}
else{
else
{
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)
{
// Light
@ -236,10 +218,11 @@ void ISEDisplay::handlePWMChange(uint8_t pin, bool state, uint16_t value){
updateAirPurifierState();
}
}
void ISEDisplay::updateDateTimeText(rtctime_t time){
void ISEDisplay::updateDateTimeText(rtctime_t time)
{
this->takeSerialMutex();
// Send the time to the display
this->displayAdapter->printf("time.txt=%02d:%02d", time.hours, time.minutes);
this->sendStopBytes();
@ -254,37 +237,41 @@ void ISEDisplay::updateDateTimeText(rtctime_t time){
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::setPMstate(bool is_pm_on, uint8_t pm_fan_speed){
void ISEDisplay::updatePMinside(float pm25_inside)
{
}
void ISEDisplay::setACstate(uint8_t ac_fan_speed, uint8_t ac_mode, uint8_t ac_temperature){
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)
{
updateACState();
}
void ISEDisplay::setLightLevel(uint8_t row, uint8_t level){
for (uint8_t i = 1; i <= 4; i++) {
if(row == i)
void ISEDisplay::setLightLevel(uint8_t row, uint8_t level)
{
for (uint8_t i = 1; i <= 4; i++)
{
if (row == i)
this->outputCard->setState(row, level);
}
}
void ISEDisplay::updateLightGroupStatePageStandby(){
void ISEDisplay::updateLightGroupStatePageStandby()
{
// Calculate the state
bool state = calculateLightGroupState();
// Send the state to the display
this->takeSerialMutex();
this->displayAdapter->print("s_light_toggle.pic=");
this->displayAdapter->print(state ? COMPONENT_STANDBY_LIGHT_PIC_ON : COMPONENT_STANDBY_LIGHT_PIC_OFF);
this->sendStopBytes();
@ -295,12 +282,13 @@ void ISEDisplay::updateLightGroupStatePageStandby(){
this->giveSerialMutex();
}
void ISEDisplay::updateLightGroupStatePageDashboard(){
void ISEDisplay::updateLightGroupStatePageDashboard()
{
// Calculate the state
bool state = calculateLightGroupState();
// Send the state to the display
this->takeSerialMutex();
this->displayAdapter->print("light_master.pic=");
this->displayAdapter->print(state ? COMPONENT_LIGHT_MASTER_ON : COMPONENT_LIGHT_MASTER_OFF);
this->sendStopBytes();
@ -309,7 +297,8 @@ void ISEDisplay::updateLightGroupStatePageDashboard(){
this->displayAdapter->print(state ? COMPONENT_LIGHT_MASTER_ON_PRESSED : COMPONENT_LIGHT_MASTER_OFF_PRESSED);
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);
switch (state)
{
@ -348,18 +337,22 @@ void ISEDisplay::updateLightGroupStatePageDashboard(){
this->giveSerialMutex();
}
bool ISEDisplay::calculateLightGroupState() {
bool ISEDisplay::calculateLightGroupState()
{
// Check if all lights are on
bool lightOn = false;
for (uint8_t i = 1; i <= 4; i++) {
if (this->outputCard->getState(i) != 0) {
for (uint8_t i = 1; i <= 4; i++)
{
if (this->outputCard->getState(i) != 0)
{
lightOn = true;
break;
}
}
return lightOn;
}
void ISEDisplay::updateAirPurifierState(){
void ISEDisplay::updateAirPurifierState()
{
// Get the state
bool state = this->outputCard->getState(5);
uint8_t fan_speed = this->outputCard->getState(5);
@ -373,7 +366,7 @@ void ISEDisplay::updateAirPurifierState(){
this->displayAdapter->print("pm_sw.pic2=");
this->displayAdapter->print(state ? COMPONENT_PM_TOGGLE_PIC_ON_PRESSED : COMPONENT_PM_TOGGLE_PIC_OFF_PRESSED);
this->sendStopBytes();
this->displayAdapter->print("pm_speed.txt=\"");
this->displayAdapter->print(fan_speed);
this->displayAdapter->print("\"");
@ -386,12 +379,13 @@ void ISEDisplay::updateAirPurifierState(){
this->giveSerialMutex();
}
void ISEDisplay::updateACState(){
// Get the state
void ISEDisplay::updateACState()
{
// Get the state
uint8_t mode = this->climateCard->getMode();
if(mode == 0){
if (mode == 0)
{
}
uint8_t fan_speed = this->climateCard->getFanSpeed();
uint8_t temperature = this->climateCard->getTemperature();
@ -399,8 +393,8 @@ void ISEDisplay::updateACState(){
this->takeSerialMutex();
// Send the state to the display
if (mode == 0 ){
if (mode == 0)
{
this->displayAdapter->print("ac_temp.pco=");
this->displayAdapter->print(33841);
@ -409,9 +403,9 @@ void ISEDisplay::updateACState(){
this->displayAdapter->print("ac_temp.pic=");
this->displayAdapter->print(COMPONENT_AC_STATUS_OFF);
this->sendStopBytes();
}
else{
else
{
this->displayAdapter->print("ac_temp.pco=");
this->displayAdapter->print(34486);
this->sendStopBytes();
@ -430,61 +424,61 @@ void ISEDisplay::updateACState(){
this->sendStopBytes();
switch (user_mode)
{
case 1:
this->displayAdapter->print("ac_mode.pic=");
this->displayAdapter->print(COMPONENT_AC_MODE_COOL_PIC);
this->sendStopBytes();
this->displayAdapter->print("ac_mode.pic2=");
this->displayAdapter->print(COMPONENT_AC_MODE_COOL_PIC_PRESSED);
this->sendStopBytes();
break;
case 2:
this->displayAdapter->print("ac_mode.pic=");
this->displayAdapter->print(COMPONENT_AC_MODE_FAN_PIC);
this->sendStopBytes();
this->displayAdapter->print("ac_mode.pic2=");
this->displayAdapter->print(COMPONENT_AC_MODE_FAN_PIC_PRESSED);
this->sendStopBytes();
break;
default:
break;
case 1:
this->displayAdapter->print("ac_mode.pic=");
this->displayAdapter->print(COMPONENT_AC_MODE_COOL_PIC);
this->sendStopBytes();
this->displayAdapter->print("ac_mode.pic2=");
this->displayAdapter->print(COMPONENT_AC_MODE_COOL_PIC_PRESSED);
this->sendStopBytes();
break;
case 2:
this->displayAdapter->print("ac_mode.pic=");
this->displayAdapter->print(COMPONENT_AC_MODE_FAN_PIC);
this->sendStopBytes();
this->displayAdapter->print("ac_mode.pic2=");
this->displayAdapter->print(COMPONENT_AC_MODE_FAN_PIC_PRESSED);
this->sendStopBytes();
break;
default:
break;
}
switch (fan_speed)
{
case 0:
this->displayAdapter->print("ac_fan.pic=");
this->displayAdapter->print(COMPONENT_AC_FAN_MODE_AUTO_PIC);
this->sendStopBytes();
this->displayAdapter->print("ac_fan.pic2=");
this->displayAdapter->print(COMPONENT_AC_FAN_MODE_AUTO_PIC_PRESSED);
this->sendStopBytes();
break;
case 1:
this->displayAdapter->print("ac_fan.pic=");
this->displayAdapter->print(COMPONENT_AC_FAN_MODE_HIGH_PIC);
this->sendStopBytes();
this->displayAdapter->print("ac_fan.pic2=");
this->displayAdapter->print(COMPONENT_AC_FAN_MODE_HIGH_PIC_PRESSED);
this->sendStopBytes();
break;
case 2:
this->displayAdapter->print("ac_fan.pic=");
this->displayAdapter->print(COMPONENT_AC_FAN_MODE_MID_PIC);
this->sendStopBytes();
this->displayAdapter->print("ac_fan.pic2=");
this->displayAdapter->print(COMPONENT_AC_FAN_MODE_MID_PIC_PRESSED);
this->sendStopBytes();
break;
case 3:
this->displayAdapter->print("ac_fan.pic=");
this->displayAdapter->print(COMPONENT_AC_FAN_MODE_LOW_PIC);
this->sendStopBytes();
this->displayAdapter->print("ac_fan.pic2=");
this->displayAdapter->print(COMPONENT_AC_FAN_MODE_LOW_PIC_PRESSED);
this->sendStopBytes();
break;
default:
break;
case 0:
this->displayAdapter->print("ac_fan.pic=");
this->displayAdapter->print(COMPONENT_AC_FAN_MODE_AUTO_PIC);
this->sendStopBytes();
this->displayAdapter->print("ac_fan.pic2=");
this->displayAdapter->print(COMPONENT_AC_FAN_MODE_AUTO_PIC_PRESSED);
this->sendStopBytes();
break;
case 1:
this->displayAdapter->print("ac_fan.pic=");
this->displayAdapter->print(COMPONENT_AC_FAN_MODE_HIGH_PIC);
this->sendStopBytes();
this->displayAdapter->print("ac_fan.pic2=");
this->displayAdapter->print(COMPONENT_AC_FAN_MODE_HIGH_PIC_PRESSED);
this->sendStopBytes();
break;
case 2:
this->displayAdapter->print("ac_fan.pic=");
this->displayAdapter->print(COMPONENT_AC_FAN_MODE_MID_PIC);
this->sendStopBytes();
this->displayAdapter->print("ac_fan.pic2=");
this->displayAdapter->print(COMPONENT_AC_FAN_MODE_MID_PIC_PRESSED);
this->sendStopBytes();
break;
case 3:
this->displayAdapter->print("ac_fan.pic=");
this->displayAdapter->print(COMPONENT_AC_FAN_MODE_LOW_PIC);
this->sendStopBytes();
this->displayAdapter->print("ac_fan.pic2=");
this->displayAdapter->print(COMPONENT_AC_FAN_MODE_LOW_PIC_PRESSED);
this->sendStopBytes();
break;
default:
break;
}
this->displayAdapter->print("ac_temp.txt=\"");
@ -494,4 +488,3 @@ void ISEDisplay::updateACState(){
this->giveSerialMutex();
}