diff --git a/Firmware/RTK_Everywhere/Bluetooth.ino b/Firmware/RTK_Everywhere/Bluetooth.ino index 72f62e411..523a41fd6 100644 --- a/Firmware/RTK_Everywhere/Bluetooth.ino +++ b/Firmware/RTK_Everywhere/Bluetooth.ino @@ -19,9 +19,7 @@ =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ -//---------------------------------------- -// Constants -//---------------------------------------- +#ifdef COMPILE_BT //---------------------------------------- // Locals - compiled out @@ -29,10 +27,6 @@ static volatile BTState bluetoothState = BT_OFF; -BluetoothRadioType_e bluetoothRadioPreviousOnType = BLUETOOTH_RADIO_OFF; - -#ifdef COMPILE_BT - #include BTSerialInterface *bluetoothSerialSpp = nullptr; @@ -50,8 +44,6 @@ BleBatteryService bluetoothBatteryService; TaskHandle_t bluetoothCommandTaskHandle = nullptr; // Task to monitor incoming CLI from BLE -#endif // COMPILE_BT - //---------------------------------------- // Global Bluetooth Routines //---------------------------------------- @@ -59,7 +51,6 @@ TaskHandle_t bluetoothCommandTaskHandle = nullptr; // Task to monitor incoming C // Check if Bluetooth is connected void bluetoothUpdate() { -#ifdef COMPILE_BT static uint32_t lastCheck = millis(); // Check if connected every 100ms if ((millis() - lastCheck) > 100) { @@ -95,14 +86,12 @@ void bluetoothUpdate() bluetoothState = BT_NOTCONNECTED; } } -#endif // COMPILE_BT } // Test each interface to see if there is a connection // Return true if one is bool bluetoothIsConnected() { -#ifdef COMPILE_BT if (bluetoothGetState() == BT_OFF) return (false); @@ -127,7 +116,6 @@ bool bluetoothIsConnected() if (bluetoothSerialSpp->connected() == true) return (true); } -#endif // COMPILE_BT return (false); } @@ -135,7 +123,6 @@ bool bluetoothIsConnected() // Return true if the BLE Command channel is connected bool bluetoothCommandIsConnected() { -#ifdef COMPILE_BT if (bluetoothGetState() == BT_OFF) return (false); @@ -157,7 +144,6 @@ bool bluetoothCommandIsConnected() { return (false); } -#endif // COMPILE_BT return (false); } @@ -165,17 +151,12 @@ bool bluetoothCommandIsConnected() // Return the Bluetooth state byte bluetoothGetState() { -#ifdef COMPILE_BT return bluetoothState; -#else // COMPILE_BT - return BT_OFF; -#endif // COMPILE_BT } // Read data from the Bluetooth device int bluetoothRead(uint8_t *buffer, int length) { -#ifdef COMPILE_BT if (bluetoothGetState() == BT_OFF) return 0; @@ -201,16 +182,11 @@ int bluetoothRead(uint8_t *buffer, int length) return 0; // Nothing to do here. SDP takes care of everything... return 0; - -#else // COMPILE_BT - return 0; -#endif // COMPILE_BT } // Read data from the Bluetooth command interface int bluetoothCommandRead(uint8_t *buffer, int length) { -#ifdef COMPILE_BT if (settings.bluetoothRadioType == BLUETOOTH_RADIO_SPP_AND_BLE || settings.bluetoothRadioType == BLUETOOTH_RADIO_BLE) { @@ -219,15 +195,11 @@ int bluetoothCommandRead(uint8_t *buffer, int length) } return 0; -#else // COMPILE_BT - return 0; -#endif // COMPILE_BT } // Read data from the Bluetooth device uint8_t bluetoothRead() { -#ifdef COMPILE_BT if (bluetoothGetState() == BT_OFF) return 0; @@ -247,28 +219,20 @@ uint8_t bluetoothRead() return 0; // Nothing to do here. SDP takes care of everything... return 0; -#else // COMPILE_BT - return 0; -#endif // COMPILE_BT } // Read data from the BLE Command interface uint8_t bluetoothCommandRead() { -#ifdef COMPILE_BT if (settings.bluetoothRadioType == BLUETOOTH_RADIO_SPP_AND_BLE || settings.bluetoothRadioType == BLUETOOTH_RADIO_BLE) return bluetoothSerialBleCommands->read(); return (0); -#else // COMPILE_BT - return 0; -#endif // COMPILE_BT } // Determine if data is available int bluetoothRxDataAvailable() { -#ifdef COMPILE_BT if (bluetoothGetState() == BT_OFF) return 0; @@ -288,28 +252,20 @@ int bluetoothRxDataAvailable() return 0; // Nothing to do here. SDP takes care of everything... return (0); -#else // COMPILE_BT - return 0; -#endif // COMPILE_BT } // Determine if data is available on the BLE Command interface int bluetoothCommandAvailable() { -#ifdef COMPILE_BT if (settings.bluetoothRadioType == BLUETOOTH_RADIO_SPP_AND_BLE || settings.bluetoothRadioType == BLUETOOTH_RADIO_BLE) return bluetoothSerialBleCommands->available(); return (0); -#else // COMPILE_BT - return 0; -#endif // COMPILE_BT } // Write data to the Bluetooth device int bluetoothWrite(const uint8_t *buffer, int length) { -#ifdef COMPILE_BT if (bluetoothGetState() == BT_OFF) return length; // Avoid buffer full warnings @@ -341,15 +297,11 @@ int bluetoothWrite(const uint8_t *buffer, int length) return length; // Nothing to do here. SDP takes care of everything... return (0); -#else // COMPILE_BT - return 0; -#endif // COMPILE_BT } // Write data to the BLE Command interface int bluetoothCommandWrite(const uint8_t *buffer, int length) { -#ifdef COMPILE_BT if (settings.bluetoothRadioType == BLUETOOTH_RADIO_SPP_AND_BLE) { return (bluetoothSerialBleCommands->write(buffer, length)); @@ -370,15 +322,11 @@ int bluetoothCommandWrite(const uint8_t *buffer, int length) return length; // Nothing to do here. SDP takes care of everything... return (0); -#else // COMPILE_BT - return 0; -#endif // COMPILE_BT } // Write data to the Bluetooth device int bluetoothWrite(uint8_t value) { -#ifdef COMPILE_BT if (bluetoothGetState() == BT_OFF) return 1; // Avoid buffer full warnings @@ -407,15 +355,11 @@ int bluetoothWrite(uint8_t value) return 1; // Nothing to do here. SDP takes care of everything... return (0); -#else // COMPILE_BT - return 0; -#endif // COMPILE_BT } // Flush Bluetooth device void bluetoothFlush() { -#ifdef COMPILE_BT if (bluetoothGetState() == BT_OFF) return; @@ -434,9 +378,6 @@ void bluetoothFlush() } else if (settings.bluetoothRadioType == BLUETOOTH_RADIO_SPP_ACCESSORY_MODE) bluetoothSerialSpp->flush(); // Needed? Not sure... TODO -#else // COMPILE_BT - return; -#endif // COMPILE_BT } void BTConfirmRequestCallback(uint32_t numVal) { @@ -445,9 +386,7 @@ void BTConfirmRequestCallback(uint32_t numVal) { // TODO: if the RTK device has an OLED, we should display the PIN so user can confirm systemPrintf("Device sent PIN: %06lu. Sending confirmation\r\n", numVal); -#ifdef COMPILE_BT bluetoothSerialSpp->confirmReply(true); // AUTO_PAIR - equivalent to enableSSP(false, true); -#endif // COMPILE_BT } void deviceNameSpacesToUnderscores() @@ -492,7 +431,6 @@ void bluetoothStart(bool skipOnlineCheck) } } -#ifdef COMPILE_BT { // Maintain the indentation for now. TODO: delete the braces and correct indentation bluetoothState = BT_OFF; // Indicate to tasks that BT is unavailable @@ -756,14 +694,12 @@ void bluetoothStart(bool skipOnlineCheck) online.bluetooth = true; bluetoothRadioPreviousOnType = settings.bluetoothRadioType; } // if (1) -#endif // COMPILE_BT } // Assign Bluetooth interrupts to the core that started the task. See: // https://github.com/espressif/arduino-esp32/issues/3386 // void pinBluetoothTask(void *pvParameters) // { -// #ifdef COMPILE_BT // if (bluetoothSerial->begin(deviceName, false, settings.sppRxQueueSize, settings.sppTxQueueSize) == // false) // localName, isMaster, rxBufferSize, // { @@ -775,13 +711,11 @@ void bluetoothStart(bool skipOnlineCheck) // bluetoothPinned = true; // vTaskDelete(nullptr); // Delete task once it has run once -// #endif // COMPILE_BT // } // This function stops BT so that it can be restarted later void bluetoothStop() { -#ifdef COMPILE_BT if (online.bluetooth) { if (settings.debugNetworkLayer) @@ -866,7 +800,6 @@ void bluetoothStop() reportHeapNow(false); online.bluetooth = false; } -#endif // COMPILE_BT bluetoothIncomingRTCM = false; } @@ -906,7 +839,6 @@ void bluetoothPrintStatus() // Send over dedicated BLE service void bluetoothSendBatteryPercent(int batteryLevelPercent) { -#ifdef COMPILE_BT if (bluetoothGetState() == BT_OFF) return; @@ -915,5 +847,6 @@ void bluetoothSendBatteryPercent(int batteryLevelPercent) return; bluetoothBatteryService.reportBatteryPercent(batteryLevelPercent); +} + #endif // COMPILE_BT -} \ No newline at end of file diff --git a/Firmware/RTK_Everywhere/Developer.ino b/Firmware/RTK_Everywhere/Developer.ino index 75ce977f5..a85597c5b 100644 --- a/Firmware/RTK_Everywhere/Developer.ino +++ b/Firmware/RTK_Everywhere/Developer.ino @@ -183,6 +183,28 @@ bool webServerIsRunning() {return false;} #endif // COMPILE_AP +//---------------------------------------- +// Global Bluetooth Routines +//---------------------------------------- + +#ifndef COMPILE_BT +int bluetoothCommandAvailable() {return 0;} +bool bluetoothCommandIsConnected() {return false;} +uint8_t bluetoothCommandRead() {return 0;} +int bluetoothCommandWrite(const uint8_t *buffer, int length) {return 0;} +void bluetoothFlush() {} +byte bluetoothGetState() {return BT_OFF;} +void bluetoothPrintStatus() {} +uint8_t bluetoothRead() {return 0;} +int bluetoothRxDataAvailable() {return 0;} +void bluetoothSendBatteryPercent(int batteryLevelPercent) {} +void bluetoothStart() {} +void bluetoothStartSkipOnlineCheck() {} +void bluetoothStop() {} +void bluetoothUpdate() {} +int bluetoothWrite(const uint8_t *buffer, int length) {return 0;} +#endif // COMPILE_BT + //---------------------------------------- // ESP-NOW //---------------------------------------- @@ -322,4 +344,4 @@ void convertGnssTimeToEpoch(uint32_t *epochSecs, uint32_t *epochMicros) { void beginAuthCoPro(TwoWire *i2cBus) {systemPrintln("**MFi Authentication Not Compiled**");} void updateAuthCoPro() {} -#endif // COMPILE_AUTHENTICATION \ No newline at end of file +#endif // COMPILE_AUTHENTICATION diff --git a/Firmware/RTK_Everywhere/RTK_Everywhere.ino b/Firmware/RTK_Everywhere/RTK_Everywhere.ino index 20cdf21b7..30a5dbdb9 100644 --- a/Firmware/RTK_Everywhere/RTK_Everywhere.ino +++ b/Firmware/RTK_Everywhere/RTK_Everywhere.ino @@ -561,6 +561,8 @@ float batteryChargingPercentPerHour; #include "bluetoothSelect.h" #endif // COMPILE_BT +BluetoothRadioType_e bluetoothRadioPreviousOnType = BLUETOOTH_RADIO_OFF; + // This value controls the data that is output from the USB serial port // to the host PC. By default (false) status and debug messages are output // to the USB serial port. When this value is set to true then the status