1919
2020 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2121
22- // ----------------------------------------
23- // Constants
24- // ----------------------------------------
22+ #ifdef COMPILE_BT
2523
2624// ----------------------------------------
2725// Locals - compiled out
2826// ----------------------------------------
2927
3028static volatile BTState bluetoothState = BT_OFF;
3129
32- BluetoothRadioType_e bluetoothRadioPreviousOnType = BLUETOOTH_RADIO_OFF;
33-
34- #ifdef COMPILE_BT
35-
3630#include < BleBatteryService.h>
3731
3832BTSerialInterface *bluetoothSerialSpp = nullptr ;
@@ -50,16 +44,13 @@ BleBatteryService bluetoothBatteryService;
5044
5145TaskHandle_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
6052void 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
10393bool 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
136124bool 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
166152byte 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
176158int 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
211188int 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
228201uint8_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
256225uint8_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
269234int 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
297258int 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
310267int 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
350303int 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
379328int 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
416361void 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
442383void 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
453392void 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
@@ -756,14 +694,12 @@ void bluetoothStart(bool skipOnlineCheck)
756694 online.bluetooth = true ;
757695 bluetoothRadioPreviousOnType = settings.bluetoothRadioType ;
758696 } // if (1)
759- #endif // COMPILE_BT
760697}
761698
762699// Assign Bluetooth interrupts to the core that started the task. See:
763700// https://github.com/espressif/arduino-esp32/issues/3386
764701// void pinBluetoothTask(void *pvParameters)
765702// {
766- // #ifdef COMPILE_BT
767703// if (bluetoothSerial->begin(deviceName, false, settings.sppRxQueueSize, settings.sppTxQueueSize) ==
768704// false) // localName, isMaster, rxBufferSize,
769705// {
@@ -775,13 +711,11 @@ void bluetoothStart(bool skipOnlineCheck)
775711// bluetoothPinned = true;
776712
777713// vTaskDelete(nullptr); // Delete task once it has run once
778- // #endif // COMPILE_BT
779714// }
780715
781716// This function stops BT so that it can be restarted later
782717void bluetoothStop ()
783718{
784- #ifdef COMPILE_BT
785719 if (online.bluetooth )
786720 {
787721 if (settings.debugNetworkLayer )
@@ -866,7 +800,6 @@ void bluetoothStop()
866800 reportHeapNow (false );
867801 online.bluetooth = false ;
868802 }
869- #endif // COMPILE_BT
870803 bluetoothIncomingRTCM = false ;
871804}
872805
@@ -906,7 +839,6 @@ void bluetoothPrintStatus()
906839// Send over dedicated BLE service
907840void bluetoothSendBatteryPercent (int batteryLevelPercent)
908841{
909- #ifdef COMPILE_BT
910842 if (bluetoothGetState () == BT_OFF)
911843 return ;
912844
@@ -915,5 +847,6 @@ void bluetoothSendBatteryPercent(int batteryLevelPercent)
915847 return ;
916848
917849 bluetoothBatteryService.reportBatteryPercent (batteryLevelPercent);
850+ }
851+
918852#endif // COMPILE_BT
919- }
0 commit comments