From 19aae95252963826dcedfa61d5064b639144984f Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Sun, 31 Dec 2023 00:37:50 +0700 Subject: [PATCH] display climate implementation --- .../lib/ESPMegaPRO/ClimateCard.cpp | 12 +++++++++++ .../lib/ESPMegaPRO/InternalDisplay.cpp | 20 ++++++------------- .../lib/ESPMegaPRO/InternalDisplay.hpp | 3 --- ESPMegaPRO-firmware/src/main.cpp | 3 +++ 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/ESPMegaPRO-firmware/lib/ESPMegaPRO/ClimateCard.cpp b/ESPMegaPRO-firmware/lib/ESPMegaPRO/ClimateCard.cpp index f3fda4e..650a1bb 100644 --- a/ESPMegaPRO-firmware/lib/ESPMegaPRO/ClimateCard.cpp +++ b/ESPMegaPRO-firmware/lib/ESPMegaPRO/ClimateCard.cpp @@ -92,6 +92,18 @@ void ClimateCard::saveStateToFRAM() void ClimateCard::loadStateFromFRAM() { fram->readObject(fram_address, this->state); + // If temperature is out of range, set to its respective maximum or minimum + if (state.ac_temperature > ac.max_temperature) + state.ac_temperature = ac.max_temperature; + else if (state.ac_temperature < ac.min_temperature) + state.ac_temperature = ac.min_temperature; + // If mode is out of range, set to 0 + if (state.ac_mode > ac.modes) + state.ac_mode = 0; + // If fan speed is out of range, set to 0 + if (state.ac_fan_speed > ac.fan_speeds) + state.ac_fan_speed = 0; + updateAirConditioner(); } void ClimateCard::setTemperature(uint8_t temperature) diff --git a/ESPMegaPRO-firmware/lib/ESPMegaPRO/InternalDisplay.cpp b/ESPMegaPRO-firmware/lib/ESPMegaPRO/InternalDisplay.cpp index 80f6234..4be284b 100644 --- a/ESPMegaPRO-firmware/lib/ESPMegaPRO/InternalDisplay.cpp +++ b/ESPMegaPRO-firmware/lib/ESPMegaPRO/InternalDisplay.cpp @@ -73,6 +73,10 @@ void InternalDisplay::handlePwmStateChange(uint8_t pin, bool state, uint16_t val // Update the output state this->setOutputBar(pin, value); this->setOutputStateColor(pin, state); + // Refresh the PWM Adjustment page if the current page is the PWM Adjustment page and the pin is the same + if (this->currentPage == INTERNAL_DISPLAY_PWM_ADJUSTMENT_PAGE && this->pmwAdjustmentPin == pin) { + this->refreshPWMAdjustment(); + } } void InternalDisplay::handlePageChange(uint8_t page) { @@ -171,7 +175,7 @@ void InternalDisplay::refreshOutput() { void InternalDisplay::refreshAC() { this->displayAdapter->print("temp.txt=\""); this->displayAdapter->print(this->climateCard->getTemperature()); - this->displayAdapter->print(" C\""); + this->displayAdapter->print("C\""); this->sendStopBytes(); this->displayAdapter->print("fan_auto.pic="); this->displayAdapter->print(this->climateCard->getFanSpeed() == AC_FAN_SPEED_AUTO ? PIC_AC_FAN_SPEED_AUTO_ACTIVE : PIC_AC_FAN_SPEED_AUTO_INACTIVE); @@ -179,7 +183,7 @@ void InternalDisplay::refreshAC() { this->displayAdapter->print("fan_low.pic="); this->displayAdapter->print(this->climateCard->getFanSpeed() == AC_FAN_SPEED_LOW ? PIC_AC_FAN_SPEED_LOW_ACTIVE : PIC_AC_FAN_SPEED_LOW_INACTIVE); this->sendStopBytes(); - this->displayAdapter->print("fan_med.pic="); + this->displayAdapter->print("fan_mid.pic="); this->displayAdapter->print(this->climateCard->getFanSpeed() == AC_FAN_SPEED_MEDIUM ? PIC_AC_FAN_SPEED_MEDIUM_ACTIVE : PIC_AC_FAN_SPEED_MEDIUM_INACTIVE); this->sendStopBytes(); this->displayAdapter->print("fan_high.pic="); @@ -217,18 +221,6 @@ void InternalDisplay::refreshAC() { } } -void InternalDisplay::setPWMAdjustmentSlider(uint16_t value) { - // TODO: implementation -} - -void InternalDisplay::setPWMAdjustmentPin(uint8_t pin) { - // TODO: implementation -} - -void InternalDisplay::setPWMAdjustmentButton(bool state) { - // TODO: implementation -} - void InternalDisplay::setOutputBar(uint8_t pin, uint16_t value) { // Write the value to the output bar this->displayAdapter->print("j"); diff --git a/ESPMegaPRO-firmware/lib/ESPMegaPRO/InternalDisplay.hpp b/ESPMegaPRO-firmware/lib/ESPMegaPRO/InternalDisplay.hpp index 4a0051b..2927916 100644 --- a/ESPMegaPRO-firmware/lib/ESPMegaPRO/InternalDisplay.hpp +++ b/ESPMegaPRO-firmware/lib/ESPMegaPRO/InternalDisplay.hpp @@ -84,9 +84,6 @@ class InternalDisplay : public ESPMegaDisplay { void setOutputBar(uint8_t pin, uint16_t value); void setOutputStateColor(uint8_t pin, bool state); void setInputMarker(uint8_t pin, bool state); - void setPWMAdjustmentSlider(uint16_t value); - void setPWMAdjustmentPin(uint8_t pin); - void setPWMAdjustmentButton(bool state); void saveNetworkConfig(); void saveMQTTConfig(); void updateStatusIcons(bool networkStatus, bool mqttStatus); diff --git a/ESPMegaPRO-firmware/src/main.cpp b/ESPMegaPRO-firmware/src/main.cpp index 43dd917..06fd5c1 100644 --- a/ESPMegaPRO-firmware/src/main.cpp +++ b/ESPMegaPRO-firmware/src/main.cpp @@ -89,6 +89,9 @@ void setup() { espmega.inputs.registerCallback(input_change_callback); Serial.println("Installing Climate Card"); espmega.installCard(2, &climateCard); + climateCard.bindFRAM(&espmega.fram, 2000); + climateCard.loadStateFromFRAM(); + climateCard.setFRAMAutoSave(true); Serial.println("Enabling Internal Display"); espmega.enableInternalDisplay(&Serial); espmega.display->bindClimateCard(&climateCard);