delay sending A/C when Rapid Button Press is detected
This commit is contained in:
parent
294f41f838
commit
245709870b
|
@ -46,6 +46,7 @@
|
||||||
#define DISPLAY_OTA_BAUDRATE 921600
|
#define DISPLAY_OTA_BAUDRATE 921600
|
||||||
#define DEFAULT_TEMP_LOWER_BOUND 18
|
#define DEFAULT_TEMP_LOWER_BOUND 18
|
||||||
#define DEFAULT_TEMP_UPPER_BOUND 30
|
#define DEFAULT_TEMP_UPPER_BOUND 30
|
||||||
|
#define AC_TEMP_PRESS_DELAY 500 // ms
|
||||||
|
|
||||||
/***********************************************
|
/***********************************************
|
||||||
* Persistent Storage Configuration *
|
* Persistent Storage Configuration *
|
||||||
|
@ -56,7 +57,6 @@
|
||||||
#define AC_DISPLAY_TEMP_LOWER_BOUND_ADDR 10030 // 6 byte
|
#define AC_DISPLAY_TEMP_LOWER_BOUND_ADDR 10030 // 6 byte
|
||||||
#define AC_DISPLAY_TEMP_UPPER_BOUND_ADDR 10040 // 6 byte
|
#define AC_DISPLAY_TEMP_UPPER_BOUND_ADDR 10040 // 6 byte
|
||||||
|
|
||||||
|
|
||||||
/***********************************************
|
/***********************************************
|
||||||
* Remote Variables & Smart Variables *
|
* Remote Variables & Smart Variables *
|
||||||
***********************************************/
|
***********************************************/
|
||||||
|
|
|
@ -155,6 +155,23 @@ void CUDDisplay::begin(cud_display_cards_t cards)
|
||||||
this->display_init();
|
this->display_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CUDDisplay::loop() {
|
||||||
|
ESPMegaDisplay::loop();
|
||||||
|
// Check if the AC button press is pending
|
||||||
|
if (this->ac_button_press_pending)
|
||||||
|
{
|
||||||
|
// Check if the delay has passed
|
||||||
|
if (millis() - this->last_ac_button_press > AC_TEMP_PRESS_DELAY)
|
||||||
|
{
|
||||||
|
ESP_LOGV("CUD Display", "Sending pending temperature");
|
||||||
|
// Send the pending temperature
|
||||||
|
this->cards.ac->setTemperature(this->pending_temperature);
|
||||||
|
// Reset the pending flag
|
||||||
|
this->ac_button_press_pending = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CUDDisplay::display_init()
|
void CUDDisplay::display_init()
|
||||||
{
|
{
|
||||||
// Perform a reset on the display
|
// Perform a reset on the display
|
||||||
|
@ -387,7 +404,13 @@ void CUDDisplay::handle_touch(uint8_t page_id, uint8_t element_id, uint8_t touch
|
||||||
// Is the control locked? If it is, we can ignore the touch
|
// Is the control locked? If it is, we can ignore the touch
|
||||||
if (this->get_ac_lock())
|
if (this->get_ac_lock())
|
||||||
return;
|
return;
|
||||||
uint8_t newTemp = this->cards.ac->getTemperature() + 1;
|
uint8_t newTemp = this->cards.ac->getTemperature();
|
||||||
|
if (this->ac_button_press_pending)
|
||||||
|
{
|
||||||
|
// If the button press is pending, use the pending temperature as base
|
||||||
|
newTemp = this->pending_temperature;
|
||||||
|
}
|
||||||
|
newTemp++;
|
||||||
// Does the temperature exceed the upper bound?, if it does, bound it
|
// Does the temperature exceed the upper bound?, if it does, bound it
|
||||||
ESP_LOGD("CUD Display", "Requested Temp: %d, Lower Bound: %d", newTemp, this->ac_temp_lower_bound.getIntValue());
|
ESP_LOGD("CUD Display", "Requested Temp: %d, Lower Bound: %d", newTemp, this->ac_temp_lower_bound.getIntValue());
|
||||||
if (newTemp > this->ac_temp_upper_bound.getIntValue())
|
if (newTemp > this->ac_temp_upper_bound.getIntValue())
|
||||||
|
@ -396,7 +419,14 @@ void CUDDisplay::handle_touch(uint8_t page_id, uint8_t element_id, uint8_t touch
|
||||||
}
|
}
|
||||||
ESP_LOGD("CUD Display", "New Temp: %d", newTemp);
|
ESP_LOGD("CUD Display", "New Temp: %d", newTemp);
|
||||||
// Increase the AC temperature
|
// Increase the AC temperature
|
||||||
this->cards.ac->setTemperature(newTemp);
|
pending_temperature = newTemp;
|
||||||
|
ac_button_press_pending = true;
|
||||||
|
last_ac_button_press = millis();
|
||||||
|
// Send the new temperature to the Display
|
||||||
|
this->takeSerialMutex();
|
||||||
|
this->displayAdapter->printf("%s.txt=%d", LCD_DASHBOARD_ELEMENT_NAME_AC_TEMPERATURE, newTemp);
|
||||||
|
this->sendStopBytes();
|
||||||
|
this->giveSerialMutex();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Check if element_id is the AC temperature down button
|
// Check if element_id is the AC temperature down button
|
||||||
|
@ -405,7 +435,12 @@ void CUDDisplay::handle_touch(uint8_t page_id, uint8_t element_id, uint8_t touch
|
||||||
// Is the control locked? If it is, we can ignore the touch
|
// Is the control locked? If it is, we can ignore the touch
|
||||||
if (this->get_ac_lock())
|
if (this->get_ac_lock())
|
||||||
return;
|
return;
|
||||||
uint8_t newTemp = this->cards.ac->getTemperature() - 1;
|
uint8_t newTemp = this->cards.ac->getTemperature();
|
||||||
|
if (this->ac_button_press_pending)
|
||||||
|
{
|
||||||
|
// If the button press is pending, use the pending temperature as base
|
||||||
|
newTemp = this->pending_temperature;
|
||||||
|
}
|
||||||
// Does the temperature exceed the lower bound?, if it does, bound it
|
// Does the temperature exceed the lower bound?, if it does, bound it
|
||||||
ESP_LOGD("CUD Display", "Requested Temp: %d, Lower Bound: %d", newTemp, this->ac_temp_lower_bound.getIntValue());
|
ESP_LOGD("CUD Display", "Requested Temp: %d, Lower Bound: %d", newTemp, this->ac_temp_lower_bound.getIntValue());
|
||||||
if (newTemp < this->ac_temp_lower_bound.getIntValue())
|
if (newTemp < this->ac_temp_lower_bound.getIntValue())
|
||||||
|
@ -414,7 +449,14 @@ void CUDDisplay::handle_touch(uint8_t page_id, uint8_t element_id, uint8_t touch
|
||||||
}
|
}
|
||||||
ESP_LOGD("CUD Display", "New Temp: %d", newTemp);
|
ESP_LOGD("CUD Display", "New Temp: %d", newTemp);
|
||||||
// Decrease the AC temperature
|
// Decrease the AC temperature
|
||||||
this->cards.ac->setTemperature(newTemp);
|
pending_temperature = newTemp;
|
||||||
|
ac_button_press_pending = true;
|
||||||
|
last_ac_button_press = millis();
|
||||||
|
// Send the new temperature to the Display
|
||||||
|
this->takeSerialMutex();
|
||||||
|
this->displayAdapter->printf("%s.txt=%d", LCD_DASHBOARD_ELEMENT_NAME_AC_TEMPERATURE, newTemp);
|
||||||
|
this->sendStopBytes();
|
||||||
|
this->giveSerialMutex();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (element_id == LCD_DASHBOARD_ELEMENT_ALL_SYSTEM_TOGGLE)
|
if (element_id == LCD_DASHBOARD_ELEMENT_ALL_SYSTEM_TOGGLE)
|
||||||
|
|
|
@ -72,6 +72,7 @@ public:
|
||||||
void display_init();
|
void display_init();
|
||||||
void set_ac_lock(bool state);
|
void set_ac_lock(bool state);
|
||||||
bool get_ac_lock();
|
bool get_ac_lock();
|
||||||
|
void loop();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// States Calculation
|
// States Calculation
|
||||||
|
@ -102,6 +103,9 @@ private:
|
||||||
void system_toggle();
|
void system_toggle();
|
||||||
// AC Functions and Variables
|
// AC Functions and Variables
|
||||||
uint8_t previous_mode; // Used to store mode prior to turning off
|
uint8_t previous_mode; // Used to store mode prior to turning off
|
||||||
|
uint32_t last_ac_button_press;
|
||||||
|
uint8_t pending_temperature;
|
||||||
|
bool ac_button_press_pending;
|
||||||
// Local Variables
|
// Local Variables
|
||||||
cud_display_conf_t *conf;
|
cud_display_conf_t *conf;
|
||||||
cud_display_cards_t cards;
|
cud_display_cards_t cards;
|
||||||
|
|
Loading…
Reference in New Issue