mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-09-14 15:16:40 +00:00
refactored companion interfaces to allow for multiple active connection modes
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
#include <helpers/ui/DisplayDriver.h>
|
||||
#include <helpers/ui/UIScreen.h>
|
||||
#include <helpers/SensorManager.h>
|
||||
#include <helpers/BaseSerialInterface.h>
|
||||
#include <helpers/MultiSerialInterface.h>
|
||||
#include <Arduino.h>
|
||||
|
||||
#ifdef PIN_BUZZER
|
||||
@@ -25,10 +25,10 @@ enum class UIEventType {
|
||||
class AbstractUITask {
|
||||
protected:
|
||||
mesh::MainBoard* _board;
|
||||
BaseSerialInterface* _serial;
|
||||
MultiSerialInterface* _interfaceManager;
|
||||
bool _connected;
|
||||
|
||||
AbstractUITask(mesh::MainBoard* board, BaseSerialInterface* serial) : _board(board), _serial(serial) {
|
||||
AbstractUITask(mesh::MainBoard* board, MultiSerialInterface* interfaceManager) : _board(board), _interfaceManager(interfaceManager) {
|
||||
_connected = false;
|
||||
}
|
||||
|
||||
@@ -36,9 +36,9 @@ public:
|
||||
void setHasConnection(bool connected) { _connected = connected; }
|
||||
bool hasConnection() const { return _connected; }
|
||||
uint16_t getBattMilliVolts() const { return _board->getBattMilliVolts(); }
|
||||
bool isSerialEnabled() const { return _serial->isEnabled(); }
|
||||
void enableSerial() { _serial->enable(); }
|
||||
void disableSerial() { _serial->disable(); }
|
||||
bool isBluetoothEnabled() const { return _interfaceManager->isBluetoothEnabled(); }
|
||||
void enableBluetooth() { _interfaceManager->enableBluetooth(); }
|
||||
void disableBluetooth() { _interfaceManager->disableBluetooth(); }
|
||||
virtual void msgRead(int msgcount) = 0;
|
||||
virtual void newMsg(uint8_t path_len, const char* from_name, const char* text, int msgcount) = 0;
|
||||
virtual void notify(UIEventType t = UIEventType::none) = 0;
|
||||
|
||||
@@ -12,6 +12,67 @@ static uint32_t _atoi(const char* sp) {
|
||||
return n;
|
||||
}
|
||||
|
||||
// interface manager
|
||||
#include <helpers/MultiSerialInterface.h>
|
||||
MultiSerialInterface interface_manager;
|
||||
|
||||
// include bluetooth interface
|
||||
#if defined(BLE_PIN_CODE)
|
||||
#ifdef ESP32
|
||||
// include esp32 bluetooth interface
|
||||
#include <helpers/esp32/SerialBLEInterface.h>
|
||||
SerialBLEInterface bluetooth_interface;
|
||||
#elif defined(NRF52_PLATFORM)
|
||||
// include nrf52 bluetooth interface
|
||||
#include <helpers/nrf52/SerialBLEInterface.h>
|
||||
SerialBLEInterface bluetooth_interface;
|
||||
#else
|
||||
#error "SerialBLEInterface is not defined for this platform"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// include wifi interface
|
||||
#ifdef WIFI_SSID
|
||||
#ifndef TCP_PORT
|
||||
#define TCP_PORT 5000
|
||||
#endif
|
||||
#ifdef ESP32
|
||||
// include esp32 wifi interface
|
||||
#include <helpers/esp32/SerialWifiInterface.h>
|
||||
SerialWifiInterface wifi_interface;
|
||||
#else
|
||||
#error "SerialWifiInterface is not defined for this platform"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// include usb interface
|
||||
#if defined(ENABLE_USB_INTERFACE)
|
||||
#include <helpers/ArduinoSerialInterface.h>
|
||||
ArduinoSerialInterface usb_serial_interface;
|
||||
#endif
|
||||
|
||||
// include ethernet interface
|
||||
#if defined(ETHERNET_ENABLED)
|
||||
// todo refactor rak/nrf52 SerialEthernetInterface to new EthernetInterface
|
||||
#if defined(NRF52_PLATFORM)
|
||||
// include nrf52 ethernet interface
|
||||
#include <helpers/nrf52/SerialEthernetInterface.h>
|
||||
SerialEthernetInterface ethernet_interface;
|
||||
#else
|
||||
// include ethernet interface
|
||||
#include <helpers/ethernet/EthernetInterface.h>
|
||||
ETHERNET_CLASS ethernet_interface;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// include hardware serial interface
|
||||
#if defined(SERIAL_RX)
|
||||
#include <helpers/ArduinoSerialInterface.h>
|
||||
ArduinoSerialInterface hardware_serial_interface;
|
||||
HardwareSerial companion_serial(1);
|
||||
#endif
|
||||
|
||||
// platform file system
|
||||
#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
|
||||
#include <InternalFileSystem.h>
|
||||
#if defined(QSPIFLASH)
|
||||
@@ -34,67 +95,10 @@ static uint32_t _atoi(const char* sp) {
|
||||
DataStore store(SPIFFS, rtc_clock);
|
||||
#endif
|
||||
|
||||
#ifdef ESP32
|
||||
#ifdef WIFI_SSID
|
||||
#include <helpers/esp32/SerialWifiInterface.h>
|
||||
SerialWifiInterface serial_interface;
|
||||
#ifndef TCP_PORT
|
||||
#define TCP_PORT 5000
|
||||
#endif
|
||||
#elif defined(BLE_PIN_CODE)
|
||||
#include <helpers/esp32/SerialBLEInterface.h>
|
||||
SerialBLEInterface serial_interface;
|
||||
#elif defined(SERIAL_RX)
|
||||
#include <helpers/ArduinoSerialInterface.h>
|
||||
ArduinoSerialInterface serial_interface;
|
||||
HardwareSerial companion_serial(1);
|
||||
#elif defined(ETHERNET_ENABLED)
|
||||
#include <helpers/ethernet/EthernetInterface.h>
|
||||
ETHERNET_CLASS serial_interface;
|
||||
#else
|
||||
#include <helpers/ArduinoSerialInterface.h>
|
||||
ArduinoSerialInterface serial_interface;
|
||||
#endif
|
||||
#elif defined(RP2040_PLATFORM)
|
||||
//#ifdef WIFI_SSID
|
||||
// #include <helpers/rp2040/SerialWifiInterface.h>
|
||||
// SerialWifiInterface serial_interface;
|
||||
// #ifndef TCP_PORT
|
||||
// #define TCP_PORT 5000
|
||||
// #endif
|
||||
// #elif defined(BLE_PIN_CODE)
|
||||
// #include <helpers/rp2040/SerialBLEInterface.h>
|
||||
// SerialBLEInterface serial_interface;
|
||||
#if defined(SERIAL_RX)
|
||||
#include <helpers/ArduinoSerialInterface.h>
|
||||
ArduinoSerialInterface serial_interface;
|
||||
HardwareSerial companion_serial(1);
|
||||
#else
|
||||
#include <helpers/ArduinoSerialInterface.h>
|
||||
ArduinoSerialInterface serial_interface;
|
||||
#endif
|
||||
#elif defined(NRF52_PLATFORM)
|
||||
#ifdef BLE_PIN_CODE
|
||||
#include <helpers/nrf52/SerialBLEInterface.h>
|
||||
SerialBLEInterface serial_interface;
|
||||
#elif defined(ETHERNET_ENABLED)
|
||||
#include <helpers/nrf52/SerialEthernetInterface.h>
|
||||
SerialEthernetInterface serial_interface;
|
||||
#else
|
||||
#include <helpers/ArduinoSerialInterface.h>
|
||||
ArduinoSerialInterface serial_interface;
|
||||
#endif
|
||||
#elif defined(STM32_PLATFORM)
|
||||
#include <helpers/ArduinoSerialInterface.h>
|
||||
ArduinoSerialInterface serial_interface;
|
||||
#else
|
||||
#error "need to define a serial interface"
|
||||
#endif
|
||||
|
||||
/* GLOBAL OBJECTS */
|
||||
#ifdef DISPLAY_CLASS
|
||||
#include "UITask.h"
|
||||
UITask ui_task(&board, &serial_interface);
|
||||
UITask ui_task(&board, &interface_manager);
|
||||
#endif
|
||||
|
||||
StdRNG fast_rng;
|
||||
@@ -164,26 +168,6 @@ void setup() {
|
||||
false
|
||||
#endif
|
||||
);
|
||||
|
||||
#ifdef BLE_PIN_CODE
|
||||
serial_interface.begin(BLE_NAME_PREFIX, the_mesh.getNodePrefs()->node_name, the_mesh.getBLEPin());
|
||||
the_mesh.startInterface(serial_interface);
|
||||
#elif defined(ETHERNET_ENABLED)
|
||||
Serial.print("Waiting for serial to connect...\n");
|
||||
unsigned long timeout = millis();
|
||||
while (!Serial) {
|
||||
if ((millis() - timeout) < 5000) { delay(100); } else { break; }
|
||||
}
|
||||
Serial.println("Initializing Ethernet adapter...");
|
||||
if (serial_interface.begin()) {
|
||||
the_mesh.startInterface(serial_interface);
|
||||
} else {
|
||||
Serial.println("ETH: Init failed, continuing without Ethernet (mesh only)");
|
||||
}
|
||||
#else
|
||||
serial_interface.begin(Serial);
|
||||
the_mesh.startInterface(serial_interface);
|
||||
#endif
|
||||
#elif defined(RP2040_PLATFORM)
|
||||
LittleFS.begin();
|
||||
store.begin();
|
||||
@@ -194,22 +178,6 @@ void setup() {
|
||||
false
|
||||
#endif
|
||||
);
|
||||
|
||||
//#ifdef WIFI_SSID
|
||||
// WiFi.begin(WIFI_SSID, WIFI_PWD);
|
||||
// serial_interface.begin(TCP_PORT);
|
||||
// #elif defined(BLE_PIN_CODE)
|
||||
// char dev_name[32+16];
|
||||
// sprintf(dev_name, "%s%s", BLE_NAME_PREFIX, the_mesh.getNodeName());
|
||||
// serial_interface.begin(dev_name, the_mesh.getBLEPin());
|
||||
#if defined(SERIAL_RX)
|
||||
companion_serial.setPins(SERIAL_RX, SERIAL_TX);
|
||||
companion_serial.begin(115200);
|
||||
serial_interface.begin(companion_serial);
|
||||
#else
|
||||
serial_interface.begin(Serial);
|
||||
#endif
|
||||
the_mesh.startInterface(serial_interface);
|
||||
#elif defined(ESP32)
|
||||
SPIFFS.begin(true);
|
||||
store.begin();
|
||||
@@ -220,7 +188,17 @@ void setup() {
|
||||
false
|
||||
#endif
|
||||
);
|
||||
#else
|
||||
#error "need to define filesystem"
|
||||
#endif
|
||||
|
||||
// add bluetooth interface
|
||||
#if defined(BLE_PIN_CODE)
|
||||
bluetooth_interface.begin(BLE_NAME_PREFIX, the_mesh.getNodePrefs()->node_name, the_mesh.getBLEPin());
|
||||
interface_manager.addInterface(InterfaceType::Bluetooth, &bluetooth_interface);
|
||||
#endif
|
||||
|
||||
// add wifi interface
|
||||
#ifdef WIFI_SSID
|
||||
board.setInhibitSleep(true); // prevent sleep when WiFi is active
|
||||
WiFi.setAutoReconnect(true);
|
||||
@@ -236,23 +214,31 @@ void setup() {
|
||||
});
|
||||
|
||||
WiFi.begin(WIFI_SSID, WIFI_PWD);
|
||||
serial_interface.begin(TCP_PORT);
|
||||
#elif defined(BLE_PIN_CODE)
|
||||
serial_interface.begin(BLE_NAME_PREFIX, the_mesh.getNodePrefs()->node_name, the_mesh.getBLEPin());
|
||||
#elif defined(SERIAL_RX)
|
||||
companion_serial.setPins(SERIAL_RX, SERIAL_TX);
|
||||
companion_serial.begin(115200);
|
||||
serial_interface.begin(companion_serial);
|
||||
#elif defined(ETHERNET_ENABLED)
|
||||
serial_interface.begin();
|
||||
#else
|
||||
serial_interface.begin(Serial);
|
||||
#endif
|
||||
the_mesh.startInterface(serial_interface);
|
||||
#else
|
||||
#error "need to define filesystem"
|
||||
wifi_interface.begin(TCP_PORT);
|
||||
interface_manager.addInterface(InterfaceType::WiFi, &wifi_interface);
|
||||
#endif
|
||||
|
||||
// add usb interface
|
||||
#if defined(ENABLE_USB_INTERFACE)
|
||||
usb_serial_interface.begin(Serial);
|
||||
interface_manager.addInterface(InterfaceType::USB, &usb_serial_interface);
|
||||
#endif
|
||||
|
||||
// add ethernet interface
|
||||
#if defined(ETHERNET_ENABLED)
|
||||
ethernet_interface.begin();
|
||||
interface_manager.addInterface(InterfaceType::Ethernet, ðernet_interface);
|
||||
#endif
|
||||
|
||||
// add hardware serial interface
|
||||
#if defined(SERIAL_RX)
|
||||
companion_serial.setPins(SERIAL_RX, SERIAL_TX);
|
||||
companion_serial.begin(115200);
|
||||
hardware_serial_interface.begin(companion_serial);
|
||||
interface_manager.addInterface(InterfaceType::HardwareSerial, &hardware_serial_interface);
|
||||
#endif
|
||||
|
||||
the_mesh.startInterface(interface_manager);
|
||||
sensors.begin();
|
||||
|
||||
#if ENV_INCLUDE_GPS == 1
|
||||
@@ -268,6 +254,7 @@ void setup() {
|
||||
|
||||
void loop() {
|
||||
the_mesh.loop();
|
||||
interface_manager.loop();
|
||||
sensors.loop();
|
||||
#ifdef DISPLAY_CLASS
|
||||
ui_task.loop();
|
||||
@@ -277,10 +264,6 @@ void loop() {
|
||||
external_watchdog.loop();
|
||||
#endif
|
||||
|
||||
#ifdef ETHERNET_ENABLED
|
||||
serial_interface.loop();
|
||||
#endif
|
||||
|
||||
if (!the_mesh.hasPendingWork()) {
|
||||
#if defined(NRF52_PLATFORM)
|
||||
board.sleep(0); // nrf ignores seconds param, sleeps whenever possible
|
||||
|
||||
@@ -289,7 +289,7 @@ public:
|
||||
} else if (_page == HomePage::BLUETOOTH) {
|
||||
display.setColor(UIColor::corp_blue);
|
||||
display.drawXbm((display.width() - 32) / 2, 18,
|
||||
_task->isSerialEnabled() ? bluetooth_on : bluetooth_off,
|
||||
_task->isBluetoothEnabled() ? bluetooth_on : bluetooth_off,
|
||||
32, 32);
|
||||
display.setColor(UIColor::secondary_txt);
|
||||
display.setTextSize(1);
|
||||
@@ -449,10 +449,10 @@ public:
|
||||
return true;
|
||||
}
|
||||
if (c == KEY_ENTER && _page == HomePage::BLUETOOTH) {
|
||||
if (_task->isSerialEnabled()) { // toggle Bluetooth on/off
|
||||
_task->disableSerial();
|
||||
if (_task->isBluetoothEnabled()) { // toggle Bluetooth on/off
|
||||
_task->disableBluetooth();
|
||||
} else {
|
||||
_task->enableSerial();
|
||||
_task->enableBluetooth();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <helpers/ui/DisplayDriver.h>
|
||||
#include <helpers/ui/UIScreen.h>
|
||||
#include <helpers/SensorManager.h>
|
||||
#include <helpers/BaseSerialInterface.h>
|
||||
#include <helpers/MultiSerialInterface.h>
|
||||
#include <Arduino.h>
|
||||
#include <helpers/sensors/LPPDataHelpers.h>
|
||||
|
||||
@@ -65,7 +65,7 @@ class UITask : public AbstractUITask {
|
||||
|
||||
public:
|
||||
|
||||
UITask(mesh::MainBoard* board, BaseSerialInterface* serial) : AbstractUITask(board, serial), _display(NULL), _sensors(NULL) {
|
||||
UITask(mesh::MainBoard* board, MultiSerialInterface* serial) : AbstractUITask(board, serial), _display(NULL), _sensors(NULL) {
|
||||
next_batt_chck = _next_refresh = 0;
|
||||
ui_started_at = 0;
|
||||
curr = NULL;
|
||||
|
||||
@@ -54,7 +54,7 @@ class UITask : public AbstractUITask {
|
||||
|
||||
public:
|
||||
|
||||
UITask(mesh::MainBoard* board, BaseSerialInterface* serial) : AbstractUITask(board, serial), _display(NULL), _sensors(NULL) {
|
||||
UITask(mesh::MainBoard* board, MultiSerialInterface* serial) : AbstractUITask(board, serial), _display(NULL), _sensors(NULL) {
|
||||
_next_refresh = 0;
|
||||
ui_started_at = 0;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <helpers/ui/DisplayDriver.h>
|
||||
#include <helpers/ui/UIScreen.h>
|
||||
#include <helpers/SensorManager.h>
|
||||
#include <helpers/BaseSerialInterface.h>
|
||||
#include <helpers/MultiSerialInterface.h>
|
||||
#include <Arduino.h>
|
||||
#include <helpers/sensors/LPPDataHelpers.h>
|
||||
|
||||
@@ -71,7 +71,7 @@ class UITask : public AbstractUITask {
|
||||
|
||||
public:
|
||||
|
||||
UITask(mesh::MainBoard* board, BaseSerialInterface* serial) : AbstractUITask(board, serial), _display(NULL), _sensors(NULL) {
|
||||
UITask(mesh::MainBoard* board, MultiSerialInterface* serial) : AbstractUITask(board, serial), _display(NULL), _sensors(NULL) {
|
||||
next_batt_chck = _next_refresh = 0;
|
||||
_cached_batt_mv = 0;
|
||||
ui_started_at = 0;
|
||||
|
||||
Reference in New Issue
Block a user