change logging method
This commit is contained in:
parent
b5806498ea
commit
53937dd0ed
|
@ -1,4 +1,4 @@
|
||||||
.pio
|
.pio/
|
||||||
.vscode/.browse.c_cpp.db*
|
.vscode/.browse.c_cpp.db*
|
||||||
.vscode/c_cpp_properties.json
|
.vscode/c_cpp_properties.json
|
||||||
.vscode/launch.json
|
.vscode/launch.json
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include <AnalogCard.hpp>
|
#include <AnalogCard.hpp>
|
||||||
|
#include "esp_log.h"
|
||||||
|
|
||||||
AnalogCard::AnalogCard() : dac0(DAC0_ADDRESS),
|
AnalogCard::AnalogCard() : dac0(DAC0_ADDRESS),
|
||||||
dac1(DAC1_ADDRESS),
|
dac1(DAC1_ADDRESS),
|
||||||
|
@ -12,12 +13,14 @@ AnalogCard::AnalogCard() : dac0(DAC0_ADDRESS),
|
||||||
|
|
||||||
void AnalogCard::dacWrite(uint8_t pin, uint16_t value)
|
void AnalogCard::dacWrite(uint8_t pin, uint16_t value)
|
||||||
{
|
{
|
||||||
|
ESP_LOGV("AnalogCard", "DAC Write: %d, %d", pin, value);
|
||||||
this->setDACState(pin, value > 0);
|
this->setDACState(pin, value > 0);
|
||||||
this->setDACValue(pin, value);
|
this->setDACValue(pin, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AnalogCard::setDACState(uint8_t pin, bool state)
|
void AnalogCard::setDACState(uint8_t pin, bool state)
|
||||||
{
|
{
|
||||||
|
ESP_LOGD("AnalogCard", "Setting DAC state: %d, %d", pin, state);
|
||||||
this->dac_state[pin] = state;
|
this->dac_state[pin] = state;
|
||||||
this->sendDataToDAC(pin, this->dac_value[pin]*state);
|
this->sendDataToDAC(pin, this->dac_value[pin]*state);
|
||||||
for (int i = 0; i < this->dac_change_callbacks.size(); i++)
|
for (int i = 0; i < this->dac_change_callbacks.size(); i++)
|
||||||
|
@ -28,6 +31,7 @@ void AnalogCard::setDACState(uint8_t pin, bool state)
|
||||||
|
|
||||||
void AnalogCard::setDACValue(uint8_t pin, uint16_t value)
|
void AnalogCard::setDACValue(uint8_t pin, uint16_t value)
|
||||||
{
|
{
|
||||||
|
ESP_LOGD("AnalogCard", "Setting DAC value: %d, %d", pin, value);
|
||||||
this->dac_value[pin] = value;
|
this->dac_value[pin] = value;
|
||||||
this->sendDataToDAC(pin, value*this->dac_state[pin]);
|
this->sendDataToDAC(pin, value*this->dac_state[pin]);
|
||||||
for (int i = 0; i < this->dac_change_callbacks.size(); i++)
|
for (int i = 0; i < this->dac_change_callbacks.size(); i++)
|
||||||
|
@ -80,32 +84,32 @@ bool AnalogCard::begin()
|
||||||
{
|
{
|
||||||
if (!this->dac0.begin())
|
if (!this->dac0.begin())
|
||||||
{
|
{
|
||||||
Serial.println("Card Analog ERROR: Failed to install DAC0");
|
ESP_LOGE("AnalogCard", "Card Analog ERROR: Failed to install DAC0");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!this->dac1.begin())
|
if (!this->dac1.begin())
|
||||||
{
|
{
|
||||||
Serial.println("Card Analog ERROR: Failed to install DAC1");
|
ESP_LOGE("AnalogCard", "Card Analog ERROR: Failed to install DAC1");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!this->dac2.begin())
|
if (!this->dac2.begin())
|
||||||
{
|
{
|
||||||
Serial.println("Card Analog ERROR: Failed to install DAC2");
|
ESP_LOGE("AnalogCard", "Card Analog ERROR: Failed to install DAC2");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!this->dac3.begin())
|
if (!this->dac3.begin())
|
||||||
{
|
{
|
||||||
Serial.println("Card Analog ERROR: Failed to install DAC3");
|
ESP_LOGE("AnalogCard", "Card Analog ERROR: Failed to install DAC3");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!this->analogInputBankA.begin())
|
if (!this->analogInputBankA.begin())
|
||||||
{
|
{
|
||||||
Serial.println("Card Analog ERROR: Failed to install analog input bank A");
|
ESP_LOGE("AnalogCard", "Card Analog ERROR: Failed to install analog input bank A");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!this->analogInputBankB.begin())
|
if (!this->analogInputBankB.begin())
|
||||||
{
|
{
|
||||||
Serial.println("Card Analog ERROR: Failed to install analog input bank B");
|
ESP_LOGE("AnalogCard", "Card Analog ERROR: Failed to install analog input bank B");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -34,11 +34,11 @@ bool DigitalInputCard::begin()
|
||||||
this->inputBankA = PCF8574(this->address_a);
|
this->inputBankA = PCF8574(this->address_a);
|
||||||
this->inputBankB = PCF8574(this->address_b);
|
this->inputBankB = PCF8574(this->address_b);
|
||||||
if (!this->inputBankA.begin()) {
|
if (!this->inputBankA.begin()) {
|
||||||
Serial.println("Input Card ERROR: Failed to install input bank A");
|
ESP_LOGE("DigitalInputCard", "Input Card ERROR: Failed to install input bank A");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!this->inputBankB.begin()) {
|
if (!this->inputBankB.begin()) {
|
||||||
Serial.println("Input Card ERROR: Failed to install input bank B");
|
ESP_LOGE("DigitalInputCard", "Input Card ERROR: Failed to install input bank B");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Set the debounce time for all pins to 50ms
|
// Set the debounce time for all pins to 50ms
|
||||||
|
@ -158,9 +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");
|
ESP_LOGD("DigitalInputCard", "Registering callback");
|
||||||
callbacks.push_back(callback);
|
callbacks.push_back(callback);
|
||||||
Serial.println("Pushed back on Input Card Callbacks");
|
ESP_LOGD("DigitalInputCard", "Callback registered");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refresh the input buffer for bank A
|
// Refresh the input buffer for bank A
|
||||||
|
|
|
@ -12,7 +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");
|
ESP_LOGD("DigitalOutputIoT", "Beginning DigitalOutputIoT");
|
||||||
this->mqtt = mqtt;
|
this->mqtt = mqtt;
|
||||||
this->base_topic = base_topic;
|
this->base_topic = base_topic;
|
||||||
this->card = (DigitalOutputCard *) card;
|
this->card = (DigitalOutputCard *) card;
|
||||||
|
@ -25,11 +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");
|
ESP_LOGV("DigitalOutputIoT", "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");
|
ESP_LOGV("DigitalOutputIoT", "DigitalOutputIoT::begin complete");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -125,7 +125,7 @@ void ESPMegaIoT::registerCard(uint8_t card_id)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Serial.println("Unsupported card type");
|
ESP_LOGE("ESPMegaIoT", "Registering card %d failed: Unknown card", card_id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -214,10 +214,11 @@ bool ESPMegaIoT::connectToMqtt(char *client_id, char *mqtt_server, uint16_t mqtt
|
||||||
components[i]->publishReport();
|
components[i]->publishReport();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ESP_LOGI("ESPMegaIoT", "MQTT Connected");
|
||||||
mqtt_connected = true;
|
mqtt_connected = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Serial.println("Failed to connect to mqtt");
|
ESP_LOGW("ESPMegaIoT", "MQTT Connection failed: %d", mqtt.state());
|
||||||
mqtt_connected = false;
|
mqtt_connected = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,8 @@ bool ESPMegaPRO::begin() {
|
||||||
outputs.bindFRAM(&fram,0);
|
outputs.bindFRAM(&fram,0);
|
||||||
outputs.loadFromFRAM();
|
outputs.loadFromFRAM();
|
||||||
if(!this->installCard(0, &inputs)) {
|
if(!this->installCard(0, &inputs)) {
|
||||||
Serial.println("Failed to initialize inputs");
|
ESP_LOGE("ESPMegaPRO", "Failed to initialize inputs");
|
||||||
Serial.println("Is this an ESPMegaPRO device?");
|
ESP_LOGE("ESPMegaPRO", "Is this an ESPMegaPRO device?");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
uint8_t pinMap[16] = {0, 1, 2, 3, 4, 5, 6, 7, 15, 14, 13, 12, 11, 10, 9, 8};
|
uint8_t pinMap[16] = {0, 1, 2, 3, 4, 5, 6, 7, 15, 14, 13, 12, 11, 10, 9, 8};
|
||||||
|
@ -31,12 +31,11 @@ void ESPMegaPRO::loop() {
|
||||||
bool ESPMegaPRO::installCard(uint8_t slot, ExpansionCard* card) {
|
bool ESPMegaPRO::installCard(uint8_t slot, ExpansionCard* card) {
|
||||||
if (slot > 255) return false;
|
if (slot > 255) return false;
|
||||||
if (cardInstalled[slot]) {
|
if (cardInstalled[slot]) {
|
||||||
Serial.println("Card already installed");
|
ESP_LOGE("ESPMegaPRO", "Card already installed at slot %d", slot);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!card->begin()) {
|
if (!card->begin()) {
|
||||||
Serial.print("Failed to install card at slot ");
|
ESP_LOGE("ESPMegaPRO", "Failed to initialize card at slot %d", slot);
|
||||||
Serial.println(slot);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
cards[slot] = card;
|
cards[slot] = card;
|
||||||
|
@ -103,18 +102,18 @@ ExpansionCard* ESPMegaPRO::getCard(uint8_t slot) {
|
||||||
void ESPMegaPRO::enableInternalDisplay(HardwareSerial *serial) {
|
void ESPMegaPRO::enableInternalDisplay(HardwareSerial *serial) {
|
||||||
if (internalDisplayEnabled) return;
|
if (internalDisplayEnabled) return;
|
||||||
if (!iotEnabled) {
|
if (!iotEnabled) {
|
||||||
Serial.println("Cannot Enable Internal Display without IoT Module being enabled!");
|
ESP_LOGE("ESPMegaPRO", "Cannot enable internal display without IoT module enabled");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Serial.println("Insantiating Internal Display");
|
ESP_LOGD("ESPMegaPRO", "Enabling Internal Display");
|
||||||
display = new InternalDisplay(serial);
|
display = new InternalDisplay(serial);
|
||||||
Serial.println("Binding Internal Display to IoT Module");
|
ESP_LOGD("ESPMegaPRO", "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");
|
ESP_LOGD("ESPMegaPRO", "Binding Internal Display to Input/Output Cards");
|
||||||
display->bindInputCard(&inputs);
|
display->bindInputCard(&inputs);
|
||||||
display->bindOutputCard(&outputs);
|
display->bindOutputCard(&outputs);
|
||||||
display->begin(this->iot,bindedGetTime);
|
display->begin(this->iot,bindedGetTime);
|
||||||
internalDisplayEnabled = true;
|
internalDisplayEnabled = true;
|
||||||
Serial.println("Internal Display Enabled");
|
ESP_LOGD("ESPMegaPRO", "Internal Display Enabled");
|
||||||
|
|
||||||
}
|
}
|
|
@ -2,37 +2,38 @@
|
||||||
|
|
||||||
|
|
||||||
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");
|
ESP_LOGD("InternalDisplay", "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");
|
ESP_LOGD("InternalDisplay", "Acquiring 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
|
||||||
Serial.println("Registering Callbacks");
|
ESP_LOGD("InternalDisplay", "Registering Callbacks");
|
||||||
Serial.println("Binding Page Change Callback");
|
ESP_LOGD("InternalDisplay", "Binding Page Change Callback");
|
||||||
auto bindedInputStateChangeCallback = std::bind(&InternalDisplay::handleInputStateChange, this, std::placeholders::_1, std::placeholders::_2);
|
auto bindedInputStateChangeCallback = std::bind(&InternalDisplay::handleInputStateChange, this, std::placeholders::_1, std::placeholders::_2);
|
||||||
Serial.println("Binding Input State Change Callback");
|
ESP_LOGD("InternalDisplay", "Binding Input State Change Callback");
|
||||||
auto bindedPwmStateChangeCallback = std::bind(&InternalDisplay::handlePwmStateChange, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
|
auto bindedPwmStateChangeCallback = std::bind(&InternalDisplay::handlePwmStateChange, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
|
||||||
Serial.println("Registering inputCard Callbacks");
|
ESP_LOGD("InternalDisplay", "Registering inputCard Callbacks");
|
||||||
this->inputCard->registerCallback(bindedInputStateChangeCallback);
|
this->inputCard->registerCallback(bindedInputStateChangeCallback);
|
||||||
Serial.println("Registering outputCard Callbacks");
|
ESP_LOGD("InternalDisplay", "Registering outputCard Callbacks");
|
||||||
this->outputCard->registerChangeCallback(bindedPwmStateChangeCallback);
|
this->outputCard->registerChangeCallback(bindedPwmStateChangeCallback);
|
||||||
// Initialize the display
|
// Initialize the display
|
||||||
Serial.println("Initializing DisplayAdapter");
|
ESP_LOGD("InternalDisplay", "Initializing DisplayAdapter");
|
||||||
this->displayAdapter->begin(115200);
|
this->displayAdapter->begin(115200);
|
||||||
Serial.println("Setting DisplayAdapter Timeout");
|
ESP_LOGD("InternalDisplay", "Setting DisplayAdapter Timeout");
|
||||||
this->displayAdapter->setTimeout(100);
|
this->displayAdapter->setTimeout(100);
|
||||||
Serial.println("Flushing DisplayAdapter");
|
ESP_LOGD("InternalDisplay", "Flushing DisplayAdapter");
|
||||||
this->displayAdapter->flush();
|
this->displayAdapter->flush();
|
||||||
Serial.println("Resetting Display");
|
ESP_LOGD("InternalDisplay", "Resetting Display");
|
||||||
this->reset();
|
this->reset();
|
||||||
delay(500);
|
delay(500);
|
||||||
Serial.println("Jumping to Page 1");
|
ESP_LOGD("InternalDisplay", "Jumping to Page 1");
|
||||||
this->jumpToPage(1);
|
this->jumpToPage(1);
|
||||||
Serial.println("Display Initialization Complete");
|
ESP_LOGD("InternalDisplay", "Display Initialization Complete");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void InternalDisplay::loop() {
|
void InternalDisplay::loop() {
|
||||||
// Keep reading the Serial Adapter
|
// Keep reading the Serial Adapter
|
||||||
this->recieveSerialCommand();
|
this->recieveSerialCommand();
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
#include <ETH.h>
|
#include <ETH.h>
|
||||||
#include <ClimateCard.hpp>
|
#include <ClimateCard.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Demo PLC firmware using the ESPMegaPRO OOP library
|
// Demo PLC firmware using the ESPMegaPRO OOP library
|
||||||
|
|
||||||
ESPMegaPRO espmega = ESPMegaPRO();
|
ESPMegaPRO espmega = ESPMegaPRO();
|
||||||
|
@ -15,6 +17,18 @@ void input_change_callback(uint8_t pin, uint8_t value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
// Set each class's log level
|
||||||
|
esp_log_level_set("ESPMegaPRO", ESP_LOG_VERBOSE);
|
||||||
|
esp_log_level_set("DigitalOutputCard", ESP_LOG_VERBOSE);
|
||||||
|
esp_log_level_set("DigitalOutputIoT", ESP_LOG_VERBOSE);
|
||||||
|
esp_log_level_set("DigitalInputCard", ESP_LOG_VERBOSE);
|
||||||
|
esp_log_level_set("DigitalInputIoT", ESP_LOG_VERBOSE);
|
||||||
|
esp_log_level_set("AnalogCard", ESP_LOG_VERBOSE);
|
||||||
|
esp_log_level_set("AnalogIoT", ESP_LOG_VERBOSE);
|
||||||
|
esp_log_level_set("ClimateCard", ESP_LOG_VERBOSE);
|
||||||
|
esp_log_level_set("ClimateIoT", ESP_LOG_VERBOSE);
|
||||||
|
esp_log_level_set("InternalDisplay", ESP_LOG_VERBOSE);
|
||||||
|
esp_log_level_set("InternalDisplayIoT", ESP_LOG_VERBOSE);
|
||||||
espmega.begin();
|
espmega.begin();
|
||||||
espmega.enableIotModule();
|
espmega.enableIotModule();
|
||||||
ETH.begin();
|
ETH.begin();
|
||||||
|
|
Loading…
Reference in New Issue