display climate implementation

This commit is contained in:
Siwat Sirichai 2023-12-31 00:37:50 +07:00
parent ea2c2e076b
commit 19aae95252
4 changed files with 21 additions and 17 deletions

View File

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

View File

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

View File

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

View File

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