From 09aee8d5f86d0d6b7cc72ef0bab71ccec3035ffd Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Sun, 3 Nov 2024 13:33:10 +0700 Subject: [PATCH] digital output card --- .../lib/ESPMegaPRO/DigitalOutputCard.cpp | 2 +- ESPMegaPRO-OS-SDK/src/main.cpp | 33 ++++++++++++------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/DigitalOutputCard.cpp b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/DigitalOutputCard.cpp index d760dc1..9735579 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(0x20+bit0+bit1*2+bit2*4+bit3*8+bit4*16) + DigitalOutputCard(0x40+bit0+bit1*2+bit2*4+bit3*8+bit4*16) { diff --git a/ESPMegaPRO-OS-SDK/src/main.cpp b/ESPMegaPRO-OS-SDK/src/main.cpp index 98fd31d..4c79918 100644 --- a/ESPMegaPRO-OS-SDK/src/main.cpp +++ b/ESPMegaPRO-OS-SDK/src/main.cpp @@ -1,7 +1,7 @@ /** * @file main.cpp * @brief Test firmware for the ESPMegaPRO OOP library -*/ + */ #include #include #include @@ -17,20 +17,24 @@ // #define FRAM_DEBUG // #define MQTT_DEBUG // #define RTC_DEBUG -//#define WRITE_DEFAULT_NETCONF -//#define CLIMATE_CARD_ENABLE -//#define MQTT_CARD_REGISTER +// #define WRITE_DEFAULT_NETCONF +// #define CLIMATE_CARD_ENABLE +#define MQTT_CARD_REGISTER // #define DISPLAY_ENABLE -//#define WEB_SERVER_ENABLE -//#define LCD_OTA_ENABLE -// #define REMOTE_VARIABLE_ENABLE -// #define CT_ENABLE -// #define SMART_VARIABLE_ENABLE - +#define WEB_SERVER_ENABLE +// #define LCD_OTA_ENABLE +// #define REMOTE_VARIABLE_ENABLE +// #define CT_ENABLE +// #define SMART_VARIABLE_ENABLE +#define EXTERNAL_DIGITAL_OUTPUT_CARD_ENABLE // Demo PLC firmware using the ESPMegaPRO OOP library ESPMegaPRO espmega = ESPMegaPRO(); +#ifdef EXTERNAL_DIGITAL_OUTPUT_CARD_ENABLE +DigitalOutputCard externalDigitalOutputCard = DigitalOutputCard(1, 0, 1, 1, 0); +#endif + // Remote Variable #ifdef REMOTE_VARIABLE_ENABLE RemoteVariable testVar = RemoteVariable(); @@ -166,6 +170,9 @@ void setup() { ESP_LOGI("Initializer", "Starting ESPMegaPRO OOP demo"); espmega.begin(); +#ifdef EXTERNAL_DIGITAL_OUTPUT_CARD_ENABLE + espmega.installCard(6, &externalDigitalOutputCard); +#endif espmega.setTimezone("UTC-7"); ESP_LOGI("Initializer", "Enabling IOT module"); espmega.enableIotModule(); @@ -205,6 +212,10 @@ void setup() espmega.iot->registerCard(0); ESP_LOGI("Initializer", "Registering cards 1"); espmega.iot->registerCard(1); +#ifdef EXTERNAL_DIGITAL_OUTPUT_CARD_ENABLE + ESP_LOGI("Initializer", "Registering cards 6"); + espmega.iot->registerCard(6); +#endif #endif ESP_LOGI("Initializer", "Registering Input change callback"); espmega.inputs.registerCallback(input_change_callback); @@ -240,7 +251,7 @@ void setup() #endif #ifdef REMOTE_VARIABLE_ENABLE ESP_LOGI("Initializer", "Initializing testvar"); - testVar.begin(32, "/xm/fan_speed", espmega.iot, true,"/pm/request_fan_speed"); + testVar.begin(32, "/xm/fan_speed", espmega.iot, true, "/pm/request_fan_speed"); testVar.enableSetValue("/pm/request_switch_state"); #endif #ifdef CT_ENABLE