Skip to content

Commit a0d50f9

Browse files
committed
ESP-NOW: Move COMPILE_ESPNOW conditionals into Developer.ino
1 parent 391e7fc commit a0d50f9

File tree

2 files changed

+24
-41
lines changed

2 files changed

+24
-41
lines changed

Firmware/RTK_Everywhere/Developer.ino

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,31 @@ bool parseIncomingSettings() {return false;}
162162
void sendStringToWebsocket(const char* stringToSend) {}
163163

164164
#endif // COMPILE_AP
165-
#ifndef COMPILE_WIFI
165+
166+
//----------------------------------------
167+
// ESP-NOW
168+
//----------------------------------------
169+
170+
#ifndef COMPILE_ESPNOW
171+
172+
bool espnowIsPaired() {return false;}
173+
void espnowProcessRTCM(byte incoming) {}
174+
esp_err_t espnowRemovePeer(uint8_t *peerMac) {return ESP_OK;}
175+
esp_err_t espnowSendPairMessage(uint8_t *sendToMac) {return ESP_OK;}
176+
bool espnowSetChannel(uint8_t channelNumber) {return false;}
177+
void espnowStart() {}
178+
void espnowStaticPairing() {}
179+
void espnowStop() {}
180+
void updateEspnow() {}
181+
182+
#endif // COMPILE_ESPNOW
166183

167184
//----------------------------------------
168185
// WiFi
169186
//----------------------------------------
170187

188+
#ifndef COMPILE_WIFI
189+
171190
void menuWiFi() {systemPrintln("**WiFi not compiled**");}
172191
bool wifiConnect(bool startWiFiStation, bool startWiFiAP, unsigned long timeout) {return false;}
173192
bool wifiStart() {return false;}

Firmware/RTK_Everywhere/ESPNOW.ino

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
few seconds so a single dropped frame is not critical.
1414
*/
1515

16+
#ifdef COMPILE_ESPNOW
17+
1618
// Called from main loop
1719
// Control incoming/outgoing RTCM data from internal ESP NOW radio
1820
// Use the ESP32 to directly transmit/receive RTCM over 2.4GHz (no WiFi needed)
1921
void updateEspnow()
2022
{
21-
#ifdef COMPILE_ESPNOW
2223
if (settings.enableEspNow == true)
2324
{
2425
if (espnowState == ESPNOW_PAIRED || espnowState == ESPNOW_BROADCASTING)
@@ -51,7 +52,6 @@ void updateEspnow()
5152
espnowRSSI = -255;
5253
}
5354
}
54-
#endif // COMPILE_ESPNOW
5555
}
5656

5757
// Create a struct for ESP NOW pairing
@@ -64,7 +64,6 @@ typedef struct PairMessage
6464
} PairMessage;
6565

6666
// Callback when data is sent
67-
#ifdef COMPILE_ESPNOW
6867
void espnowOnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status)
6968
{
7069
// systemPrint("Last Packet Send Status: ");
@@ -73,16 +72,10 @@ void espnowOnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status)
7372
// else
7473
// systemPrintln("Delivery Fail");
7574
}
76-
#endif // COMPILE_ESPNOW
77-
78-
#ifndef COMPILE_ESPNOW
79-
#define esp_now_recv_info uint8_t
80-
#endif
8175

8276
// Callback when data is received
8377
void espnowOnDataReceived(const esp_now_recv_info *mac, const uint8_t *incomingData, int len)
8478
{
85-
#ifdef COMPILE_ESPNOW
8679
if (espnowState == ESPNOW_PAIRING)
8780
{
8881
if (len == sizeof(PairMessage)) // First error check
@@ -127,7 +120,6 @@ void espnowOnDataReceived(const esp_now_recv_info *mac, const uint8_t *incomingD
127120
espnowIncomingRTCM = true; // Display a download icon
128121
lastEspnowRssiUpdate = millis();
129122
}
130-
#endif // COMPILE_ESPNOW
131123
}
132124

133125
// Callback for all RX Packets
@@ -154,8 +146,6 @@ void espnowStart()
154146
return;
155147
}
156148

157-
#ifdef COMPILE_ESPNOW
158-
159149
// Before we can issue esp_wifi_() commands WiFi must be started
160150
if (WiFi.getMode() != WIFI_STA)
161151
WiFi.mode(WIFI_STA);
@@ -298,14 +288,12 @@ void espnowStart()
298288
}
299289

300290
systemPrintln("ESP-Now Started");
301-
#endif // COMPILE_ESPNOW
302291
}
303292

304293
// If WiFi is already enabled, simply remove the LR protocol
305294
// If WiFi is off, stop the radio entirely
306295
void espnowStop()
307296
{
308-
#ifdef COMPILE_ESPNOW
309297
if (espnowState == ESPNOW_OFF)
310298
return;
311299

@@ -377,8 +365,6 @@ void espnowStop()
377365
systemPrintln("ESP-Now starting WiFi");
378366
wifiStart(); // Force WiFi to restart
379367
}
380-
381-
#endif // COMPILE_ESPNOW
382368
}
383369

384370
// Start ESP-Now if needed, put ESP-Now into broadcast state
@@ -396,7 +382,6 @@ void espnowBeginPairing()
396382
// Regularly call during pairing to see if we've received a Pairing message
397383
bool espnowIsPaired()
398384
{
399-
#ifdef COMPILE_ESPNOW
400385
if (espnowState == ESPNOW_MAC_RECEIVED)
401386
{
402387
// Remove broadcast peer
@@ -430,14 +415,12 @@ bool espnowIsPaired()
430415
espnowSetState(ESPNOW_PAIRED);
431416
return (true);
432417
}
433-
#endif // COMPILE_ESPNOW
434418
return (false);
435419
}
436420

437421
// Create special pair packet to a given MAC
438422
esp_err_t espnowSendPairMessage(uint8_t *sendToMac)
439423
{
440-
#ifdef COMPILE_ESPNOW
441424
// Assemble message to send
442425
PairMessage pairMessage;
443426

@@ -451,9 +434,6 @@ esp_err_t espnowSendPairMessage(uint8_t *sendToMac)
451434
pairMessage.crc += wifiMACAddress[x];
452435

453436
return (esp_now_send(sendToMac, (uint8_t *)&pairMessage, sizeof(pairMessage))); // Send packet to given MAC
454-
#else // COMPILE_ESPNOW
455-
return (ESP_OK);
456-
#endif // COMPILE_ESPNOW
457437
}
458438

459439
// Add a given MAC address to the peer list
@@ -464,7 +444,6 @@ esp_err_t espnowAddPeer(uint8_t *peerMac)
464444

465445
esp_err_t espnowAddPeer(uint8_t *peerMac, bool encrypt)
466446
{
467-
#ifdef COMPILE_ESPNOW
468447
esp_now_peer_info_t peerInfo;
469448

470449
memcpy(peerInfo.peer_addr, peerMac, 6);
@@ -482,15 +461,11 @@ esp_err_t espnowAddPeer(uint8_t *peerMac, bool encrypt)
482461
peerMac[3], peerMac[4], peerMac[5]);
483462
}
484463
return (result);
485-
#else // COMPILE_ESPNOW
486-
return (ESP_OK);
487-
#endif // COMPILE_ESPNOW
488464
}
489465

490466
// Remove a given MAC address from the peer list
491467
esp_err_t espnowRemovePeer(uint8_t *peerMac)
492468
{
493-
#ifdef COMPILE_ESPNOW
494469
esp_err_t response = esp_now_del_peer(peerMac);
495470
if (response != ESP_OK)
496471
{
@@ -499,9 +474,6 @@ esp_err_t espnowRemovePeer(uint8_t *peerMac)
499474
}
500475

501476
return (response);
502-
#else // COMPILE_ESPNOW
503-
return (ESP_OK);
504-
#endif // COMPILE_ESPNOW
505477
}
506478

507479
// Update the state of the ESP Now state machine
@@ -540,7 +512,6 @@ void espnowSetState(ESPNOWState newState)
540512

541513
void espnowProcessRTCM(byte incoming)
542514
{
543-
#ifdef COMPILE_ESPNOW
544515
// If we are paired,
545516
// Or if the radio is broadcasting
546517
// Then add bytes to the outgoing buffer
@@ -571,7 +542,6 @@ void espnowProcessRTCM(byte incoming)
571542

572543
espnowOutgoingRTCM = true;
573544
}
574-
#endif // COMPILE_ESPNOW
575545
}
576546

577547
// A blocking function that is used to pair two devices
@@ -622,7 +592,6 @@ void espnowStaticPairing()
622592
// Returns the current channel being used by WiFi
623593
uint8_t espnowGetChannel()
624594
{
625-
#ifdef COMPILE_ESPNOW
626595
if (espnowState == ESPNOW_OFF)
627596
return 0;
628597

@@ -647,15 +616,11 @@ uint8_t espnowGetChannel()
647616
esp_wifi_set_promiscuous(false);
648617

649618
return (primaryChannelNumber);
650-
#else
651-
return (0);
652-
#endif
653619
}
654620

655621
// Returns the current channel being used by WiFi
656622
bool espnowSetChannel(uint8_t channelNumber)
657623
{
658-
#ifdef COMPILE_ESPNOW
659624
if (wifiIsConnected() == true)
660625
{
661626
systemPrintln("ESP-NOW channel can't be modified while WiFi is connected.");
@@ -683,7 +648,6 @@ bool espnowSetChannel(uint8_t channelNumber)
683648
esp_wifi_set_promiscuous(false);
684649

685650
return (setSuccess);
686-
#else
687-
return (false);
688-
#endif
689651
}
652+
653+
#endif // COMPILE_ESPNOW

0 commit comments

Comments
 (0)