change to callback
This commit is contained in:
parent
974f7ac007
commit
ea4974893e
4 changed files with 170 additions and 42 deletions
55
.vscode/settings.json
vendored
55
.vscode/settings.json
vendored
|
|
@ -55,5 +55,58 @@
|
||||||
"C_Cpp_Runner.useLeakSanitizer": false,
|
"C_Cpp_Runner.useLeakSanitizer": false,
|
||||||
"C_Cpp_Runner.showCompilationTime": false,
|
"C_Cpp_Runner.showCompilationTime": false,
|
||||||
"C_Cpp_Runner.useLinkTimeOptimization": false,
|
"C_Cpp_Runner.useLinkTimeOptimization": false,
|
||||||
"C_Cpp_Runner.msvcSecureNoWarnings": false
|
"C_Cpp_Runner.msvcSecureNoWarnings": false,
|
||||||
|
"C_Cpp.errorSquiggles": "disabled",
|
||||||
|
"files.associations": {
|
||||||
|
"array": "cpp",
|
||||||
|
"atomic": "cpp",
|
||||||
|
"*.tcc": "cpp",
|
||||||
|
"bitset": "cpp",
|
||||||
|
"cctype": "cpp",
|
||||||
|
"clocale": "cpp",
|
||||||
|
"cmath": "cpp",
|
||||||
|
"cstdarg": "cpp",
|
||||||
|
"cstddef": "cpp",
|
||||||
|
"cstdint": "cpp",
|
||||||
|
"cstdio": "cpp",
|
||||||
|
"cstdlib": "cpp",
|
||||||
|
"cstring": "cpp",
|
||||||
|
"ctime": "cpp",
|
||||||
|
"cwchar": "cpp",
|
||||||
|
"cwctype": "cpp",
|
||||||
|
"deque": "cpp",
|
||||||
|
"unordered_map": "cpp",
|
||||||
|
"unordered_set": "cpp",
|
||||||
|
"vector": "cpp",
|
||||||
|
"exception": "cpp",
|
||||||
|
"algorithm": "cpp",
|
||||||
|
"functional": "cpp",
|
||||||
|
"iterator": "cpp",
|
||||||
|
"map": "cpp",
|
||||||
|
"memory": "cpp",
|
||||||
|
"memory_resource": "cpp",
|
||||||
|
"numeric": "cpp",
|
||||||
|
"optional": "cpp",
|
||||||
|
"random": "cpp",
|
||||||
|
"regex": "cpp",
|
||||||
|
"string": "cpp",
|
||||||
|
"string_view": "cpp",
|
||||||
|
"system_error": "cpp",
|
||||||
|
"tuple": "cpp",
|
||||||
|
"type_traits": "cpp",
|
||||||
|
"utility": "cpp",
|
||||||
|
"fstream": "cpp",
|
||||||
|
"initializer_list": "cpp",
|
||||||
|
"iomanip": "cpp",
|
||||||
|
"iosfwd": "cpp",
|
||||||
|
"istream": "cpp",
|
||||||
|
"limits": "cpp",
|
||||||
|
"new": "cpp",
|
||||||
|
"ostream": "cpp",
|
||||||
|
"sstream": "cpp",
|
||||||
|
"stdexcept": "cpp",
|
||||||
|
"streambuf": "cpp",
|
||||||
|
"cinttypes": "cpp",
|
||||||
|
"typeinfo": "cpp"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
146
src/main.cpp
146
src/main.cpp
|
|
@ -100,6 +100,29 @@ void setup()
|
||||||
climateCard.loadStateFromFRAM();
|
climateCard.loadStateFromFRAM();
|
||||||
climateCard.setFRAMAutoSave(true);
|
climateCard.setFRAMAutoSave(true);
|
||||||
espmega.display->bindClimateCard(&climateCard);
|
espmega.display->bindClimateCard(&climateCard);
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
// pm25_out.registerCallback(std::function<void (char*)>(binded_display_update_on_pm25_out));
|
||||||
|
// pm25_in.registerCallback(std::function<void (char*)>(binded_display_update_on_pm25_in));
|
||||||
|
// temp_out.registerCallback(std::function<void (char*)>(binded_display_update_on_temp_out));
|
||||||
|
// weather.registerCallback(std::function<void (char*)>(binded_display_update_on_weather));
|
||||||
|
// pm_switch.registerCallback(std::function<void (char*)>(binded_display_update_on_pm_switch));
|
||||||
|
// pm_fan_speed.registerCallback(std::function<void (char*)>(binded_display_update_on_pm_fan_speed));
|
||||||
|
|
||||||
|
pm25_out.registerCallback(&pm25outupdatedisplay);
|
||||||
|
pm25_in.registerCallback(&pm25inupdatedisplay);
|
||||||
|
temp_out.registerCallback(&tempoutupdatedisplay);
|
||||||
|
weather.registerCallback(&weatherupdatedisplay);
|
||||||
|
pm_switch.registerCallback(&pmswitchupdatedisplay);
|
||||||
|
pm_fan_speed.registerCallback(&pmfanspeedupdatedisplay);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// placeholder
|
// placeholder
|
||||||
// PM2.5 PPM Remote Variable
|
// PM2.5 PPM Remote Variable
|
||||||
// 12 bytes remote variable, 11 characters + null terminator
|
// 12 bytes remote variable, 11 characters + null terminator
|
||||||
|
|
@ -128,6 +151,51 @@ void setup()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// void update_display(uint8_t type, char *value){
|
||||||
|
// switch (type)
|
||||||
|
// {
|
||||||
|
// case 0:
|
||||||
|
// iseDisplay.updatePMoutside(get_pm25_out());
|
||||||
|
// break;
|
||||||
|
// case 1:
|
||||||
|
// iseDisplay.updatePMinside(get_pm25_in());
|
||||||
|
// break;
|
||||||
|
// case 2:
|
||||||
|
// iseDisplay.updateTempOutside(get_temp_out());
|
||||||
|
// break;
|
||||||
|
// case 3:
|
||||||
|
// iseDisplay.updateWeather(weather.getValue());
|
||||||
|
// break;
|
||||||
|
// case 4:
|
||||||
|
// iseDisplay.updateAirPurifierState();
|
||||||
|
// break;
|
||||||
|
// case 5:
|
||||||
|
// iseDisplay.updateAirPurifierState();
|
||||||
|
// break;
|
||||||
|
// default:
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
void pm25outupdatedisplay(char* value){
|
||||||
|
iseDisplay.updatePMoutside(get_pm25_out());
|
||||||
|
}
|
||||||
|
void pm25inupdatedisplay(char* value){
|
||||||
|
iseDisplay.updatePMinside(get_pm25_in());
|
||||||
|
}
|
||||||
|
void tempoutupdatedisplay(char* value){
|
||||||
|
iseDisplay.updateTempOutside(get_temp_out());
|
||||||
|
}
|
||||||
|
void weatherupdatedisplay(char* value){
|
||||||
|
iseDisplay.updateWeather(weather.getValue());
|
||||||
|
}
|
||||||
|
void pmfanspeedupdatedisplay(char* value){
|
||||||
|
iseDisplay.updateAirPurifierState();
|
||||||
|
}
|
||||||
|
void pmswitchupdatedisplay(char* value){
|
||||||
|
iseDisplay.updateAirPurifierState();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
espmega.loop();
|
espmega.loop();
|
||||||
|
|
@ -155,46 +223,46 @@ void loop()
|
||||||
iseDisplay.updateDateTimeText(time);
|
iseDisplay.updateDateTimeText(time);
|
||||||
last_time_updated = millis();
|
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;
|
// static uint32_t last_pm25_out_update = 0;
|
||||||
if (millis() - last_pm25_out_update > 15000)
|
// if (millis() - last_pm25_out_update > 15000)
|
||||||
{
|
// {
|
||||||
uint16_t pm25_out_value = get_pm25_out();
|
// 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);
|
// iseDisplay.updatePMoutside(pm25_out_value);
|
||||||
last_pm25_out_update = millis();
|
// last_pm25_out_update = millis();
|
||||||
}
|
// }
|
||||||
// Update the PM2.5 PPM value every 15 seconds
|
// // Update the PM2.5 PPM value every 15 seconds
|
||||||
static uint32_t last_pm25_in_update = 0;
|
// static uint32_t last_pm25_in_update = 0;
|
||||||
if (millis() - last_pm25_in_update > 15000)
|
// if (millis() - last_pm25_in_update > 15000)
|
||||||
{
|
// {
|
||||||
uint8_t pm25_in_value = get_pm25_in();
|
// uint8_t pm25_in_value = get_pm25_in();
|
||||||
iseDisplay.updatePMinside(pm25_in_value);
|
// iseDisplay.updatePMinside(pm25_in_value);
|
||||||
last_pm25_in_update = millis();
|
// last_pm25_in_update = millis();
|
||||||
}
|
// }
|
||||||
// Update the temperature value every 15 seconds
|
// Update the temperature value every 15 seconds
|
||||||
static uint32_t last_temp_out_update = 0;
|
// static uint32_t last_temp_out_update = 0;
|
||||||
if (millis() - last_temp_out_update > 15000)
|
// if (millis() - last_temp_out_update > 15000)
|
||||||
{
|
// {
|
||||||
float temp_out_value = get_temp_out();
|
// float temp_out_value = get_temp_out();
|
||||||
iseDisplay.updateTempOutside(temp_out_value);
|
// iseDisplay.updateTempOutside(temp_out_value);
|
||||||
last_temp_out_update = millis();
|
// last_temp_out_update = millis();
|
||||||
}
|
// }
|
||||||
// Update the weather value every 15 seconds
|
// // Update the weather value every 15 seconds
|
||||||
static uint32_t last_weather_update = 0;
|
// static uint32_t last_weather_update = 0;
|
||||||
if (millis() - last_weather_update > 15000)
|
// if (millis() - last_weather_update > 15000)
|
||||||
{
|
// {
|
||||||
char *weather_value = weather.getValue();
|
// char *weather_value = weather.getValue();
|
||||||
iseDisplay.updateWeather(weather_value);
|
// iseDisplay.updateWeather(weather_value);
|
||||||
last_weather_update = millis();
|
// last_weather_update = millis();
|
||||||
}
|
// }
|
||||||
// Update the PM state every 1 seconds
|
// // Update the PM state every 1 seconds
|
||||||
static uint32_t last_pm_switch_update = 0;
|
// static uint32_t last_pm_switch_update = 0;
|
||||||
if (millis() - last_pm_switch_update > 500)
|
// if (millis() - last_pm_switch_update > 500)
|
||||||
{
|
// {
|
||||||
iseDisplay.updateAirPurifierState();
|
// iseDisplay.updateAirPurifierState();
|
||||||
last_pm_switch_update = millis();
|
// last_pm_switch_update = millis();
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_pin_change(uint8_t pin, uint8_t value)
|
void on_pin_change(uint8_t pin, uint8_t value)
|
||||||
|
|
|
||||||
|
|
@ -39,3 +39,10 @@ uint16_t get_pm25_in();
|
||||||
float get_temp_out();
|
float get_temp_out();
|
||||||
void toggle_pm_switch();
|
void toggle_pm_switch();
|
||||||
void set_pm_fanspeed(uint8_t speed);
|
void set_pm_fanspeed(uint8_t speed);
|
||||||
|
void display_update();
|
||||||
|
void pm25outupdatedisplay(char* value);
|
||||||
|
void pm25inupdatedisplay(char* value);
|
||||||
|
void tempoutupdatedisplay(char* value);
|
||||||
|
void weatherupdatedisplay(char* value);
|
||||||
|
void pmfanspeedupdatedisplay(char* value);
|
||||||
|
void pmswitchupdatedisplay(char* value);
|
||||||
Loading…
Add table
Add a link
Reference in a new issue