only fan speed not working
This commit is contained in:
parent
34eeca14e0
commit
c08a762c00
6 changed files with 106 additions and 52 deletions
|
|
@ -6,11 +6,13 @@ ISEDisplay::ISEDisplay(HardwareSerial *adapter) : ESPMegaDisplay(adapter, 115200
|
|||
// TODO : Implement
|
||||
// debug to work
|
||||
|
||||
void ISEDisplay::begin(DigitalInputCard *inputCard, DigitalOutputCard *outputCard, ClimateCard *climateCard)
|
||||
void ISEDisplay::begin(DigitalInputCard *inputCard, DigitalOutputCard *outputCard, ClimateCard *climateCard, RemoteVariable* pm_switch, RemoteVariable* pm_fan_speed)
|
||||
{
|
||||
this->inputCard = inputCard;
|
||||
this->outputCard = outputCard;
|
||||
this->climateCard = climateCard;
|
||||
this->pm_switch = pm_switch;
|
||||
this->remote_pm_fan_speed = pm_fan_speed;
|
||||
auto bindedHandlePWMChange = std::bind(&ISEDisplay::handlePWMChange, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
|
||||
auto bindedHandleACChange = std::bind(&ISEDisplay::handleACChange, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
|
||||
auto bindedHandleTouch = std::bind(&ISEDisplay::handleTouch, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
|
||||
|
|
@ -18,6 +20,7 @@ void ISEDisplay::begin(DigitalInputCard *inputCard, DigitalOutputCard *outputCar
|
|||
this->climateCallbackHandle = this->climateCard->registerChangeCallback(bindedHandleACChange);
|
||||
this->user_mode = 1; // initialized to cool by default
|
||||
this->pm_fan_speed = 10;
|
||||
//remote_pm_fan_speed->setValue(pm_fan_speed);
|
||||
this->ac_fan_speed = 0;
|
||||
this->ac_mode = 0;
|
||||
this->ac_temperature = 25;
|
||||
|
|
@ -36,8 +39,7 @@ void ISEDisplay::begin(DigitalInputCard *inputCard, DigitalOutputCard *outputCar
|
|||
this->updateAirPurifierState();
|
||||
this->updateACState();
|
||||
this->updateLightGroupStatePageDashboard();
|
||||
this->outputCard->setValue(6, pm_fan_speed);
|
||||
this->outputCard->setValue(5, 0);
|
||||
|
||||
this->outputCard->setValue(1, 0);
|
||||
this->outputCard->setValue(2, 0);
|
||||
this->outputCard->setValue(3, 0);
|
||||
|
|
@ -70,6 +72,7 @@ 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
|
||||
char buffer[4];
|
||||
if (page == PAGE_STANDBY)
|
||||
{
|
||||
switch (component)
|
||||
|
|
@ -232,22 +235,24 @@ void ISEDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t touch_type
|
|||
case COMPONENT_PM_FAN_SPEED_DECREASE:
|
||||
if (touch_type != TOUCH_TYPE_RELEASE)
|
||||
break;
|
||||
pm_fan_speed = this->outputCard->getValue(6);
|
||||
pm_fan_speed = (int) atof(remote_pm_fan_speed->getValue());
|
||||
ESP_LOGI("ISEDisplay", "Current PM fan speed: %d", pm_fan_speed);
|
||||
if (pm_fan_speed >= 1 && pm_fan_speed <= 20)
|
||||
this->outputCard->setValue(6, (pm_fan_speed - 1));
|
||||
itoa(pm_fan_speed - 1, buffer, DEC);
|
||||
remote_pm_fan_speed->setValue(buffer);
|
||||
ESP_LOGI("ISEDisplay", "New PM fan speed: %d", pm_fan_speed);
|
||||
updateAirPurifierState();
|
||||
//updateAirPurifierState();
|
||||
break;
|
||||
case COMPONENT_PM_FAN_SPEED_INCREASE:
|
||||
if (touch_type != TOUCH_TYPE_RELEASE)
|
||||
break;
|
||||
pm_fan_speed = this->outputCard->getValue(6);
|
||||
pm_fan_speed = (int) atof(remote_pm_fan_speed->getValue());
|
||||
ESP_LOGI("ISEDisplay", "Current PM fan speed: %d", pm_fan_speed);
|
||||
if (pm_fan_speed >= 0 && pm_fan_speed <= 19)
|
||||
this->outputCard->setValue(6, (pm_fan_speed + 1));
|
||||
itoa(pm_fan_speed + 1, buffer, DEC);
|
||||
remote_pm_fan_speed->setValue(buffer);
|
||||
ESP_LOGI("ISEDisplay", "New PM fan speed: %d", pm_fan_speed);
|
||||
updateAirPurifierState();
|
||||
//updateAirPurifierState();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
@ -273,7 +278,7 @@ void ISEDisplay::handlePWMChange(uint8_t pin, bool state, uint16_t value)
|
|||
updateLightGroupStatePageStandby();
|
||||
// time_since_last_screen_update = millis(); // update time since last activity
|
||||
}
|
||||
else if (pin == 4 || pin == 5)
|
||||
else if (pin == 5 || pin == 6)
|
||||
{
|
||||
// Air Purifier
|
||||
updateAirPurifierStateStandby();
|
||||
|
|
@ -288,7 +293,7 @@ void ISEDisplay::handlePWMChange(uint8_t pin, bool state, uint16_t value)
|
|||
updateLightGroupStatePageDashboard();
|
||||
// time_since_last_screen_update = millis(); // update time since last activity
|
||||
}
|
||||
else if (pin == 4 || pin == 5)
|
||||
else if (pin == 5 || pin == 6)
|
||||
{
|
||||
// Air Purifier
|
||||
updateAirPurifierState();
|
||||
|
|
@ -438,7 +443,11 @@ void ISEDisplay::updatePMinside(u_int16_t pm25_inside)
|
|||
|
||||
void ISEDisplay::setPMstate(bool is_pm_on, uint8_t pm_fan_speed)
|
||||
{
|
||||
// TODO : set data to HA's Xiaomi air purifier sensor
|
||||
ESP_LOGI("ISEDisplay", "Setting PM state: %d, fan speed: %d", is_pm_on, pm_fan_speed);
|
||||
char buffer[4];
|
||||
itoa(pm_fan_speed, buffer, DEC);
|
||||
remote_pm_fan_speed->setValue(buffer);
|
||||
pm_switch->setValue(is_pm_on ? "1" : "0");
|
||||
}
|
||||
|
||||
void ISEDisplay::setACstate(uint8_t ac_fan_speed, uint8_t ac_mode, uint8_t ac_temperature)
|
||||
|
|
@ -479,26 +488,22 @@ void ISEDisplay::toggleLightGroupStateStandby()
|
|||
void ISEDisplay::togglePM()
|
||||
{
|
||||
// Get the current group state
|
||||
bool state = this->outputCard->getState(5);
|
||||
bool state = strcmp(pm_switch->getValue(), "on") == 0;
|
||||
ESP_LOGI("ISEDisplay", "Current PM state: %d", state);
|
||||
// Toggle the state
|
||||
state = !state;
|
||||
// Set the state
|
||||
this->outputCard->setState(5, state);
|
||||
pm_switch->setValue(state ? "off" : "on");
|
||||
ESP_LOGI("ISEDisplay", "New PM state: %d", state);
|
||||
updateAirPurifierState();
|
||||
//updateAirPurifierState();
|
||||
}
|
||||
void ISEDisplay::togglePMStandby()
|
||||
{
|
||||
// Get the current group state
|
||||
bool state = this->outputCard->getState(5);
|
||||
bool state = strcmp(pm_switch->getValue(), "on") == 0;
|
||||
ESP_LOGI("ISEDisplay", "Current PM state: %d", state);
|
||||
// Toggle the state
|
||||
state = !state;
|
||||
// Set the state
|
||||
this->outputCard->setState(5, state);
|
||||
pm_switch->setValue(state ? "off" : "on");
|
||||
ESP_LOGI("ISEDisplay", "New PM state: %d", state);
|
||||
updateAirPurifierStateStandby();
|
||||
//updateAirPurifierStateStandby();
|
||||
}
|
||||
void ISEDisplay::toggleAC()
|
||||
{
|
||||
|
|
@ -690,7 +695,7 @@ void ISEDisplay::toggleSliderLight(uint8_t row, uint8_t lightLevel)
|
|||
void ISEDisplay::updateAirPurifierStateStandby()
|
||||
{
|
||||
// Get the state
|
||||
bool state = this->outputCard->getState(5);
|
||||
bool state = strcmp(pm_switch->getValue(), "on") == 0;
|
||||
// Send the state to the display
|
||||
this->takeSerialMutex();
|
||||
|
||||
|
|
@ -708,8 +713,9 @@ void ISEDisplay::updateAirPurifierStateStandby()
|
|||
void ISEDisplay::updateAirPurifierState()
|
||||
{
|
||||
// Get the state
|
||||
bool state = this->outputCard->getState(5);
|
||||
pm_fan_speed = this->outputCard->getValue(6);
|
||||
bool state = strcmp(pm_switch->getValue(), "on") == 0;
|
||||
ESP_LOGI("ISEDisplay", "Updating air purifier state to: %d", state);
|
||||
pm_fan_speed = (int) atof(remote_pm_fan_speed->getValue());
|
||||
// Send the state to the display
|
||||
this->takeSerialMutex();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue