Skip to content

Commit 0f042e0

Browse files
authored
Merge pull request #775 from LeeLeahy2/no-bluetooth
Bluetooth: Reduce use of COMPILE_BT conditionals
2 parents 0eb59c3 + f382343 commit 0f042e0

File tree

3 files changed

+28
-71
lines changed

3 files changed

+28
-71
lines changed

Firmware/RTK_Everywhere/Bluetooth.ino

Lines changed: 3 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,14 @@
1919
2020
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2121

22-
//----------------------------------------
23-
// Constants
24-
//----------------------------------------
22+
#ifdef COMPILE_BT
2523

2624
//----------------------------------------
2725
// Locals - compiled out
2826
//----------------------------------------
2927

3028
static volatile BTState bluetoothState = BT_OFF;
3129

32-
BluetoothRadioType_e bluetoothRadioPreviousOnType = BLUETOOTH_RADIO_OFF;
33-
34-
#ifdef COMPILE_BT
35-
3630
#include <BleBatteryService.h>
3731

3832
BTSerialInterface *bluetoothSerialSpp = nullptr;
@@ -50,16 +44,13 @@ BleBatteryService bluetoothBatteryService;
5044

5145
TaskHandle_t bluetoothCommandTaskHandle = nullptr; // Task to monitor incoming CLI from BLE
5246

53-
#endif // COMPILE_BT
54-
5547
//----------------------------------------
5648
// Global Bluetooth Routines
5749
//----------------------------------------
5850

5951
// Check if Bluetooth is connected
6052
void bluetoothUpdate()
6153
{
62-
#ifdef COMPILE_BT
6354
static uint32_t lastCheck = millis(); // Check if connected every 100ms
6455
if ((millis() - lastCheck) > 100)
6556
{
@@ -95,14 +86,12 @@ void bluetoothUpdate()
9586
bluetoothState = BT_NOTCONNECTED;
9687
}
9788
}
98-
#endif // COMPILE_BT
9989
}
10090

10191
// Test each interface to see if there is a connection
10292
// Return true if one is
10393
bool bluetoothIsConnected()
10494
{
105-
#ifdef COMPILE_BT
10695
if (bluetoothGetState() == BT_OFF)
10796
return (false);
10897

@@ -127,15 +116,13 @@ bool bluetoothIsConnected()
127116
if (bluetoothSerialSpp->connected() == true)
128117
return (true);
129118
}
130-
#endif // COMPILE_BT
131119

132120
return (false);
133121
}
134122

135123
// Return true if the BLE Command channel is connected
136124
bool bluetoothCommandIsConnected()
137125
{
138-
#ifdef COMPILE_BT
139126
if (bluetoothGetState() == BT_OFF)
140127
return (false);
141128

@@ -157,25 +144,19 @@ bool bluetoothCommandIsConnected()
157144
{
158145
return (false);
159146
}
160-
#endif // COMPILE_BT
161147

162148
return (false);
163149
}
164150

165151
// Return the Bluetooth state
166152
byte bluetoothGetState()
167153
{
168-
#ifdef COMPILE_BT
169154
return bluetoothState;
170-
#else // COMPILE_BT
171-
return BT_OFF;
172-
#endif // COMPILE_BT
173155
}
174156

175157
// Read data from the Bluetooth device
176158
int bluetoothRead(uint8_t *buffer, int length)
177159
{
178-
#ifdef COMPILE_BT
179160
if (bluetoothGetState() == BT_OFF)
180161
return 0;
181162

@@ -201,16 +182,11 @@ int bluetoothRead(uint8_t *buffer, int length)
201182
return 0; // Nothing to do here. SDP takes care of everything...
202183

203184
return 0;
204-
205-
#else // COMPILE_BT
206-
return 0;
207-
#endif // COMPILE_BT
208185
}
209186

210187
// Read data from the Bluetooth command interface
211188
int bluetoothCommandRead(uint8_t *buffer, int length)
212189
{
213-
#ifdef COMPILE_BT
214190
if (settings.bluetoothRadioType == BLUETOOTH_RADIO_SPP_AND_BLE ||
215191
settings.bluetoothRadioType == BLUETOOTH_RADIO_BLE)
216192
{
@@ -219,15 +195,11 @@ int bluetoothCommandRead(uint8_t *buffer, int length)
219195
}
220196

221197
return 0;
222-
#else // COMPILE_BT
223-
return 0;
224-
#endif // COMPILE_BT
225198
}
226199

227200
// Read data from the Bluetooth device
228201
uint8_t bluetoothRead()
229202
{
230-
#ifdef COMPILE_BT
231203
if (bluetoothGetState() == BT_OFF)
232204
return 0;
233205

@@ -247,28 +219,20 @@ uint8_t bluetoothRead()
247219
return 0; // Nothing to do here. SDP takes care of everything...
248220

249221
return 0;
250-
#else // COMPILE_BT
251-
return 0;
252-
#endif // COMPILE_BT
253222
}
254223

255224
// Read data from the BLE Command interface
256225
uint8_t bluetoothCommandRead()
257226
{
258-
#ifdef COMPILE_BT
259227
if (settings.bluetoothRadioType == BLUETOOTH_RADIO_SPP_AND_BLE ||
260228
settings.bluetoothRadioType == BLUETOOTH_RADIO_BLE)
261229
return bluetoothSerialBleCommands->read();
262230
return (0);
263-
#else // COMPILE_BT
264-
return 0;
265-
#endif // COMPILE_BT
266231
}
267232

268233
// Determine if data is available
269234
int bluetoothRxDataAvailable()
270235
{
271-
#ifdef COMPILE_BT
272236
if (bluetoothGetState() == BT_OFF)
273237
return 0;
274238

@@ -288,28 +252,20 @@ int bluetoothRxDataAvailable()
288252
return 0; // Nothing to do here. SDP takes care of everything...
289253

290254
return (0);
291-
#else // COMPILE_BT
292-
return 0;
293-
#endif // COMPILE_BT
294255
}
295256

296257
// Determine if data is available on the BLE Command interface
297258
int bluetoothCommandAvailable()
298259
{
299-
#ifdef COMPILE_BT
300260
if (settings.bluetoothRadioType == BLUETOOTH_RADIO_SPP_AND_BLE ||
301261
settings.bluetoothRadioType == BLUETOOTH_RADIO_BLE)
302262
return bluetoothSerialBleCommands->available();
303263
return (0);
304-
#else // COMPILE_BT
305-
return 0;
306-
#endif // COMPILE_BT
307264
}
308265

309266
// Write data to the Bluetooth device
310267
int bluetoothWrite(const uint8_t *buffer, int length)
311268
{
312-
#ifdef COMPILE_BT
313269
if (bluetoothGetState() == BT_OFF)
314270
return length; // Avoid buffer full warnings
315271

@@ -341,15 +297,11 @@ int bluetoothWrite(const uint8_t *buffer, int length)
341297
return length; // Nothing to do here. SDP takes care of everything...
342298

343299
return (0);
344-
#else // COMPILE_BT
345-
return 0;
346-
#endif // COMPILE_BT
347300
}
348301

349302
// Write data to the BLE Command interface
350303
int bluetoothCommandWrite(const uint8_t *buffer, int length)
351304
{
352-
#ifdef COMPILE_BT
353305
if (settings.bluetoothRadioType == BLUETOOTH_RADIO_SPP_AND_BLE)
354306
{
355307
return (bluetoothSerialBleCommands->write(buffer, length));
@@ -370,15 +322,11 @@ int bluetoothCommandWrite(const uint8_t *buffer, int length)
370322
return length; // Nothing to do here. SDP takes care of everything...
371323

372324
return (0);
373-
#else // COMPILE_BT
374-
return 0;
375-
#endif // COMPILE_BT
376325
}
377326

378327
// Write data to the Bluetooth device
379328
int bluetoothWrite(uint8_t value)
380329
{
381-
#ifdef COMPILE_BT
382330
if (bluetoothGetState() == BT_OFF)
383331
return 1; // Avoid buffer full warnings
384332

@@ -407,15 +355,11 @@ int bluetoothWrite(uint8_t value)
407355
return 1; // Nothing to do here. SDP takes care of everything...
408356

409357
return (0);
410-
#else // COMPILE_BT
411-
return 0;
412-
#endif // COMPILE_BT
413358
}
414359

415360
// Flush Bluetooth device
416361
void bluetoothFlush()
417362
{
418-
#ifdef COMPILE_BT
419363
if (bluetoothGetState() == BT_OFF)
420364
return;
421365

@@ -434,9 +378,6 @@ void bluetoothFlush()
434378
}
435379
else if (settings.bluetoothRadioType == BLUETOOTH_RADIO_SPP_ACCESSORY_MODE)
436380
bluetoothSerialSpp->flush(); // Needed? Not sure... TODO
437-
#else // COMPILE_BT
438-
return;
439-
#endif // COMPILE_BT
440381
}
441382

442383
void BTConfirmRequestCallback(uint32_t numVal) {
@@ -445,9 +386,7 @@ void BTConfirmRequestCallback(uint32_t numVal) {
445386

446387
// TODO: if the RTK device has an OLED, we should display the PIN so user can confirm
447388
systemPrintf("Device sent PIN: %06lu. Sending confirmation\r\n", numVal);
448-
#ifdef COMPILE_BT
449389
bluetoothSerialSpp->confirmReply(true); // AUTO_PAIR - equivalent to enableSSP(false, true);
450-
#endif // COMPILE_BT
451390
}
452391

453392
void deviceNameSpacesToUnderscores()
@@ -492,7 +431,6 @@ void bluetoothStart(bool skipOnlineCheck)
492431
}
493432
}
494433

495-
#ifdef COMPILE_BT
496434
{ // Maintain the indentation for now. TODO: delete the braces and correct indentation
497435
bluetoothState = BT_OFF; // Indicate to tasks that BT is unavailable
498436

@@ -758,14 +696,12 @@ void bluetoothStart(bool skipOnlineCheck)
758696
online.bluetooth = true;
759697
bluetoothRadioPreviousOnType = settings.bluetoothRadioType;
760698
} // if (1)
761-
#endif // COMPILE_BT
762699
}
763700

764701
// Assign Bluetooth interrupts to the core that started the task. See:
765702
// https://github.com/espressif/arduino-esp32/issues/3386
766703
// void pinBluetoothTask(void *pvParameters)
767704
// {
768-
// #ifdef COMPILE_BT
769705
// if (bluetoothSerial->begin(deviceName, false, settings.sppRxQueueSize, settings.sppTxQueueSize) ==
770706
// false) // localName, isMaster, rxBufferSize,
771707
// {
@@ -777,13 +713,11 @@ void bluetoothStart(bool skipOnlineCheck)
777713
// bluetoothPinned = true;
778714

779715
// vTaskDelete(nullptr); // Delete task once it has run once
780-
// #endif // COMPILE_BT
781716
// }
782717

783718
// This function stops BT so that it can be restarted later
784719
void bluetoothStop()
785720
{
786-
#ifdef COMPILE_BT
787721
if (online.bluetooth)
788722
{
789723
if (settings.debugNetworkLayer)
@@ -868,7 +802,6 @@ void bluetoothStop()
868802
reportHeapNow(false);
869803
online.bluetooth = false;
870804
}
871-
#endif // COMPILE_BT
872805
bluetoothIncomingRTCM = false;
873806
}
874807

@@ -908,7 +841,6 @@ void bluetoothPrintStatus()
908841
// Send over dedicated BLE service
909842
void bluetoothSendBatteryPercent(int batteryLevelPercent)
910843
{
911-
#ifdef COMPILE_BT
912844
if (bluetoothGetState() == BT_OFF)
913845
return;
914846

@@ -917,5 +849,6 @@ void bluetoothSendBatteryPercent(int batteryLevelPercent)
917849
return;
918850

919851
bluetoothBatteryService.reportBatteryPercent(batteryLevelPercent);
852+
}
853+
920854
#endif // COMPILE_BT
921-
}

Firmware/RTK_Everywhere/Developer.ino

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,28 @@ bool webServerIsRunning() {return false;}
183183

184184
#endif // COMPILE_AP
185185

186+
//----------------------------------------
187+
// Global Bluetooth Routines
188+
//----------------------------------------
189+
190+
#ifndef COMPILE_BT
191+
int bluetoothCommandAvailable() {return 0;}
192+
bool bluetoothCommandIsConnected() {return false;}
193+
uint8_t bluetoothCommandRead() {return 0;}
194+
int bluetoothCommandWrite(const uint8_t *buffer, int length) {return 0;}
195+
void bluetoothFlush() {}
196+
byte bluetoothGetState() {return BT_OFF;}
197+
void bluetoothPrintStatus() {}
198+
uint8_t bluetoothRead() {return 0;}
199+
int bluetoothRxDataAvailable() {return 0;}
200+
void bluetoothSendBatteryPercent(int batteryLevelPercent) {}
201+
void bluetoothStart() {}
202+
void bluetoothStartSkipOnlineCheck() {}
203+
void bluetoothStop() {}
204+
void bluetoothUpdate() {}
205+
int bluetoothWrite(const uint8_t *buffer, int length) {return 0;}
206+
#endif // COMPILE_BT
207+
186208
//----------------------------------------
187209
// ESP-NOW
188210
//----------------------------------------
@@ -322,4 +344,4 @@ void convertGnssTimeToEpoch(uint32_t *epochSecs, uint32_t *epochMicros) {
322344
void beginAuthCoPro(TwoWire *i2cBus) {systemPrintln("**MFi Authentication Not Compiled**");}
323345
void updateAuthCoPro() {}
324346

325-
#endif // COMPILE_AUTHENTICATION
347+
#endif // COMPILE_AUTHENTICATION

Firmware/RTK_Everywhere/RTK_Everywhere.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,8 @@ float batteryChargingPercentPerHour;
561561
#include "bluetoothSelect.h"
562562
#endif // COMPILE_BT
563563

564+
BluetoothRadioType_e bluetoothRadioPreviousOnType = BLUETOOTH_RADIO_OFF;
565+
564566
// This value controls the data that is output from the USB serial port
565567
// to the host PC. By default (false) status and debug messages are output
566568
// to the USB serial port. When this value is set to true then the status

0 commit comments

Comments
 (0)