Add callback functions for prog mode and improve documentation (#173)

This commit is contained in:
Michael Geramb 2022-02-19 20:23:50 +01:00 committed by GitHub
parent d26771c432
commit 53425e2ef7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 87 additions and 12 deletions

View File

@ -1,16 +1,55 @@
knx
===
# knx
This projects provides a knx-device stack for arduino (ESP8266, SAMD21) and linux. (more are quite easy to add)
This projects provides a knx-device stack for arduino (ESP8266, ESP32, SAMD21, RP2040, STM32), CC1310 and linux. (more are quite easy to add)
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.
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.
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/).
## 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.

View File

@ -28,7 +28,9 @@
void buttonUp();
#endif
#elif defined(ARDUINO_ARCH_ESP32)
#if !defined(LED_BUILTIN)
#define LED_BUILTIN 13
#endif
#include "esp32_platform.h"
#ifndef KNX_NO_AUTOMATIC_GLOBAL_INSTANCE
void buttonUp();
@ -39,10 +41,14 @@
void buttonUp();
#endif
#elif __linux__
#if !defined(LED_BUILTIN)
#define LED_BUILTIN 0
#endif
#include "linux_platform.h"
#else
#if !defined(LED_BUILTIN)
#define LED_BUILTIN 5 // see GPIO_PinConfig gpioPinConfigs[]
#endif
#include "cc1310_platform.h"
#ifndef KNX_NO_AUTOMATIC_GLOBAL_INSTANCE
extern void buttonUp();
@ -52,6 +58,8 @@
typedef const uint8_t* (*RestoreCallback)(const uint8_t* buffer);
typedef uint8_t* (*SaveCallback)(uint8_t* buffer);
typedef void (*IsrFunctionPtr)();
typedef void (*ProgLedOnCallback)();
typedef void (*ProgLedOffCallback)();
template <class P, class B> class KnxFacade : private SaveRestore
{
@ -158,6 +166,16 @@ template <class P, class B> class KnxFacade : private SaveRestore
_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
*/
@ -209,12 +227,12 @@ template <class P, class B> class KnxFacade : private SaveRestore
if (_progLedState)
{
println("progmode on");
digitalWrite(ledPin(), _ledPinActiveOn);
progLedOn();
}
else
{
println("progmode off");
digitalWrite(ledPin(), HIGH - _ledPinActiveOn);
progLedOff();
}
}
if (_toggleProgMode)
@ -252,10 +270,10 @@ template <class P, class B> class KnxFacade : private SaveRestore
void start()
{
pinMode(ledPin(), OUTPUT);
digitalWrite(ledPin(), HIGH - _ledPinActiveOn);
if (_progLedOffCallback == 0 || _progLedOnCallback == 0)
pinMode(ledPin(), OUTPUT);
progLedOff();
pinMode(buttonPin(), INPUT_PULLUP);
if (_progButtonISRFuncPtr)
@ -389,6 +407,8 @@ template <class P, class B> class KnxFacade : private SaveRestore
P* _platformPtr = 0;
B* _bauPtr = 0;
B& _bau;
ProgLedOnCallback _progLedOnCallback = 0;
ProgLedOffCallback _progLedOffCallback = 0;
uint32_t _ledPinActiveOn = LOW;
uint32_t _ledPin = LED_BUILTIN;
uint32_t _buttonPinInterruptOn = RISING;
@ -425,6 +445,22 @@ template <class P, class B> class KnxFacade : private SaveRestore
{
_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