touch handling
This commit is contained in:
parent
33be51aab9
commit
73425cb438
|
@ -29,10 +29,12 @@ void CUDDisplay::begin()
|
|||
auto binded_output_callback = std::bind(&CUDDisplay::handle_output_change, this, std::placeholders::_1, std::placeholders::_2);
|
||||
auto binded_aqi_callback = std::bind(&CUDDisplay::handle_aqi_change, this, std::placeholders::_1);
|
||||
auto binded_payload_callback = std::bind(&CUDDisplay::handle_payload, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
|
||||
auto binded_touch_callback = std::bind(&CUDDisplay::handle_touch, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
|
||||
this->conf->inputCard->registerCallback(binded_input_callback);
|
||||
this->conf->outputCard->registerChangeCallback(binded_output_callback);
|
||||
this->conf->aqi->registerCallback(binded_aqi_callback);
|
||||
this->registerPayloadCallback(binded_payload_callback);
|
||||
this->registerTouchCallback(binded_touch_callback);
|
||||
// Initialize the display
|
||||
this->display_init();
|
||||
}
|
||||
|
@ -99,6 +101,7 @@ void CUDDisplay::handle_output_change(uint8_t pin, bool state)
|
|||
if (pin == this->conf->light_pins[i])
|
||||
{
|
||||
this->set_display_light_state(i, state);
|
||||
this->set_display_light_all_state();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -108,12 +111,74 @@ void CUDDisplay::handle_output_change(uint8_t pin, bool state)
|
|||
if (pin == this->conf->fan_pins[i])
|
||||
{
|
||||
this->set_display_fan_state(i, state);
|
||||
this->set_display_fan_all_state();
|
||||
return;
|
||||
}
|
||||
}
|
||||
// The pin is not the one that our display is handling, so we can ignore it
|
||||
}
|
||||
|
||||
void CUDDisplay::handle_touch(uint8_t page_id, uint8_t element_id, uint8_t touch_type)
|
||||
{
|
||||
// Check if element_id is the light all button
|
||||
if (element_id == LCD_DASHBOARD_ELEMENT_LIGHT_ALL)
|
||||
{
|
||||
// If it is, toggle all the lights
|
||||
bool light_on = this->get_lights_state();
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
this->conf->outputCard->setState(this->conf->light_pins[i], !light_on);
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Check if element_id is the fan all button
|
||||
else if (element_id == LCD_DASHBOARD_ELEMENT_FAN_ALL)
|
||||
{
|
||||
// If it is, toggle all the fans
|
||||
bool fan_on = this->get_fans_state();
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
this->conf->outputCard->setState(this->conf->fan_pins[i], !fan_on);
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Check if element_id is the air purifier button
|
||||
else if (element_id == LCD_DASHBOARD_ELEMENT_AIR_PURIFIER)
|
||||
{
|
||||
// If it is, toggle the air purifier
|
||||
this->conf->outputCard->setState(this->conf->air_purifier_pin, !this->conf->outputCard->getState(this->conf->air_purifier_pin));
|
||||
return;
|
||||
}
|
||||
// Check if element_id is the mosquito zapper button
|
||||
else if (element_id == LCD_DASHBOARD_ELEMENT_MOSQUITO_ZAPPER)
|
||||
{
|
||||
// If it is, toggle the mosquito zapper
|
||||
this->conf->outputCard->setState(this->conf->mosquito_zapper_pin, !this->conf->outputCard->getState(this->conf->mosquito_zapper_pin));
|
||||
return;
|
||||
}
|
||||
// Check if element_id is a light button
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
if (element_id == this->light_group.element_id[i])
|
||||
{
|
||||
// If it is, toggle the light
|
||||
this->conf->outputCard->setState(this->conf->light_pins[i], !this->conf->outputCard->getState(this->conf->light_pins[i]));
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Check if element_id is a fan button
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
if (element_id == this->fan_group.element_id[i])
|
||||
{
|
||||
// If it is, toggle the fan
|
||||
this->conf->outputCard->setState(this->conf->fan_pins[i], !this->conf->outputCard->getState(this->conf->fan_pins[i]));
|
||||
return;
|
||||
}
|
||||
}
|
||||
// The element_id is not the one that our display is handling, so we can ignore it
|
||||
}
|
||||
|
||||
void CUDDisplay::handle_aqi_change(char *value)
|
||||
{
|
||||
// Update the AQI value on the display
|
||||
|
|
|
@ -57,6 +57,7 @@ class CUDDisplay : public ESPMegaDisplay
|
|||
void handle_output_change(uint8_t pin, bool state);
|
||||
void handle_aqi_change(char *value);
|
||||
void handle_payload(uint8_t type, uint8_t* payload, uint8_t length);
|
||||
void handle_touch(uint8_t page_id, uint8_t element_id, uint8_t touch_type);
|
||||
// Change Display Elements
|
||||
void set_display_light_state(uint8_t row, bool state);
|
||||
void set_display_light_all_state();
|
||||
|
|
Loading…
Reference in New Issue