diff --git a/ise-display/ise-display-prod.HMI b/ise-display/ise-display-prod.HMI index c394533..c7b0d8c 100644 Binary files a/ise-display/ise-display-prod.HMI and b/ise-display/ise-display-prod.HMI differ diff --git a/src/ise_display.cpp b/src/ise_display.cpp index 7f6eb9b..6aaa8be 100644 --- a/src/ise_display.cpp +++ b/src/ise_display.cpp @@ -25,7 +25,7 @@ void ISEDisplay::begin(DigitalInputCard *inputCard, DigitalOutputCard *outputCar this->lightLevelRow2 = 0; this->lightLevelRow3 = 0; this->lightLevelRow4 = 0; - this->time_since_last_screen_update = 0; + //this->time_since_last_screen_update = 0; this->registerTouchCallback(bindedHandleTouch); this->reset(); delay(1000); @@ -36,7 +36,6 @@ void ISEDisplay::begin(DigitalInputCard *inputCard, DigitalOutputCard *outputCar this->updateAirPurifierState(); this->updateACState(); this->updateLightGroupStatePageDashboard(); - this->updateLightGroupStatePageStandby(); this->outputCard->setValue(6,pm_fan_speed); this->outputCard->setValue(5,0); this->outputCard->setValue(1,0); @@ -55,22 +54,22 @@ void ISEDisplay::loop() // 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) - { - // jump to standby page if there is no activity for 2 minutes - if(this->currentPage != 1){ - this->jumpToPage(1); - ESP_LOGI("ISEDisplay", "Jumping to standby page"); - } - } + // if (current_time - this->time_since_last_screen_update > 120000) + // { + // // jump to standby page if there is no activity for 2 minutes + // if(this->currentPage != 1){ + // this->jumpToPage(1); + // ESP_LOGI("ISEDisplay", "Jumping to standby page"); + // } + // } } 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); - 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) { 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? // 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 - time_since_last_screen_update = millis(); + //time_since_last_screen_update = millis(); this->jumpToPage(2); // the function of the button is to open the dashboard from standby break; @@ -130,7 +129,6 @@ void ISEDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t touch_type { setLightLevel(i, 1); } - updateLightGroupStatePageDashboard(); break; case COMPONENT_LIGHT_MASTER_LEVEL2_TOUCHPOINT: 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); } - updateLightGroupStatePageDashboard(); break; case COMPONENT_LIGHT_MASTER_LEVEL3_TOUCHPOINT: 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); } - updateLightGroupStatePageDashboard(); break; case COMPONENT_LIGHT_ROW1_SLIDER: 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(); // 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 - this->climateCard->setFanSpeed((ac_fan_speed + 1) % 4); - updateACState(); + ESP_LOGI("ISEDisplay", "Current AC fan speed: %d", ac_fan_speed); + 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; case COMPONENT_AC_TEMP_DOWN_BUTTON: if (touch_type != TOUCH_TYPE_RELEASE) break; this->climateCard->setTemperature(this->climateCard->getTemperature() - 1); - updateACState(); + //updateACState(); break; case COMPONENT_AC_TEMP_UP_BUTTON: if (touch_type != TOUCH_TYPE_RELEASE) break; this->climateCard->setTemperature(this->climateCard->getTemperature() + 1); - updateACState(); + //updateACState(); break; case COMPONENT_PM_TOGGLE_BUTTON: if (touch_type != TOUCH_TYPE_RELEASE) @@ -273,13 +272,13 @@ void ISEDisplay::handlePWMChange(uint8_t pin, bool state, uint16_t value) { // Light 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) { // Air Purifier 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) @@ -288,13 +287,13 @@ void ISEDisplay::handlePWMChange(uint8_t pin, bool state, uint16_t value) { // Light 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) { // Air Purifier updateAirPurifierState(); - time_since_last_screen_update = millis(); // update time since last activity + //time_since_last_screen_update = millis(); // update time since last activity } } 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) { - 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); + ESP_LOGI("ISEDisplay", "AC fan speed set to: %d", ac_fan_speed); 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() { @@ -431,7 +436,6 @@ void ISEDisplay::toggleLightGroupState() { setLightLevel(i, state ? 0 : 3); } - updateLightGroupStatePageDashboard(); } void ISEDisplay::toggleLightGroupStateStandby() { @@ -443,7 +447,7 @@ void ISEDisplay::toggleLightGroupStateStandby() { setLightLevel(i, state ? 0 : 3); } - updateLightGroupStatePageStandby(); + //updateLightGroupStatePageStandby(); } void ISEDisplay::togglePM() { @@ -498,18 +502,23 @@ void ISEDisplay::changeUserACmode() { // Get the current group state uint8_t mode = this->climateCard->getMode(); + ESP_LOGI("ISEDisplay", "Current actual AC mode: %d", mode); // Toggle the state // 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) { // update mode to new mode mode = user_mode; + ESP_LOGI("ISEDisplay", "change actual AC mode to user mode: %d", mode); } else { // ie mode is off // do nothing as the state is keep in user_mode // 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 } @@ -622,7 +631,6 @@ void ISEDisplay::toggleLightIndividual(uint8_t row) } // Set the state setLightLevel(row, state); - updateLightGroupStatePageDashboard(); } 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 setLightLevel(row, state); - updateLightGroupStatePageDashboard(); } void ISEDisplay::updateAirPurifierStateStandby() { @@ -700,11 +707,13 @@ void ISEDisplay::updateAirPurifierState() } 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(); } void ISEDisplay::updateuserACmode() { this->takeSerialMutex(); + ESP_LOGI("ISEDisplay", "updating display user AC mode to: %d", user_mode); switch (user_mode) { case 1: @@ -731,38 +740,39 @@ void ISEDisplay::updateuserACmode() void ISEDisplay::updateACfanSpeed() { uint8_t fan_speed = this->climateCard->getFanSpeed(); + ESP_LOGI("ISEDisplay", "updating display AC fan speed to: %d", fan_speed); this->takeSerialMutex(); switch (fan_speed) { case 0: - this->displayAdapter->print("ac_fan.pic="); + this->displayAdapter->print("ac_speed.pic="); this->displayAdapter->print(COMPONENT_AC_FAN_MODE_AUTO_PIC); 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->sendStopBytes(); break; case 1: - this->displayAdapter->print("ac_fan.pic="); + this->displayAdapter->print("ac_speed.pic="); this->displayAdapter->print(COMPONENT_AC_FAN_MODE_HIGH_PIC); 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->sendStopBytes(); break; case 2: - this->displayAdapter->print("ac_fan.pic="); + this->displayAdapter->print("ac_speed.pic="); this->displayAdapter->print(COMPONENT_AC_FAN_MODE_MID_PIC); 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->sendStopBytes(); break; case 3: - this->displayAdapter->print("ac_fan.pic="); + this->displayAdapter->print("ac_speed.pic="); this->displayAdapter->print(COMPONENT_AC_FAN_MODE_LOW_PIC); 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->sendStopBytes(); break; @@ -821,4 +831,5 @@ void ISEDisplay::updateACState() this->sendStopBytes(); this->giveSerialMutex(); + ESP_LOGI("ISEDisplay", "display AC state updated"); } diff --git a/src/ise_display.hpp b/src/ise_display.hpp index 446b437..46e4b7e 100644 --- a/src/ise_display.hpp +++ b/src/ise_display.hpp @@ -22,6 +22,9 @@ class ISEDisplay : public ESPMegaDisplay { ISEDisplay(HardwareSerial* adapter); void begin(DigitalInputCard* inputCard, DigitalOutputCard* outputCard, ClimateCard* climateCard); void updateLightGroupStatePageDashboard(); + void updateLightGroupStatePageStandby(); + void updateAirPurifierState(); + void updateAirPurifierStateStandby(); void updateDateTimeText(rtctime_t time); void updateWeather(char *weather_string); void updateTempOutside(float temp_outside); @@ -56,14 +59,9 @@ class ISEDisplay : public ESPMegaDisplay { u_int8_t lightLevelRow3; u_int8_t lightLevelRow4; - + void updateACState(); void updateuserACmode(); void updateACfanSpeed(); - void updateLightGroupStatePageStandby(); - void updateAirPurifierState(); - void updateAirPurifierStateStandby(); - void updateACState(); - bool calculateLightGroupState(); void toggleLightGroupState(); void toggleLightGroupStateStandby(); diff --git a/src/main.cpp b/src/main.cpp index ad4f45d..992f131 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -28,7 +28,6 @@ ClimateCard climateCard = ClimateCard(AIR_CONDITIONER_IR_PIN, ac, void handleMqttMessage(char *topic, char *payload) { - } void sendStopBytes() @@ -122,19 +121,18 @@ void loop() iseDisplay.loop(); // 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; - //rtctime_t time = espmega.getTime(); - //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 - // if(!run_when_init){ - // time = espmega.getTime(); - // iseDisplay.updateDateTimeText(time); - // last_time_updated = millis(); - // run_when_init = true; - // } - - + // rtctime_t time = espmega.getTime(); + // 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 + // if(!run_when_init){ + // time = espmega.getTime(); + // iseDisplay.updateDateTimeText(time); + // last_time_updated = millis(); + // run_when_init = true; + // } + if (millis() - last_time_updated > 15000) { rtctime_t time = espmega.getTime(); @@ -168,12 +166,10 @@ void loop() // iseDisplay.updateWeather(weather_value); // last_weather_update = millis(); // } - } void on_pin_change(uint8_t pin, uint8_t value) { - } // uint16_t get_pm25_out() @@ -191,22 +187,36 @@ void on_pin_change(uint8_t pin, uint8_t value) // return temp_out_value; // } -void handlePageChange(uint8_t page) { +void handlePageChange(uint8_t page) +{ // 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); rtctime_t time = espmega.getTime(); iseDisplay.updateDateTimeText(time); - iseDisplay.updateLightGroupStatePageDashboard(); - //iseDisplay.updatePMinside(); - /* iseDisplay.updatePMoutside(get_pm25_out()); - iseDisplay.updateWeather(weather.getValue()); - iseDisplay.updateTempOutside(get_temp_out()); */ - /* iseDisplay.updateACState(); - iseDisplay.updateAirPurifierState(); - iseDisplay.updateLightGroupStatePageStandby(); - iseDisplay.updateLightGroupStatePageDashboard(); - iseDisplay.updateuserACmode(); - iseDisplay.updateAirPurifierStateStandby(); */ -} \ No newline at end of file + switch (page) + { + case PAGE_STANDBY: + iseDisplay.updateLightGroupStatePageStandby(); + iseDisplay.updateAirPurifierStateStandby(); + break; + case PAGE_DASHBOARD: + iseDisplay.updateLightGroupStatePageDashboard(); + iseDisplay.updateAirPurifierState(); + break; + default: + break; + } + + // iseDisplay.updatePMinside(); + /* iseDisplay.updatePMoutside(get_pm25_out()); + iseDisplay.updateWeather(weather.getValue()); + iseDisplay.updateTempOutside(get_temp_out()); */ + /* iseDisplay.updateACState(); + iseDisplay.updateAirPurifierState(); + iseDisplay.updateLightGroupStatePageStandby(); + iseDisplay.updateLightGroupStatePageDashboard(); + iseDisplay.updateuserACmode(); + iseDisplay.updateAirPurifierStateStandby(); */ + } \ No newline at end of file