update CT to be with current on old main

This commit is contained in:
reaw55 2024-04-20 14:31:37 +07:00
parent 88931f3001
commit d4b36336cd

View file

@ -1,20 +1,32 @@
#include <main.hpp> #include <main.hpp>
/*********************************************** /***********************************************
* Begin Configuration * * Begin Configuration *
***********************************************/ ***********************************************/
// Analog Card & Current Transformer Configuration // Analog Card & Current Transformer Configuration
// bool analogCardAvailable = false; #ifdef ANALOG_ENABLE
// AnalogCard analogCard = AnalogCard(); bool analogCardAvailable = false;
// float voltage = CT_RMS_VOLTAGE; AnalogCard analogCard = AnalogCard();
// CurrentTransformerCard ct1 = CurrentTransformerCard(&analogCard, 0, &voltage, &adc2current, 5000); float voltage = CT_RMS_VOLTAGE;
// CurrentTransformerCard ct2 = CurrentTransformerCard(&analogCard, 1, &voltage, &adc2current, 5000); #define CT_INTERVAL 5000
// CurrentTransformerCard ct3 = CurrentTransformerCard(&analogCard, 2, &voltage, &adc2current, 5000); CurrentTransformerCard ct1 = CurrentTransformerCard(&analogCard, 0, &voltage, &adc2current, CT_INTERVAL);
// CurrentTransformerCard ct4 = CurrentTransformerCard(&analogCard, 3, &voltage, &adc2current, 5000); CurrentTransformerCard ct2 = CurrentTransformerCard(&analogCard, 1, &voltage, &adc2current, CT_INTERVAL);
// CurrentTransformerCard ct5 = CurrentTransformerCard(&analogCard, 4, &voltage, &adc2current, 5000); CurrentTransformerCard ct3 = CurrentTransformerCard(&analogCard, 2, &voltage, &adc2current, CT_INTERVAL);
// CurrentTransformerCard ct6 = CurrentTransformerCard(&analogCard, 5, &voltage, &adc2current, 5000); CurrentTransformerCard ct4 = CurrentTransformerCard(&analogCard, 3, &voltage, &adc2current, CT_INTERVAL);
CurrentTransformerCard ct5 = CurrentTransformerCard(&analogCard, 6, &voltage, &adc2current, CT_INTERVAL);
CurrentTransformerCard ct6 = CurrentTransformerCard(&analogCard, 7, &voltage, &adc2current, CT_INTERVAL);
float adc2current(uint16_t adc_val)
{
// float voltage = adc_val * 0.0007-0.1994;
float adc_voltage = adc_val * 0.0007;
// 0-10V Output with 30A Current Rating CT
float ct_current = adc_voltage / 10.0 * 30.0;
return ct_current;
}
#endif
// Remote Variables // Remote Variables
RemoteVariable pm25_in = RemoteVariable(); RemoteVariable pm25_in = RemoteVariable();
@ -26,11 +38,7 @@ RemoteVariable pm_fan_speed = RemoteVariable();
RemoteVariable pm_lock = RemoteVariable(); RemoteVariable pm_lock = RemoteVariable();
RemoteVariable ac_lock = RemoteVariable(); RemoteVariable ac_lock = 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;
@ -42,8 +50,8 @@ const uint8_t light_array[4][2] = {
{LIGHT_ROW4_COLUMN1, LIGHT_ROW4_COLUMN2}}; {LIGHT_ROW4_COLUMN1, LIGHT_ROW4_COLUMN2}};
// Air Conditioner Configuration // Air Conditioner Configuration
const char *mode_names_daikin[] = {"off", "cool", "fan_only", "dry"}; const char *mode_names_daikin[] = {"off", "fan_only", "cool", "dry"};
const char *mode_names_york[] = {"off", "cool", "fan_only"}; const char *mode_names_york[] = {"off", "fan_only", "cool"};
const char *fan_speed_names[] = {"auto", "high", "medium", "low"}; const char *fan_speed_names[] = {"auto", "high", "medium", "low"};
AirConditioner ac_daikin = { AirConditioner ac_daikin = {
@ -121,11 +129,22 @@ void setup()
// 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)
// {
// Serial.print("boot_state.txt=\"Factory Resetting . . .\"");
// sendStopBytes();
// for (uint16_t i = 0; i < 32768; i++)
// {
// espmega.fram.write8(i, 0);
// }
// esp_restart();
// }
// // ------------ End Factory Reset Routine ------------ // // ------------ End Factory Reset Routine ------------
@ -161,36 +180,35 @@ 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
// espmega.installCard(4, &analogCard); #ifdef ANALOG_ENABLE
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);
ct3.bindFRAM(&espmega.fram, 6200);
// espmega.installCard(7, &ct3); espmega.iot->registerCard(7);
// ct3.bindFRAM(&espmega.fram, 6200); espmega.installCard(8, &ct4);
// espmega.iot->registerCard(7); ct4.bindFRAM(&espmega.fram, 6300);
// espmega.installCard(8, &ct4); espmega.iot->registerCard(8);
// ct4.bindFRAM(&espmega.fram, 6300); espmega.installCard(9, &ct5);
// espmega.iot->registerCard(8); ct5.bindFRAM(&espmega.fram, 6400);
// espmega.installCard(9, &ct5); espmega.iot->registerCard(9);
// ct5.bindFRAM(&espmega.fram, 6400); espmega.installCard(10, &ct6);
// espmega.iot->registerCard(9); ct6.bindFRAM(&espmega.fram, 6500);
// espmega.installCard(10, &ct6); espmega.iot->registerCard(10);
// ct6.bindFRAM(&espmega.fram, 6500); #endif
// espmega.iot->registerCard(10);
// ------------ Climate Cards Initialization Routine ------------ // ------------ Climate Cards Initialization Routine ------------
ESP_LOGD("ISE OS", "Setting up climate cards"); ESP_LOGD("ISE OS", "Setting up climate cards");
@ -206,47 +224,48 @@ 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 ------------
//ESP_LOGD("ISE OS", "Installing current transformer cards"); #ifdef ANALOG_ENABLE
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);
// If the analog card is available, install the current transformer cards // If the analog card is available, install the current transformer cards
// If the analog card is not available, current transformer cards will not be installed // If the analog card is not available, current transformer cards will not be installed
// Unless CT_FORCE_ENABLE is set to true // Unless CT_FORCE_ENABLE is set to true
// This is to prevent soft locking the device when the device tries to read from an ADC channel that does not exist // This is to prevent soft locking the device when the device tries to read from an ADC channel that does not exist
// if (analogCardAvailable || CT_FORCE_ENABLE) if (analogCardAvailable || CT_FORCE_ENABLE)
// { {
// ESP_LOGV("ISE OS", "Analog card available, installing current transformer cards"); ESP_LOGV("ISE OS", "Analog card available, installing current transformer cards");
// // espmega.installCard(5, &ct1); espmega.installCard(5, &ct1);
// // ct1.bindFRAM(&espmega.fram, 5010); ct1.bindFRAM(&espmega.fram, 5010);
// // espmega.installCard(6, &ct2); espmega.installCard(6, &ct2);
// // ct2.bindFRAM(&espmega.fram, 5020); ct2.bindFRAM(&espmega.fram, 5020);
// // espmega.installCard(7, &ct3); espmega.installCard(7, &ct3);
// // ct3.bindFRAM(&espmega.fram, 5030); ct3.bindFRAM(&espmega.fram, 5030);
// // espmega.installCard(8, &ct4); espmega.installCard(8, &ct4);
// // ct4.bindFRAM(&espmega.fram, 5040); ct4.bindFRAM(&espmega.fram, 5040);
// // espmega.installCard(9, &ct5); espmega.installCard(9, &ct5);
// // ct5.bindFRAM(&espmega.fram, 5050); ct5.bindFRAM(&espmega.fram, 5050);
// // espmega.installCard(10, &ct5); espmega.installCard(10, &ct5);
// // ct6.bindFRAM(&espmega.fram, 5060); ct6.bindFRAM(&espmega.fram, 5060);
// espmega.iot->registerCard(5); espmega.iot->registerCard(5);
// espmega.iot->registerCard(6); espmega.iot->registerCard(6);
// espmega.iot->registerCard(7); espmega.iot->registerCard(7);
// espmega.iot->registerCard(8); espmega.iot->registerCard(8);
// espmega.iot->registerCard(9); espmega.iot->registerCard(9);
// espmega.iot->registerCard(10); espmega.iot->registerCard(10);
// } }
// else else
// { {
// 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 ------------
@ -288,7 +307,7 @@ void setup()
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 ------------
@ -356,6 +375,28 @@ void loop()
iseDisplay.updateDateTimeText(time); iseDisplay.updateDateTimeText(time);
last_time_updated = millis(); last_time_updated = millis();
} }
#ifdef ANALOG_ENABLE
// Send out analog Data every 6 seconds
static uint32_t last_analog_sent = 0;
if (millis() - last_analog_sent > 6000)
{
espmega.iot->publish("/debug/up", "1");
if (analogCardAvailable || CT_FORCE_ENABLE)
{
espmega.iot->publish("/debug/log", "Sending Analog Card Data");
char topic_buffer[50];
char payload_buffer[50];
// Publish ADC Pin 0-7
for (uint8_t i = 0; i < 8; i++)
{
sprintf(topic_buffer, "/debug/analog/%d", i);
sprintf(payload_buffer, "%d", analogCard.analogRead(i));
espmega.iot->publish(topic_buffer, payload_buffer);
}
}
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)