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>
#ifdef ARDUINO_ARCH_ESP8266
#include <WiFiManager.h>
#endif
// create named references for easy access to group objects
#define goCurrent knx.getGroupObject(1)
@ -55,6 +58,11 @@ void setup()
SerialDBG.begin(115200);
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();
@ -71,6 +79,17 @@ void setup()
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.
knx.start();

View File

@ -1,37 +1,43 @@
#include "knx_facade.h"
#include "knx/bits.h"
#ifdef ARDUINO_ARCH_SAMD
SamdPlatform platform;
Bau07B0 bau(platform);
#elif ARDUINO_ARCH_ESP8266
#else
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
#ifndef __linux__
KnxFacade knx(bau);
#include "knx/bits.h"
void buttonUp()
{
if (knx.progMode())
{
digitalWrite(knx.ledPin(), LOW);
if (knx.ledPinActiveOn())
{
digitalWrite(knx.ledPin(), HIGH);
}
else
{
digitalWrite(knx.ledPin(), LOW);
}
knx.progMode(false);
}
else
{
digitalWrite(knx.ledPin(), HIGH);
if (knx.ledPinActiveOn())
{
digitalWrite(knx.ledPin(), LOW);
}
else
{
digitalWrite(knx.ledPin(), HIGH);
}
knx.progMode(true);
}
}
#endif
KnxFacade::KnxFacade(BauSystemB& bau) : _bau(bau)
{
@ -56,12 +62,14 @@ bool KnxFacade::progMode()
void KnxFacade::progMode(bool value)
{
print("progmode ");
if (value)
println("on");
else
println("off");
if (value)
{
println("progmode on");
}
else
{
println("progmode off");
}
_bau.deviceObject().progMode(value);
}
@ -70,6 +78,16 @@ bool KnxFacade::configured()
return _bau.configured();
}
bool KnxFacade::ledPinActiveOn()
{
return _ledPinActiveOn;
}
void KnxFacade::ledPinActiveOn(bool value)
{
_ledPinActiveOn = value;
}
uint32_t KnxFacade::ledPin()
{
return _ledPin;
@ -115,11 +133,6 @@ void KnxFacade::bauNumber(uint32_t value)
_bau.deviceObject().bauNumber(value);
}
uint16_t KnxFacade::induvidualAddress()
{
return _bau.deviceObject().induvidualAddress();
}
void KnxFacade::orderNumber(const char* value)
{
_bau.deviceObject().orderNumber(value);
@ -138,6 +151,15 @@ void KnxFacade::version(uint16_t value)
void KnxFacade::start()
{
pinMode(_ledPin, OUTPUT);
if (knx.ledPinActiveOn())
{
digitalWrite(_ledPin, HIGH);
}
else
{
digitalWrite(_ledPin, LOW);
}
pinMode(_buttonPin, INPUT_PULLUP);

View File

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