diff --git a/build_pio.sh b/build_pio.sh new file mode 100755 index 00000000..3f87cd80 --- /dev/null +++ b/build_pio.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +~/.platformio/penv/bin/platformio ci --lib="." --project-conf=examples/knx-usb/platformio-ci.ini examples/knx-usb/src/main.cpp && ~/.platformio/penv/bin/platformio ci --lib="." --project-conf=examples/knx-demo/platformio-ci.ini examples/knx-demo/knx-demo.ino && ~/.platformio/penv/bin/platformio ci --lib="." --project-conf=examples/knx-demo-coupler/platformio-ci.ini examples/knx-demo-coupler/knx-demo-coupler.ino diff --git a/examples/knx-demo-diy/.gitignore b/examples/knx-demo-diy/.gitignore deleted file mode 100644 index 89cc49cb..00000000 --- a/examples/knx-demo-diy/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -.pio -.vscode/.browse.c_cpp.db* -.vscode/c_cpp_properties.json -.vscode/launch.json -.vscode/ipch diff --git a/examples/knx-demo-diy/knx-demo-diy-tp.knxprod b/examples/knx-demo-diy/knx-demo-diy-tp.knxprod deleted file mode 100644 index ccb13635..00000000 Binary files a/examples/knx-demo-diy/knx-demo-diy-tp.knxprod and /dev/null differ diff --git a/examples/knx-demo-diy/knx-demo-diy-tp.xml b/examples/knx-demo-diy/knx-demo-diy-tp.xml deleted file mode 100644 index d7486680..00000000 --- a/examples/knx-demo-diy/knx-demo-diy-tp.xml +++ /dev/null @@ -1,133 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/examples/knx-demo-diy/knx-demo-diy.ino b/examples/knx-demo-diy/knx-demo-diy.ino deleted file mode 100644 index 00d3c6f9..00000000 --- a/examples/knx-demo-diy/knx-demo-diy.ino +++ /dev/null @@ -1,138 +0,0 @@ -#include -#include - -#ifdef ARDUINO_ARCH_ESP8266 -#include -#endif - -// create named references for easy access to group objects -#define goCurrent knx.getGroupObject(1) -#define goMax knx.getGroupObject(2) -#define goMin knx.getGroupObject(3) -#define goReset knx.getGroupObject(4) - -// If you don't want a global knx object, for example because you want -// to more finely control it's construction, this is an example -// of how to do so. Define KNX_NO_AUTOMATIC_GLOBAL_INSTANCE -// and then you can DIY a knx object as shown below. In this case we use -// the ESP32's secondary UART and late-bind the ISR function in setup(). -Esp32Platform knxPlatform(&Serial2); -Bau07B0 knxBau(knxPlatform); -KnxFacade knx(knxBau); - -ICACHE_RAM_ATTR void myButtonPressed() -{ - // Debounce - static uint32_t lastpressed=0; - if (millis() - lastpressed > 200) - { - knx.toggleProgMode(); - lastpressed = millis(); - } -} - -float currentValue = 0; -float maxValue = 0; -float minValue = RAND_MAX; -long lastsend = 0; - -void measureTemp() -{ - long now = millis(); - if ((now - lastsend) < 2000) - return; - - lastsend = now; - int r = rand(); - currentValue = (r * 1.0) / (RAND_MAX * 1.0); - currentValue *= 100 * 100; - - // write new value to groupobject - goCurrent.value(currentValue); - - if (currentValue > maxValue) - { - maxValue = currentValue; - goMax.value(maxValue); - } - - if (currentValue < minValue) - { - minValue = currentValue; - goMin.value(minValue); - } -} - -// callback from reset-GO -void resetCallback(GroupObject& go) -{ - if (go.value()) - { - maxValue = 0; - minValue = 10000; - } -} - -void setup() -{ - knx.setButtonISRFunction(myButtonPressed); - - Serial.begin(115200); - ArduinoPlatform::SerialDebug = &Serial; - - Serial2.begin(19200); // KNX, pin 16,17 on EPS32 - - randomSeed(millis()); - -#ifdef ARDUINO_ARCH_ESP8266 - WiFiManager wifiManager; - wifiManager.autoConnect("knx-demo"); -#endif - - // read adress table, association table, groupobject table and parameters from eeprom - knx.readMemory(); - - // print values of parameters if device is already configured - if (knx.configured()) - { - // register callback for reset GO - goReset.callback(resetCallback); - goReset.dataPointType(DPT_Trigger); - goCurrent.dataPointType(DPT_Value_Temp); - goMin.dataPointType(DPT_Value_Temp); - goMax.dataPointType(DPT_Value_Temp); - - Serial.print("Timeout: "); - Serial.println(knx.paramByte(0)); - Serial.print("Zykl. senden: "); - Serial.println(knx.paramByte(1)); - Serial.print("Min/Max senden: "); - Serial.println(knx.paramByte(2)); - Serial.print("Aenderung senden: "); - Serial.println(knx.paramByte(3)); - Serial.print("Abgleich: "); - Serial.println(knx.paramByte(4)); - } - - // pin or GPIO the programming led is connected to. Default is LED_BUILTIN - // knx.ledPin(LED_BUILTIN); - // is the led active on HIGH or low? Default is LOW - // knx.ledPinActiveOn(HIGH); - // pin or GPIO programming button is connected to. Default is 0 - // knx.buttonPin(0); - - // start the framework. - knx.start(); -} - -void loop() -{ - // don't delay here to much. Otherwise you might lose packages or mess up the timing with ETS - knx.loop(); - - // only run the application code if the device was configured with ETS - if (!knx.configured()) - return; - - measureTemp(); -} diff --git a/examples/knx-demo-diy/platformio-ci.ini b/examples/knx-demo-diy/platformio-ci.ini deleted file mode 100644 index 20711601..00000000 --- a/examples/knx-demo-diy/platformio-ci.ini +++ /dev/null @@ -1,24 +0,0 @@ -;PlatformIO Project Configuration File -; -; Build options: build flags, source filter -; Upload options: custom upload port, speed and extra flags -; Library options: dependencies, extra library storages -; Advanced options: extra scripting -; -; Please visit documentation for the other options and examples -; https://docs.platformio.org/page/projectconf.html - -; -;--- ESP32 ----------------------------------------------- - -[env:esp32dev_tp] -platform = espressif32 -board = esp32dev -framework = arduino -lib_deps = - knx - -build_flags = - -DMASK_VERSION=0x07B0 - -Wno-unknown-pragmas - -DKNX_NO_AUTOMATIC_GLOBAL_INSTANCE diff --git a/examples/knx-demo-diy/platformio.ini b/examples/knx-demo-diy/platformio.ini deleted file mode 100644 index 011e390a..00000000 --- a/examples/knx-demo-diy/platformio.ini +++ /dev/null @@ -1,33 +0,0 @@ -;PlatformIO Project Configuration File -; -; Build options: build flags, source filter -; Upload options: custom upload port, speed and extra flags -; Library options: dependencies, extra library storages -; Advanced options: extra scripting -; -; Please visit documentation for the other options and examples -; https://docs.platformio.org/page/projectconf.html -[platformio] -; We have to keep libdeps dir out the project directory otherwise, -; library scanner seems to have issues so compilation fails -libdeps_dir = /tmp/libdeps -src_dir = . - - -;--- ESP32 ----------------------------------------------- - -[env:esp32dev_tp] -platform = espressif32 -board = esp32dev -framework = arduino -; We consider that the this projects is opened within its project directory -; while working with VS Code. -lib_extra_dirs = ../../../ - -lib_deps = - knx - -build_flags = - -DMASK_VERSION=0x07B0 - -Wno-unknown-pragmas - -DKNX_NO_AUTOMATIC_GLOBAL_INSTANCE diff --git a/examples/knx-demo-smal-go/knx-demo.ino b/examples/knx-demo-smal-go/knx-demo.ino deleted file mode 100644 index 52fb386e..00000000 --- a/examples/knx-demo-smal-go/knx-demo.ino +++ /dev/null @@ -1,129 +0,0 @@ -#include - -#ifdef ARDUINO_ARCH_ESP8266 -#include -#endif - -/***************************************** - * changes necessary for SMALL_GROUPOBJECT - * are commented with //** - * This project can be used with any - * of the knxprod files of the original - * knx-demo project. - *****************************************/ - -// create named references for easy access to group objects -#define goCurrent knx.getGroupObject(1) -#define goMax knx.getGroupObject(2) -#define goMin knx.getGroupObject(3) -#define goReset knx.getGroupObject(4) - -float currentValue = 0; -float maxValue = 0; -float minValue = RAND_MAX; -long lastsend = 0; - -void measureTemp() -{ - long now = millis(); - if ((now - lastsend) < 2000) - return; - - lastsend = now; - int r = rand(); - currentValue = (r * 1.0) / (RAND_MAX * 1.0); - currentValue *= 100 * 100; - - // write new value to groupobject - goCurrent.value(currentValue, DPT_Value_Temp); //** each value access needs to done with according DPT parameter - - if (currentValue > maxValue) - { - maxValue = currentValue; - goMax.value(maxValue, DPT_Value_Temp); //** each value access needs to done with according DPT parameter - } - - if (currentValue < minValue) - { - minValue = currentValue; - goMin.value(minValue, DPT_Value_Temp); //** each value access needs to done with according DPT parameter - } -} - -// callback from reset-GO -void resetCallback(GroupObject& go) -{ - //** callbacks are now handled in the class, not per instance, - //** this means, we have to check, which GroupObject is calling back - if (go.asap() == goReset.asap()) - { - if (go.value(DPT_Trigger)) //** each value access needs to done with according DPT parameter - { - maxValue = 0; - minValue = 10000; - } - } -} - -void setup() -{ - Serial.begin(115200); - ArduinoPlatform::SerialDebug = &Serial; - - randomSeed(millis()); - -#ifdef ARDUINO_ARCH_ESP8266 - WiFiManager wifiManager; - wifiManager.autoConnect("knx-demo"); -#endif - - // read adress table, association table, groupobject table and parameters from eeprom - knx.readMemory(); - - // print values of parameters if device is already configured - if (knx.configured()) - { - // register callback for reset GO - GroupObject::classCallback(resetCallback); //** callbacks are now handled per class, not per instance - //** there is no global assignment of DPT for GroupObjects - // goReset.dataPointType(DPT_Trigger); - // goCurrent.dataPointType(DPT_Value_Temp); - // goMin.dataPointType(DPT_Value_Temp); - // goMax.dataPointType(DPT_Value_Temp); - - Serial.print("Timeout: "); - Serial.println(knx.paramByte(0)); - Serial.print("Zykl. senden: "); - Serial.println(knx.paramByte(1)); - Serial.print("Min/Max senden: "); - Serial.println(knx.paramByte(2)); - Serial.print("Aenderung senden: "); - Serial.println(knx.paramByte(3)); - Serial.print("Abgleich: "); - Serial.println(knx.paramByte(4)); - } - - // pin or GPIO the programming led is connected to. Default is LED_BUILTIN - // knx.ledPin(LED_BUILTIN); - // is the led active on HIGH or low? Default is LOW - // knx.ledPinActiveOn(HIGH); - // pin or GPIO programming button is connected to. Default is 0 - // knx.buttonPin(0); - // Is the interrup created in RISING or FALLING signal? Default is RISING - // knx.buttonPinInterruptOn(FALLING); - - // start the framework. - knx.start(); -} - -void loop() -{ - // don't delay here to much. Otherwise you might lose packages or mess up the timing with ETS - knx.loop(); - - // only run the application code if the device was configured with ETS - if (!knx.configured()) - return; - - measureTemp(); -} \ No newline at end of file diff --git a/examples/knx-demo-smal-go/platformio.ini b/examples/knx-demo-smal-go/platformio.ini deleted file mode 100644 index d028f0a9..00000000 --- a/examples/knx-demo-smal-go/platformio.ini +++ /dev/null @@ -1,117 +0,0 @@ -;PlatformIO Project Configuration File -; -; Build options: build flags, source filter -; Upload options: custom upload port, speed and extra flags -; Library options: dependencies, extra library storages -; Advanced options: extra scripting -; -; Please visit documentation for the other options and examples -; https://docs.platformio.org/page/projectconf.html -[platformio] -; We have to keep libdeps dir out the project directory otherwise, -; library scanner seems to have issues so compilation fails -libdeps_dir = /tmp/libdeps -src_dir = . - -;--- SAMD -------------------------------------------------- -[env:zeroUSB] -platform = atmelsam -board = zeroUSB -framework = arduino -; We consider that the this projects is opened within its project directory -; while working with VS Code. -lib_extra_dirs = ../../../ - -lib_deps = - SPI - knx - -build_flags = - -DMASK_VERSION=0x07B0 - -DSMALL_GROUPOBJECT - -Wno-unknown-pragmas - -; [env:adafruit_feather_m0_rf] -; platform = atmelsam -; board = adafruit_feather_m0 -; framework = arduino -; ; We consider that the this projects is opened within its project directory -; ; while working with VS Code. -; lib_extra_dirs = ../../../ - -; lib_deps = -; SPI -; knx - -; build_flags = -; -DMASK_VERSION=0x27B0 -; -Wno-unknown-pragmas -;----------------------------------------------------------- - - -;--- ESP8266 ----------------------------------------------- -#[env:nodemcuv2_ip] -#platform = espressif8266 -#board = nodemcuv2 -#framework = arduino -; We consider that the this projects is opened within its project directory -; while working with VS Code. -#lib_extra_dirs = ../../../ - -#lib_deps = -# WifiManager -# knx - -#build_flags = -# -DMASK_VERSION=0x57B0 -# -Wno-unknown-pragmas - -; [env:nodemcuv2_tp] -; platform = espressif8266 -; board = nodemcuv2 -; framework = arduino -; ; We consider that the this projects is opened within its project directory -; ; while working with VS Code. -; lib_extra_dirs = ../../../ - -; lib_deps = -; WifiManager -; knx - -; build_flags = -; -DMASK_VERSION=0x07B0 -; -Wno-unknown-pragmas - -;--------------------------------------------------------- - - -;--- ESP32 ----------------------------------------------- -; [env:esp32dev_ip] -; platform = espressif32 -; board = esp32dev -; framework = arduino -; ; We consider that the this projects is opened within its project directory -; ; while working with VS Code. -; lib_extra_dirs = ../../../ - -; lib_deps = -; knx - -; build_flags = -; -DMASK_VERSION=0x57B0 -; -Wno-unknown-pragmas - -; [env:esp32dev_tp] -; platform = espressif32 -; board = esp32dev -; framework = arduino -; ; We consider that the this projects is opened within its project directory -; ; while working with VS Code. -; lib_extra_dirs = ../../../ - -; lib_deps = -; knx - -; build_flags = -; -DMASK_VERSION=0x07B0 -; -Wno-unknown-pragmas diff --git a/examples/knx-demo/knx-demo.ino b/examples/knx-demo/knx-demo.ino index a72b214e..14c02730 100644 --- a/examples/knx-demo/knx-demo.ino +++ b/examples/knx-demo/knx-demo.ino @@ -2,9 +2,20 @@ #include #if MASK_VERSION != 0x07B0 && (defined ARDUINO_ARCH_ESP8266 || defined ARDUINO_ARCH_ESP32) -#include + #include #endif +/** If you don't want a global knx object, for example because you want + * to more finely control it's construction, this is an example + * of how to do so. Define KNX_NO_AUTOMATIC_GLOBAL_INSTANCE + * and then you can DIY a knx object as shown below. In this case we use + * the ESP32's secondary UART and late-bind the ISR function in setup(). + +Esp32Platform knxPlatform(&Serial2); +Bau07B0 knxBau(knxPlatform); +KnxFacade knx(knxBau); +*/ + // create named references for easy access to group objects #define goCurrent knx.getGroupObject(1) #define goMax knx.getGroupObject(2) @@ -19,6 +30,7 @@ long lastsend = 0; void measureTemp() { long now = millis(); + if ((now - lastsend) < 2000) return; @@ -44,9 +56,9 @@ void measureTemp() } // callback from reset-GO -void resetCallback(GroupObject& go) +void handler(GroupObject& go) { - if (go.value()) + if (go == goReset && go.value()) { maxValue = 0; minValue = 10000; @@ -55,6 +67,8 @@ void resetCallback(GroupObject& go) void setup() { + // You can configure the level of the different loggers. + //Logger::logLevel("ApplicationLayer", Logger::Info); Serial.begin(115200); ArduinoPlatform::SerialDebug = &Serial; @@ -67,12 +81,11 @@ void setup() // read adress table, association table, groupobject table and parameters from eeprom knx.readMemory(); + GroupObject::classCallback(handler); // print values of parameters if device is already configured if (knx.configured()) { - // register callback for reset GO - goReset.callback(resetCallback); goReset.dataPointType(DPT_Trigger); goCurrent.dataPointType(DPT_Value_Temp); goMin.dataPointType(DPT_Value_Temp); diff --git a/examples/knx-linux/main.cpp b/examples/knx-linux/main.cpp index 1a1ee4eb..094e5b46 100644 --- a/examples/knx-linux/main.cpp +++ b/examples/knx-linux/main.cpp @@ -77,9 +77,9 @@ void measureTemp() GO_MIN.value(currentValue); } -void resetCallback(GroupObject& go) +void handler(GroupObject& go) { - if (go.value()) + if (go == GO_RESET && go.value()) { GO_MAX.valueNoSend(-273.0); GO_MIN.valueNoSend(670433.28); @@ -105,6 +105,8 @@ void setup() if (knx.individualAddress() == 0xFFFF) knx.progMode(true); + GroupObject::classCallback(handler); + if (knx.configured()) { GO_CURR.dataPointType(Dpt(9, 1)); @@ -113,7 +115,6 @@ void setup() GO_MAX.dataPointType(Dpt(9, 1)); GO_MAX.valueNoSend(-273.0); GO_RESET.dataPointType(Dpt(1, 15)); - //GO_RESET.callback(resetCallback); LOGGER.info("Timeout: %d", knx.paramWord(0)); LOGGER.info("Zykl. senden: %d", knx.paramByte(2)); LOGGER.info("Min/Max senden: %d", knx.paramByte(3)); diff --git a/examples/scripts/stm32rdu.py b/examples/scripts/stm32rdu.py deleted file mode 100755 index d0c54006..00000000 --- a/examples/scripts/stm32rdu.py +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env python -from subprocess import run -from datetime import datetime, timedelta -from os.path import expanduser - -ocddir = expanduser("~/.platformio/packages/tool-openocd/") -chip = "stm32f1x" - -def unlock(*args, **kwargs): - print("Please connect the board within the next two minutes.") - endtime = datetime.now() + timedelta(minutes = 1) - ret = 1 - while ret != 0 and datetime.now() < endtime: - ret = run(["bin/openocd", "-f", "interface/stlink.cfg", "-f", "target/" + chip + ".cfg", "-c", "init", "-c", "reset halt", "-c", chip + " unlock 0", "-c", "reset halt", "-c", "exit"], cwd = ocddir).returncode - if ret != 0: - print("Timeout") - return ret - -try: - Import("env") -except NameError: - import sys - if len(sys.argv) > 1: - chip = sys.argv[1] - if len(sys.argv) > 2: - ocddir = sys.argv[2] - unlock(None, None) -else: - ocddir = env.PioPlatform().get_package_dir("tool-openocd") - options = env.GetProjectOptions() - for option in options: - if "unlock_chip" == option[0]: - chip = option[1] - env.AddCustomTarget("unlock", None, unlock) diff --git a/src/knx/group_object/group_object.cpp b/src/knx/group_object/group_object.cpp index 6a9f1317..855e7968 100644 --- a/src/knx/group_object/group_object.cpp +++ b/src/knx/group_object/group_object.cpp @@ -2,8 +2,9 @@ #include "datapoint_types.h" #include "../interface_object/group_object_table_object.h" -#include "../bits.h" #include "../util/logger.h" +#include "../bits.h" + #include @@ -95,7 +96,7 @@ namespace Knx return _data; } - uint16_t GroupObject::asap() + uint16_t GroupObject::asap() const { return _asap; } @@ -228,6 +229,7 @@ namespace Knx void GroupObject::processClassCallback(GroupObject& go) { LOGGER.info("processClassCallback for go %d, handlerset:%d", go.asap(), _updateHandlerStatic != 0); + if (_updateHandlerStatic != 0) _updateHandlerStatic(go); } @@ -330,4 +332,9 @@ namespace Knx return false; } + + bool operator==(const GroupObject& lhs, const GroupObject& rhs) + { + return lhs.asap() == rhs.asap(); + } } \ No newline at end of file diff --git a/src/knx/group_object/group_object.h b/src/knx/group_object/group_object.h index 46938cd0..e0001480 100644 --- a/src/knx/group_object/group_object.h +++ b/src/knx/group_object/group_object.h @@ -142,7 +142,7 @@ namespace Knx * returns the Application Service Access Point of the group object. In reality this is just the number of the group object. * (in german "KO-Nr") */ - uint16_t asap(); + uint16_t asap() const; /** * return the current value of the group object. @@ -266,4 +266,6 @@ namespace Knx Dpt _datapointType; #endif }; + + bool operator==(const GroupObject& lhs, const GroupObject& rhs); } \ No newline at end of file diff --git a/src/knx/interface_object/table_object.cpp b/src/knx/interface_object/table_object.cpp index ec8466d1..5b265012 100644 --- a/src/knx/interface_object/table_object.cpp +++ b/src/knx/interface_object/table_object.cpp @@ -1,7 +1,7 @@ #include "table_object.h" -#include "../bits.h" #include "../util/memory.h" #include "../util/logger.h" +#include "../bits.h" #define LOGGER Logger::logger("TableObject")