circuit of the led adapted for different boards (#15)

* Update knx_facade.cpp

* Update knx_facade.h

* Update knx-demo.ino
This commit is contained in:
Maggyver 2019-05-27 20:13:57 +02:00 committed by thelsing
parent 9cbd9a0760
commit 87828bd530
3 changed files with 78 additions and 34 deletions

View File

@ -1,5 +1,8 @@
#include <knx.h> #include <knx.h>
#ifdef ARDUINO_ARCH_ESP8266
#include <WiFiManager.h>
#endif
// create named references for easy access to group objects // create named references for easy access to group objects
#define goCurrent knx.getGroupObject(1) #define goCurrent knx.getGroupObject(1)
@ -56,6 +59,11 @@ void setup()
randomSeed(millis()); randomSeed(millis());
#ifdef ARDUINO_ARCH_ESP8266
WiFiManager wifiManager;
wifiManager.autoConnect("knx-demo");
#endif
// read adress table, association table, groupobject table and parameters from eeprom // read adress table, association table, groupobject table and parameters from eeprom
knx.readMemory(); knx.readMemory();
@ -72,6 +80,17 @@ void setup()
SerialDBG.print("Abgleich: "); SerialDBG.println(knx.paramByte(4)); 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. // start the framework. Will get wifi first.
knx.start(); knx.start();
} }

View File

@ -1,37 +1,43 @@
#include "knx_facade.h" #include "knx_facade.h"
#include "knx/bits.h"
#ifdef ARDUINO_ARCH_SAMD #ifdef ARDUINO_ARCH_SAMD
SamdPlatform platform; SamdPlatform platform;
Bau07B0 bau(platform); Bau07B0 bau(platform);
#elif ARDUINO_ARCH_ESP8266 #else
EspPlatform platform; EspPlatform platform;
Bau57B0 bau(platform); Bau57B0 bau(platform);
#elif __linux__ //linux
// noops on linux
#define digitalWrite(a, b)
#define pinMode(a, b)
#define attachInterrupt(a, b, c)
#endif #endif
#ifndef __linux__
KnxFacade knx(bau); KnxFacade knx(bau);
#include "knx/bits.h"
void buttonUp() void buttonUp()
{ {
if (knx.progMode()) if (knx.progMode())
{
if (knx.ledPinActiveOn())
{
digitalWrite(knx.ledPin(), HIGH);
}
else
{ {
digitalWrite(knx.ledPin(), LOW); digitalWrite(knx.ledPin(), LOW);
}
knx.progMode(false); knx.progMode(false);
} }
else else
{
if (knx.ledPinActiveOn())
{
digitalWrite(knx.ledPin(), LOW);
}
else
{ {
digitalWrite(knx.ledPin(), HIGH); digitalWrite(knx.ledPin(), HIGH);
}
knx.progMode(true); knx.progMode(true);
} }
} }
#endif
KnxFacade::KnxFacade(BauSystemB& bau) : _bau(bau) KnxFacade::KnxFacade(BauSystemB& bau) : _bau(bau)
{ {
@ -56,12 +62,14 @@ bool KnxFacade::progMode()
void KnxFacade::progMode(bool value) void KnxFacade::progMode(bool value)
{ {
print("progmode ");
if (value) if (value)
println("on"); {
println("progmode on");
}
else else
println("off"); {
println("progmode off");
}
_bau.deviceObject().progMode(value); _bau.deviceObject().progMode(value);
} }
@ -70,6 +78,16 @@ bool KnxFacade::configured()
return _bau.configured(); return _bau.configured();
} }
bool KnxFacade::ledPinActiveOn()
{
return _ledPinActiveOn;
}
void KnxFacade::ledPinActiveOn(bool value)
{
_ledPinActiveOn = value;
}
uint32_t KnxFacade::ledPin() uint32_t KnxFacade::ledPin()
{ {
return _ledPin; return _ledPin;
@ -115,11 +133,6 @@ void KnxFacade::bauNumber(uint32_t value)
_bau.deviceObject().bauNumber(value); _bau.deviceObject().bauNumber(value);
} }
uint16_t KnxFacade::induvidualAddress()
{
return _bau.deviceObject().induvidualAddress();
}
void KnxFacade::orderNumber(const char* value) void KnxFacade::orderNumber(const char* value)
{ {
_bau.deviceObject().orderNumber(value); _bau.deviceObject().orderNumber(value);
@ -139,6 +152,15 @@ void KnxFacade::start()
{ {
pinMode(_ledPin, OUTPUT); pinMode(_ledPin, OUTPUT);
if (knx.ledPinActiveOn())
{
digitalWrite(_ledPin, HIGH);
}
else
{
digitalWrite(_ledPin, LOW);
}
pinMode(_buttonPin, INPUT_PULLUP); pinMode(_buttonPin, INPUT_PULLUP);
attachInterrupt(_buttonPin, buttonUp, RISING); attachInterrupt(_buttonPin, buttonUp, RISING);

View File

@ -3,15 +3,12 @@
#ifdef ARDUINO_ARCH_SAMD #ifdef ARDUINO_ARCH_SAMD
#include "samd_platform.h" #include "samd_platform.h"
#include "knx/bau07B0.h" #include "knx/bau07B0.h"
#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
#endif #endif
#ifdef ARDUINO_ARCH_ESP8266
#include "esp_platform.h"
#include "knx/bau57B0.h"
#endif
typedef uint8_t* (*saveRestoreCallback)(uint8_t* buffer); typedef uint8_t* (*saveRestoreCallback)(uint8_t* buffer);
@ -25,13 +22,20 @@ public:
bool progMode(); bool progMode();
void progMode(bool value); void progMode(bool value);
bool configured(); bool configured();
bool ledPinActiveOn();
/**
* @brief 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);
uint32_t ledPin(); uint32_t ledPin();
void ledPin(uint32_t value); void ledPin(uint32_t value);
uint32_t buttonPin(); uint32_t buttonPin();
void buttonPin(uint32_t value); void buttonPin(uint32_t value);
void readMemory(); void readMemory();
void writeMemory(); void writeMemory();
uint16_t induvidualAddress();
void loop(); void loop();
void manufacturerId(uint16_t value); void manufacturerId(uint16_t value);
void bauNumber(uint32_t value); void bauNumber(uint32_t value);
@ -48,6 +52,7 @@ public:
GroupObject& getGroupObject(uint16_t goNr); GroupObject& getGroupObject(uint16_t goNr);
private: private:
BauSystemB& _bau; BauSystemB& _bau;
bool _ledPinActiveOn = 0;
uint32_t _ledPin = LED_BUILTIN; uint32_t _ledPin = LED_BUILTIN;
uint32_t _buttonPin = 0; uint32_t _buttonPin = 0;
#ifdef USE_STATES #ifdef USE_STATES
@ -60,6 +65,4 @@ private:
uint8_t* restore(uint8_t* buffer); uint8_t* restore(uint8_t* buffer);
}; };
#ifndef __linux__
extern KnxFacade knx; extern KnxFacade knx;
#endif