only fan speed not working

This commit is contained in:
reaw 2024-02-13 07:36:31 +07:00
parent 34eeca14e0
commit c08a762c00
6 changed files with 106 additions and 52 deletions

View file

@ -1,9 +1,11 @@
#include <main.hpp>
RemoteVariable pm25_in = RemoteVariable();
RemoteVariable pm25_out = RemoteVariable();
RemoteVariable temp_out = RemoteVariable();
RemoteVariable weather = RemoteVariable();
RemoteVariable pm25_in = RemoteVariable();
RemoteVariable pm_switch = RemoteVariable();
RemoteVariable pm_fan_speed = RemoteVariable();
const char *mode_names[] = {"off", "fan_only", "cool"};
const char *fan_speed_names[] = {"auto", "high", "medium", "low"};
@ -98,13 +100,6 @@ void setup()
climateCard.loadStateFromFRAM();
climateCard.setFRAMAutoSave(true);
espmega.display->bindClimateCard(&climateCard);
espmega.iot->registerCard(0); // Register the Input Card
espmega.iot->registerCard(1); // Register the Output Card
espmega.iot->registerCard(2); // Register the Climate Card
auto bindedGetTime = std::bind(&ESPMegaPRO::getTime, &espmega);
iseDisplay.begin(&espmega.inputs, &espmega.outputs, &climateCard);
espmega.iot->registerRelativeMqttCallback(&handleMqttMessage);
iseDisplay.registerPageChangeCallback(&handlePageChange);
// placeholder
// PM2.5 PPM Remote Variable
// 12 bytes remote variable, 11 characters + null terminator
@ -116,6 +111,21 @@ void setup()
weather.begin(45, "/weather/value", espmega.iot, true, "/weather/request_value");
// PM2.5 PPM Remote Variable
pm25_in.begin(6, "/pm/value", espmega.iot, true, "/pm/request_value");
// Air Purifier Switch Remote Variable
pm_switch.begin(6, "/pm/switch_state", espmega.iot, true, "/pm/request_switch_state");
pm_switch.enableSetValue("/pm/set_switch_state");
// 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");
espmega.iot->registerCard(0); // Register the Input Card
espmega.iot->registerCard(1); // Register the Output Card
espmega.iot->registerCard(2); // Register the Climate Card
auto bindedGetTime = std::bind(&ESPMegaPRO::getTime, &espmega);
iseDisplay.begin(&espmega.inputs, &espmega.outputs, &climateCard, &pm_switch, &pm_fan_speed);
espmega.iot->registerRelativeMqttCallback(&handleMqttMessage);
iseDisplay.registerPageChangeCallback(&handlePageChange);
}
void loop()
@ -145,12 +155,12 @@ void loop()
iseDisplay.updateDateTimeText(time);
last_time_updated = millis();
}
//Update the PM2.5 PPM value every 15 seconds
// Update the PM2.5 PPM value every 15 seconds
static uint32_t last_pm25_out_update = 0;
if (millis() - last_pm25_out_update > 15000)
{
uint16_t pm25_out_value = get_pm25_out();
//ESP_LOGI("loopPM2.5","updating PM2.5 from MQTT inside loop: %d", pm25_out_value);
// ESP_LOGI("loopPM2.5","updating PM2.5 from MQTT inside loop: %d", pm25_out_value);
iseDisplay.updatePMoutside(pm25_out_value);
last_pm25_out_update = millis();
}
@ -178,11 +188,16 @@ void loop()
iseDisplay.updateWeather(weather_value);
last_weather_update = millis();
}
// Update the PM state every 1 seconds
static uint32_t last_pm_switch_update = 0;
if (millis() - last_pm_switch_update > 5000)
{
iseDisplay.updateAirPurifierState();
}
}
void on_pin_change(uint8_t pin, uint8_t value)
{
}
{}
uint16_t get_pm25_out()
{
@ -211,6 +226,35 @@ float get_temp_out()
return temp_out_value;
}
uint8_t get_pm_fanspeed()
{
uint8_t pm_fan_speed_value = 0;
// Read PM2.5 fan speed from sensor
pm_fan_speed_value = (int) atof(pm_fan_speed.getValue());
ESP_LOGI("PM fan speed", "getting PM2.5 PPM from MQTT: %d", pm_fan_speed_value);
return pm_fan_speed_value;
}
bool get_pm_switch()
{
ESP_LOGI("PM switch", "getting PM switch state from MQTT: %d", pm_switch.getValue());
bool is_pm_switch_on = strcmp(pm_switch.getValue(),"on")== 0;
return is_pm_switch_on;
}
void toggle_pm_switch()
{
bool is_pm_switch_on = get_pm_switch();
ESP_LOGI("PM switch", "toggling PM switch state from: %d to %d", is_pm_switch_on, !is_pm_switch_on);
pm_switch.setValue(is_pm_switch_on ? "0" : "1");
}
void set_pm_fanspeed(uint8_t speed)
{
ESP_LOGI("PM fan speed", "setting PM fan speed to: %d", speed);
char buffer[4];
itoa(speed, buffer, DEC);
pm_fan_speed.setValue(buffer);
}
void handlePageChange(uint8_t page)
{
@ -233,16 +277,16 @@ void handlePageChange(uint8_t page)
break;
}
// iseDisplay.updatePMinside();
iseDisplay.updatePMoutside(get_pm25_out());
iseDisplay.updatePMinside(get_pm25_in());
iseDisplay.updateWeather(weather.getValue());
iseDisplay.updateTempOutside(get_temp_out());
/* iseDisplay.updateACState();
iseDisplay.updateAirPurifierState();
iseDisplay.updateLightGroupStatePageStandby();
iseDisplay.updateLightGroupStatePageDashboard();
iseDisplay.updateuserACmode();
iseDisplay.updateAirPurifierStateStandby(); */
}
// iseDisplay.updatePMinside();
iseDisplay.updatePMoutside(get_pm25_out());
iseDisplay.updatePMinside(get_pm25_in());
iseDisplay.updateWeather(weather.getValue());
iseDisplay.updateTempOutside(get_temp_out());
/* iseDisplay.updateACState();
iseDisplay.updateAirPurifierState();
iseDisplay.updateLightGroupStatePageStandby();
iseDisplay.updateLightGroupStatePageDashboard();
iseDisplay.updateuserACmode();
iseDisplay.updateAirPurifierStateStandby(); */
}