|
1 | | -//Tack device's MAC address to end of friendly broadcast name |
2 | | -//This allows multiple units to be on at same time |
3 | | -bool startBluetooth() |
4 | | -{ |
5 | | - //Shutdown any previous WiFi |
6 | | - caster.stop(); |
7 | | - WiFi.mode(WIFI_OFF); |
8 | | - radioState = RADIO_OFF; |
9 | | - |
10 | | - btStart(); |
11 | | - |
12 | | - if (digitalRead(baseSwitch) == HIGH) |
13 | | - { |
14 | | - //Rover mode |
15 | | - sprintf(deviceName, "Surveyor Rover-%02X%02X", unitMACAddress[4], unitMACAddress[5]); |
16 | | - } |
17 | | - else |
18 | | - { |
19 | | - //Base mode |
20 | | - sprintf(deviceName, "Surveyor Base-%02X%02X", unitMACAddress[4], unitMACAddress[5]); |
21 | | - } |
22 | | - |
23 | | - if (SerialBT.begin(deviceName) == false) |
24 | | - { |
25 | | - Serial.println(F("An error occurred initializing Bluetooth")); |
26 | | - radioState = RADIO_OFF; |
27 | | - digitalWrite(bluetoothStatusLED, LOW); |
28 | | - return (false); |
29 | | - } |
30 | | - |
31 | | - Serial.print(F("Bluetooth broadcasting as: ")); |
32 | | - Serial.println(deviceName); |
33 | | - |
34 | | - radioState = BT_ON_NOCONNECTION; |
35 | | - digitalWrite(bluetoothStatusLED, HIGH); |
36 | | - lastBluetoothLEDBlink = millis(); |
37 | | - |
38 | | - //Start the tasks for handling incoming and outgoing BT bytes to/from ZED-F9P |
39 | | - //Reduced stack size from 10,000 to 1,000 to make room for WiFi/NTRIP server capabilities |
40 | | - xTaskCreate(F9PSerialReadTask, "F9Read", 1000, NULL, 0, &F9PSerialReadTaskHandle); |
41 | | - xTaskCreate(F9PSerialWriteTask, "F9Write", 1000, NULL, 0, &F9PSerialWriteTaskHandle); |
42 | | - |
43 | | - SerialBT.setTimeout(1); |
44 | | - |
45 | | - return (true); |
46 | | -} |
47 | | - |
48 | | -//Turn off BT so we can go into WiFi mode |
49 | | -bool endBluetooth() |
50 | | -{ |
51 | | - //Kill tasks if running |
52 | | - if (F9PSerialReadTaskHandle != NULL) |
53 | | - { |
54 | | - vTaskDelete(F9PSerialReadTaskHandle); |
55 | | - F9PSerialReadTaskHandle = NULL; |
56 | | - } |
57 | | - if (F9PSerialWriteTaskHandle != NULL) |
58 | | - { |
59 | | - vTaskDelete(F9PSerialWriteTaskHandle); |
60 | | - F9PSerialWriteTaskHandle = NULL; |
61 | | - } |
62 | | - |
63 | | - //SerialBT.end(); |
64 | | - customBTstop(); //Gracefully turn off Bluetooth so we can turn it back on if needed |
65 | | - |
66 | | - Serial.println(F("Bluetooth turned off")); |
67 | | -} |
68 | | - |
69 | 1 | //Starting and restarting BT is a problem. See issue: https://github.com/espressif/arduino-esp32/issues/2718 |
70 | 2 | //To work around the bug without modifying the core we create our own btStop() function with |
71 | 3 | //the patch from github |
72 | | -bool customBTstop() { |
73 | | - if (esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_IDLE) { |
74 | | - return true; |
75 | | - } |
76 | | - if (esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_ENABLED) { |
77 | | - if (esp_bt_controller_disable()) { |
78 | | - log_e("BT Disable failed"); |
79 | | - return false; |
80 | | - } |
81 | | - while (esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_ENABLED); |
82 | | - } |
83 | | - if (esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_INITED) |
84 | | - { |
85 | | - log_i("inited"); |
86 | | - if (esp_bt_controller_deinit()) |
87 | | - { |
88 | | - log_e("BT deint failed"); |
89 | | - return false; |
90 | | - } |
91 | | - while (esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_INITED) |
92 | | - ; |
93 | | - return true; |
94 | | - } |
95 | | - log_e("BT Stop failed"); |
96 | | - return false; |
97 | | -} |
| 4 | +//bool customBTstop() { |
| 5 | +// if (esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_IDLE) { |
| 6 | +// return true; |
| 7 | +// } |
| 8 | +// if (esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_ENABLED) { |
| 9 | +// if (esp_bt_controller_disable()) { |
| 10 | +// log_e("BT Disable failed"); |
| 11 | +// return false; |
| 12 | +// } |
| 13 | +// while (esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_ENABLED); |
| 14 | +// } |
| 15 | +// if (esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_INITED) |
| 16 | +// { |
| 17 | +// log_i("inited"); |
| 18 | +// if (esp_bt_controller_deinit()) |
| 19 | +// { |
| 20 | +// log_e("BT deint failed"); |
| 21 | +// return false; |
| 22 | +// } |
| 23 | +// while (esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_INITED) |
| 24 | +// ; |
| 25 | +// return true; |
| 26 | +// } |
| 27 | +// log_e("BT Stop failed"); |
| 28 | +// return false; |
| 29 | +//} |
98 | 30 |
|
99 | 31 | //If the phone has any new data (NTRIP RTCM, etc), read it in over Bluetooth and pass along to ZED |
100 | 32 | //Task for writing to the GNSS receiver |
@@ -641,7 +573,6 @@ void btCallback(esp_spp_cb_event_t event, esp_spp_cb_param_t *param) { |
641 | 573 | Serial.println(F("Client disconnected")); |
642 | 574 | radioState = BT_ON_NOCONNECTION; |
643 | 575 | digitalWrite(bluetoothStatusLED, LOW); |
644 | | - lastBluetoothLEDBlink = millis(); |
645 | 576 | } |
646 | 577 | } |
647 | 578 |
|
|
0 commit comments