From 03d8dc9c8bcbbf27312a733fe4a1497b3c493804 Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Sun, 10 Mar 2024 00:28:37 +0700 Subject: [PATCH 1/5] rebase and reverse ct --- platformio.ini | 2 +- src/main.cpp | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/platformio.ini b/platformio.ini index b8ee1dc..e977df1 100644 --- a/platformio.ini +++ b/platformio.ini @@ -12,7 +12,7 @@ platform = espressif32 board = wt32-eth01 framework = arduino -lib_deps = siwats/ESPMegaPROR3@^2.3.6 +lib_deps = siwats/ESPMegaPROR3@^2.3.7 monitor_speed = 115200 build_flags = -DCORE_DEBUG_LEVEL=0 upload_port = COM32 diff --git a/src/main.cpp b/src/main.cpp index ef6dbe4..6a502f5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -35,7 +35,6 @@ AirConditioner ac = { .fan_speeds = 4, .fan_speed_names = fan_speed_names, .getInfraredCode = &getInfraredCode}; - /*********************************************** * End Configuration * ***********************************************/ @@ -47,7 +46,7 @@ ClimateCard climateCard = ClimateCard(AIR_CONDITIONER_IR_PIN, ac, AIR_CONDITIONER_SENSOR_TYPE, AIR_CONDITIONER_SENSOR_PIN, AIR_CONDITIONER_RMT_CHANNEL); -void adc2current(uint16_t adc_value) +float adcToCurrent(uint16_t adc_value) { // 16 bit ADC value to current in amps // ADC Range is 0-65535, It have an input range of 0-3.3V @@ -129,11 +128,11 @@ void setup() } espmega.outputs.setState(12, true); espmega.outputs.setValue(12,4095); - espmega.installCard(2, &climateCard_daikin); + espmega.installCard(2, &climateCard); climateCard.bindFRAM(&espmega.fram, 5000); climateCard.loadStateFromFRAM(); climateCard.setFRAMAutoSave(true); - espmega.display->bindclimateCard(&climateCard); + espmega.display->bindClimateCard(&climateCard); espmega.installCard(4, &ct_light_phase1); espmega.installCard(5, &ct_light_phase2); espmega.installCard(6, &ct_socket); From fe75c3acebb7066b53f7ca7cbf7867e609b33687 Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Sun, 10 Mar 2024 00:52:56 +0700 Subject: [PATCH 2/5] fix bug regarding analog card call error --- platformio.ini | 4 +--- src/main.cpp | 4 ++++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/platformio.ini b/platformio.ini index e977df1..da5e8cd 100644 --- a/platformio.ini +++ b/platformio.ini @@ -14,6 +14,4 @@ board = wt32-eth01 framework = arduino lib_deps = siwats/ESPMegaPROR3@^2.3.7 monitor_speed = 115200 -build_flags = -DCORE_DEBUG_LEVEL=0 -upload_port = COM32 -monitor_port = COM32 \ No newline at end of file +build_flags = -DCORE_DEBUG_LEVEL=5 \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 6a502f5..07637b7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -121,6 +121,7 @@ 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++) { @@ -128,17 +129,20 @@ void setup() } espmega.outputs.setState(12, true); espmega.outputs.setValue(12,4095); + ESP_LOGD("ISE OS", "Setting up climate cards"); espmega.installCard(2, &climateCard); climateCard.bindFRAM(&espmega.fram, 5000); climateCard.loadStateFromFRAM(); 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); + ESP_LOGD("ISE OS", "Registering Current Transformer Cards with IoT Module"); espmega.iot->registerCard(4); espmega.iot->registerCard(5); espmega.iot->registerCard(6); From 29a975a1aff24efa6ccf9c546f202b8b42bc15f6 Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Sun, 10 Mar 2024 01:07:23 +0700 Subject: [PATCH 3/5] 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); From 439dc7480ec6d132ee20ecaead3c1d18aff79fbd Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Sun, 10 Mar 2024 01:08:32 +0700 Subject: [PATCH 4/5] CT state saving --- src/main.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index ce33d4e..3570e53 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -141,11 +141,17 @@ void setup() if (analogCardAvailable) { ESP_LOGV("ISE OS", "Analog card available, installing current transformer cards"); espmega.installCard(5, &ct_light_phase1); + ct_light_phase1.bindFRAM(&espmega.fram, 5010); espmega.installCard(6, &ct_light_phase2); + ct_light_phase2.bindFRAM(&espmega.fram, 5020); espmega.installCard(7, &ct_socket); + ct_socket.bindFRAM(&espmega.fram, 5030); espmega.installCard(8, &ct_ac_phase1); + ct_ac_phase1.bindFRAM(&espmega.fram, 5040); espmega.installCard(9, &ct_ac_phase2); + ct_ac_phase2.bindFRAM(&espmega.fram, 5050); espmega.installCard(10, &ct_ac_phase3); + ct_ac_phase3.bindFRAM(&espmega.fram, 5060); espmega.iot->registerCard(4); espmega.iot->registerCard(5); espmega.iot->registerCard(6); From 7f82967f8419abb4179205bc67fa965e43ea986d Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Sun, 10 Mar 2024 01:12:00 +0700 Subject: [PATCH 5/5] CT analog avail awareness --- platformio.ini | 2 +- src/ise_display_definitions.hpp | 7 ------- src/main.cpp | 2 +- src/main.hpp | 10 ++++++++++ 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/platformio.ini b/platformio.ini index da5e8cd..09540d7 100644 --- a/platformio.ini +++ b/platformio.ini @@ -12,6 +12,6 @@ platform = espressif32 board = wt32-eth01 framework = arduino -lib_deps = siwats/ESPMegaPROR3@^2.3.7 +lib_deps = siwats/ESPMegaPROR3@^2.3.8 monitor_speed = 115200 build_flags = -DCORE_DEBUG_LEVEL=5 \ No newline at end of file diff --git a/src/ise_display_definitions.hpp b/src/ise_display_definitions.hpp index 6a7d034..a41862a 100644 --- a/src/ise_display_definitions.hpp +++ b/src/ise_display_definitions.hpp @@ -1,13 +1,6 @@ #pragma once //start definition -#define CT_RMS_VOLTAGE 220.0 -#define CT_PIN_LIGHT_PHASE1 0 -#define CT_PIN_LIGHT_PHASE2 1 -#define CT_PIN_SOCKET 2 -#define CT_PIN_AC_PHASE1 3 -#define CT_PIN_AC_PHASE2 4 -#define CT_PIN_AC_PHASE3 5 /* tentetive pin mapping diff --git a/src/main.cpp b/src/main.cpp index 3570e53..0b5604f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -138,7 +138,7 @@ void setup() espmega.display->bindClimateCard(&climateCard); ESP_LOGD("ISE OS", "Installing current transformer cards"); analogCardAvailable = espmega.installCard(4, &analogCard); - if (analogCardAvailable) { + if (analogCardAvailable || CT_FORCE_ENABLE) { ESP_LOGV("ISE OS", "Analog card available, installing current transformer cards"); espmega.installCard(5, &ct_light_phase1); ct_light_phase1.bindFRAM(&espmega.fram, 5010); diff --git a/src/main.hpp b/src/main.hpp index 58f9919..cac73d3 100644 --- a/src/main.hpp +++ b/src/main.hpp @@ -22,6 +22,16 @@ SET_LOOP_TASK_STACK_SIZE(32*1024); #define AIR_CONDITIONER_IR_PIN 5 #define AIR_CONDITIONER_RMT_CHANNEL RMT_CHANNEL_0 +// CT Configuration +#define CT_FORCE_ENABLE false +#define CT_RMS_VOLTAGE 220.0 +#define CT_PIN_LIGHT_PHASE1 0 +#define CT_PIN_LIGHT_PHASE2 1 +#define CT_PIN_SOCKET 2 +#define CT_PIN_AC_PHASE1 3 +#define CT_PIN_AC_PHASE2 4 +#define CT_PIN_AC_PHASE3 5 + void handleMqttMessage(char *topic, char *payload); void subscribeToMqttTopics(); void handlePageChange(uint8_t page);