From 29a975a1aff24efa6ccf9c546f202b8b42bc15f6 Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Sun, 10 Mar 2024 01:07:23 +0700 Subject: [PATCH] better handle interaction between CT and analog card --- src/main.cpp | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 07637b7..ce33d4e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,7 @@ #include +bool analogCardAvailable = false; + RemoteVariable pm25_in = RemoteVariable(); RemoteVariable pm25_out = RemoteVariable(); RemoteVariable temp_out = RemoteVariable(); @@ -121,7 +123,6 @@ void setup() espmega.enableWebServer(80); espmega.inputs.registerCallback(on_pin_change); espmega.outputs.setAutoSaveToFRAM(true); - analogCard.begin(); // Set value of pin 0-12 to 4095 for (uint8_t i = 0; i < 13; i++) { @@ -136,19 +137,26 @@ void setup() climateCard.setFRAMAutoSave(true); espmega.display->bindClimateCard(&climateCard); ESP_LOGD("ISE OS", "Installing current transformer cards"); - espmega.installCard(4, &ct_light_phase1); - espmega.installCard(5, &ct_light_phase2); - espmega.installCard(6, &ct_socket); - espmega.installCard(7, &ct_ac_phase1); - espmega.installCard(8, &ct_ac_phase2); - espmega.installCard(9, &ct_ac_phase3); + analogCardAvailable = espmega.installCard(4, &analogCard); + if (analogCardAvailable) { + ESP_LOGV("ISE OS", "Analog card available, installing current transformer cards"); + espmega.installCard(5, &ct_light_phase1); + espmega.installCard(6, &ct_light_phase2); + espmega.installCard(7, &ct_socket); + espmega.installCard(8, &ct_ac_phase1); + espmega.installCard(9, &ct_ac_phase2); + espmega.installCard(10, &ct_ac_phase3); + espmega.iot->registerCard(4); + espmega.iot->registerCard(5); + espmega.iot->registerCard(6); + espmega.iot->registerCard(7); + espmega.iot->registerCard(8); + espmega.iot->registerCard(9); + } else { + ESP_LOGE("ISE OS", "Analog card not available, current transformer cards cannot and will not be installed."); + } ESP_LOGD("ISE OS", "Registering Current Transformer Cards with IoT Module"); - espmega.iot->registerCard(4); - espmega.iot->registerCard(5); - espmega.iot->registerCard(6); - espmega.iot->registerCard(7); - espmega.iot->registerCard(8); - espmega.iot->registerCard(9); + // 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);