CT revamp
This commit is contained in:
parent
978cf36e1e
commit
a3b59507e0
3 changed files with 31 additions and 42 deletions
|
|
@ -12,6 +12,6 @@
|
||||||
platform = espressif32
|
platform = espressif32
|
||||||
board = wt32-eth01
|
board = wt32-eth01
|
||||||
framework = arduino
|
framework = arduino
|
||||||
lib_deps = siwats/ESPMegaPROR3@^2.5.3
|
lib_deps = siwats/ESPMegaPROR3@^2.5.9
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
build_flags = -DCORE_DEBUG_LEVEL=0
|
build_flags = -DCORE_DEBUG_LEVEL=0
|
||||||
|
|
|
||||||
70
src/main.cpp
70
src/main.cpp
|
|
@ -1,20 +1,27 @@
|
||||||
#include <main.hpp>
|
#include <main.hpp>
|
||||||
|
|
||||||
|
|
||||||
/***********************************************
|
/***********************************************
|
||||||
* Begin Configuration *
|
* Begin Configuration *
|
||||||
***********************************************/
|
***********************************************/
|
||||||
|
|
||||||
// Analog Card & Current Transformer Configuration
|
// Analog Card & Current Transformer Configuration
|
||||||
|
#ifdef ANALOG_ENABLE
|
||||||
bool analogCardAvailable = false;
|
bool analogCardAvailable = false;
|
||||||
AnalogCard analogCard = AnalogCard();
|
AnalogCard analogCard = AnalogCard();
|
||||||
float voltage = CT_RMS_VOLTAGE;
|
float voltage = CT_RMS_VOLTAGE;
|
||||||
CurrentTransformerCard ct1 = CurrentTransformerCard(&analogCard, 0, &voltage, &adc2current, 5000);
|
#define CT_INTERVAL 5000
|
||||||
CurrentTransformerCard ct2 = CurrentTransformerCard(&analogCard, 1, &voltage, &adc2current, 5000);
|
CurrentTransformerCard ct1 = CurrentTransformerCard(&analogCard, 0, &voltage, &adc2current, CT_INTERVAL);
|
||||||
CurrentTransformerCard ct3 = CurrentTransformerCard(&analogCard, 2, &voltage, &adc2current, 5000);
|
CurrentTransformerCard ct2 = CurrentTransformerCard(&analogCard, 1, &voltage, &adc2current, CT_INTERVAL);
|
||||||
CurrentTransformerCard ct4 = CurrentTransformerCard(&analogCard, 3, &voltage, &adc2current, 5000);
|
CurrentTransformerCard ct3 = CurrentTransformerCard(&analogCard, 2, &voltage, &adc2current, CT_INTERVAL);
|
||||||
CurrentTransformerCard ct5 = CurrentTransformerCard(&analogCard, 4, &voltage, &adc2current, 5000);
|
CurrentTransformerCard ct4 = CurrentTransformerCard(&analogCard, 3, &voltage, &adc2current, CT_INTERVAL);
|
||||||
CurrentTransformerCard ct6 = CurrentTransformerCard(&analogCard, 5, &voltage, &adc2current, 5000);
|
CurrentTransformerCard ct5 = CurrentTransformerCard(&analogCard, 4, &voltage, &adc2current, CT_INTERVAL);
|
||||||
|
CurrentTransformerCard ct6 = CurrentTransformerCard(&analogCard, 5, &voltage, &adc2current, CT_INTERVAL);
|
||||||
|
float adc2current(uint16_t adc_val)
|
||||||
|
{
|
||||||
|
return adc_val * 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
// Remote Variables
|
// Remote Variables
|
||||||
RemoteVariable pm25_in = RemoteVariable();
|
RemoteVariable pm25_in = RemoteVariable();
|
||||||
|
|
@ -24,12 +31,6 @@ RemoteVariable weather = RemoteVariable();
|
||||||
RemoteVariable pm_switch = RemoteVariable();
|
RemoteVariable pm_switch = RemoteVariable();
|
||||||
RemoteVariable pm_fan_speed = RemoteVariable();
|
RemoteVariable pm_fan_speed = RemoteVariable();
|
||||||
|
|
||||||
float adc2current(uint16_t adc_val) {
|
|
||||||
return adc_val * 1.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define CT_INTERVAL 5000
|
|
||||||
|
|
||||||
// Light Configuration
|
// Light Configuration
|
||||||
uint8_t row = 4;
|
uint8_t row = 4;
|
||||||
uint8_t column = 2;
|
uint8_t column = 2;
|
||||||
|
|
@ -93,7 +94,6 @@ void setup()
|
||||||
bool clear_fram = !gpio_get_level(GPIO_NUM_2);
|
bool clear_fram = !gpio_get_level(GPIO_NUM_2);
|
||||||
// ------------ End GPIO 2 Factory Reset Check ------------
|
// ------------ End GPIO 2 Factory Reset Check ------------
|
||||||
|
|
||||||
|
|
||||||
// ------------ Display Pre Initialization Routine ------------
|
// ------------ Display Pre Initialization Routine ------------
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
iseDisplayAdapter.begin(ISE_DISPLAY_BAUD_RATE, SERIAL_8N1, ISE_DISPLAY_RX_PIN, ISE_DISPLAY_TX_PIN);
|
iseDisplayAdapter.begin(ISE_DISPLAY_BAUD_RATE, SERIAL_8N1, ISE_DISPLAY_RX_PIN, ISE_DISPLAY_TX_PIN);
|
||||||
|
|
@ -106,21 +106,19 @@ void setup()
|
||||||
Serial.print("boot_state.txt=\"Core Initializing . . .\"");
|
Serial.print("boot_state.txt=\"Core Initializing . . .\"");
|
||||||
sendStopBytes();
|
sendStopBytes();
|
||||||
// ------------ End Display Pre Initialization Routine ------------
|
// ------------ End Display Pre Initialization Routine ------------
|
||||||
|
|
||||||
|
|
||||||
// Give flow of control to OS and scheduler
|
// Give flow of control to OS and scheduler
|
||||||
espmega.begin();
|
espmega.begin();
|
||||||
|
|
||||||
|
|
||||||
// // ------------ Factory Reset Routine ------------
|
// // ------------ Factory Reset Routine ------------
|
||||||
// Disable factory reset for now
|
// Disable factory reset for now
|
||||||
espmega.inputs.loop();
|
espmega.inputs.loop();
|
||||||
|
|
||||||
//set debounce time to 200 for pin 0-7
|
// set debounce time to 200 for pin 0-7
|
||||||
for (uint16_t i = 0; i < 8; i++){
|
for (uint16_t i = 0; i < 8; i++)
|
||||||
espmega.inputs.setDebounceTime(i,200);
|
{
|
||||||
|
espmega.inputs.setDebounceTime(i, 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// if (clear_fram)
|
// if (clear_fram)
|
||||||
// {
|
// {
|
||||||
|
|
@ -134,7 +132,6 @@ void setup()
|
||||||
// }
|
// }
|
||||||
// // ------------ End Factory Reset Routine ------------
|
// // ------------ End Factory Reset Routine ------------
|
||||||
|
|
||||||
|
|
||||||
// ------------ IoT Module Initialization Routine ------------
|
// ------------ IoT Module Initialization Routine ------------
|
||||||
Serial.print("boot_state.txt=\"IoT Initializing . . .\"");
|
Serial.print("boot_state.txt=\"IoT Initializing . . .\"");
|
||||||
sendStopBytes();
|
sendStopBytes();
|
||||||
|
|
@ -167,24 +164,22 @@ void setup()
|
||||||
}
|
}
|
||||||
// ------------ End Inputs and Outputs Initialization Routine ------------
|
// ------------ End Inputs and Outputs Initialization Routine ------------
|
||||||
espmega.outputs.setState(12, true);
|
espmega.outputs.setState(12, true);
|
||||||
espmega.outputs.setValue(12,4095);
|
espmega.outputs.setValue(12, 4095);
|
||||||
espmega.installCard(2, &climateCard_daikin);
|
espmega.installCard(2, &climateCard_daikin);
|
||||||
climateCard_daikin.bindFRAM(&espmega.fram, 5000);
|
climateCard_daikin.bindFRAM(&espmega.fram, 5000);
|
||||||
climateCard_daikin.loadStateFromFRAM();
|
climateCard_daikin.loadStateFromFRAM();
|
||||||
climateCard_daikin.setFRAMAutoSave(true);
|
climateCard_daikin.setFRAMAutoSave(true);
|
||||||
espmega.display->bindClimateCard(&climateCard_daikin);
|
espmega.display->bindClimateCard(&climateCard_daikin);
|
||||||
|
|
||||||
// Current Transformers
|
// Current Transformers
|
||||||
|
#ifdef ANALOG_ENABLE
|
||||||
espmega.installCard(4, &analogCard);
|
espmega.installCard(4, &analogCard);
|
||||||
|
|
||||||
espmega.installCard(5, &ct1);
|
espmega.installCard(5, &ct1);
|
||||||
ct1.bindFRAM(&espmega.fram, 6000);
|
ct1.bindFRAM(&espmega.fram, 6000);
|
||||||
espmega.iot->registerCard(5);
|
espmega.iot->registerCard(5);
|
||||||
|
|
||||||
espmega.installCard(6, &ct2);
|
espmega.installCard(6, &ct2);
|
||||||
ct2.bindFRAM(&espmega.fram, 6100);
|
ct2.bindFRAM(&espmega.fram, 6100);
|
||||||
espmega.iot->registerCard(6);
|
espmega.iot->registerCard(6);
|
||||||
|
|
||||||
espmega.installCard(7, &ct3);
|
espmega.installCard(7, &ct3);
|
||||||
ct3.bindFRAM(&espmega.fram, 6200);
|
ct3.bindFRAM(&espmega.fram, 6200);
|
||||||
espmega.iot->registerCard(7);
|
espmega.iot->registerCard(7);
|
||||||
|
|
@ -197,14 +192,7 @@ void setup()
|
||||||
espmega.installCard(10, &ct6);
|
espmega.installCard(10, &ct6);
|
||||||
ct6.bindFRAM(&espmega.fram, 6500);
|
ct6.bindFRAM(&espmega.fram, 6500);
|
||||||
espmega.iot->registerCard(10);
|
espmega.iot->registerCard(10);
|
||||||
|
#endif
|
||||||
// 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 ------------
|
// ------------ Climate Cards Initialization Routine ------------
|
||||||
ESP_LOGD("ISE OS", "Setting up climate cards");
|
ESP_LOGD("ISE OS", "Setting up climate cards");
|
||||||
|
|
@ -220,13 +208,14 @@ void setup()
|
||||||
|
|
||||||
// York Climate Card
|
// York Climate Card
|
||||||
ESP_LOGD("ISE OS", "Installing york climate card");
|
ESP_LOGD("ISE OS", "Installing york climate card");
|
||||||
espmega.installCard(10, &climateCard_york);
|
espmega.installCard(3, &climateCard_york);
|
||||||
climateCard_york.bindFRAM(&espmega.fram, 5005);
|
climateCard_york.bindFRAM(&espmega.fram, 5005);
|
||||||
climateCard_york.loadStateFromFRAM();
|
climateCard_york.loadStateFromFRAM();
|
||||||
climateCard_york.setFRAMAutoSave(true);
|
climateCard_york.setFRAMAutoSave(true);
|
||||||
// ------------ End Climate Cards Initialization Routine ------------
|
// ------------ End Climate Cards Initialization Routine ------------
|
||||||
|
|
||||||
// ------------ Current Transformer Cards Initialization Routine ------------
|
// ------------ Current Transformer Cards Initialization Routine ------------
|
||||||
|
#ifdef ANALOG_ENABLE
|
||||||
ESP_LOGD("ISE OS", "Installing current transformer cards");
|
ESP_LOGD("ISE OS", "Installing current transformer cards");
|
||||||
// First try to install the analog card
|
// First try to install the analog card
|
||||||
analogCardAvailable = espmega.installCard(4, &analogCard);
|
analogCardAvailable = espmega.installCard(4, &analogCard);
|
||||||
|
|
@ -260,10 +249,9 @@ void setup()
|
||||||
{
|
{
|
||||||
ESP_LOGE("ISE OS", "Analog card not available, current transformer cards cannot and will not be installed.");
|
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");
|
#endif
|
||||||
// ------------ End Current Transformer Cards Initialization Routine ------------
|
// ------------ End Current Transformer Cards Initialization Routine ------------
|
||||||
|
|
||||||
|
|
||||||
// ------------ Remote Variables Initialization Routine ------------
|
// ------------ Remote Variables Initialization Routine ------------
|
||||||
pm25_out.registerCallback(&pm25outupdatedisplay);
|
pm25_out.registerCallback(&pm25outupdatedisplay);
|
||||||
pm25_in.registerCallback(&pm25inupdatedisplay);
|
pm25_in.registerCallback(&pm25inupdatedisplay);
|
||||||
|
|
@ -288,15 +276,13 @@ void setup()
|
||||||
pm_fan_speed.enableSetValue("/pm/set_fan_speed");
|
pm_fan_speed.enableSetValue("/pm/set_fan_speed");
|
||||||
// ------------ End Remote Variables Initialization Routine ------------
|
// ------------ End Remote Variables Initialization Routine ------------
|
||||||
|
|
||||||
|
|
||||||
// ------------ IoT Card Registration Routine ------------
|
// ------------ IoT Card Registration Routine ------------
|
||||||
espmega.iot->registerCard(0); // Register the Input Card
|
espmega.iot->registerCard(0); // Register the Input Card
|
||||||
espmega.iot->registerCard(1); // Register the Output Card
|
espmega.iot->registerCard(1); // Register the Output Card
|
||||||
espmega.iot->registerCard(2); // Register the Climate Card Daikin
|
espmega.iot->registerCard(2); // Register the Climate Card Daikin
|
||||||
espmega.iot->registerCard(10); // Register the Climate Card York
|
espmega.iot->registerCard(3); // Register the Climate Card York
|
||||||
// ------------ End IoT Card Registration Routine ------------
|
// ------------ End IoT Card Registration Routine ------------
|
||||||
|
|
||||||
|
|
||||||
// ------------ External Display Initialization Routine ------------
|
// ------------ External Display Initialization Routine ------------
|
||||||
auto bindedGetTime = std::bind(&ESPMegaPRO::getTime, &espmega);
|
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);
|
||||||
|
|
@ -347,6 +333,7 @@ void loop()
|
||||||
last_time_updated = millis();
|
last_time_updated = millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef ANALOG_ENABLE
|
||||||
// Send out analog Data every 6 seconds
|
// Send out analog Data every 6 seconds
|
||||||
static uint32_t last_analog_sent = 0;
|
static uint32_t last_analog_sent = 0;
|
||||||
if (millis() - last_analog_sent > 6000)
|
if (millis() - last_analog_sent > 6000)
|
||||||
|
|
@ -367,6 +354,7 @@ void loop()
|
||||||
}
|
}
|
||||||
last_analog_sent = millis();
|
last_analog_sent = millis();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_pin_change(uint8_t pin, uint8_t value)
|
void on_pin_change(uint8_t pin, uint8_t value)
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ SET_LOOP_TASK_STACK_SIZE(32*1024);
|
||||||
#define AIR_CONDITIONER_RMT_CHANNEL0 RMT_CHANNEL_0
|
#define AIR_CONDITIONER_RMT_CHANNEL0 RMT_CHANNEL_0
|
||||||
#define AIR_CONDITIONER_RMT_CHANNEL1 RMT_CHANNEL_1
|
#define AIR_CONDITIONER_RMT_CHANNEL1 RMT_CHANNEL_1
|
||||||
// CT Configuration
|
// CT Configuration
|
||||||
|
#define ANALOG_ENABLE
|
||||||
#define CT_FORCE_ENABLE true
|
#define CT_FORCE_ENABLE true
|
||||||
#define CT_RMS_VOLTAGE 1.0
|
#define CT_RMS_VOLTAGE 1.0
|
||||||
#define CT_PIN_LIGHT_PHASE1 0
|
#define CT_PIN_LIGHT_PHASE1 0
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue