fix aircon and other

This commit is contained in:
reaw 2024-02-09 15:52:01 +07:00
parent c99348bb72
commit 742027acf0
4 changed files with 93 additions and 74 deletions

Binary file not shown.

View file

@ -25,7 +25,7 @@ void ISEDisplay::begin(DigitalInputCard *inputCard, DigitalOutputCard *outputCar
this->lightLevelRow2 = 0; this->lightLevelRow2 = 0;
this->lightLevelRow3 = 0; this->lightLevelRow3 = 0;
this->lightLevelRow4 = 0; this->lightLevelRow4 = 0;
this->time_since_last_screen_update = 0; //this->time_since_last_screen_update = 0;
this->registerTouchCallback(bindedHandleTouch); this->registerTouchCallback(bindedHandleTouch);
this->reset(); this->reset();
delay(1000); delay(1000);
@ -36,7 +36,6 @@ void ISEDisplay::begin(DigitalInputCard *inputCard, DigitalOutputCard *outputCar
this->updateAirPurifierState(); this->updateAirPurifierState();
this->updateACState(); this->updateACState();
this->updateLightGroupStatePageDashboard(); this->updateLightGroupStatePageDashboard();
this->updateLightGroupStatePageStandby();
this->outputCard->setValue(6,pm_fan_speed); this->outputCard->setValue(6,pm_fan_speed);
this->outputCard->setValue(5,0); this->outputCard->setValue(5,0);
this->outputCard->setValue(1,0); this->outputCard->setValue(1,0);
@ -55,22 +54,22 @@ void ISEDisplay::loop()
// Update the time since the last screen update using millis() // Update the time since the last screen update using millis()
u_int32_t current_time = millis(); // u_int32_t current_time = millis();
if (current_time - this->time_since_last_screen_update > 120000) // if (current_time - this->time_since_last_screen_update > 120000)
{ // {
// jump to standby page if there is no activity for 2 minutes // // jump to standby page if there is no activity for 2 minutes
if(this->currentPage != 1){ // if(this->currentPage != 1){
this->jumpToPage(1); // this->jumpToPage(1);
ESP_LOGI("ISEDisplay", "Jumping to standby page"); // ESP_LOGI("ISEDisplay", "Jumping to standby page");
} // }
} // }
} }
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)
{ {
ESP_LOGD("ISEDisplay", "Touch detected on page %d, component %d, touch type %d", page, component, touch_type); ESP_LOGD("ISEDisplay", "Touch detected on page %d, component %d, touch type %d", page, component, touch_type);
time_since_last_screen_update = millis(); // update time since last activity //time_since_last_screen_update = millis(); // update time since last activity
if (page == PAGE_STANDBY) if (page == PAGE_STANDBY)
{ {
switch (component) switch (component)
@ -81,7 +80,7 @@ void ISEDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t touch_type
// TODO : Should you really jump to page 2 here? should't page jumping be handled reactivly? // TODO : Should you really jump to page 2 here? should't page jumping be handled reactivly?
// EX. if atleast one light is on, then jump to active page, else jump to standby page // EX. if atleast one light is on, then jump to active page, else jump to standby page
// This will allow page to change correctly when the system is started and when controlled remotely which won't call handleTouch // This will allow page to change correctly when the system is started and when controlled remotely which won't call handleTouch
time_since_last_screen_update = millis(); //time_since_last_screen_update = millis();
this->jumpToPage(2); this->jumpToPage(2);
// the function of the button is to open the dashboard from standby // the function of the button is to open the dashboard from standby
break; break;
@ -130,7 +129,6 @@ void ISEDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t touch_type
{ {
setLightLevel(i, 1); setLightLevel(i, 1);
} }
updateLightGroupStatePageDashboard();
break; break;
case COMPONENT_LIGHT_MASTER_LEVEL2_TOUCHPOINT: case COMPONENT_LIGHT_MASTER_LEVEL2_TOUCHPOINT:
if (touch_type != TOUCH_TYPE_RELEASE) if (touch_type != TOUCH_TYPE_RELEASE)
@ -139,7 +137,6 @@ void ISEDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t touch_type
{ {
setLightLevel(i, 2); setLightLevel(i, 2);
} }
updateLightGroupStatePageDashboard();
break; break;
case COMPONENT_LIGHT_MASTER_LEVEL3_TOUCHPOINT: case COMPONENT_LIGHT_MASTER_LEVEL3_TOUCHPOINT:
if (touch_type != TOUCH_TYPE_RELEASE) if (touch_type != TOUCH_TYPE_RELEASE)
@ -148,7 +145,6 @@ void ISEDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t touch_type
{ {
setLightLevel(i, 3); setLightLevel(i, 3);
} }
updateLightGroupStatePageDashboard();
break; break;
case COMPONENT_LIGHT_ROW1_SLIDER: case COMPONENT_LIGHT_ROW1_SLIDER:
if (touch_type != TOUCH_TYPE_RELEASE) if (touch_type != TOUCH_TYPE_RELEASE)
@ -211,20 +207,23 @@ void ISEDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t touch_type
ac_fan_speed = this->climateCard->getFanSpeed(); ac_fan_speed = this->climateCard->getFanSpeed();
// We have auto, low, mid, high right?, that's 0,1,2,3 a modulo operation of 3 only gives 0,1,2 // We have auto, low, mid, high right?, that's 0,1,2,3 a modulo operation of 3 only gives 0,1,2
// mod 4 should fixed it // mod 4 should fixed it
this->climateCard->setFanSpeed((ac_fan_speed + 1) % 4); ESP_LOGI("ISEDisplay", "Current AC fan speed: %d", ac_fan_speed);
updateACState(); ac_fan_speed = (ac_fan_speed + 1) % 4;
ESP_LOGI("ISEDisplay", "New AC fan speed: %d", ac_fan_speed);
this->climateCard->setFanSpeed(ac_fan_speed);
//updateACState();
break; break;
case COMPONENT_AC_TEMP_DOWN_BUTTON: case COMPONENT_AC_TEMP_DOWN_BUTTON:
if (touch_type != TOUCH_TYPE_RELEASE) if (touch_type != TOUCH_TYPE_RELEASE)
break; break;
this->climateCard->setTemperature(this->climateCard->getTemperature() - 1); this->climateCard->setTemperature(this->climateCard->getTemperature() - 1);
updateACState(); //updateACState();
break; break;
case COMPONENT_AC_TEMP_UP_BUTTON: case COMPONENT_AC_TEMP_UP_BUTTON:
if (touch_type != TOUCH_TYPE_RELEASE) if (touch_type != TOUCH_TYPE_RELEASE)
break; break;
this->climateCard->setTemperature(this->climateCard->getTemperature() + 1); this->climateCard->setTemperature(this->climateCard->getTemperature() + 1);
updateACState(); //updateACState();
break; break;
case COMPONENT_PM_TOGGLE_BUTTON: case COMPONENT_PM_TOGGLE_BUTTON:
if (touch_type != TOUCH_TYPE_RELEASE) if (touch_type != TOUCH_TYPE_RELEASE)
@ -273,13 +272,13 @@ void ISEDisplay::handlePWMChange(uint8_t pin, bool state, uint16_t value)
{ {
// Light // Light
updateLightGroupStatePageStandby(); updateLightGroupStatePageStandby();
time_since_last_screen_update = millis(); // update time since last activity //time_since_last_screen_update = millis(); // update time since last activity
} }
else if (pin == 4 || pin == 5) else if (pin == 4 || pin == 5)
{ {
// Air Purifier // Air Purifier
updateAirPurifierStateStandby(); updateAirPurifierStateStandby();
time_since_last_screen_update = millis(); // update time since last activity //time_since_last_screen_update = millis(); // update time since last activity
} }
} }
else if (current_page == PAGE_DASHBOARD) else if (current_page == PAGE_DASHBOARD)
@ -288,13 +287,13 @@ void ISEDisplay::handlePWMChange(uint8_t pin, bool state, uint16_t value)
{ {
// Light // Light
updateLightGroupStatePageDashboard(); updateLightGroupStatePageDashboard();
time_since_last_screen_update = millis(); // update time since last activity //time_since_last_screen_update = millis(); // update time since last activity
} }
else if (pin == 4 || pin == 5) else if (pin == 4 || pin == 5)
{ {
// Air Purifier // Air Purifier
updateAirPurifierState(); updateAirPurifierState();
time_since_last_screen_update = millis(); // update time since last activity //time_since_last_screen_update = millis(); // update time since last activity
} }
} }
else else
@ -416,10 +415,16 @@ 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)
{ {
this->climateCard->setTemperature(ac_temperature); ESP_LOGI("ISEDisplay", "Setting AC state: = fan speed: %d, mode: %d, temperature: %d", ac_fan_speed, ac_mode, ac_temperature);
this->climateCard->setFanSpeed(ac_fan_speed); this->climateCard->setFanSpeed(ac_fan_speed);
ESP_LOGI("ISEDisplay", "AC fan speed set to: %d", ac_fan_speed);
this->climateCard->setMode(ac_mode); this->climateCard->setMode(ac_mode);
updateACState(); ESP_LOGI("ISEDisplay", "AC mode set to: %d", ac_mode);
this->climateCard->setTemperature(ac_temperature);
ESP_LOGI("ISEDisplay", "AC temperature set to: %d", ac_temperature);
//updateACState();
} }
void ISEDisplay::toggleLightGroupState() void ISEDisplay::toggleLightGroupState()
{ {
@ -431,7 +436,6 @@ void ISEDisplay::toggleLightGroupState()
{ {
setLightLevel(i, state ? 0 : 3); setLightLevel(i, state ? 0 : 3);
} }
updateLightGroupStatePageDashboard();
} }
void ISEDisplay::toggleLightGroupStateStandby() void ISEDisplay::toggleLightGroupStateStandby()
{ {
@ -443,7 +447,7 @@ void ISEDisplay::toggleLightGroupStateStandby()
{ {
setLightLevel(i, state ? 0 : 3); setLightLevel(i, state ? 0 : 3);
} }
updateLightGroupStatePageStandby(); //updateLightGroupStatePageStandby();
} }
void ISEDisplay::togglePM() void ISEDisplay::togglePM()
{ {
@ -498,18 +502,23 @@ void ISEDisplay::changeUserACmode()
{ {
// Get the current group state // Get the current group state
uint8_t mode = this->climateCard->getMode(); uint8_t mode = this->climateCard->getMode();
ESP_LOGI("ISEDisplay", "Current actual AC mode: %d", mode);
// Toggle the state // Toggle the state
// user mode alternate between 1 and 2 // user mode alternate between 1 and 2
user_mode = (user_mode + 1) % 2 + 1; ESP_LOGI("ISEDisplay", "User mode BEFORE: %d", user_mode);
user_mode = (user_mode) % 2 + 1;
ESP_LOGI("ISEDisplay", "User mode AFTER: %d", user_mode);
if (mode != 0) if (mode != 0)
{ {
// update mode to new mode // update mode to new mode
mode = user_mode; mode = user_mode;
ESP_LOGI("ISEDisplay", "change actual AC mode to user mode: %d", mode);
} }
else else
{ // ie mode is off { // ie mode is off
// do nothing as the state is keep in user_mode // do nothing as the state is keep in user_mode
// the mode will change to user_mode when turn on by toggleAC() // the mode will change to user_mode when turn on by toggleAC()
ESP_LOGI("ISEDisplay", "do nothing; user mode: %d , actual mode: %d", user_mode, mode);
} }
updateuserACmode(); // call to update mode part of the display seperately updateuserACmode(); // call to update mode part of the display seperately
} }
@ -622,7 +631,6 @@ void ISEDisplay::toggleLightIndividual(uint8_t row)
} }
// Set the state // Set the state
setLightLevel(row, state); setLightLevel(row, state);
updateLightGroupStatePageDashboard();
} }
void ISEDisplay::toggleSliderLight(uint8_t row, uint8_t lightLevel) void ISEDisplay::toggleSliderLight(uint8_t row, uint8_t lightLevel)
{ {
@ -651,7 +659,6 @@ void ISEDisplay::toggleSliderLight(uint8_t row, uint8_t lightLevel)
} }
// Set the state // Set the state
setLightLevel(row, state); setLightLevel(row, state);
updateLightGroupStatePageDashboard();
} }
void ISEDisplay::updateAirPurifierStateStandby() void ISEDisplay::updateAirPurifierStateStandby()
{ {
@ -700,11 +707,13 @@ void ISEDisplay::updateAirPurifierState()
} }
void ISEDisplay::handleACChange(uint8_t mode, uint8_t fan_speed, uint8_t temperature) void ISEDisplay::handleACChange(uint8_t mode, uint8_t fan_speed, uint8_t temperature)
{ {
ESP_LOGI("ISEDisplay", "AC state changed: mode: %d, fan speed: %d, temperature: %d", mode, fan_speed, temperature);
updateACState(); updateACState();
} }
void ISEDisplay::updateuserACmode() void ISEDisplay::updateuserACmode()
{ {
this->takeSerialMutex(); this->takeSerialMutex();
ESP_LOGI("ISEDisplay", "updating display user AC mode to: %d", user_mode);
switch (user_mode) switch (user_mode)
{ {
case 1: case 1:
@ -731,38 +740,39 @@ void ISEDisplay::updateuserACmode()
void ISEDisplay::updateACfanSpeed() void ISEDisplay::updateACfanSpeed()
{ {
uint8_t fan_speed = this->climateCard->getFanSpeed(); uint8_t fan_speed = this->climateCard->getFanSpeed();
ESP_LOGI("ISEDisplay", "updating display AC fan speed to: %d", fan_speed);
this->takeSerialMutex(); this->takeSerialMutex();
switch (fan_speed) switch (fan_speed)
{ {
case 0: case 0:
this->displayAdapter->print("ac_fan.pic="); this->displayAdapter->print("ac_speed.pic=");
this->displayAdapter->print(COMPONENT_AC_FAN_MODE_AUTO_PIC); this->displayAdapter->print(COMPONENT_AC_FAN_MODE_AUTO_PIC);
this->sendStopBytes(); this->sendStopBytes();
this->displayAdapter->print("ac_fan.pic2="); this->displayAdapter->print("ac_speed.pic2=");
this->displayAdapter->print(COMPONENT_AC_FAN_MODE_AUTO_PIC_PRESSED); this->displayAdapter->print(COMPONENT_AC_FAN_MODE_AUTO_PIC_PRESSED);
this->sendStopBytes(); this->sendStopBytes();
break; break;
case 1: case 1:
this->displayAdapter->print("ac_fan.pic="); this->displayAdapter->print("ac_speed.pic=");
this->displayAdapter->print(COMPONENT_AC_FAN_MODE_HIGH_PIC); this->displayAdapter->print(COMPONENT_AC_FAN_MODE_HIGH_PIC);
this->sendStopBytes(); this->sendStopBytes();
this->displayAdapter->print("ac_fan.pic2="); this->displayAdapter->print("ac_speed.pic2=");
this->displayAdapter->print(COMPONENT_AC_FAN_MODE_HIGH_PIC_PRESSED); this->displayAdapter->print(COMPONENT_AC_FAN_MODE_HIGH_PIC_PRESSED);
this->sendStopBytes(); this->sendStopBytes();
break; break;
case 2: case 2:
this->displayAdapter->print("ac_fan.pic="); this->displayAdapter->print("ac_speed.pic=");
this->displayAdapter->print(COMPONENT_AC_FAN_MODE_MID_PIC); this->displayAdapter->print(COMPONENT_AC_FAN_MODE_MID_PIC);
this->sendStopBytes(); this->sendStopBytes();
this->displayAdapter->print("ac_fan.pic2="); this->displayAdapter->print("ac_speed.pic2=");
this->displayAdapter->print(COMPONENT_AC_FAN_MODE_MID_PIC_PRESSED); this->displayAdapter->print(COMPONENT_AC_FAN_MODE_MID_PIC_PRESSED);
this->sendStopBytes(); this->sendStopBytes();
break; break;
case 3: case 3:
this->displayAdapter->print("ac_fan.pic="); this->displayAdapter->print("ac_speed.pic=");
this->displayAdapter->print(COMPONENT_AC_FAN_MODE_LOW_PIC); this->displayAdapter->print(COMPONENT_AC_FAN_MODE_LOW_PIC);
this->sendStopBytes(); this->sendStopBytes();
this->displayAdapter->print("ac_fan.pic2="); this->displayAdapter->print("ac_speed.pic2=");
this->displayAdapter->print(COMPONENT_AC_FAN_MODE_LOW_PIC_PRESSED); this->displayAdapter->print(COMPONENT_AC_FAN_MODE_LOW_PIC_PRESSED);
this->sendStopBytes(); this->sendStopBytes();
break; break;
@ -821,4 +831,5 @@ void ISEDisplay::updateACState()
this->sendStopBytes(); this->sendStopBytes();
this->giveSerialMutex(); this->giveSerialMutex();
ESP_LOGI("ISEDisplay", "display AC state updated");
} }

View file

@ -22,6 +22,9 @@ class ISEDisplay : public ESPMegaDisplay {
ISEDisplay(HardwareSerial* adapter); ISEDisplay(HardwareSerial* adapter);
void begin(DigitalInputCard* inputCard, DigitalOutputCard* outputCard, ClimateCard* climateCard); void begin(DigitalInputCard* inputCard, DigitalOutputCard* outputCard, ClimateCard* climateCard);
void updateLightGroupStatePageDashboard(); void updateLightGroupStatePageDashboard();
void updateLightGroupStatePageStandby();
void updateAirPurifierState();
void updateAirPurifierStateStandby();
void updateDateTimeText(rtctime_t time); void updateDateTimeText(rtctime_t time);
void updateWeather(char *weather_string); void updateWeather(char *weather_string);
void updateTempOutside(float temp_outside); void updateTempOutside(float temp_outside);
@ -56,14 +59,9 @@ class ISEDisplay : public ESPMegaDisplay {
u_int8_t lightLevelRow3; u_int8_t lightLevelRow3;
u_int8_t lightLevelRow4; u_int8_t lightLevelRow4;
void updateACState();
void updateuserACmode(); void updateuserACmode();
void updateACfanSpeed(); void updateACfanSpeed();
void updateLightGroupStatePageStandby();
void updateAirPurifierState();
void updateAirPurifierStateStandby();
void updateACState();
bool calculateLightGroupState(); bool calculateLightGroupState();
void toggleLightGroupState(); void toggleLightGroupState();
void toggleLightGroupStateStandby(); void toggleLightGroupStateStandby();

View file

@ -28,7 +28,6 @@ ClimateCard climateCard = ClimateCard(AIR_CONDITIONER_IR_PIN, ac,
void handleMqttMessage(char *topic, char *payload) void handleMqttMessage(char *topic, char *payload)
{ {
} }
void sendStopBytes() void sendStopBytes()
@ -122,10 +121,10 @@ void loop()
iseDisplay.loop(); iseDisplay.loop();
// Update the time every 15 seconds // Update the time every 15 seconds
//static bool run_when_init = false; // No static ? , this shit will reset to 0 every loop // static bool run_when_init = false; // No static ? , this shit will reset to 0 every loop
static uint32_t last_time_updated = 0; static uint32_t last_time_updated = 0;
//rtctime_t time = espmega.getTime(); // rtctime_t time = espmega.getTime();
//when init update once then update every 15 seconds // when init update once then update every 15 seconds
// You don't need this, when it go from page 0 to 1 it call handlePageChange // You don't need this, when it go from page 0 to 1 it call handlePageChange
// if(!run_when_init){ // if(!run_when_init){
// time = espmega.getTime(); // time = espmega.getTime();
@ -134,7 +133,6 @@ void loop()
// run_when_init = true; // run_when_init = true;
// } // }
if (millis() - last_time_updated > 15000) if (millis() - last_time_updated > 15000)
{ {
rtctime_t time = espmega.getTime(); rtctime_t time = espmega.getTime();
@ -168,12 +166,10 @@ void loop()
// iseDisplay.updateWeather(weather_value); // iseDisplay.updateWeather(weather_value);
// last_weather_update = millis(); // last_weather_update = millis();
// } // }
} }
void on_pin_change(uint8_t pin, uint8_t value) void on_pin_change(uint8_t pin, uint8_t value)
{ {
} }
// uint16_t get_pm25_out() // uint16_t get_pm25_out()
@ -191,15 +187,29 @@ void on_pin_change(uint8_t pin, uint8_t value)
// return temp_out_value; // return temp_out_value;
// } // }
void handlePageChange(uint8_t page) { void handlePageChange(uint8_t page)
{
// Which already send the time // Which already send the time
//printESP_LOGI the page have changed // printESP_LOGI the page have changed
ESP_LOGI("Page", "Page change to: %d", page); ESP_LOGI("Page", "Page change to: %d", page);
rtctime_t time = espmega.getTime(); rtctime_t time = espmega.getTime();
iseDisplay.updateDateTimeText(time); iseDisplay.updateDateTimeText(time);
switch (page)
{
case PAGE_STANDBY:
iseDisplay.updateLightGroupStatePageStandby();
iseDisplay.updateAirPurifierStateStandby();
break;
case PAGE_DASHBOARD:
iseDisplay.updateLightGroupStatePageDashboard(); iseDisplay.updateLightGroupStatePageDashboard();
//iseDisplay.updatePMinside(); iseDisplay.updateAirPurifierState();
break;
default:
break;
}
// iseDisplay.updatePMinside();
/* iseDisplay.updatePMoutside(get_pm25_out()); /* iseDisplay.updatePMoutside(get_pm25_out());
iseDisplay.updateWeather(weather.getValue()); iseDisplay.updateWeather(weather.getValue());
iseDisplay.updateTempOutside(get_temp_out()); */ iseDisplay.updateTempOutside(get_temp_out()); */
@ -209,4 +219,4 @@ void handlePageChange(uint8_t page) {
iseDisplay.updateLightGroupStatePageDashboard(); iseDisplay.updateLightGroupStatePageDashboard();
iseDisplay.updateuserACmode(); iseDisplay.updateuserACmode();
iseDisplay.updateAirPurifierStateStandby(); */ iseDisplay.updateAirPurifierStateStandby(); */
} }