running demo
This commit is contained in:
parent
c224aba193
commit
b5806498ea
|
@ -5,7 +5,8 @@ AnalogCard::AnalogCard() : dac0(DAC0_ADDRESS),
|
|||
dac2(DAC2_ADDRESS),
|
||||
dac3(DAC3_ADDRESS),
|
||||
analogInputBankA(),
|
||||
analogInputBankB()
|
||||
analogInputBankB(),
|
||||
dac_change_callbacks()
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include <AnalogIoT.hpp>
|
||||
|
||||
AnalogIoT::AnalogIoT() {
|
||||
AnalogIoT::AnalogIoT() : adc_conversion_callbacks() {
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
adc_publish_enabled[i] = false;
|
||||
adc_conversion_interval[i] = 1000;
|
||||
|
|
|
@ -19,6 +19,9 @@ ClimateCard::ClimateCard(uint8_t ir_pin)
|
|||
this->state.ac_temperature = 25;
|
||||
this->state.ac_mode = 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
|
||||
gpio_num_t gpio_num = gpio_num_t(ir_pin);
|
||||
rmt_config_t rmt_tx = RMT_DEFAULT_CONFIG_TX(gpio_num, RMT_TX_CHANNEL);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include <DigitalInputCard.hpp>
|
||||
|
||||
// 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_b = address_b;
|
||||
|
@ -158,7 +158,9 @@ uint8_t DigitalInputCard::getInputBufferB()
|
|||
// Register a callback function to be called when a pin changes
|
||||
void DigitalInputCard::registerCallback(std::function<void(uint8_t, bool)> callback)
|
||||
{
|
||||
Serial.println("Pushing back on Input Card Callbacks");
|
||||
callbacks.push_back(callback);
|
||||
Serial.println("Pushed back on Input Card Callbacks");
|
||||
}
|
||||
|
||||
// Refresh the input buffer for bank A
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include <DigitalOutputCard.hpp>
|
||||
|
||||
DigitalOutputCard::DigitalOutputCard(uint8_t address) {
|
||||
DigitalOutputCard::DigitalOutputCard(uint8_t address) : change_callbacks(){
|
||||
this->address = address;
|
||||
// load default pin map
|
||||
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) {
|
||||
Serial.println("DigitalOutputIoT::begin");
|
||||
this->mqtt = mqtt;
|
||||
this->base_topic = base_topic;
|
||||
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);
|
||||
strcpy(this->state_report_topic, "00/state");
|
||||
strcpy(this->value_report_topic, "00/value");
|
||||
Serial.println("Registering callbacks inside DigitalOutputIoT::begin");
|
||||
// Register callbacks
|
||||
auto bindedCallback = std::bind(&DigitalOutputIoT::handleValueChange, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
|
||||
this->card->registerChangeCallback(bindedCallback);
|
||||
Serial.println("DigitalOutputIoT::begin complete");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -106,9 +106,15 @@ void ESPMegaPRO::enableInternalDisplay(HardwareSerial *serial) {
|
|||
Serial.println("Cannot Enable Internal Display without IoT Module being enabled!");
|
||||
return;
|
||||
}
|
||||
Serial.println("Insantiating Internal Display");
|
||||
display = new InternalDisplay(serial);
|
||||
Serial.println("Binding Internal Display to IoT Module");
|
||||
auto bindedGetTime = std::bind(&ESPMegaPRO::getTime, this);
|
||||
Serial.println("Initializing Internal Display");
|
||||
display->bindInputCard(&inputs);
|
||||
display->bindOutputCard(&outputs);
|
||||
display->begin(this->iot,bindedGetTime);
|
||||
internalDisplayEnabled = true;
|
||||
Serial.println("Internal Display Enabled");
|
||||
|
||||
}
|
|
@ -2,13 +2,35 @@
|
|||
|
||||
|
||||
void InternalDisplay::begin(ESPMegaIoT *iot, std::function<rtctime_t()> getRtcTime) {
|
||||
Serial.println("Assigning IoT Module and RTC Time Getter");
|
||||
this->iot = iot;
|
||||
this->getRtcTime = getRtcTime;
|
||||
Serial.println("Aqquring Network and MQTT Configs");
|
||||
this->mqttConfig = this->iot->getMqttConfig();
|
||||
this->networkConfig = this->iot->getNetworkConfig();
|
||||
// Register callbacks
|
||||
this->inputCard->registerCallback(std::bind(&InternalDisplay::handleInputStateChange, this, std::placeholders::_1, std::placeholders::_2));
|
||||
this->outputCard->registerChangeCallback(std::bind(&InternalDisplay::handlePwmStateChange, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
|
||||
Serial.println("Registering Callbacks");
|
||||
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() {
|
||||
|
@ -177,4 +199,12 @@ void InternalDisplay::setInputMarker(uint8_t pin, bool state) {
|
|||
|
||||
InternalDisplay::InternalDisplay(HardwareSerial *displayAdapter) : ESPMegaDisplay(displayAdapter) {
|
||||
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:
|
||||
DigitalInputCard *inputCard;
|
||||
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 handlePwmStateChange(uint8_t pin, bool state, uint16_t value);
|
||||
void handlePageChange(uint8_t page);
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
#include <ETH.h>
|
||||
#include <ClimateCard.hpp>
|
||||
|
||||
// Demo PLC firmware using the ESPMegaPRO OOP library
|
||||
|
||||
ESPMegaPRO espmega = ESPMegaPRO();
|
||||
|
||||
void input_change_callback(uint8_t pin, uint8_t value) {
|
||||
|
@ -46,12 +48,15 @@ void setup() {
|
|||
espmega.iot->setMqttConfig(mqtt_config);
|
||||
Serial.println("Connecting to MQTT");
|
||||
espmega.iot->connectToMqtt();
|
||||
Serial.println("Registering cards");
|
||||
Serial.println("Registering Output Card");
|
||||
espmega.iot->registerCard(0);
|
||||
Serial.println("Registering Input Card");
|
||||
espmega.iot->registerCard(1);
|
||||
Serial.println("Initialization Routine Complete");
|
||||
Serial.println("Registering Input Change Callback");
|
||||
espmega.inputs.registerCallback(input_change_callback);
|
||||
Serial.println("Enabling Internal Display");
|
||||
espmega.enableInternalDisplay(&Serial);
|
||||
Serial.println("Initialization Routine Complete");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
|
Loading…
Reference in New Issue