From e4dbda5f1635103e144b400ff53324d6f73285c1 Mon Sep 17 00:00:00 2001 From: Bernhard Date: Sun, 8 Sep 2019 17:50:54 +0200 Subject: [PATCH] -bugfix Arduino set knxUart --- src/arduino_platform.cpp | 26 ++++++++++++++------------ src/arduino_platform.h | 8 ++++---- src/esp32_platform.cpp | 8 ++++---- src/esp32_platform.h | 3 +-- src/esp_platform.cpp | 6 +++--- src/esp_platform.h | 3 +-- src/samd_platform.cpp | 6 +++--- src/samd_platform.h | 6 ++---- 8 files changed, 32 insertions(+), 34 deletions(-) diff --git a/src/arduino_platform.cpp b/src/arduino_platform.cpp index a8ccfad..19d7d37 100644 --- a/src/arduino_platform.cpp +++ b/src/arduino_platform.cpp @@ -3,9 +3,9 @@ #include -Stream& ArduinoPlatform::SerialDebug = Serial; +Stream& ArduinoPlatform::SerialDebug = SerialUSB; -ArduinoPlatform::ArduinoPlatform(HardwareSerial& knxSerial) : _knxSerial(knxSerial) +ArduinoPlatform::ArduinoPlatform(HardwareSerial* knxSerial) : _knxSerial(knxSerial) { } @@ -68,19 +68,21 @@ int ArduinoPlatform::readBytes(uint8_t * buffer, uint16_t maxLen) return 0; } -void ArduinoPlatform::knxUart( HardwareSerial& serial ) +void ArduinoPlatform::knxUart( HardwareSerial* serial ) { + closeUart(); _knxSerial = serial; + setupUart(); } -HardwareSerial& ArduinoPlatform::knxUart() +HardwareSerial* ArduinoPlatform::knxUart() { return _knxSerial; } void ArduinoPlatform::setupUart() { - _knxSerial.begin(19200, SERIAL_8E1); + _knxSerial->begin(19200, SERIAL_8E1); while (!_knxSerial) ; } @@ -88,33 +90,33 @@ void ArduinoPlatform::setupUart() void ArduinoPlatform::closeUart() { - _knxSerial.end(); + _knxSerial->end(); } int ArduinoPlatform::uartAvailable() { - return _knxSerial.available(); + return _knxSerial->available(); } size_t ArduinoPlatform::writeUart(const uint8_t data) { //printHex("write(data); } size_t ArduinoPlatform::writeUart(const uint8_t *buffer, size_t size) { //printHex("write(buffer, size); } int ArduinoPlatform::readUart() { - int val = _knxSerial.read(); + int val = _knxSerial->read(); //if(val > 0) // printHex("p>", (uint8_t*)&val, 1); return val; @@ -127,7 +129,7 @@ size_t ArduinoPlatform::readBytesUart(uint8_t *buffer, size_t length) uint8_t* pos = buffer; while (toRead > 0) { - size_t val = _knxSerial.readBytes(pos, toRead); + size_t val = _knxSerial->readBytes(pos, toRead); pos += val; toRead -= val; } @@ -267,4 +269,4 @@ void println(double num) void println(void) { ArduinoPlatform::SerialDebug.println(); -} \ No newline at end of file +} diff --git a/src/arduino_platform.h b/src/arduino_platform.h index ab2ba29..3a33195 100644 --- a/src/arduino_platform.h +++ b/src/arduino_platform.h @@ -7,7 +7,7 @@ extern Stream& _serialDBG; class ArduinoPlatform : public Platform { public: - ArduinoPlatform(HardwareSerial& knxSerial); + ArduinoPlatform(HardwareSerial* knxSerial); // ip stuff uint32_t currentIpAddress(); @@ -25,8 +25,8 @@ class ArduinoPlatform : public Platform int readBytes(uint8_t* buffer, uint16_t maxLen); //uart - virtual void knxUart( HardwareSerial& serial ); - virtual HardwareSerial& knxUart(); + virtual void knxUart( HardwareSerial* serial); + virtual HardwareSerial* knxUart(); virtual void setupUart(); virtual void closeUart(); virtual int uartAvailable(); @@ -40,5 +40,5 @@ class ArduinoPlatform : public Platform protected: uint32_t _mulitcastAddr; uint16_t _mulitcastPort; - HardwareSerial& _knxSerial; + HardwareSerial* _knxSerial; }; diff --git a/src/esp32_platform.cpp b/src/esp32_platform.cpp index fc8cc1d..3598eb4 100644 --- a/src/esp32_platform.cpp +++ b/src/esp32_platform.cpp @@ -6,11 +6,11 @@ #include "knx/bits.h" -Esp32Platform::Esp32Platform() : ArduinoPlatform(Serial1) +Esp32Platform::Esp32Platform() : ArduinoPlatform(&Serial1) { } -Esp32Platform::Esp32Platform( HardwareSerial& s) : ArduinoPlatform(s) +Esp32Platform::Esp32Platform( HardwareSerial* s) : ArduinoPlatform(s) { } @@ -36,7 +36,7 @@ void Esp32Platform::macAddress(uint8_t * addr) void Esp32Platform::restart() { - Serial.println("restart"); + ArduinoPlatform::SerialDebug.println("restart"); ESP.restart(); } @@ -95,4 +95,4 @@ void Esp32Platform::commitToEeprom() EEPROM.commit(); } -#endif \ No newline at end of file +#endif diff --git a/src/esp32_platform.h b/src/esp32_platform.h index 79c0f96..dba4b3a 100644 --- a/src/esp32_platform.h +++ b/src/esp32_platform.h @@ -3,7 +3,6 @@ #include #include -#define SerialDBG Serial class Esp32Platform : public ArduinoPlatform { @@ -35,4 +34,4 @@ private: WiFiUDP _udp; }; -#endif \ No newline at end of file +#endif diff --git a/src/esp_platform.cpp b/src/esp_platform.cpp index 2ca2c5e..061b601 100644 --- a/src/esp_platform.cpp +++ b/src/esp_platform.cpp @@ -7,11 +7,11 @@ #include "knx/bits.h" -EspPlatform::EspPlatform() : ArduinoPlatform(Serial) +EspPlatform::EspPlatform() : ArduinoPlatform(&Serial) { } -EspPlatform::EspPlatform( HardwareSerial& s) : ArduinoPlatform(s) +EspPlatform::EspPlatform( HardwareSerial* s) : ArduinoPlatform(s) { } @@ -37,7 +37,7 @@ void EspPlatform::macAddress(uint8_t * addr) void EspPlatform::restart() { - Serial.println("restart"); + ArduinoPlatform::SerialDebug.println("restart"); ESP.reset(); } diff --git a/src/esp_platform.h b/src/esp_platform.h index a9b4670..e0e57de 100644 --- a/src/esp_platform.h +++ b/src/esp_platform.h @@ -3,7 +3,6 @@ #include #include -#define SerialDBG Serial class EspPlatform : public ArduinoPlatform { @@ -36,4 +35,4 @@ private: WiFiUDP _udp; }; -#endif \ No newline at end of file +#endif diff --git a/src/samd_platform.cpp b/src/samd_platform.cpp index 31b1f03..700f34c 100644 --- a/src/samd_platform.cpp +++ b/src/samd_platform.cpp @@ -6,17 +6,17 @@ #include #include -SamdPlatform::SamdPlatform() : ArduinoPlatform(Serial1) +SamdPlatform::SamdPlatform() : ArduinoPlatform(&Serial1) { } -SamdPlatform::SamdPlatform( HardwareSerial& s) : ArduinoPlatform(s) +SamdPlatform::SamdPlatform( HardwareSerial* s) : ArduinoPlatform(s) { } void SamdPlatform::restart() { - SerialDBG.println("restart"); + ArduinoPlatform::SerialDebug.println("restart"); NVIC_SystemReset(); } diff --git a/src/samd_platform.h b/src/samd_platform.h index 7dbc70a..6b45c83 100644 --- a/src/samd_platform.h +++ b/src/samd_platform.h @@ -4,17 +4,15 @@ #ifdef ARDUINO_ARCH_SAMD -#define SerialDBG SerialUSB - class SamdPlatform : public ArduinoPlatform { public: SamdPlatform(); - SamdPlatform( HardwareSerial& s); + SamdPlatform( HardwareSerial* s); void restart(); uint8_t* getEepromBuffer(uint16_t size); void commitToEeprom(); }; -#endif \ No newline at end of file +#endif