diff --git a/examples/knx-demo/knx-demo.ino b/examples/knx-demo/knx-demo.ino
index 15dff44..13f4068 100644
--- a/examples/knx-demo/knx-demo.ino
+++ b/examples/knx-demo/knx-demo.ino
@@ -17,7 +17,6 @@ long lastsend = 0;
void measureTemp()
{
-
long now = millis();
if ((now - lastsend) < 2000)
return;
@@ -58,11 +57,11 @@ void setup()
SerialDBG.begin(115200);
randomSeed(millis());
-
- #ifdef ARDUINO_ARCH_ESP8266
- WiFiManager wifiManager;
+
+#ifdef ARDUINO_ARCH_ESP8266
+ WiFiManager wifiManager;
wifiManager.autoConnect("knx-demo");
- #endif
+#endif
// read adress table, association table, groupobject table and parameters from eeprom
knx.readMemory();
@@ -72,30 +71,31 @@ void setup()
{
// register callback for reset GO
goReset.callback(resetCallback);
-
- SerialDBG.print("Timeout: "); SerialDBG.println(knx.paramByte(0));
- SerialDBG.print("Zykl. senden: "); SerialDBG.println(knx.paramByte(1));
- SerialDBG.print("Min/Max senden: "); SerialDBG.println(knx.paramByte(2));
- SerialDBG.print("Aenderung senden: "); SerialDBG.println(knx.paramByte(3));
- SerialDBG.print("Abgleich: "); SerialDBG.println(knx.paramByte(4));
- }
-
- #ifdef ARDUINO_ARCH_ESP8266
- // GPIO (?) of the ESP8266, in which case this is determined by the board selection
- knx.ledPin(LED_BUILTIN);
- // GPIO (?) of the ESP8266, the value depends on the circuit used on the board of the led
- // if "0" or "low" then the output switches to gnd, at "1" or "high" the output switches to vcc
- // if the next line is commented out then the default is: output switches to gnd
- //knx.ledPinActiveOn(HIGH);
- // GPIO (14) of the ESP8266, in which case it is the connector pin D5 on WeMos D1 R2
- knx.buttonPin(14);
- #endif
- // start the framework. Will get wifi first.
+ SerialDBG.print("Timeout: ");
+ SerialDBG.println(knx.paramByte(0));
+ SerialDBG.print("Zykl. senden: ");
+ SerialDBG.println(knx.paramByte(1));
+ SerialDBG.print("Min/Max senden: ");
+ SerialDBG.println(knx.paramByte(2));
+ SerialDBG.print("Aenderung senden: ");
+ SerialDBG.println(knx.paramByte(3));
+ SerialDBG.print("Abgleich: ");
+ SerialDBG.println(knx.paramByte(4));
+ }
+
+ // pin or GPIO the programming led is connected to. Default is LED_BUILDIN
+ // 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()
+void loop()
{
// don't delay here to much. Otherwise you might lose packages or mess up the timing with ETS
knx.loop();
diff --git a/src/knx/bits.cpp b/src/knx/bits.cpp
index 2a913f0..81db6f0 100644
--- a/src/knx/bits.cpp
+++ b/src/knx/bits.cpp
@@ -10,7 +10,7 @@ uint8_t* popByte(uint8_t& b, uint8_t* data)
void printHex(const char* suffix, const uint8_t *data, size_t length)
{
print(suffix);
- for (uint i = 0; i < length; i++) {
+ for (size_t i = 0; i < length; i++) {
if (data[i] < 0x10) { print("0"); }
print(data[i], HEX);
print(" ");
diff --git a/src/knx_facade.cpp b/src/knx_facade.cpp
index 020389a..131c32c 100644
--- a/src/knx_facade.cpp
+++ b/src/knx_facade.cpp
@@ -1,45 +1,30 @@
#include "knx_facade.h"
+#include "knx/bits.h"
+
#ifdef ARDUINO_ARCH_SAMD
SamdPlatform platform;
Bau07B0 bau(platform);
-#else
+#elif ARDUINO_ARCH_ESP8266
EspPlatform platform;
Bau57B0 bau(platform);
+#elif __linux__ //linux
+// noops on linux
+#define digitalWrite(a, b)
+#define pinMode(a, b)
+#define attachInterrupt(a, b, c)
#endif
-KnxFacade knx(bau);
-#include "knx/bits.h"
+#ifndef __linux__
+KnxFacade knx(bau);
void buttonUp()
{
- if (knx.progMode())
- {
- if (knx.ledPinActiveOn())
- {
- digitalWrite(knx.ledPin(), HIGH);
- }
- else
- {
- digitalWrite(knx.ledPin(), LOW);
- }
- knx.progMode(false);
- }
- else
- {
- if (knx.ledPinActiveOn())
- {
- digitalWrite(knx.ledPin(), LOW);
- }
- else
- {
- digitalWrite(knx.ledPin(), HIGH);
- }
- knx.progMode(true);
- }
+ knx.progMode(!knx.progMode());
}
+#endif
-KnxFacade::KnxFacade(BauSystemB& bau) : _bau(bau)
+KnxFacade::KnxFacade(BauSystemB &bau) : _bau(bau)
{
manufacturerId(0xfa);
_bau.addSaveRestore(this);
@@ -62,14 +47,17 @@ bool KnxFacade::progMode()
void KnxFacade::progMode(bool value)
{
- if (value)
- {
- println("progmode on");
- }
- else
- {
- println("progmode off");
- }
+ if (value)
+ {
+ println("progmode on");
+ digitalWrite(knx.ledPin(), _ledPinActiveOn);
+ }
+ else
+ {
+ println("progmode off");
+ digitalWrite(knx.ledPin(), HIGH - _ledPinActiveOn);
+ }
+
_bau.deviceObject().progMode(value);
}
@@ -78,12 +66,12 @@ bool KnxFacade::configured()
return _bau.configured();
}
-bool KnxFacade::ledPinActiveOn()
+uint32_t KnxFacade::ledPinActiveOn()
{
return _ledPinActiveOn;
}
-void KnxFacade::ledPinActiveOn(bool value)
+void KnxFacade::ledPinActiveOn(uint32_t value)
{
_ledPinActiveOn = value;
}
@@ -133,12 +121,17 @@ void KnxFacade::bauNumber(uint32_t value)
_bau.deviceObject().bauNumber(value);
}
-void KnxFacade::orderNumber(const char* value)
+uint16_t KnxFacade::induvidualAddress()
+{
+ return _bau.deviceObject().induvidualAddress();
+}
+
+void KnxFacade::orderNumber(const char *value)
{
_bau.deviceObject().orderNumber(value);
}
-void KnxFacade::hardwareType(uint8_t* value)
+void KnxFacade::hardwareType(uint8_t *value)
{
_bau.deviceObject().hardwareType(value);
}
@@ -151,27 +144,20 @@ void KnxFacade::version(uint16_t value)
void KnxFacade::start()
{
pinMode(_ledPin, OUTPUT);
-
- if (knx.ledPinActiveOn())
- {
- digitalWrite(_ledPin, HIGH);
- }
- else
- {
- digitalWrite(_ledPin, LOW);
- }
+
+ digitalWrite(_ledPin, HIGH - _ledPinActiveOn);
pinMode(_buttonPin, INPUT_PULLUP);
-
+
attachInterrupt(_buttonPin, buttonUp, RISING);
enabled(true);
}
-uint8_t* KnxFacade::paramData(uint32_t addr)
+uint8_t *KnxFacade::paramData(uint32_t addr)
{
if (!_bau.configured())
return nullptr;
-
+
return _bau.parameters().data(addr);
}
@@ -199,38 +185,33 @@ uint32_t KnxFacade::paramInt(uint32_t addr)
return _bau.parameters().getInt(addr);
}
-
void KnxFacade::setSaveCallback(saveRestoreCallback func)
{
_saveCallback = func;
}
-
void KnxFacade::setRestoreCallback(saveRestoreCallback func)
{
_restoreCallback = func;
}
-
-uint8_t* KnxFacade::save(uint8_t* buffer)
+uint8_t *KnxFacade::save(uint8_t *buffer)
{
if (_saveCallback != 0)
return _saveCallback(buffer);
-
+
return buffer;
}
-
-uint8_t* KnxFacade::restore(uint8_t* buffer)
+uint8_t *KnxFacade::restore(uint8_t *buffer)
{
if (_restoreCallback != 0)
return _restoreCallback(buffer);
-
+
return buffer;
}
-
-GroupObject& KnxFacade::getGroupObject(uint16_t goNr)
+GroupObject &KnxFacade::getGroupObject(uint16_t goNr)
{
return _bau.groupObjectTable().get(goNr);
}
diff --git a/src/knx_facade.h b/src/knx_facade.h
index 35ec721..c8b79c9 100644
--- a/src/knx_facade.h
+++ b/src/knx_facade.h
@@ -3,11 +3,15 @@
#ifdef ARDUINO_ARCH_SAMD
#include "samd_platform.h"
#include "knx/bau07B0.h"
-#endif
-
-#ifdef ARDUINO_ARCH_ESP8266
+#elif ARDUINO_ARCH_ESP8266
#include "esp_platform.h"
#include "knx/bau57B0.h"
+#else
+#include "linux_platform.h"
+#include "knx/bau57B0.h"
+#define LED_BUILTIN 0
+#define HIGH 1
+#define LOW 0
#endif
@@ -22,20 +26,24 @@ public:
bool progMode();
void progMode(bool value);
bool configured();
- bool ledPinActiveOn();
+ /**
+ * returns HIGH if led is active on HIGH, LOW otherwise
+ */
+ uint32_t ledPinActiveOn();
/**
- * @brief To adapt the output to hardware.
+ * To adapt the output to hardware.
*
* @param ledPinActiveOn = "0" or "low" --> GPIO--LED--RESISTOR--VDD (for example NODE MCU)
* @param ledPinActiveOn = "1" or "high" --> GPIO--RESISTOR--LED--GND (for example WeMos D1 R2)
*/
- void ledPinActiveOn(bool value);
+ void ledPinActiveOn(uint32_t value);
uint32_t ledPin();
void ledPin(uint32_t value);
uint32_t buttonPin();
void buttonPin(uint32_t value);
void readMemory();
void writeMemory();
+ uint16_t induvidualAddress();
void loop();
void manufacturerId(uint16_t value);
void bauNumber(uint32_t value);
@@ -52,7 +60,7 @@ public:
GroupObject& getGroupObject(uint16_t goNr);
private:
BauSystemB& _bau;
- bool _ledPinActiveOn = 0;
+ uint32_t _ledPinActiveOn = LOW;
uint32_t _ledPin = LED_BUILTIN;
uint32_t _buttonPin = 0;
#ifdef USE_STATES
@@ -65,4 +73,6 @@ private:
uint8_t* restore(uint8_t* buffer);
};
+#ifndef __linux__
extern KnxFacade knx;
+#endif
\ No newline at end of file
diff --git a/visualstudio/knx-demo.vgdbproj b/visualstudio/knx-demo.vgdbproj
index f74ad5d..f5c4b41 100644
--- a/visualstudio/knx-demo.vgdbproj
+++ b/visualstudio/knx-demo.vgdbproj
@@ -236,104 +236,6 @@
Sketch
-
- NodeMCU_1 0_(ESP-12E_Module)
-
-
-
-
- false
- false
- false
- false
- false
- false
- false
- false
- false
-
- false
- false
- false
- false
- false
- false
- true
- false
- None
- false
- false
- main
- true
- false
- false
- false
- 0
-
-
- true
- Auto
- 0
- false
- false
- true
- false
- false
-
- _estack
- 0
- false
- true
-
-
- esp8266:esp8266:nodemcuv2
-
-
-
- xtal
- 80
-
-
- vt
- flash
-
-
- exception
- disabled
-
-
- ssl
- all
-
-
- eesz
- 4M
-
-
- ip
- lm2f
-
-
- dbg
- Disabled
-
-
- lvl
- None____
-
-
- wipe
- none
-
-
- baud
- 115200
-
-
-
- Sketch
-
-
\ No newline at end of file
diff --git a/visualstudio/knx.sln b/visualstudio/knx.sln
index 0c37c06..17b1414 100644
--- a/visualstudio/knx.sln
+++ b/visualstudio/knx.sln
@@ -18,25 +18,21 @@ Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Arduino Genuino Zero (Native USB Port) = Debug|Arduino Genuino Zero (Native USB Port)
Debug|Mixed = Debug|Mixed
- Debug|NodeMCU_1 0_(ESP-12E_Module) = Debug|NodeMCU_1 0_(ESP-12E_Module)
Debug|VisualGDB = Debug|VisualGDB
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
MinSizeRel|Arduino Genuino Zero (Native USB Port) = MinSizeRel|Arduino Genuino Zero (Native USB Port)
MinSizeRel|Mixed = MinSizeRel|Mixed
- MinSizeRel|NodeMCU_1 0_(ESP-12E_Module) = MinSizeRel|NodeMCU_1 0_(ESP-12E_Module)
MinSizeRel|VisualGDB = MinSizeRel|VisualGDB
MinSizeRel|x64 = MinSizeRel|x64
MinSizeRel|x86 = MinSizeRel|x86
Release|Arduino Genuino Zero (Native USB Port) = Release|Arduino Genuino Zero (Native USB Port)
Release|Mixed = Release|Mixed
- Release|NodeMCU_1 0_(ESP-12E_Module) = Release|NodeMCU_1 0_(ESP-12E_Module)
Release|VisualGDB = Release|VisualGDB
Release|x64 = Release|x64
Release|x86 = Release|x86
RelWithDebInfo|Arduino Genuino Zero (Native USB Port) = RelWithDebInfo|Arduino Genuino Zero (Native USB Port)
RelWithDebInfo|Mixed = RelWithDebInfo|Mixed
- RelWithDebInfo|NodeMCU_1 0_(ESP-12E_Module) = RelWithDebInfo|NodeMCU_1 0_(ESP-12E_Module)
RelWithDebInfo|VisualGDB = RelWithDebInfo|VisualGDB
RelWithDebInfo|x64 = RelWithDebInfo|x64
RelWithDebInfo|x86 = RelWithDebInfo|x86
@@ -84,8 +80,7 @@ Global
{6165CD6A-91A4-49FA-977A-48F22086CA8E}.Debug|Arduino Genuino Zero (Native USB Port).Build.0 = Debug|Arduino Genuino Zero (Native USB Port)
{6165CD6A-91A4-49FA-977A-48F22086CA8E}.Debug|Mixed.ActiveCfg = Debug|Arduino Genuino Zero (Native USB Port)
{6165CD6A-91A4-49FA-977A-48F22086CA8E}.Debug|Mixed.Build.0 = Debug|Arduino Genuino Zero (Native USB Port)
- {6165CD6A-91A4-49FA-977A-48F22086CA8E}.Debug|NodeMCU_1 0_(ESP-12E_Module).ActiveCfg = Debug|NodeMCU_1 0_(ESP-12E_Module)
- {6165CD6A-91A4-49FA-977A-48F22086CA8E}.Debug|NodeMCU_1 0_(ESP-12E_Module).Build.0 = Debug|NodeMCU_1 0_(ESP-12E_Module)
+ {6165CD6A-91A4-49FA-977A-48F22086CA8E}.Debug|NodeMCU_1 0_(ESP-12E_Module).ActiveCfg = Debug|Arduino Genuino Zero (Native USB Port)
{6165CD6A-91A4-49FA-977A-48F22086CA8E}.Debug|VisualGDB.ActiveCfg = Debug|Arduino Genuino Zero (Native USB Port)
{6165CD6A-91A4-49FA-977A-48F22086CA8E}.Debug|x64.ActiveCfg = Debug|Arduino Genuino Zero (Native USB Port)
{6165CD6A-91A4-49FA-977A-48F22086CA8E}.Debug|x86.ActiveCfg = Debug|Arduino Genuino Zero (Native USB Port)
@@ -93,8 +88,8 @@ Global
{6165CD6A-91A4-49FA-977A-48F22086CA8E}.MinSizeRel|Arduino Genuino Zero (Native USB Port).Build.0 = Release|Arduino Genuino Zero (Native USB Port)
{6165CD6A-91A4-49FA-977A-48F22086CA8E}.MinSizeRel|Mixed.ActiveCfg = Release|Arduino Genuino Zero (Native USB Port)
{6165CD6A-91A4-49FA-977A-48F22086CA8E}.MinSizeRel|Mixed.Build.0 = Release|Arduino Genuino Zero (Native USB Port)
- {6165CD6A-91A4-49FA-977A-48F22086CA8E}.MinSizeRel|NodeMCU_1 0_(ESP-12E_Module).ActiveCfg = Release|NodeMCU_1 0_(ESP-12E_Module)
- {6165CD6A-91A4-49FA-977A-48F22086CA8E}.MinSizeRel|NodeMCU_1 0_(ESP-12E_Module).Build.0 = Release|NodeMCU_1 0_(ESP-12E_Module)
+ {6165CD6A-91A4-49FA-977A-48F22086CA8E}.MinSizeRel|NodeMCU_1 0_(ESP-12E_Module).ActiveCfg = Release|Arduino Genuino Zero (Native USB Port)
+ {6165CD6A-91A4-49FA-977A-48F22086CA8E}.MinSizeRel|NodeMCU_1 0_(ESP-12E_Module).Build.0 = Release|Arduino Genuino Zero (Native USB Port)
{6165CD6A-91A4-49FA-977A-48F22086CA8E}.MinSizeRel|VisualGDB.ActiveCfg = Release|Arduino Genuino Zero (Native USB Port)
{6165CD6A-91A4-49FA-977A-48F22086CA8E}.MinSizeRel|VisualGDB.Build.0 = Release|Arduino Genuino Zero (Native USB Port)
{6165CD6A-91A4-49FA-977A-48F22086CA8E}.MinSizeRel|x64.ActiveCfg = Release|Arduino Genuino Zero (Native USB Port)
@@ -104,8 +99,7 @@ Global
{6165CD6A-91A4-49FA-977A-48F22086CA8E}.Release|Arduino Genuino Zero (Native USB Port).ActiveCfg = Release|Arduino Genuino Zero (Native USB Port)
{6165CD6A-91A4-49FA-977A-48F22086CA8E}.Release|Arduino Genuino Zero (Native USB Port).Build.0 = Release|Arduino Genuino Zero (Native USB Port)
{6165CD6A-91A4-49FA-977A-48F22086CA8E}.Release|Mixed.ActiveCfg = Release|Arduino Genuino Zero (Native USB Port)
- {6165CD6A-91A4-49FA-977A-48F22086CA8E}.Release|NodeMCU_1 0_(ESP-12E_Module).ActiveCfg = Release|NodeMCU_1 0_(ESP-12E_Module)
- {6165CD6A-91A4-49FA-977A-48F22086CA8E}.Release|NodeMCU_1 0_(ESP-12E_Module).Build.0 = Release|NodeMCU_1 0_(ESP-12E_Module)
+ {6165CD6A-91A4-49FA-977A-48F22086CA8E}.Release|NodeMCU_1 0_(ESP-12E_Module).ActiveCfg = Release|Arduino Genuino Zero (Native USB Port)
{6165CD6A-91A4-49FA-977A-48F22086CA8E}.Release|VisualGDB.ActiveCfg = Release|Arduino Genuino Zero (Native USB Port)
{6165CD6A-91A4-49FA-977A-48F22086CA8E}.Release|x64.ActiveCfg = Release|Arduino Genuino Zero (Native USB Port)
{6165CD6A-91A4-49FA-977A-48F22086CA8E}.Release|x86.ActiveCfg = Release|Arduino Genuino Zero (Native USB Port)
@@ -113,8 +107,8 @@ Global
{6165CD6A-91A4-49FA-977A-48F22086CA8E}.RelWithDebInfo|Arduino Genuino Zero (Native USB Port).Build.0 = Release|Arduino Genuino Zero (Native USB Port)
{6165CD6A-91A4-49FA-977A-48F22086CA8E}.RelWithDebInfo|Mixed.ActiveCfg = Release|Arduino Genuino Zero (Native USB Port)
{6165CD6A-91A4-49FA-977A-48F22086CA8E}.RelWithDebInfo|Mixed.Build.0 = Release|Arduino Genuino Zero (Native USB Port)
- {6165CD6A-91A4-49FA-977A-48F22086CA8E}.RelWithDebInfo|NodeMCU_1 0_(ESP-12E_Module).ActiveCfg = Release|NodeMCU_1 0_(ESP-12E_Module)
- {6165CD6A-91A4-49FA-977A-48F22086CA8E}.RelWithDebInfo|NodeMCU_1 0_(ESP-12E_Module).Build.0 = Release|NodeMCU_1 0_(ESP-12E_Module)
+ {6165CD6A-91A4-49FA-977A-48F22086CA8E}.RelWithDebInfo|NodeMCU_1 0_(ESP-12E_Module).ActiveCfg = Release|Arduino Genuino Zero (Native USB Port)
+ {6165CD6A-91A4-49FA-977A-48F22086CA8E}.RelWithDebInfo|NodeMCU_1 0_(ESP-12E_Module).Build.0 = Release|Arduino Genuino Zero (Native USB Port)
{6165CD6A-91A4-49FA-977A-48F22086CA8E}.RelWithDebInfo|VisualGDB.ActiveCfg = Release|Arduino Genuino Zero (Native USB Port)
{6165CD6A-91A4-49FA-977A-48F22086CA8E}.RelWithDebInfo|VisualGDB.Build.0 = Release|Arduino Genuino Zero (Native USB Port)
{6165CD6A-91A4-49FA-977A-48F22086CA8E}.RelWithDebInfo|x64.ActiveCfg = Release|Arduino Genuino Zero (Native USB Port)