diff --git a/examples/simple_repeater/MyMesh.cpp b/examples/simple_repeater/MyMesh.cpp index f310a2fe..4265ca6a 100644 --- a/examples/simple_repeater/MyMesh.cpp +++ b/examples/simple_repeater/MyMesh.cpp @@ -208,7 +208,7 @@ void MyMesh::logRx(mesh::Packet *pkt, int len, float score) { void MyMesh::logTx(mesh::Packet *pkt, int len) { #ifdef WITH_BRIDGE - bridge->onPacketTransmitted(pkt); + bridge.onPacketTransmitted(pkt); #endif if (_logging) { File f = openAppend(PACKET_LOG_FILE); @@ -473,16 +473,13 @@ bool MyMesh::onPeerPathRecv(mesh::Packet *packet, int sender_idx, const uint8_t MyMesh::MyMesh(mesh::MainBoard &board, mesh::Radio &radio, mesh::MillisecondClock &ms, mesh::RNG &rng, mesh::RTCClock &rtc, mesh::MeshTables &tables) : mesh::Mesh(radio, ms, rng, rtc, *new StaticPoolPacketManager(32), tables), - _cli(board, rtc, &_prefs, this), telemetry(MAX_PACKET_PAYLOAD - 4) { -#ifdef WITH_BRIDGE + _cli(board, rtc, &_prefs, this), telemetry(MAX_PACKET_PAYLOAD - 4) #if defined(WITH_RS232_BRIDGE) - bridge = new RS232Bridge(WITH_RS232_BRIDGE, _mgr, &rtc); + , bridge(WITH_RS232_BRIDGE, _mgr, &rtc) #elif defined(WITH_ESPNOW_BRIDGE) - bridge = new ESPNowBridge(_mgr, &rtc); -#else -#error "You must choose either RS232 or ESPNow bridge" -#endif + , bridge(_mgr, &rtc) #endif +{ memset(known_clients, 0, sizeof(known_clients)); next_local_advert = next_flood_advert = 0; set_radio_at = revert_radio_at = 0; @@ -518,6 +515,10 @@ void MyMesh::begin(FILESYSTEM *fs) { // load persisted prefs _cli.loadPrefs(_fs); +#ifdef WITH_BRIDGE + bridge.begin(); +#endif + radio_set_params(_prefs.freq, _prefs.bw, _prefs.sf, _prefs.cr); radio_set_tx_power(_prefs.tx_power_dbm); @@ -668,7 +669,7 @@ void MyMesh::handleCommand(uint32_t sender_timestamp, char *command, char *reply void MyMesh::loop() { #ifdef WITH_BRIDGE - bridge->loop(); + bridge.loop(); #endif mesh::Mesh::loop(); diff --git a/examples/simple_repeater/MyMesh.h b/examples/simple_repeater/MyMesh.h index d315f58b..06e7ebe4 100644 --- a/examples/simple_repeater/MyMesh.h +++ b/examples/simple_repeater/MyMesh.h @@ -102,6 +102,11 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks { uint8_t pending_sf; uint8_t pending_cr; int matching_peer_indexes[MAX_CLIENTS]; +#if defined(WITH_RS232_BRIDGE) + RS232Bridge bridge; +#elif defined(WITH_ESPNOW_BRIDGE) + ESPNowBridge bridge; +#endif ClientInfo* putClient(const mesh::Identity& id); void putNeighbour(const mesh::Identity& id, uint32_t timestamp, float snr); diff --git a/examples/simple_repeater/main.cpp b/examples/simple_repeater/main.cpp index 08c0e875..7db0e7d4 100644 --- a/examples/simple_repeater/main.cpp +++ b/examples/simple_repeater/main.cpp @@ -8,10 +8,6 @@ static UITask ui_task(display); #endif -#ifdef WITH_BRIDGE -AbstractBridge* bridge; -#endif - StdRNG fast_rng; SimpleMeshTables tables; @@ -27,10 +23,6 @@ void setup() { Serial.begin(115200); delay(1000); -#ifdef WITH_BRIDGE - bridge->begin(); -#endif - board.begin(); #ifdef DISPLAY_CLASS