running demo
This commit is contained in:
parent
c224aba193
commit
b5806498ea
|
@ -5,7 +5,8 @@ AnalogCard::AnalogCard() : dac0(DAC0_ADDRESS),
|
||||||
dac2(DAC2_ADDRESS),
|
dac2(DAC2_ADDRESS),
|
||||||
dac3(DAC3_ADDRESS),
|
dac3(DAC3_ADDRESS),
|
||||||
analogInputBankA(),
|
analogInputBankA(),
|
||||||
analogInputBankB()
|
analogInputBankB(),
|
||||||
|
dac_change_callbacks()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include <AnalogIoT.hpp>
|
#include <AnalogIoT.hpp>
|
||||||
|
|
||||||
AnalogIoT::AnalogIoT() {
|
AnalogIoT::AnalogIoT() : adc_conversion_callbacks() {
|
||||||
for (uint8_t i = 0; i < 8; i++) {
|
for (uint8_t i = 0; i < 8; i++) {
|
||||||
adc_publish_enabled[i] = false;
|
adc_publish_enabled[i] = false;
|
||||||
adc_conversion_interval[i] = 1000;
|
adc_conversion_interval[i] = 1000;
|
||||||
|
|
|
@ -19,6 +19,9 @@ ClimateCard::ClimateCard(uint8_t ir_pin)
|
||||||
this->state.ac_temperature = 25;
|
this->state.ac_temperature = 25;
|
||||||
this->state.ac_mode = 0;
|
this->state.ac_mode = 0;
|
||||||
this->state.ac_fan_speed = 0;
|
this->state.ac_fan_speed = 0;
|
||||||
|
// Initialize callbacks
|
||||||
|
this->callbacks = std::vector<std::function<void(uint8_t, uint8_t, uint8_t)>>();
|
||||||
|
this->sensor_callbacks = std::vector<std::function<void(float, float)>>();
|
||||||
// Initialize RMT
|
// Initialize RMT
|
||||||
gpio_num_t gpio_num = gpio_num_t(ir_pin);
|
gpio_num_t gpio_num = gpio_num_t(ir_pin);
|
||||||
rmt_config_t rmt_tx = RMT_DEFAULT_CONFIG_TX(gpio_num, RMT_TX_CHANNEL);
|
rmt_config_t rmt_tx = RMT_DEFAULT_CONFIG_TX(gpio_num, RMT_TX_CHANNEL);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include <DigitalInputCard.hpp>
|
#include <DigitalInputCard.hpp>
|
||||||
|
|
||||||
// Instantiate the card with the specified address
|
// Instantiate the card with the specified address
|
||||||
DigitalInputCard::DigitalInputCard(uint8_t address_a, uint8_t address_b)
|
DigitalInputCard::DigitalInputCard(uint8_t address_a, uint8_t address_b) : callbacks()
|
||||||
{
|
{
|
||||||
this->address_a = address_a;
|
this->address_a = address_a;
|
||||||
this->address_b = address_b;
|
this->address_b = address_b;
|
||||||
|
@ -158,7 +158,9 @@ uint8_t DigitalInputCard::getInputBufferB()
|
||||||
// Register a callback function to be called when a pin changes
|
// Register a callback function to be called when a pin changes
|
||||||
void DigitalInputCard::registerCallback(std::function<void(uint8_t, bool)> callback)
|
void DigitalInputCard::registerCallback(std::function<void(uint8_t, bool)> callback)
|
||||||
{
|
{
|
||||||
|
Serial.println("Pushing back on Input Card Callbacks");
|
||||||
callbacks.push_back(callback);
|
callbacks.push_back(callback);
|
||||||
|
Serial.println("Pushed back on Input Card Callbacks");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refresh the input buffer for bank A
|
// Refresh the input buffer for bank A
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include <DigitalOutputCard.hpp>
|
#include <DigitalOutputCard.hpp>
|
||||||
|
|
||||||
DigitalOutputCard::DigitalOutputCard(uint8_t address) {
|
DigitalOutputCard::DigitalOutputCard(uint8_t address) : change_callbacks(){
|
||||||
this->address = address;
|
this->address = address;
|
||||||
// load default pin map
|
// load default pin map
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
|
|
|
@ -12,6 +12,7 @@ DigitalOutputIoT::~DigitalOutputIoT() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DigitalOutputIoT::begin(uint8_t card_id, ExpansionCard *card, PubSubClient *mqtt, char *base_topic) {
|
bool DigitalOutputIoT::begin(uint8_t card_id, ExpansionCard *card, PubSubClient *mqtt, char *base_topic) {
|
||||||
|
Serial.println("DigitalOutputIoT::begin");
|
||||||
this->mqtt = mqtt;
|
this->mqtt = mqtt;
|
||||||
this->base_topic = base_topic;
|
this->base_topic = base_topic;
|
||||||
this->card = (DigitalOutputCard *) card;
|
this->card = (DigitalOutputCard *) card;
|
||||||
|
@ -24,9 +25,11 @@ bool DigitalOutputIoT::begin(uint8_t card_id, ExpansionCard *card, PubSubClient
|
||||||
this->publish_enable_length = strlen(PUBLISH_ENABLE_TOPIC);
|
this->publish_enable_length = strlen(PUBLISH_ENABLE_TOPIC);
|
||||||
strcpy(this->state_report_topic, "00/state");
|
strcpy(this->state_report_topic, "00/state");
|
||||||
strcpy(this->value_report_topic, "00/value");
|
strcpy(this->value_report_topic, "00/value");
|
||||||
|
Serial.println("Registering callbacks inside DigitalOutputIoT::begin");
|
||||||
// Register callbacks
|
// Register callbacks
|
||||||
auto bindedCallback = std::bind(&DigitalOutputIoT::handleValueChange, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
|
auto bindedCallback = std::bind(&DigitalOutputIoT::handleValueChange, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
|
||||||
this->card->registerChangeCallback(bindedCallback);
|
this->card->registerChangeCallback(bindedCallback);
|
||||||
|
Serial.println("DigitalOutputIoT::begin complete");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -106,9 +106,15 @@ void ESPMegaPRO::enableInternalDisplay(HardwareSerial *serial) {
|
||||||
Serial.println("Cannot Enable Internal Display without IoT Module being enabled!");
|
Serial.println("Cannot Enable Internal Display without IoT Module being enabled!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Serial.println("Insantiating Internal Display");
|
||||||
display = new InternalDisplay(serial);
|
display = new InternalDisplay(serial);
|
||||||
|
Serial.println("Binding Internal Display to IoT Module");
|
||||||
auto bindedGetTime = std::bind(&ESPMegaPRO::getTime, this);
|
auto bindedGetTime = std::bind(&ESPMegaPRO::getTime, this);
|
||||||
|
Serial.println("Initializing Internal Display");
|
||||||
|
display->bindInputCard(&inputs);
|
||||||
|
display->bindOutputCard(&outputs);
|
||||||
display->begin(this->iot,bindedGetTime);
|
display->begin(this->iot,bindedGetTime);
|
||||||
internalDisplayEnabled = true;
|
internalDisplayEnabled = true;
|
||||||
|
Serial.println("Internal Display Enabled");
|
||||||
|
|
||||||
}
|
}
|
|
@ -2,13 +2,35 @@
|
||||||
|
|
||||||
|
|
||||||
void InternalDisplay::begin(ESPMegaIoT *iot, std::function<rtctime_t()> getRtcTime) {
|
void InternalDisplay::begin(ESPMegaIoT *iot, std::function<rtctime_t()> getRtcTime) {
|
||||||
|
Serial.println("Assigning IoT Module and RTC Time Getter");
|
||||||
this->iot = iot;
|
this->iot = iot;
|
||||||
this->getRtcTime = getRtcTime;
|
this->getRtcTime = getRtcTime;
|
||||||
|
Serial.println("Aqquring Network and MQTT Configs");
|
||||||
this->mqttConfig = this->iot->getMqttConfig();
|
this->mqttConfig = this->iot->getMqttConfig();
|
||||||
this->networkConfig = this->iot->getNetworkConfig();
|
this->networkConfig = this->iot->getNetworkConfig();
|
||||||
// Register callbacks
|
// Register callbacks
|
||||||
this->inputCard->registerCallback(std::bind(&InternalDisplay::handleInputStateChange, this, std::placeholders::_1, std::placeholders::_2));
|
Serial.println("Registering Callbacks");
|
||||||
this->outputCard->registerChangeCallback(std::bind(&InternalDisplay::handlePwmStateChange, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
|
Serial.println("Binding Page Change Callback");
|
||||||
|
auto bindedInputStateChangeCallback = std::bind(&InternalDisplay::handleInputStateChange, this, std::placeholders::_1, std::placeholders::_2);
|
||||||
|
Serial.println("Binding Input State Change Callback");
|
||||||
|
auto bindedPwmStateChangeCallback = std::bind(&InternalDisplay::handlePwmStateChange, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
|
||||||
|
Serial.println("Registering inputCard Callbacks");
|
||||||
|
this->inputCard->registerCallback(bindedInputStateChangeCallback);
|
||||||
|
Serial.println("Registering outputCard Callbacks");
|
||||||
|
this->outputCard->registerChangeCallback(bindedPwmStateChangeCallback);
|
||||||
|
// Initialize the display
|
||||||
|
Serial.println("Initializing DisplayAdapter");
|
||||||
|
this->displayAdapter->begin(115200);
|
||||||
|
Serial.println("Setting DisplayAdapter Timeout");
|
||||||
|
this->displayAdapter->setTimeout(100);
|
||||||
|
Serial.println("Flushing DisplayAdapter");
|
||||||
|
this->displayAdapter->flush();
|
||||||
|
Serial.println("Resetting Display");
|
||||||
|
this->reset();
|
||||||
|
delay(500);
|
||||||
|
Serial.println("Jumping to Page 1");
|
||||||
|
this->jumpToPage(1);
|
||||||
|
Serial.println("Display Initialization Complete");
|
||||||
}
|
}
|
||||||
|
|
||||||
void InternalDisplay::loop() {
|
void InternalDisplay::loop() {
|
||||||
|
@ -177,4 +199,12 @@ void InternalDisplay::setInputMarker(uint8_t pin, bool state) {
|
||||||
|
|
||||||
InternalDisplay::InternalDisplay(HardwareSerial *displayAdapter) : ESPMegaDisplay(displayAdapter) {
|
InternalDisplay::InternalDisplay(HardwareSerial *displayAdapter) : ESPMegaDisplay(displayAdapter) {
|
||||||
this->currentPage = INTERNAL_DISPLAY_DASHBOARD_PAGE;
|
this->currentPage = INTERNAL_DISPLAY_DASHBOARD_PAGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void InternalDisplay::bindInputCard(DigitalInputCard *inputCard) {
|
||||||
|
this->inputCard = inputCard;
|
||||||
|
}
|
||||||
|
|
||||||
|
void InternalDisplay::bindOutputCard(DigitalOutputCard *outputCard) {
|
||||||
|
this->outputCard = outputCard;
|
||||||
}
|
}
|
|
@ -38,9 +38,6 @@ class InternalDisplay : public ESPMegaDisplay {
|
||||||
private:
|
private:
|
||||||
DigitalInputCard *inputCard;
|
DigitalInputCard *inputCard;
|
||||||
DigitalOutputCard *outputCard;
|
DigitalOutputCard *outputCard;
|
||||||
// Previously registered callbacks of input and output cards
|
|
||||||
// We need to call them when the respective card is binded to the display
|
|
||||||
// Because we will replace the callbacks with the display's own callbacks
|
|
||||||
void handleInputStateChange(uint8_t pin, bool state);
|
void handleInputStateChange(uint8_t pin, bool state);
|
||||||
void handlePwmStateChange(uint8_t pin, bool state, uint16_t value);
|
void handlePwmStateChange(uint8_t pin, bool state, uint16_t value);
|
||||||
void handlePageChange(uint8_t page);
|
void handlePageChange(uint8_t page);
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
#include <ETH.h>
|
#include <ETH.h>
|
||||||
#include <ClimateCard.hpp>
|
#include <ClimateCard.hpp>
|
||||||
|
|
||||||
|
// Demo PLC firmware using the ESPMegaPRO OOP library
|
||||||
|
|
||||||
ESPMegaPRO espmega = ESPMegaPRO();
|
ESPMegaPRO espmega = ESPMegaPRO();
|
||||||
|
|
||||||
void input_change_callback(uint8_t pin, uint8_t value) {
|
void input_change_callback(uint8_t pin, uint8_t value) {
|
||||||
|
@ -46,12 +48,15 @@ void setup() {
|
||||||
espmega.iot->setMqttConfig(mqtt_config);
|
espmega.iot->setMqttConfig(mqtt_config);
|
||||||
Serial.println("Connecting to MQTT");
|
Serial.println("Connecting to MQTT");
|
||||||
espmega.iot->connectToMqtt();
|
espmega.iot->connectToMqtt();
|
||||||
Serial.println("Registering cards");
|
Serial.println("Registering Output Card");
|
||||||
espmega.iot->registerCard(0);
|
espmega.iot->registerCard(0);
|
||||||
|
Serial.println("Registering Input Card");
|
||||||
espmega.iot->registerCard(1);
|
espmega.iot->registerCard(1);
|
||||||
Serial.println("Initialization Routine Complete");
|
Serial.println("Registering Input Change Callback");
|
||||||
espmega.inputs.registerCallback(input_change_callback);
|
espmega.inputs.registerCallback(input_change_callback);
|
||||||
|
Serial.println("Enabling Internal Display");
|
||||||
espmega.enableInternalDisplay(&Serial);
|
espmega.enableInternalDisplay(&Serial);
|
||||||
|
Serial.println("Initialization Routine Complete");
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|
Loading…
Reference in New Issue