From 17db87e042ed1e1fb5d8af9ea1b75d970ed4cd9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Mon, 12 Sep 2022 10:08:32 +0200 Subject: [PATCH] implement #1542 --- src/modules/Modules.cpp | 2 +- src/modules/{esp32 => }/SerialModule.cpp | 20 +++++++++++++------- src/modules/{esp32 => }/SerialModule.h | 0 3 files changed, 14 insertions(+), 8 deletions(-) rename src/modules/{esp32 => }/SerialModule.cpp (94%) rename src/modules/{esp32 => }/SerialModule.h (100%) diff --git a/src/modules/Modules.cpp b/src/modules/Modules.cpp index a049651b..9d36116b 100644 --- a/src/modules/Modules.cpp +++ b/src/modules/Modules.cpp @@ -19,11 +19,11 @@ #endif #ifdef ARCH_ESP32 #include "modules/esp32/RangeTestModule.h" -#include "modules/esp32/SerialModule.h" #include "modules/esp32/StoreForwardModule.h" #endif #if defined(ARCH_ESP32) || defined(ARCH_NRF52) #include "modules/ExternalNotificationModule.h" +#include "modules/SerialModule.h" #endif /** * Create module instances here. If you are adding a new module, you must 'new' it here (or somewhere else) diff --git a/src/modules/esp32/SerialModule.cpp b/src/modules/SerialModule.cpp similarity index 94% rename from src/modules/esp32/SerialModule.cpp rename to src/modules/SerialModule.cpp index 0a7f4f68..f88ad659 100644 --- a/src/modules/esp32/SerialModule.cpp +++ b/src/modules/SerialModule.cpp @@ -69,8 +69,7 @@ SerialModuleRadio::SerialModuleRadio() : SinglePortModule("SerialModuleRadio", P int32_t SerialModule::runOnce() { -#ifdef ARCH_ESP32 - +#if defined(ARCH_ESP32) || defined(ARCH_NRF52) /* Uncomment the preferences below if you want to use the module without having to configure it from the PythonAPI or WebUI. @@ -140,22 +139,29 @@ int32_t SerialModule::runOnce() baud = 921600; } +#ifdef ARCH_ESP32 if (moduleConfig.serial.rxd && moduleConfig.serial.txd) { Serial2.begin(baud, SERIAL_8N1, moduleConfig.serial.rxd, moduleConfig.serial.txd); } else { Serial2.begin(baud, SERIAL_8N1, RXD2, TXD2); } +#else + if (moduleConfig.serial.rxd && moduleConfig.serial.txd) + Serial2.setPins(moduleConfig.serial.rxd, moduleConfig.serial.txd); + Serial2.begin(baud, SERIAL_8N1); + +#endif if (moduleConfig.serial.timeout) { - Serial2.setTimeout( - moduleConfig.serial.timeout); // Number of MS to wait to set the timeout for the string. - + Serial2.setTimeout(moduleConfig.serial.timeout); // Number of MS to wait to set the timeout for the string. } else { Serial2.setTimeout(TIMEOUT); // Number of MS to wait to set the timeout for the string. } +#ifdef ARCH_ESP32 Serial2.setRxBufferSize(RX_BUFFER); +#endif serialModuleRadio = new SerialModuleRadio(); @@ -209,8 +215,7 @@ void SerialModuleRadio::sendPayload(NodeNum dest, bool wantReplies) ProcessMessage SerialModuleRadio::handleReceived(const MeshPacket &mp) { -#ifdef ARCH_ESP32 - +#if defined(ARCH_ESP32) || defined(ARCH_NRF52) if (moduleConfig.serial.enabled) { auto &p = mp.decoded; @@ -244,6 +249,7 @@ ProcessMessage SerialModuleRadio::handleReceived(const MeshPacket &mp) Serial2.printf("%s", p.payload.bytes); } else if (moduleConfig.serial.mode == ModuleConfig_SerialConfig_Serial_Mode_PROTO) { + // TODO this needs to be implemented } } diff --git a/src/modules/esp32/SerialModule.h b/src/modules/SerialModule.h similarity index 100% rename from src/modules/esp32/SerialModule.h rename to src/modules/SerialModule.h