mirror of
https://github.com/thelsing/knx.git
synced 2024-12-18 19:08:18 +01:00
Add callback functions for prog mode and improve documentation (#173)
This commit is contained in:
parent
d26771c432
commit
53425e2ef7
51
README.md
51
README.md
@ -1,16 +1,55 @@
|
|||||||
knx
|
# knx
|
||||||
===
|
|
||||||
|
|
||||||
|
This projects provides a knx-device stack for arduino (ESP8266, ESP32, SAMD21, RP2040, STM32), CC1310 and linux. (more are quite easy to add)
|
||||||
|
|
||||||
This projects provides a knx-device stack for arduino (ESP8266, SAMD21) and linux. (more are quite easy to add)
|
|
||||||
It implements most of System-B specification and can be configured with ETS.
|
It implements most of System-B specification and can be configured with ETS.
|
||||||
The necessary knxprod-files can be generated with my [CreateKnxProd](https://github.com/thelsing/CreateKnxProd) tool.
|
The necessary knxprod-files can be generated with my [CreateKnxProd](https://github.com/thelsing/CreateKnxProd) tool.
|
||||||
|
|
||||||
For esp8266 [WifiManager](https://github.com/tzapu/WiFiManager) is used to configure wifi.
|
For ESP8266 and ESP32 [WifiManager](https://github.com/tzapu/WiFiManager) is used to configure wifi.
|
||||||
|
|
||||||
Don't forget to reset ESP8266 manually (disconnect power) after flashing. The reboot doen't work during configuration with ETS otherwise.
|
Don't forget to reset ESP8266 manually (disconnect power) after flashing. The reboot doen't work during configuration with ETS otherwise.
|
||||||
|
|
||||||
The SAMD21 version uses my version of the [FlashStorage](https://github.com/thelsing/FlashStorage) lib (Pull request pending).
|
The SAMD21 version uses my version of the [FlashStorage](https://github.com/thelsing/FlashStorage) lib (Pull request pending).
|
||||||
|
|
||||||
Generated documentation can be found [here](https://knx.readthedocs.io/en/latest/).
|
Generated documentation can be found [here](https://knx.readthedocs.io/en/latest/).
|
||||||
|
|
||||||
|
## Stack configuration possibilities
|
||||||
|
|
||||||
|
Specify prog button GPIO other then `GPIO0`:
|
||||||
|
```C++
|
||||||
|
knx.buttonPin(3); // Use GPIO3 Pin
|
||||||
|
```
|
||||||
|
|
||||||
|
Specify a LED GPIO for programming mode other then the `LED_BUILTIN`:
|
||||||
|
```C++
|
||||||
|
knx.ledPin(5);
|
||||||
|
```
|
||||||
|
|
||||||
|
Use a custom function instead of a LED connected to GPIO to indicate the programming mode:
|
||||||
|
```C++
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
#include <knx.h>
|
||||||
|
// create a pixel strand with 1 pixel on PIN_NEOPIXEL
|
||||||
|
Adafruit_NeoPixel pixels(1, PIN_NEOPIXEL);
|
||||||
|
|
||||||
|
void progLedOff()
|
||||||
|
{
|
||||||
|
pixels.clear();
|
||||||
|
pixels.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
void progLedOn()
|
||||||
|
{
|
||||||
|
pixels.setPixelColor(0, pixels.Color(20, 0, 0));
|
||||||
|
pixels.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
void main ()
|
||||||
|
{
|
||||||
|
knx.setProgLedOffCallback(progLedOff);
|
||||||
|
knx.setProgLedOnCallback(progLedOn);
|
||||||
|
[...]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
More configuration options can be found in the examples.
|
@ -28,7 +28,9 @@
|
|||||||
void buttonUp();
|
void buttonUp();
|
||||||
#endif
|
#endif
|
||||||
#elif defined(ARDUINO_ARCH_ESP32)
|
#elif defined(ARDUINO_ARCH_ESP32)
|
||||||
|
#if !defined(LED_BUILTIN)
|
||||||
#define LED_BUILTIN 13
|
#define LED_BUILTIN 13
|
||||||
|
#endif
|
||||||
#include "esp32_platform.h"
|
#include "esp32_platform.h"
|
||||||
#ifndef KNX_NO_AUTOMATIC_GLOBAL_INSTANCE
|
#ifndef KNX_NO_AUTOMATIC_GLOBAL_INSTANCE
|
||||||
void buttonUp();
|
void buttonUp();
|
||||||
@ -39,10 +41,14 @@
|
|||||||
void buttonUp();
|
void buttonUp();
|
||||||
#endif
|
#endif
|
||||||
#elif __linux__
|
#elif __linux__
|
||||||
|
#if !defined(LED_BUILTIN)
|
||||||
#define LED_BUILTIN 0
|
#define LED_BUILTIN 0
|
||||||
|
#endif
|
||||||
#include "linux_platform.h"
|
#include "linux_platform.h"
|
||||||
#else
|
#else
|
||||||
|
#if !defined(LED_BUILTIN)
|
||||||
#define LED_BUILTIN 5 // see GPIO_PinConfig gpioPinConfigs[]
|
#define LED_BUILTIN 5 // see GPIO_PinConfig gpioPinConfigs[]
|
||||||
|
#endif
|
||||||
#include "cc1310_platform.h"
|
#include "cc1310_platform.h"
|
||||||
#ifndef KNX_NO_AUTOMATIC_GLOBAL_INSTANCE
|
#ifndef KNX_NO_AUTOMATIC_GLOBAL_INSTANCE
|
||||||
extern void buttonUp();
|
extern void buttonUp();
|
||||||
@ -52,6 +58,8 @@
|
|||||||
typedef const uint8_t* (*RestoreCallback)(const uint8_t* buffer);
|
typedef const uint8_t* (*RestoreCallback)(const uint8_t* buffer);
|
||||||
typedef uint8_t* (*SaveCallback)(uint8_t* buffer);
|
typedef uint8_t* (*SaveCallback)(uint8_t* buffer);
|
||||||
typedef void (*IsrFunctionPtr)();
|
typedef void (*IsrFunctionPtr)();
|
||||||
|
typedef void (*ProgLedOnCallback)();
|
||||||
|
typedef void (*ProgLedOffCallback)();
|
||||||
|
|
||||||
template <class P, class B> class KnxFacade : private SaveRestore
|
template <class P, class B> class KnxFacade : private SaveRestore
|
||||||
{
|
{
|
||||||
@ -158,6 +166,16 @@ template <class P, class B> class KnxFacade : private SaveRestore
|
|||||||
_ledPin = value;
|
_ledPin = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setProgLedOffCallback(ProgLedOffCallback progLedOffCallback)
|
||||||
|
{
|
||||||
|
_progLedOffCallback = progLedOffCallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setProgLedOnCallback(ProgLedOnCallback progLedOnCallback)
|
||||||
|
{
|
||||||
|
_progLedOnCallback = progLedOnCallback;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns RISING if interrupt is created in a rising signal, FALLING otherwise
|
* returns RISING if interrupt is created in a rising signal, FALLING otherwise
|
||||||
*/
|
*/
|
||||||
@ -209,12 +227,12 @@ template <class P, class B> class KnxFacade : private SaveRestore
|
|||||||
if (_progLedState)
|
if (_progLedState)
|
||||||
{
|
{
|
||||||
println("progmode on");
|
println("progmode on");
|
||||||
digitalWrite(ledPin(), _ledPinActiveOn);
|
progLedOn();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
println("progmode off");
|
println("progmode off");
|
||||||
digitalWrite(ledPin(), HIGH - _ledPinActiveOn);
|
progLedOff();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (_toggleProgMode)
|
if (_toggleProgMode)
|
||||||
@ -252,10 +270,10 @@ template <class P, class B> class KnxFacade : private SaveRestore
|
|||||||
|
|
||||||
void start()
|
void start()
|
||||||
{
|
{
|
||||||
|
if (_progLedOffCallback == 0 || _progLedOnCallback == 0)
|
||||||
pinMode(ledPin(), OUTPUT);
|
pinMode(ledPin(), OUTPUT);
|
||||||
|
|
||||||
digitalWrite(ledPin(), HIGH - _ledPinActiveOn);
|
progLedOff();
|
||||||
|
|
||||||
pinMode(buttonPin(), INPUT_PULLUP);
|
pinMode(buttonPin(), INPUT_PULLUP);
|
||||||
|
|
||||||
if (_progButtonISRFuncPtr)
|
if (_progButtonISRFuncPtr)
|
||||||
@ -389,6 +407,8 @@ template <class P, class B> class KnxFacade : private SaveRestore
|
|||||||
P* _platformPtr = 0;
|
P* _platformPtr = 0;
|
||||||
B* _bauPtr = 0;
|
B* _bauPtr = 0;
|
||||||
B& _bau;
|
B& _bau;
|
||||||
|
ProgLedOnCallback _progLedOnCallback = 0;
|
||||||
|
ProgLedOffCallback _progLedOffCallback = 0;
|
||||||
uint32_t _ledPinActiveOn = LOW;
|
uint32_t _ledPinActiveOn = LOW;
|
||||||
uint32_t _ledPin = LED_BUILTIN;
|
uint32_t _ledPin = LED_BUILTIN;
|
||||||
uint32_t _buttonPinInterruptOn = RISING;
|
uint32_t _buttonPinInterruptOn = RISING;
|
||||||
@ -425,6 +445,22 @@ template <class P, class B> class KnxFacade : private SaveRestore
|
|||||||
{
|
{
|
||||||
_saveSize = size;
|
_saveSize = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void progLedOn()
|
||||||
|
{
|
||||||
|
if (_progLedOnCallback == 0)
|
||||||
|
digitalWrite(ledPin(), _ledPinActiveOn);
|
||||||
|
else
|
||||||
|
_progLedOnCallback();
|
||||||
|
}
|
||||||
|
|
||||||
|
void progLedOff()
|
||||||
|
{
|
||||||
|
if (_progLedOffCallback == 0)
|
||||||
|
digitalWrite(ledPin(), HIGH - _ledPinActiveOn);
|
||||||
|
else
|
||||||
|
_progLedOffCallback();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef KNX_NO_AUTOMATIC_GLOBAL_INSTANCE
|
#ifndef KNX_NO_AUTOMATIC_GLOBAL_INSTANCE
|
||||||
|
Loading…
Reference in New Issue
Block a user