complied now

This commit is contained in:
reaw55 2024-04-06 04:06:17 +07:00
parent ac4316d659
commit 2eb06c1c25
15 changed files with 1091 additions and 516 deletions

View file

@ -23,6 +23,8 @@ RemoteVariable temp_out = RemoteVariable();
RemoteVariable weather = RemoteVariable();
RemoteVariable pm_switch = RemoteVariable();
RemoteVariable pm_fan_speed = RemoteVariable();
RemoteVariable pm_lock = RemoteVariable();
RemoteVariable ac_lock = RemoteVariable();
float adc2current(uint16_t adc_val) {
return adc_val * 1.0;
@ -45,8 +47,8 @@ const char *mode_names_york[] = {"off", "cool", "fan_only"};
const char *fan_speed_names[] = {"auto", "high", "medium", "low"};
AirConditioner ac_daikin = {
.max_temperature = 30,
.min_temperature = 18,
.max_temperature = DAIKIN_MAX_TEMP,
.min_temperature = DAIKIN_MIN_TEMP,
.modes = 4,
.mode_names = mode_names_daikin,
.fan_speeds = 4,
@ -54,8 +56,8 @@ AirConditioner ac_daikin = {
.getInfraredCode = &getInfraredCode_daikin};
AirConditioner ac_york = {
.max_temperature = 30,
.min_temperature = 18,
.max_temperature = YORK_MAX_TEMP,
.min_temperature = YORK_MIN_TEMP,
.modes = 3,
.mode_names = mode_names_york,
.fan_speeds = 4,
@ -121,17 +123,6 @@ void setup()
espmega.inputs.setDebounceTime(i,200);
}
// if (clear_fram)
// {
// Serial.print("boot_state.txt=\"Factory Resetting . . .\"");
// sendStopBytes();
// for (uint16_t i = 0; i < 32768; i++)
// {
// espmega.fram.write8(i, 0);
// }
// esp_restart();
// }
// // ------------ End Factory Reset Routine ------------
@ -198,14 +189,6 @@ void setup()
ct6.bindFRAM(&espmega.fram, 6500);
espmega.iot->registerCard(10);
// auto binded_display_update_on_pm25_out = std::bind(&display_update,0,std::placeholders::_1);
// auto binded_display_update_on_pm25_in = std::bind(&display_update,1,std::placeholders::_1);
// auto binded_display_update_on_temp_out = std::bind(&display_update,2,std::placeholders::_1);
// auto binded_display_update_on_weather = std::bind(&display_update,3,std::placeholders::_1);
// auto binded_display_update_on_pm_switch = std::bind(&display_update,4,std::placeholders::_1);
// auto binded_display_update_on_pm_fan_speed = std::bind(&display_update,5,std::placeholders::_1);
// ------------ Climate Cards Initialization Routine ------------
ESP_LOGD("ISE OS", "Setting up climate cards");
@ -271,6 +254,9 @@ void setup()
weather.registerCallback(&weatherupdatedisplay);
pm_switch.registerCallback(&pmswitchupdatedisplay);
pm_fan_speed.registerCallback(&pmfanspeedupdatedisplay);
pm_lock.registerCallback(&pmlockupdatedisplay);
ac_lock.registerCallback(&aclockupdatedisplay);
// PM2.5 PPM Remote Variable
pm25_out.begin(6, "/aqi/value", espmega.iot, true, "/aqi/request_value");
@ -286,6 +272,12 @@ void setup()
// Air Purifier Fan Speed Remote Variable
pm_fan_speed.begin(6, "/pm/fan_speed", espmega.iot, true, "/pm/request_fan_speed");
pm_fan_speed.enableSetValue("/pm/set_fan_speed");
// Air Purifier Lock Remote Variable
pm_lock.begin(6, "/pm/lock_state", espmega.iot, true, "/pm/request_lock_pm_state");
pm_lock.enableSetValue("/pm/set_lock_pm_state");
// Air Conditioner Lock Remote Variable
ac_lock.begin(6, "/ac/lock_state", espmega.iot, true, "/ac/request_lock_ac_state");
ac_lock.enableSetValue("/ac/set_lock_ac_state");
// ------------ End Remote Variables Initialization Routine ------------
@ -299,7 +291,7 @@ void setup()
// ------------ External Display Initialization Routine ------------
auto bindedGetTime = std::bind(&ESPMegaPRO::getTime, &espmega);
iseDisplay.begin(&espmega.inputs, &espmega.outputs, &climateCard_daikin, &climateCard_york, &pm_switch, &pm_fan_speed);
iseDisplay.begin(&espmega.inputs, &espmega.outputs, &climateCard_daikin, &climateCard_york, &pm_switch, &pm_fan_speed, &pm_lock, &ac_lock);
espmega.iot->registerRelativeMqttCallback(&handleMqttMessage);
iseDisplay.registerPageChangeCallback(&handlePageChange);
// ------------ End External Display Initialization Routine ------------
@ -315,11 +307,11 @@ void pm25inupdatedisplay(char *value)
}
void tempoutupdatedisplay(char *value)
{
iseDisplay.updateTempOutside(get_temp_out());
//iseDisplay.updateTempOutside(get_temp_out());
}
void weatherupdatedisplay(char *value)
{
iseDisplay.updateWeather(weather.getValue());
//iseDisplay.updateWeather(weather.getValue());
}
void pmfanspeedupdatedisplay(char *value)
{
@ -331,6 +323,18 @@ void pmswitchupdatedisplay(char *value)
iseDisplay.updateAirPurifierState();
ESP_LOGI("PM switch", "toggling PM switch state from: %d to %d", pm_switch.getValue(), !pm_switch.getValue());
}
void pmlockupdatedisplay(char *value)
{
ESP_LOGI("PM lock", "getting PM lock state from MQTT: %d", pm_lock.getValue());
iseDisplay.updateAirPurifierState();
ESP_LOGI("PM lock", "toggling PM lock state from: %d to %d", pm_lock.getValue(), !pm_lock.getValue());
}
void aclockupdatedisplay(char *value)
{
ESP_LOGI("AC lock", "getting AC lock state from MQTT: %d", ac_lock.getValue());
iseDisplay.updateACState();
ESP_LOGI("AC lock", "toggling AC lock state from: %d to %d", ac_lock.getValue(), !ac_lock.getValue());
}
void loop()
{
@ -418,6 +422,20 @@ uint8_t get_pm_fanspeed()
return pm_fan_speed_value;
}
bool get_pm_lock()
{
ESP_LOGI("PM lock", "getting PM lock state from MQTT: %d", pm_lock.getValue());
bool is_pm_lock_on = strcmp(pm_lock.getValue(), "on") == 0;
return is_pm_lock_on;
}
bool get_ac_lock()
{
ESP_LOGI("AC lock", "getting AC lock state from MQTT: %d", ac_lock.getValue());
bool is_ac_lock_on = strcmp(ac_lock.getValue(), "on") == 0;
return is_ac_lock_on;
}
/**
* @brief Get the PM switch state from home assistant
* @return true if the PM switch is on, false if the PM switch is off
@ -436,6 +454,20 @@ void toggle_pm_switch()
pm_switch.setValue(is_pm_switch_on ? "0" : "1");
}
void toggle_ac_lock()
{
bool is_ac_lock_on = get_ac_lock();
ESP_LOGI("AC lock", "toggling AC lock state from: %d to %d", is_ac_lock_on, !is_ac_lock_on);
ac_lock.setValue(is_ac_lock_on ? "0" : "1");
}
void toggle_pm_lock()
{
bool is_pm_lock_on = get_pm_lock();
ESP_LOGI("PM lock", "toggling PM lock state from: %d to %d", is_pm_lock_on, !is_pm_lock_on);
pm_lock.setValue(is_pm_lock_on ? "0" : "1");
}
void set_pm_fanspeed(uint8_t speed)
{
ESP_LOGI("PM fan speed", "setting PM fan speed to: %d", speed);
@ -458,6 +490,7 @@ void handlePageChange(uint8_t page)
case PAGE_DASHBOARD:
iseDisplay.updateLightGroupStatePageDashboard();
iseDisplay.updateAirPurifierState();
iseDisplay.updateSystemtoggle();
break;
default:
break;
@ -465,8 +498,8 @@ void handlePageChange(uint8_t page)
iseDisplay.updatePMoutside(get_pm25_out());
iseDisplay.updatePMinside(get_pm25_in());
iseDisplay.updateWeather(weather.getValue());
iseDisplay.updateTempOutside(get_temp_out());
//iseDisplay.updateWeather(weather.getValue());
//iseDisplay.updateTempOutside(get_temp_out());
iseDisplay.updateACState();
}