diff --git a/.gitignore b/.gitignore
index 4538236..9bea433 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,2 @@
-.DS_Store
\ No newline at end of file
+.DS_Store
diff --git a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/CLAUDE.md b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/CLAUDE.md
deleted file mode 100644
index 83bcc8c..0000000
--- a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/CLAUDE.md
+++ /dev/null
@@ -1,183 +0,0 @@
-# CLAUDE.md
-
-This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
-
-## Project Overview
-
-This is the ESPMegaPRO library - a comprehensive Arduino/PlatformIO library for the ESPMegaPRO industrial automation board. The library provides both procedural (legacy) and object-oriented interfaces for interfacing with the ESP32-based ESPMegaPRO hardware platform.
-
-## Architecture
-
-### Core Components
-
-**ESPMegaPRO.h**: Legacy procedural interface for basic board functions (digital I/O, analog I/O, RTC, PWM)
-
-**ESPMegaProOS.hpp**: Modern OOP interface - main class that manages the entire system including:
-- Built-in Digital Input Card (slot 0)
-- Built-in Digital Output Card (slot 1)
-- Expansion card management (255 slots)
-- IoT module integration
-- Internal display management
-- Web server functionality
-- Recovery mode
-
-### Expansion Card System
-
-The library uses a modular expansion card architecture:
-
-**ExpansionCard.hpp**: Base abstract class for all expansion cards
-- All cards inherit from this class
-- Defines standard interface: `begin()`, `loop()`, `getType()`
-
-**Available Card Types**:
-- `DigitalInputCard`: 16-channel digital input with debouncing and callbacks
-- `DigitalOutputCard`: 16-channel PWM/digital output with FRAM persistence
-- `AnalogCard`: 8-channel ADC input + 4-channel DAC output (MCP4725)
-- `ClimateCard`: IR-controlled AC + DHT/DS18B20 sensors
-- `CurrentTransformerCard`: AC current monitoring
-
-### Protocol Support
-- **RTU Classes**: ModbusTCP/RTU support for industrial protocols
-- **IR Communication**: Climate card supports IR AC control
-- **Web Interface**: AsyncWebServer for configuration
-- **OTA Updates**: Built-in firmware update capability
-
-### IoT Integration
-
-**IoTComponent.hpp**: Base class for MQTT-enabled card interfaces
-- Provides MQTT publish/subscribe helpers
-- Each expansion card can have a corresponding IoT component
-- Pattern: `{CardName}IoT` classes (e.g., `DigitalInputIoT`, `AnalogIoT`)
-
-**ESPMegaIoT**: Main IoT management class handling WiFi and MQTT connectivity
-
-### Display & Interface
-
-**InternalDisplay**: Nextion display interface for boards with built-in displays
-**ESPMegaWebServer**: HTTP server for web-based configuration
-**ESPMegaRecovery**: Bootloop recovery system
-**SmartVariable/RemoteVariable**: MQTT-enabled configuration variables
-
-## File Naming Conventions
-- Card classes: `{Name}Card.hpp/.cpp`
-- IoT components: `{Name}IoT.hpp/.cpp`
-- RTU components: `{Name}RTU.hpp/.cpp`
-- Display classes: `ESPMegaDisplay`, `InternalDisplay`
-- Utility classes: `SmartVariable`, `RemoteVariable`
-
-## Development Workflow
-
-### File Structure
-- `*.hpp`: Header files with class definitions
-- `*.cpp`: Implementation files
-- `html/`: Web interface templates
-- `*_html.h`: Compiled HTML resources
-
-### Key Constants
-- I2C addresses defined in headers (0x21, 0x22, 0x5F, etc.)
-- Card type constants (CARD_TYPE_DIGITAL_INPUT = 0x01, etc.)
-- Hardware pin mappings and interrupt pins
-- Default debounce time: 50ms for digital inputs
-- PWM range: 0-4095 (12-bit)
-- FRAM addresses: 0-1000 reserved for internal use
-
-### Special Files
-- `ESPMegaCommon.hpp`: Shared constants and typedefs
-- `TimeStructure.hpp`: Time-related structures
-- `html/*.html`: Web interface templates
-- `*_html.h`: Compiled HTML as C arrays
-- `all_html.h`: Combined HTML resources
-
-### Memory Management
-- Uses FRAM (0x56) for persistent storage
-- Built-in RTC (0x68) for timekeeping
-- NTP synchronization support
-
-## Development Guidelines
-
-### Adding New Cards
-1. Inherit from `ExpansionCard`
-2. Implement required virtual methods
-3. Define unique card type constant
-4. Create corresponding `IoTComponent` if MQTT support needed
-
-### Working with I2C
-- Multiple I2C devices with fixed addresses
-- Cards typically use PCF8574 GPIO expanders
-- Analog cards use ADS1X15 ADCs and MCP4725 DACs
-- Wire.begin(14, 33) - specific SDA/SCL pins for ESPMegaPRO
-
-### Callback System
-- Digital inputs support callback registration with debouncing
-- Use `std::function` for pin change callbacks
-- Output cards use `std::function` for state/value changes
-- Analog cards use `std::function` for DAC changes
-
-### Card Installation Pattern
-```cpp
-ESPMegaPRO megapro;
-megapro.installCard(slot, &card); // Automatically calls card.begin()
-```
-
-### FRAM Usage Pattern
-```cpp
-card.bindFRAM(&fram, baseAddress);
-card.setAutoSaveToFRAM(true);
-card.loadFromFRAM(); // Restore state on boot
-```
-
-### IoT Component Pattern
-```cpp
-DigitalInputCard card;
-DigitalInputIoT cardIoT;
-cardIoT.begin(cardId, &card, &mqtt, baseTopic);
-```
-
-## Key Implementation Patterns
-
-### Memory Management
-- **FRAM Integration**: Persistent storage using I2C FRAM (address 0x56)
- - Cards can bind to FRAM with `bindFRAM(fram, address)`
- - Auto-save functionality for state persistence
- - Memory layout reservations (0-1000 for ESPMegaPRO internal use)
-
-### Callback Architecture
-- **std::function**: Extensive use of C++ std::function for callbacks
-- **std::map**: Callback storage using maps with handler IDs
-- **Pin Change Detection**: Debounced input handling with configurable timing
-- **Change Notifications**: State change callbacks for outputs/DACs
-
-### Pin Mapping System
-- **Virtual Pin Maps**: Configurable pin mapping between logical and physical pins
-- **Dual Arrays**: `pinMap[16]` (virtual→physical) and `virtualPinMap[16]` (physical→virtual)
-- **Flexible Addressing**: Support both I2C addresses and DIP switch configurations
-
-### Error Handling & Logging
-- **ESP_LOG**: Consistent ESP-IDF logging throughout (LOGD, LOGE, LOGV, LOGI)
-- **Initialization Checking**: Cards track `initOk` status and validate before operations
-- **Graceful Degradation**: Failed card initialization doesn't crash the system
-
-### MQTT/IoT Integration
-- **Topic Structure**: `{base_topic}/{card_id}/{subtopic}` hierarchy
-- **Relative Publishing**: Helper functions for topic construction
-- **State Requests**: Global `/requeststate` and `/requestinfo` endpoints
-- **Component Registration**: Cards register IoT components for MQTT handling
-
-### Thread Safety
-- **Mutex Protection**: Serial communication protected with mutexes
-- **IRAM Functions**: Interrupt handlers marked with `IRAM_ATTR`
-- **Buffer Management**: Circular buffers for serial communication
-
-### Hardware Abstraction
-- **I2C Multiplexing**: Multiple devices on shared I2C bus
-- **PWM Management**: Adafruit PWM driver for outputs with push-pull configuration
-- **ADC/DAC**: Multi-channel analog I/O via dedicated ICs
-- **RTC Integration**: DS1307 RTC with NTP synchronization
-
-### Development Conventions
-- **Doxygen Documentation**: Comprehensive function documentation
-- **Namespace Prefixes**: `ESPMega_` for procedural, class names for OOP
-- **Header Guards**: `#pragma once` used consistently
-- **File Organization**: Separate `.hpp/.cpp` pairs for each major component
-
-This is a pure library with no build system - it's designed to be included in Arduino/PlatformIO projects as a dependency.
\ No newline at end of file
diff --git a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/CurrentTransformerCard.cpp b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/CurrentTransformerCard.cpp
index d9f230c..f5ce161 100644
--- a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/CurrentTransformerCard.cpp
+++ b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/CurrentTransformerCard.cpp
@@ -84,9 +84,6 @@ void CurrentTransformerCard::saveEnergy(){
}
void CurrentTransformerCard::loadEnergy(){
this->fram->read(this->framAddress, (uint8_t*)&this->energy, sizeof(this->energy));
- if (this->energy < 0 || isnan(this->energy)) {
- this->energy = 0;
- }
}
void CurrentTransformerCard::setEnergyAutoSave(bool autoSave){
diff --git a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/DigitalInputCard.cpp b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/DigitalInputCard.cpp
index fc9f2cf..86ad5a1 100644
--- a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/DigitalInputCard.cpp
+++ b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/DigitalInputCard.cpp
@@ -3,8 +3,8 @@
/**
* @brief Create a new Digital Input Card object with the specified address
* @note If you are using the ESPMegaI/O board, you should use the dip switch constructor
- *
- * @param address_a The ESPMegaI/O address of bank A
+ *
+ * @param address_a The ESPMegaI/O address of bank A
* @param address_b The ESPMegaI/O address of bank B
*/
DigitalInputCard::DigitalInputCard(uint8_t address_a, uint8_t address_b) : callbacks()
@@ -16,11 +16,11 @@ DigitalInputCard::DigitalInputCard(uint8_t address_a, uint8_t address_b) : callb
/**
* @brief Create a new Digital Input Card object with the specified position on the dip switch
- *
+ *
* @note The bit 0 are at the left of the dip switch
- *
+ *
* @warning There are 6 switches on the dip switch, 3 for bank A and 3 for bank B, They should be unique for each bank accross all the cards
- *
+ *
* @param bit0 The position of the first switch on the dip switch
* @param bit1 The position of the second switch on the dip switch
* @param bit2 The position of the third switch on the dip switch
@@ -50,23 +50,19 @@ DigitalInputCard::DigitalInputCard(bool bit0, bool bit1, bool bit2, bool bit3, b
/**
* @brief Initialize the Digital Input Card
- *
+ *
* @return True if the initialization is successful, false otherwise
*/
bool DigitalInputCard::begin()
{
this->inputBankA = PCF8574(this->address_a);
this->inputBankB = PCF8574(this->address_b);
- if (!this->inputBankA.begin())
- {
+ if (!this->inputBankA.begin()) {
ESP_LOGE("DigitalInputCard", "Input Card ERROR: Failed to install input bank A");
- this->initOk = false;
return false;
}
- if (!this->inputBankB.begin())
- {
+ if (!this->inputBankB.begin()) {
ESP_LOGE("DigitalInputCard", "Input Card ERROR: Failed to install input bank B");
- this->initOk = false;
return false;
}
// Set the debounce time for all pins to 50ms
@@ -81,13 +77,12 @@ bool DigitalInputCard::begin()
this->pinMap[i] = i;
this->virtualPinMap[i] = i;
}
- this->initOk = true;
return true;
}
/**
* @brief Read the input from the specified pin, always refresh the input buffers
- *
+ *
* @param pin The pin to read from
* @return True if the pin is HIGH, false if the pin is LOW
*/
@@ -98,18 +93,13 @@ bool DigitalInputCard::digitalRead(uint8_t pin)
/**
* @brief Read the input from the specified pin, also refresh the input buffers if refresh is true
- *
+ *
* @param pin The pin to read from
* @param refresh If true, the input buffers will be refreshed before reading the pin
* @return True if the pin is HIGH, false if the pin is LOW
*/
bool DigitalInputCard::digitalRead(uint8_t pin, bool refresh)
{
- if(!this->initOk)
- {
- ESP_LOGE("DigitalInputCard", "Input Card ERROR: Card not initialized");
- return false;
- }
pin = pinMap[pin];
// First check if the pin is in bank A or B
if (pin >= 0 && pin <= 7)
@@ -128,14 +118,14 @@ bool DigitalInputCard::digitalRead(uint8_t pin, bool refresh)
// Extract the bit from the buffer
return ((inputBufferB >> (15 - pin)) & 1);
}
- return false;
+ return 255;
}
/**
* @brief Check if the specified pin changed since the last call to this function
- *
+ *
* @note This function compares the current input buffer with the previous input buffer to detect changes
- *
+ *
* @param pin The pin to check
* @param currentBuffer The current input buffer
* @param previousBuffer The previous input buffer
@@ -144,89 +134,33 @@ void DigitalInputCard::handlePinChange(int pin, uint8_t ¤tBuffer, uint8_t
{
// Get the index of the pin in the pin map
uint8_t virtualPin = virtualPinMap[pin];
- if (pin < 8)
+ // Handle Bank A
+ if (((previousBuffer >> (7 - pin)) & 1) != ((currentBuffer >> (7 - pin)) & 1))
{
- // Handle Bank A
- if (((previousBuffer >> (7 - pin)) & 1) != ((currentBuffer >> (7 - pin)) & 1))
+ if (millis() - lastDebounceTime[pin] > debounceTime[pin])
{
- // When the pin first change, store the time
- if (!pinChanged[virtualPin])
- {
- ESP_LOGD("DigitalInputCard", "Pin %d changed", virtualPin);
- pinChanged[virtualPin] = true;
- lastDebounceTime[virtualPin] = millis();
- }
- else
- {
- ESP_LOGD("DigitalInputCard", "Pin %d (%d>%d) debounce time: %d", virtualPin, ((previousBuffer >> (7 - pin)) & 1), ((currentBuffer >> (7 - pin)) & 1), millis() - lastDebounceTime[virtualPin]);
- // If the pin was already changed, check if the debounce time has passed
- if ((millis() - lastDebounceTime[virtualPin]) > debounceTime[virtualPin])
- {
- ESP_LOGD("DigitalInputCard", "Pin %d triggered", virtualPin);
- // Call the callback function
- for (auto const &callback : callbacks)
- {
- callback.second(virtualPin, ((currentBuffer >> (7 - pin)) & 1));
- }
- // Store the previous buffer at the specified pin (bitwise operation)
- // new value : (currentBuffer >> (7 - pin)) & 1)
- previousBuffer = (previousBuffer & ~(1 << (7 - pin))) | (((currentBuffer >> (7 - pin)) & 1) << (7 - pin));
- // Reset the pin changed flag
- pinChanged[virtualPin] = false;
- }
- }
- }
- else
- {
- // Pin bounce back to previous state, reset the debounce time
- lastDebounceTime[virtualPin] = millis();
- pinChanged[virtualPin] = false;
+ lastDebounceTime[pin] = millis();
+ previousBuffer ^= (-((currentBuffer >> (7 - pin)) & 1) ^ previousBuffer) & (1UL << (7 - pin));
+ for(const auto& callback : callbacks)
+ callback.second(virtualPin, ((currentBuffer >> (7 - pin)) & 1));
}
}
- else
+ // Handle Bank B
+ if (((previousBuffer >> (15 - pin)) & 1) != ((currentBuffer >> (15 - pin)) & 1))
{
- // Handle Bank B
- if (((previousBuffer >> (15 - pin)) & 1) != ((currentBuffer >> (15 - pin)) & 1))
+ if (millis() - lastDebounceTime[pin] > debounceTime[pin])
{
- // When the pin first change, store the time
- if (!pinChanged[virtualPin])
- {
- ESP_LOGD("DigitalInputCard", "Pin %d changed", virtualPin);
- pinChanged[virtualPin] = true;
- lastDebounceTime[virtualPin] = millis();
- }
- else
- {
- ESP_LOGD("DigitalInputCard", "Pin %d (%d>%d) debounce time: %d", virtualPin, ((previousBuffer >> (15 - pin)) & 1), ((currentBuffer >> (15 - pin)) & 1), millis() - lastDebounceTime[virtualPin]);
- // If the pin was already changed, check if the debounce time has passed
- if ((millis() - lastDebounceTime[virtualPin]) > debounceTime[virtualPin])
- {
- ESP_LOGD("DigitalInputCard", "Pin %d triggered", virtualPin);
- // Call the callback function
- for (auto const &callback : callbacks)
- {
- callback.second(virtualPin, ((currentBuffer >> (15 - pin)) & 1));
- }
- // Store the previous buffer at the specified pin (bitwise operation)
- // new value : (currentBuffer >> (15 - pin)) & 1)
- previousBuffer = (previousBuffer & ~(1 << (15 - pin))) | (((currentBuffer >> (15 - pin)) & 1) << (15 - pin));
- // Reset the pin changed flag
- pinChanged[virtualPin] = false;
- }
- }
- }
- else
- {
- // Pin bounce back to previous state, reset the debounce time
- lastDebounceTime[virtualPin] = millis();
- pinChanged[virtualPin] = false;
+ lastDebounceTime[pin] = millis();
+ previousBuffer ^= (-((currentBuffer >> (15 - pin)) & 1) ^ previousBuffer) & (1UL << (15 - pin));
+ for (const auto& callback : callbacks)
+ callback.second(virtualPin, ((currentBuffer >> (15 - pin)) & 1));
}
}
}
/**
- * @brief A loop to refresh the input buffers and check for pin changes
- *
+ * @brief A loop to refresh the input buffers and check for pin changes
+ *
* @note Although this function can be called in the main loop, it is recommended install the card in ESPMega to automatically manage the loop
*/
// Preform a loop to refresh the input buffers
@@ -252,7 +186,7 @@ void DigitalInputCard::loop()
/**
* @brief Get the input buffer for bank A (the first 8 pins)
- *
+ *
* @return The input buffer for bank A where the first bit is the first pin and the last bit is the last pin
*/
uint8_t DigitalInputCard::getInputBufferA()
@@ -268,7 +202,7 @@ uint8_t DigitalInputCard::getInputBufferA()
/**
* @brief Get the input buffer for bank B (the last 8 pins)
- *
+ *
* @return The input buffer for bank B where the first bit is the first pin and the last bit is the last pin
*/
uint8_t DigitalInputCard::getInputBufferB()
@@ -284,7 +218,7 @@ uint8_t DigitalInputCard::getInputBufferB()
/**
* @brief Register a callback function to be called when a pin changes
- *
+ *
* @param callback The callback function to be called
* @return The handler of the callback function
*/
@@ -299,11 +233,6 @@ uint8_t DigitalInputCard::registerCallback(std::function ca
*/
void DigitalInputCard::refreshInputBankA()
{
- if(!this->initOk)
- {
- ESP_LOGE("DigitalInputCard", "Input Card ERROR: Card not initialized");
- return;
- }
inputBufferA = inputBankA.read8();
}
@@ -312,21 +241,16 @@ void DigitalInputCard::refreshInputBankA()
*/
void DigitalInputCard::refreshInputBankB()
{
- if(!this->initOk)
- {
- ESP_LOGE("DigitalInputCard", "Input Card ERROR: Card not initialized");
- return;
- }
inputBufferB = inputBankB.read8();
}
/**
* @brief Set the debounce time for the specified pin
- *
+ *
* Debounce is the time in milliseconds that the pin should be stable before the callback function is called
* This is useful to prevent false triggers when the input is noisy
* An example of this is when the input is connected to a mechanical switch
- *
+ *
* @param pin The pin to set the debounce time for
* @param debounceTime The debounce time in milliseconds
*/
@@ -338,7 +262,7 @@ void DigitalInputCard::setDebounceTime(uint8_t pin, uint32_t debounceTime)
/**
* @brief Unregister a callback function
- *
+ *
* @param handler The handler of the callback function to unregister
*/
void DigitalInputCard::unregisterCallback(uint8_t handler)
@@ -348,12 +272,12 @@ void DigitalInputCard::unregisterCallback(uint8_t handler)
/**
* @brief Load the pin map for the card
- *
+ *
* A pin map is an array of 16 elements that maps the physical pins to virtual pins
* The virtual pins are the pins that are used in the callback functions and are used for all the functions in this class
* The physical pins are the pins on the Input IC, This can be found on the schematic of the ESPMegaI/O board
* This function is useful if you want to change the number identification of the pins to match your project needs
- *
+ *
* @param pinMap The pin map to load
*/
void DigitalInputCard::loadPinMap(uint8_t pinMap[16])
@@ -369,33 +293,10 @@ void DigitalInputCard::loadPinMap(uint8_t pinMap[16])
/**
* @brief Get the type of the card
- *
+ *
* @return The type of the card
*/
uint8_t DigitalInputCard::getType()
{
return CARD_TYPE_DIGITAL_INPUT;
-}
-
-/**
- * @brief Preload the previous input buffer and the input buffer
- *
- * @note This function is useful if you want to preload the input buffers with a run-time value
- */
-void DigitalInputCard::preloadInputBuffer()
-{
- refreshInputBankA();
- refreshInputBankB();
- previousInputBufferA = inputBufferA;
- previousInputBufferB = inputBufferB;
-}
-
-/**
- * @brief Get the status of the card
- *
- * @return True if the card is initialized, false otherwise
- */
-bool DigitalInputCard::getStatus()
-{
- return this->initOk;
}
\ No newline at end of file
diff --git a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/DigitalInputCard.hpp b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/DigitalInputCard.hpp
index d73f639..a140029 100644
--- a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/DigitalInputCard.hpp
+++ b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/DigitalInputCard.hpp
@@ -41,14 +41,9 @@ class DigitalInputCard : public ExpansionCard {
void unregisterCallback(uint8_t handler);
// Load a new pin map
void loadPinMap(uint8_t pinMap[16]);
- // Preload previousInputBuffer and inputBuffer
- void preloadInputBuffer();
- // Status of card
- bool getStatus();
// Get type of card
uint8_t getType();
private:
- bool initOk = false;
PCF8574 inputBankA;
PCF8574 inputBankB;
uint8_t address_a;
@@ -59,7 +54,6 @@ class DigitalInputCard : public ExpansionCard {
uint8_t previousInputBufferB;
uint32_t debounceTime[16];
uint32_t lastDebounceTime[16];
- bool pinChanged[16];
// A map of the physical pin to the virtual pin
uint8_t pinMap[16];
// A map of the virtual pin to the physical pin
diff --git a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/DigitalInputIoT.cpp b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/DigitalInputIoT.cpp
index ac1ba0c..f138e52 100644
--- a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/DigitalInputIoT.cpp
+++ b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/DigitalInputIoT.cpp
@@ -17,9 +17,6 @@
*/
bool DigitalInputIoT::begin(uint8_t card_id, ExpansionCard *card, PubSubClient *mqtt, char *base_topic) {
this->card = (DigitalInputCard *)card;
- if(!this->card->getStatus()) {
- return false;
- }
this->card_id = card_id;
this->mqtt = mqtt;
this->base_topic = base_topic;
diff --git a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/DigitalOutputCard.cpp b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/DigitalOutputCard.cpp
index 9735579..cefa8e8 100644
--- a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/DigitalOutputCard.cpp
+++ b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/DigitalOutputCard.cpp
@@ -32,7 +32,7 @@ DigitalOutputCard::DigitalOutputCard(uint8_t address) : change_callbacks(){
* @param bit4 The position of the fifth switch on the dip switch
*/
DigitalOutputCard::DigitalOutputCard(bool bit0, bool bit1, bool bit2, bool bit3, bool bit4) :
- DigitalOutputCard(0x40+bit0+bit1*2+bit2*4+bit3*8+bit4*16)
+ DigitalOutputCard(0x20+bit0+bit1*2+bit2*4+bit3*8+bit4*16)
{
@@ -306,13 +306,4 @@ void DigitalOutputCard::saveStateToFRAM() {
if(!framBinded) return;
uint16_t packed = packStates();
this->fram->write16(framAddress, packed);
-}
-
-/**
- * @brief Toggle the state of the specified pin
- *
- * @param pin The pin to toggle
- */
-void DigitalOutputCard::toggleState(uint8_t pin) {
- this->setState(pin, !this->state_buffer[pin]);
}
\ No newline at end of file
diff --git a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/DigitalOutputCard.hpp b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/DigitalOutputCard.hpp
index 88ebbaa..a3ed97c 100644
--- a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/DigitalOutputCard.hpp
+++ b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/DigitalOutputCard.hpp
@@ -58,8 +58,6 @@ public:
void setValue(uint8_t pin, uint16_t value);
// Get the state of the specified pin
bool getState(uint8_t pin);
- // Toggle the state of the specified pin
- void toggleState(uint8_t pin);
// Get the pwm value of the specified pin
uint16_t getValue(uint8_t pin);
// Register a callback function that will be called when the state of a pin changes
diff --git a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaCommon.hpp b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaCommon.hpp
index de9233f..a724426 100644
--- a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaCommon.hpp
+++ b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaCommon.hpp
@@ -1,3 +1,3 @@
#pragma once
-#define SDK_VESRION "2.10.0"
\ No newline at end of file
+#define SDK_VESRION "2.6.1"
\ No newline at end of file
diff --git a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaIoT.cpp b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaIoT.cpp
index d0837f8..80fd0d3 100644
--- a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaIoT.cpp
+++ b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaIoT.cpp
@@ -56,22 +56,6 @@ void ESPMegaIoT::mqttCallback(char *topic, byte *payload, unsigned int length)
{
callback.second(topic_without_base, payload_buffer);
}
- // Check for global state request
- if (!strcmp(topic_without_base,"requeststate")) {
- for (int i = 0; i < 255; i++)
- {
- if (components[i] != NULL)
- {
- components[i]->publishReport();
- }
- }
- return;
- }
- // Check for global summary request
- if (!strcmp(topic_without_base,"requestinfo")) {
- this->publishSystemSummary();
- return;
- }
// Call the respective card's mqtt callback
// Note that after the base topic, there should be the card id
// /base_topic/card_id/...
@@ -144,12 +128,6 @@ void ESPMegaIoT::registerCard(uint8_t card_id)
{
return;
}
- // Check if the physical card is installed
- if (cards[card_id] == NULL)
- {
- ESP_LOGE("ESPMegaIoT", "Registering card %d failed: Card not installed", card_id);
- return;
- }
// Get the card type
uint8_t card_type = cards[card_id]->getType();
// Create the respective IoT component
@@ -401,18 +379,6 @@ void ESPMegaIoT::publish(const char *topic, const char *payload)
mqtt.publish(topic, payload);
}
-/**
- * @brief Publish a message to a topic
- *
- * @param topic The topic to publish to
- * @param payload The payload to publish
- * @param length The length of the payload
- */
-void ESPMegaIoT::publish(const char *topic, const char *payload, unsigned int length)
-{
- mqtt.publish(topic, (const uint8_t *)payload, length);
-}
-
/**
* @brief Register a callback for MQTT messages
*
@@ -436,7 +402,7 @@ void ESPMegaIoT::unregisterMqttCallback(uint16_t handler)
}
/**
- * @brief Subscribe to all components's topics and all other topics
+ * @brief Subscribe to all components's topics
*/
void ESPMegaIoT::mqttSubscribe()
{
@@ -456,9 +422,6 @@ void ESPMegaIoT::mqttSubscribe()
mqtt.loop();
}
}
- // Global topics
- this->subscribeRelative("requeststate");
- this->subscribeRelative("requestinfo");
}
/**
@@ -554,21 +517,6 @@ void ESPMegaIoT::publishRelative(const char *topic, const char *payload)
mqtt.loop();
}
-/**
- * @brief Publish a message relative to the base topic
- *
- * @param topic The topic to publish to
- * @param payload The payload to publish
- * @param length The length of the payload
- */
-void ESPMegaIoT::publishRelative(const char *topic, const char *payload, unsigned int length)
-{
- char absolute_topic[100];
- sprintf(absolute_topic, "%s/%s", this->mqtt_config.base_topic, topic);
- mqtt.publish(absolute_topic, (const uint8_t *)payload, length);
- mqtt.loop();
-}
-
/**
* @brief Subscribe to a topic relative to the base topic
*
@@ -631,22 +579,6 @@ void ESPMegaIoT::loadNetworkConfig()
network_config.wifiUseAuth = fram->read8(IOT_FRAM_ADDRESS + 54);
fram->read(IOT_FRAM_ADDRESS + 55, (uint8_t *)network_config.ssid, 32);
fram->read(IOT_FRAM_ADDRESS + 87, (uint8_t *)network_config.password, 32);
-
- // If ip,gateway,subnet,dns1,dns2 is 0, the device is not configured
- // set to default values
- // ip: 192.168.0.99
- // gateway: 192.168.0.1
- // subnet: 255.255.255.0
- // dns1: 1.1.1.1
- // dns2: 9.9.9.9
- if ((uint32_t)network_config.ip == 0 && (uint32_t)network_config.gateway == 0 && (uint32_t)network_config.subnet == 0 && (uint32_t)network_config.dns1 == 0 && (uint32_t)network_config.dns2 == 0)
- {
- network_config.ip = IPAddress(192, 168, 0, 99);
- network_config.gateway = IPAddress(192, 168, 0, 1);
- network_config.subnet = IPAddress(255, 255, 255, 0);
- network_config.dns1 = IPAddress(1, 1, 1, 1);
- network_config.useStaticIp = true;
- }
}
/**
@@ -902,30 +834,3 @@ String ESPMegaIoT::getMac()
else
return this->getETHMac();
}
-
-/**
- * @brief Publish a json object containing the system summary
- */
-void ESPMegaIoT::publishSystemSummary() {
- char payload[1024];
- StaticJsonDocument<1024> doc;
- JsonObject root = doc.to();
- root["ip"] = this->getIp().toString();
- root["firmware"] = SW_VERSION;
- root["sdk_version"] = SDK_VESRION;
- root["board_model"] = BOARD_MODEL;
- JsonArray cards = root.createNestedArray("cards");
- for (int i = 0; i < 255; i++)
- {
- if (components[i] != NULL)
- {
- JsonObject card = cards.createNestedObject();
- card["id"] = i;
- card["type"] = components[i]->getType();
- }
- }
- serializeJson(doc, payload);
- ESP_LOGD("ESPMegaIoT", "Publishing system summary: %s", payload);
- mqtt.loop();
- this->publishRelative("info", payload, strlen(payload));
-}
\ No newline at end of file
diff --git a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaIoT.hpp b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaIoT.hpp
index 76498c0..c5467b2 100644
--- a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaIoT.hpp
+++ b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaIoT.hpp
@@ -16,8 +16,6 @@
#include
#include
#include
-
- Uptime
- Loading ...
-
Model
Loading ...
@@ -64,7 +60,7 @@
SIWAT SYSTEM 2023