clean up code
This commit is contained in:
parent
f0bdfe0d03
commit
3345cf6ae1
1 changed files with 115 additions and 122 deletions
|
|
@ -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:
|
||||
|
|
@ -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)
|
||||
{
|
||||
case COMPONENT_LIGHT_MASTER_BUTTON:
|
||||
|
|
@ -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,7 +218,8 @@ 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
|
||||
|
||||
|
|
@ -254,32 +237,36 @@ 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::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();
|
||||
}
|
||||
|
||||
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
|
||||
|
|
@ -295,7 +282,8 @@ void ISEDisplay::updateLightGroupStatePageStandby(){
|
|||
|
||||
this->giveSerialMutex();
|
||||
}
|
||||
void ISEDisplay::updateLightGroupStatePageDashboard(){
|
||||
void ISEDisplay::updateLightGroupStatePageDashboard()
|
||||
{
|
||||
// Calculate the state
|
||||
bool state = calculateLightGroupState();
|
||||
// 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->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);
|
||||
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue