Skip to content

Commit df5cf92

Browse files
committed
Move BLE control to system menu
1 parent c1a8c09 commit df5cf92

File tree

6 files changed

+154
-189
lines changed

6 files changed

+154
-189
lines changed

Firmware/RTK_Surveyor/Bluetooth.ino

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,7 @@ void bluetoothStart()
119119
if (settings.enableBLE)
120120
bluetoothSerial = new BTLESerial();
121121
else
122-
{
123122
bluetoothSerial = new BTClassicSerial();
124-
}
125123

126124
if (bluetoothSerial->begin(deviceName, false, settings.sppRxQueueSize, settings.sppTxQueueSize) == false) //localName, isMaster, rxBufferSize, txBufferSize
127125
{

Firmware/RTK_Surveyor/bluetoothSelect.h

Lines changed: 136 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -5,154 +5,154 @@
55

66
class BTSerialInterface
77
{
8-
public:
9-
virtual bool begin(String deviceName, bool isMaster, uint16_t rxQueueSize, uint16_t txQueueSize) = 0;
10-
virtual void disconnect() = 0;
11-
virtual void end() = 0;
12-
virtual esp_err_t register_callback(esp_spp_cb_t * callback) = 0;
13-
virtual void setTimeout(unsigned long timeout) = 0;
14-
15-
virtual int available() = 0;
16-
virtual size_t readBytes(uint8_t *buffer, size_t bufferSize) = 0;
17-
18-
virtual bool isCongested() = 0;
19-
virtual size_t write(const uint8_t *buffer, size_t size) = 0;
20-
virtual void flush() = 0;
8+
public:
9+
virtual bool begin(String deviceName, bool isMaster, uint16_t rxQueueSize, uint16_t txQueueSize) = 0;
10+
virtual void disconnect() = 0;
11+
virtual void end() = 0;
12+
virtual esp_err_t register_callback(esp_spp_cb_t * callback) = 0;
13+
virtual void setTimeout(unsigned long timeout) = 0;
14+
15+
virtual int available() = 0;
16+
virtual size_t readBytes(uint8_t *buffer, size_t bufferSize) = 0;
17+
18+
virtual bool isCongested() = 0;
19+
virtual size_t write(const uint8_t *buffer, size_t size) = 0;
20+
virtual void flush() = 0;
2121
};
2222

2323

2424
class BTClassicSerial : public virtual BTSerialInterface, public BluetoothSerial
2525
{
2626
// Everything is already implemented in BluetoothSerial since the code was
2727
// originally written using that class
28-
public:
29-
bool begin(String deviceName, bool isMaster, uint16_t rxQueueSize, uint16_t txQueueSize)
30-
{
31-
return BluetoothSerial::begin(deviceName, isMaster, rxQueueSize, txQueueSize);
32-
}
33-
34-
void disconnect()
35-
{
36-
BluetoothSerial::disconnect();
37-
}
38-
39-
void end()
40-
{
41-
BluetoothSerial::end();
42-
}
43-
44-
esp_err_t register_callback(esp_spp_cb_t * callback)
45-
{
46-
return BluetoothSerial::register_callback(callback);
47-
}
48-
49-
void setTimeout(unsigned long timeout)
50-
{
51-
BluetoothSerial::setTimeout(timeout);
52-
}
53-
54-
int available()
55-
{
56-
return BluetoothSerial::available();
57-
}
58-
59-
size_t readBytes(uint8_t *buffer, size_t bufferSize)
60-
{
61-
return BluetoothSerial::readBytes(buffer, bufferSize);
62-
}
63-
64-
bool isCongested()
65-
{
66-
return BluetoothSerial::isCongested();
67-
}
68-
69-
size_t write(const uint8_t *buffer, size_t size)
70-
{
71-
return BluetoothSerial::write(buffer, size);
72-
}
73-
74-
void flush()
75-
{
76-
BluetoothSerial::flush();
77-
}
28+
public:
29+
bool begin(String deviceName, bool isMaster, uint16_t rxQueueSize, uint16_t txQueueSize)
30+
{
31+
return BluetoothSerial::begin(deviceName, isMaster, rxQueueSize, txQueueSize);
32+
}
33+
34+
void disconnect()
35+
{
36+
BluetoothSerial::disconnect();
37+
}
38+
39+
void end()
40+
{
41+
BluetoothSerial::end();
42+
}
43+
44+
esp_err_t register_callback(esp_spp_cb_t * callback)
45+
{
46+
return BluetoothSerial::register_callback(callback);
47+
}
48+
49+
void setTimeout(unsigned long timeout)
50+
{
51+
BluetoothSerial::setTimeout(timeout);
52+
}
53+
54+
int available()
55+
{
56+
return BluetoothSerial::available();
57+
}
58+
59+
size_t readBytes(uint8_t *buffer, size_t bufferSize)
60+
{
61+
return BluetoothSerial::readBytes(buffer, bufferSize);
62+
}
63+
64+
bool isCongested()
65+
{
66+
return BluetoothSerial::isCongested();
67+
}
68+
69+
size_t write(const uint8_t *buffer, size_t size)
70+
{
71+
return BluetoothSerial::write(buffer, size);
72+
}
73+
74+
void flush()
75+
{
76+
BluetoothSerial::flush();
77+
}
7878
};
7979

8080

8181
class BTLESerial: public virtual BTSerialInterface, public BleSerial
8282
{
83-
public:
84-
// Missing from BleSerial
85-
bool begin(String deviceName, bool isMaster, uint16_t rxQueueSuze, uint16_t txQueueSize)
86-
{
87-
// Curretnly ignoring rxQueueSize
88-
// transmitBufferLength = txQueueSize;
89-
BleSerial::begin(deviceName.c_str());
90-
return true;
91-
}
92-
93-
void disconnect()
94-
{
95-
Server->disconnect(Server->getConnId());
96-
}
97-
98-
void end()
99-
{
100-
BleSerial::end();
101-
}
102-
103-
esp_err_t register_callback(esp_spp_cb_t * callback)
104-
{
105-
connectionCallback = callback;
106-
return ESP_OK;
107-
}
108-
109-
void setTimeout(unsigned long timeout)
110-
{
111-
BleSerial::setTimeout(timeout);
112-
}
113-
114-
int available()
115-
{
116-
return BleSerial::available();
117-
}
118-
119-
size_t readBytes(uint8_t *buffer, size_t bufferSize)
120-
{
121-
return BleSerial::readBytes(buffer, bufferSize);
122-
}
123-
124-
bool isCongested()
125-
{
126-
// not currently supported in this implementation
127-
return false;
128-
}
129-
130-
size_t write(const uint8_t *buffer, size_t size)
131-
{
132-
return BleSerial::write(buffer, size);
133-
}
134-
135-
void flush()
136-
{
137-
BleSerial::flush();
138-
}
139-
140-
// override BLEServerCallbacks
141-
void onConnect(BLEServer *pServer)
142-
{
143-
bleConnected = true;
144-
connectionCallback(ESP_SPP_SRV_OPEN_EVT, nullptr);
145-
}
146-
147-
void onDisconnect(BLEServer *pServer)
148-
{
149-
bleConnected = false;
150-
connectionCallback(ESP_SPP_CLOSE_EVT, nullptr);
151-
Server->startAdvertising();
152-
}
153-
154-
private:
155-
esp_spp_cb_t * connectionCallback;
83+
public:
84+
// Missing from BleSerial
85+
bool begin(String deviceName, bool isMaster, uint16_t rxQueueSuze, uint16_t txQueueSize)
86+
{
87+
// Curretnly ignoring rxQueueSize
88+
// transmitBufferLength = txQueueSize;
89+
BleSerial::begin(deviceName.c_str());
90+
return true;
91+
}
92+
93+
void disconnect()
94+
{
95+
Server->disconnect(Server->getConnId());
96+
}
97+
98+
void end()
99+
{
100+
BleSerial::end();
101+
}
102+
103+
esp_err_t register_callback(esp_spp_cb_t * callback)
104+
{
105+
connectionCallback = callback;
106+
return ESP_OK;
107+
}
108+
109+
void setTimeout(unsigned long timeout)
110+
{
111+
BleSerial::setTimeout(timeout);
112+
}
113+
114+
int available()
115+
{
116+
return BleSerial::available();
117+
}
118+
119+
size_t readBytes(uint8_t *buffer, size_t bufferSize)
120+
{
121+
return BleSerial::readBytes(buffer, bufferSize);
122+
}
123+
124+
bool isCongested()
125+
{
126+
// not currently supported in this implementation
127+
return false;
128+
}
129+
130+
size_t write(const uint8_t *buffer, size_t size)
131+
{
132+
return BleSerial::write(buffer, size);
133+
}
134+
135+
void flush()
136+
{
137+
BleSerial::flush();
138+
}
139+
140+
// override BLEServerCallbacks
141+
void onConnect(BLEServer *pServer)
142+
{
143+
bleConnected = true;
144+
connectionCallback(ESP_SPP_SRV_OPEN_EVT, nullptr);
145+
}
146+
147+
void onDisconnect(BLEServer *pServer)
148+
{
149+
bleConnected = false;
150+
connectionCallback(ESP_SPP_CLOSE_EVT, nullptr);
151+
Server->startAdvertising();
152+
}
153+
154+
private:
155+
esp_spp_cb_t * connectionCallback;
156156

157157
};
158158

Firmware/RTK_Surveyor/menuBluetooth.ino

Lines changed: 0 additions & 45 deletions
This file was deleted.

Firmware/RTK_Surveyor/menuMain.ino

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ void menuMain()
5151

5252
Serial.println("5) Configure Logging");
5353

54-
Serial.println("6) Configure Bluetooth");
55-
5654
Serial.println("p) Configure Profiles");
5755

5856
#ifdef COMPILE_ESPNOW
@@ -83,8 +81,6 @@ void menuMain()
8381
menuPorts();
8482
else if (incoming == '5')
8583
menuLog();
86-
else if (incoming == '6')
87-
menuBluetooth();
8884
else if (incoming == 's')
8985
menuSystem();
9086
else if (incoming == 'p')

Firmware/RTK_Surveyor/menuSystem.ino

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@ void menuSystem()
152152
Serial.printf("m) Set time zone minutes: %d\r\n", settings.timeZoneMinutes);
153153
Serial.printf("s) Set time zone seconds: %d\r\n", settings.timeZoneSeconds);
154154

155+
Serial.print(F("b) Set Bluetooth Mode: "));
156+
if (settings.enableBLE == true)
157+
Serial.println(F("BLE"));
158+
else
159+
Serial.println(F("Classic"));
160+
155161
Serial.println("r) Reset all settings to default");
156162

157163
// Support mode switching
@@ -205,6 +211,17 @@ void menuSystem()
205211
updateRTC();
206212
}
207213
}
214+
else if (incoming == 'b')
215+
{
216+
// Restart Bluetooth
217+
bluetoothStop();
218+
if (settings.enableBLE == false)
219+
settings.enableBLE = true;
220+
else
221+
settings.enableBLE = false;
222+
bluetoothStart();
223+
224+
}
208225
else if (incoming == 'r')
209226
{
210227
Serial.println("\r\nResetting to factory defaults. Press 'y' to confirm:");

0 commit comments

Comments
 (0)