add IR code

This commit is contained in:
reaw 2024-02-17 00:41:19 +07:00
parent 44687da028
commit 68dac6a4d0
6 changed files with 254 additions and 104 deletions

View file

@ -47,9 +47,10 @@ void ISEDisplay::begin(DigitalInputCard *inputCard, DigitalOutputCard *outputCar
// this->outputCard->setValue(2, 0);
// this->outputCard->setValue(3, 0);
// this->outputCard->setValue(4, 0);
this->climateCard->setTemperature(ac_temperature);
this->climateCard->setFanSpeed(ac_fan_speed);
this->climateCard->setMode(ac_mode);
// this->climateCard->setTemperature(ac_temperature);
// this->climateCard->setFanSpeed(ac_fan_speed);
// this->climateCard->setMode(ac_mode);
this->climateCard->setState(ac_mode, ac_fan_speed, ac_temperature);
}
void ISEDisplay::loop()
{
@ -298,7 +299,8 @@ void ISEDisplay::handlePWMChange(uint8_t pin, bool state, uint16_t value)
}
void ISEDisplay::updateDateTimeText(rtctime_t time)
{
this->takeSerialMutex();
if (!this->takeSerialMutex())
return;
// Send the time to the display
this->displayAdapter->printf("time.txt=\"%02d:%02d\"", time.hours, time.minutes);
@ -400,7 +402,8 @@ void ISEDisplay::updateTempOutside(float temp_outside)
// change temp_outside to int then display
u_int8_t temp_outside_int = (u_int8_t)temp_outside;
ESP_LOGI("ISEDisplay", "Updating temperature outside to: %d", temp_outside_int);
this->takeSerialMutex();
if (!this->takeSerialMutex())
return;
this->displayAdapter->printf("outside_temp.txt=\"%d\"", temp_outside_int);
this->sendStopBytes();
this->giveSerialMutex();
@ -411,7 +414,8 @@ void ISEDisplay::updatePMoutside(u_int16_t pm25_outside)
u_int16_t curPage = this->currentPage;
if (curPage == 2)
{
this->takeSerialMutex();
if (!this->takeSerialMutex())
return;
this->displayAdapter->printf("pm_out.txt=\"%d\"", pm25_outside);
this->sendStopBytes();
this->giveSerialMutex();
@ -425,7 +429,8 @@ void ISEDisplay::updatePMinside(u_int16_t pm25_inside)
u_int16_t curPage = this->currentPage;
if (curPage == 2)
{
this->takeSerialMutex();
if (!this->takeSerialMutex())
return;
this->displayAdapter->printf("pm_in.txt=\"%d\"", pm25_inside);
this->sendStopBytes();
this->giveSerialMutex();
@ -445,12 +450,13 @@ void ISEDisplay::setACstate(uint8_t ac_fan_speed, uint8_t ac_mode, uint8_t ac_te
{
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);
ESP_LOGI("ISEDisplay", "AC mode set to: %d", ac_mode);
this->climateCard->setTemperature(ac_temperature);
//this->climateCard->setTemperature(ac_temperature);
ESP_LOGI("ISEDisplay", "AC temperature set to: %d", ac_temperature);
this->climateCard->setState(ac_mode, ac_fan_speed, ac_temperature);
// updateACState();
}
void ISEDisplay::toggleLightGroupState()
@ -628,6 +634,7 @@ lightPosition ISEDisplay::getRowCol(uint8_t pin){
return position;
}
}
return position;
}
@ -636,7 +643,8 @@ void ISEDisplay::updateLightGroupStatePageStandby()
// Calculate the state
bool state = calculateLightGroupState();
// Send the state to the display
this->takeSerialMutex();
if (!this->takeSerialMutex())
return;
this->displayAdapter->print("s_light_toggle.pic=");
this->displayAdapter->print(state ? COMPONENT_STANDBY_LIGHT_PIC_ON : COMPONENT_STANDBY_LIGHT_PIC_OFF);
@ -653,7 +661,8 @@ void ISEDisplay::updateLightGroupStatePageDashboard()
// Calculate the state
bool state = calculateLightGroupState();
// Send the state to the display
this->takeSerialMutex();
if (!this->takeSerialMutex())
return;
this->displayAdapter->print("light_master.pic=");
this->displayAdapter->print(state ? COMPONENT_LIGHT_MASTER_ON : COMPONENT_LIGHT_MASTER_OFF);
@ -766,7 +775,8 @@ void ISEDisplay::updateAirPurifierStateStandby()
// Get the state
bool state = strcmp(pm_switch->getValue(), "on") == 0;
// Send the state to the display
this->takeSerialMutex();
if (!this->takeSerialMutex())
return;
this->displayAdapter->print("s_pm_toggle.pic=");
this->displayAdapter->print(state ? COMPONENT_STANDBY_PM_PIC_ON : COMPONENT_STANDBY_PM_PIC_OFF);
@ -782,13 +792,15 @@ void ISEDisplay::updateAirPurifierStateStandby()
void ISEDisplay::updateAirPurifierState()
{
//check for page
if(currentPage != 1){
if(currentPage == PAGE_DASHBOARD){
ESP_LOGI("ISEDisplay", "Updating dashboard");
// Get the state
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();
if (!this->takeSerialMutex())
return;
this->displayAdapter->print("pm_sw.pic=");
this->displayAdapter->print(state ? COMPONENT_PM_TOGGLE_PIC_ON : COMPONENT_PM_TOGGLE_PIC_OFF);
@ -808,12 +820,11 @@ void ISEDisplay::updateAirPurifierState()
this->sendStopBytes();
this->giveSerialMutex();
return;
}
else if(currentPage == 1){
else if(currentPage == PAGE_STANDBY){
ESP_LOGI("ISEDisplay", "Updating standby");
updateAirPurifierStateStandby();
return;
}
}
void ISEDisplay::handleACChange(uint8_t mode, uint8_t fan_speed, uint8_t temperature)
@ -823,7 +834,8 @@ void ISEDisplay::handleACChange(uint8_t mode, uint8_t fan_speed, uint8_t tempera
}
void ISEDisplay::updateuserACmode()
{
this->takeSerialMutex();
if (!this->takeSerialMutex())
return;
ESP_LOGI("ISEDisplay", "updating display user AC mode to: %d", user_mode);
switch (user_mode)
{
@ -852,7 +864,8 @@ void ISEDisplay::updateACfanSpeed()
{
uint8_t fan_speed = this->climateCard->getFanSpeed();
ESP_LOGI("ISEDisplay", "updating display AC fan speed to: %d", fan_speed);
this->takeSerialMutex();
if (!this->takeSerialMutex())
return;
switch (fan_speed)
{
case 0:
@ -900,7 +913,8 @@ void ISEDisplay::updateACState()
uint8_t mode = this->climateCard->getMode();
uint8_t temperature = this->climateCard->getTemperature();
if(currentPage != 1){
this->takeSerialMutex();
if (!this->takeSerialMutex())
return;
// Send the state to the display
if (mode == 0)
@ -944,7 +958,8 @@ void ISEDisplay::updateACState()
}
else if (currentPage == 1)
{
this->takeSerialMutex();
if (!this->takeSerialMutex())
return;
this->displayAdapter->print("s_ac_toggle.pic=");
this->displayAdapter->print(mode != 0 ? COMPONENT_STANDBY_AC_PIC_ON : COMPONENT_STANDBY_AC_PIC_OFF);