Compare commits
3 commits
main
...
test-analo
| Author | SHA1 | Date | |
|---|---|---|---|
| 2a244c2a1b | |||
| a3b59507e0 | |||
|
|
978cf36e1e |
3 changed files with 54 additions and 44 deletions
|
|
@ -12,6 +12,6 @@
|
|||
platform = espressif32
|
||||
board = wt32-eth01
|
||||
framework = arduino
|
||||
lib_deps = siwats/ESPMegaPROR3@^2.5.3
|
||||
lib_deps = siwats/ESPMegaPROR3@^2.5.9
|
||||
monitor_speed = 115200
|
||||
build_flags = -DCORE_DEBUG_LEVEL=0
|
||||
|
|
|
|||
82
src/main.cpp
82
src/main.cpp
|
|
@ -1,20 +1,28 @@
|
|||
#include <main.hpp>
|
||||
|
||||
|
||||
/***********************************************
|
||||
* Begin Configuration *
|
||||
***********************************************/
|
||||
|
||||
// Analog Card & Current Transformer Configuration
|
||||
#ifdef ANALOG_ENABLE
|
||||
bool analogCardAvailable = false;
|
||||
AnalogCard analogCard = AnalogCard();
|
||||
float voltage = CT_RMS_VOLTAGE;
|
||||
CurrentTransformerCard ct1 = CurrentTransformerCard(&analogCard, 0, &voltage, &adc2current, 5000);
|
||||
CurrentTransformerCard ct2 = CurrentTransformerCard(&analogCard, 1, &voltage, &adc2current, 5000);
|
||||
CurrentTransformerCard ct3 = CurrentTransformerCard(&analogCard, 2, &voltage, &adc2current, 5000);
|
||||
CurrentTransformerCard ct4 = CurrentTransformerCard(&analogCard, 3, &voltage, &adc2current, 5000);
|
||||
CurrentTransformerCard ct5 = CurrentTransformerCard(&analogCard, 4, &voltage, &adc2current, 5000);
|
||||
CurrentTransformerCard ct6 = CurrentTransformerCard(&analogCard, 5, &voltage, &adc2current, 5000);
|
||||
#define CT_INTERVAL 5000
|
||||
CurrentTransformerCard ct1 = CurrentTransformerCard(&analogCard, 0, &voltage, &adc2current, CT_INTERVAL);
|
||||
CurrentTransformerCard ct2 = CurrentTransformerCard(&analogCard, 1, &voltage, &adc2current, CT_INTERVAL);
|
||||
CurrentTransformerCard ct3 = CurrentTransformerCard(&analogCard, 2, &voltage, &adc2current, CT_INTERVAL);
|
||||
CurrentTransformerCard ct4 = CurrentTransformerCard(&analogCard, 3, &voltage, &adc2current, CT_INTERVAL);
|
||||
CurrentTransformerCard ct5 = CurrentTransformerCard(&analogCard, 4, &voltage, &adc2current, CT_INTERVAL);
|
||||
CurrentTransformerCard ct6 = CurrentTransformerCard(&analogCard, 5, &voltage, &adc2current, CT_INTERVAL);
|
||||
float adc2current(uint16_t adc_val)
|
||||
{
|
||||
float voltage = adc_val * 0.0007-0.1994;
|
||||
return voltage;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// Remote Variables
|
||||
RemoteVariable pm25_in = RemoteVariable();
|
||||
|
|
@ -24,12 +32,6 @@ RemoteVariable weather = RemoteVariable();
|
|||
RemoteVariable pm_switch = RemoteVariable();
|
||||
RemoteVariable pm_fan_speed = RemoteVariable();
|
||||
|
||||
float adc2current(uint16_t adc_val) {
|
||||
return adc_val * 1.0;
|
||||
}
|
||||
|
||||
#define CT_INTERVAL 5000
|
||||
|
||||
// Light Configuration
|
||||
uint8_t row = 4;
|
||||
uint8_t column = 2;
|
||||
|
|
@ -93,7 +95,6 @@ void setup()
|
|||
bool clear_fram = !gpio_get_level(GPIO_NUM_2);
|
||||
// ------------ End GPIO 2 Factory Reset Check ------------
|
||||
|
||||
|
||||
// ------------ Display Pre Initialization Routine ------------
|
||||
Serial.begin(115200);
|
||||
iseDisplayAdapter.begin(ISE_DISPLAY_BAUD_RATE, SERIAL_8N1, ISE_DISPLAY_RX_PIN, ISE_DISPLAY_TX_PIN);
|
||||
|
|
@ -107,21 +108,19 @@ void setup()
|
|||
sendStopBytes();
|
||||
// ------------ End Display Pre Initialization Routine ------------
|
||||
|
||||
|
||||
// Give flow of control to OS and scheduler
|
||||
espmega.begin();
|
||||
|
||||
|
||||
// // ------------ Factory Reset Routine ------------
|
||||
// Disable factory reset for now
|
||||
espmega.inputs.loop();
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
||||
// if (clear_fram)
|
||||
// {
|
||||
// Serial.print("boot_state.txt=\"Factory Resetting . . .\"");
|
||||
|
|
@ -134,7 +133,6 @@ void setup()
|
|||
// }
|
||||
// // ------------ End Factory Reset Routine ------------
|
||||
|
||||
|
||||
// ------------ IoT Module Initialization Routine ------------
|
||||
Serial.print("boot_state.txt=\"IoT Initializing . . .\"");
|
||||
sendStopBytes();
|
||||
|
|
@ -175,16 +173,14 @@ void setup()
|
|||
espmega.display->bindClimateCard(&climateCard_daikin);
|
||||
|
||||
// Current Transformers
|
||||
#ifdef ANALOG_ENABLE
|
||||
espmega.installCard(4, &analogCard);
|
||||
|
||||
espmega.installCard(5, &ct1);
|
||||
ct1.bindFRAM(&espmega.fram, 6000);
|
||||
espmega.iot->registerCard(5);
|
||||
|
||||
espmega.installCard(6, &ct2);
|
||||
ct2.bindFRAM(&espmega.fram, 6100);
|
||||
espmega.iot->registerCard(6);
|
||||
|
||||
espmega.installCard(7, &ct3);
|
||||
ct3.bindFRAM(&espmega.fram, 6200);
|
||||
espmega.iot->registerCard(7);
|
||||
|
|
@ -197,14 +193,7 @@ void setup()
|
|||
espmega.installCard(10, &ct6);
|
||||
ct6.bindFRAM(&espmega.fram, 6500);
|
||||
espmega.iot->registerCard(10);
|
||||
|
||||
// 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);
|
||||
|
||||
#endif
|
||||
|
||||
// ------------ Climate Cards Initialization Routine ------------
|
||||
ESP_LOGD("ISE OS", "Setting up climate cards");
|
||||
|
|
@ -220,13 +209,14 @@ void setup()
|
|||
|
||||
// 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.loadStateFromFRAM();
|
||||
climateCard_york.setFRAMAutoSave(true);
|
||||
// ------------ End Climate Cards Initialization Routine ------------
|
||||
|
||||
// ------------ Current Transformer Cards Initialization Routine ------------
|
||||
#ifdef ANALOG_ENABLE
|
||||
ESP_LOGD("ISE OS", "Installing current transformer cards");
|
||||
// First try to install the analog card
|
||||
analogCardAvailable = espmega.installCard(4, &analogCard);
|
||||
|
|
@ -260,10 +250,9 @@ void setup()
|
|||
{
|
||||
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 ------------
|
||||
|
||||
|
||||
// ------------ Remote Variables Initialization Routine ------------
|
||||
pm25_out.registerCallback(&pm25outupdatedisplay);
|
||||
pm25_in.registerCallback(&pm25inupdatedisplay);
|
||||
|
|
@ -288,15 +277,13 @@ void setup()
|
|||
pm_fan_speed.enableSetValue("/pm/set_fan_speed");
|
||||
// ------------ End Remote Variables Initialization Routine ------------
|
||||
|
||||
|
||||
// ------------ IoT Card Registration Routine ------------
|
||||
espmega.iot->registerCard(0); // Register the Input Card
|
||||
espmega.iot->registerCard(1); // Register the Output Card
|
||||
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 ------------
|
||||
|
||||
|
||||
// ------------ External Display Initialization Routine ------------
|
||||
auto bindedGetTime = std::bind(&ESPMegaPRO::getTime, &espmega);
|
||||
iseDisplay.begin(&espmega.inputs, &espmega.outputs, &climateCard_daikin, &climateCard_york, &pm_switch, &pm_fan_speed);
|
||||
|
|
@ -346,6 +333,29 @@ void loop()
|
|||
iseDisplay.updateDateTimeText(time);
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -25,9 +25,9 @@ SET_LOOP_TASK_STACK_SIZE(32*1024);
|
|||
#define AIR_CONDITIONER_YORK_IR_PIN 15
|
||||
#define AIR_CONDITIONER_RMT_CHANNEL0 RMT_CHANNEL_0
|
||||
#define AIR_CONDITIONER_RMT_CHANNEL1 RMT_CHANNEL_1
|
||||
|
||||
// CT Configuration
|
||||
#define CT_FORCE_ENABLE false
|
||||
#define ANALOG_ENABLE
|
||||
#define CT_FORCE_ENABLE true
|
||||
#define CT_RMS_VOLTAGE 1.0
|
||||
#define CT_PIN_LIGHT_PHASE1 0
|
||||
#define CT_PIN_LIGHT_PHASE2 1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue