@@ -28,8 +28,7 @@ Bluetooth States:
2828// ----------------------------------------
2929
3030#ifdef COMPILE_BT
31-
32- static BluetoothSerial bluetoothSerial;
31+ BTSerialInterface *bluetoothSerial;
3332static volatile byte bluetoothState = BT_OFF;
3433
3534// ----------------------------------------
@@ -74,7 +73,7 @@ byte bluetoothGetState()
7473bool bluetoothIsCongested ()
7574{
7675#ifdef COMPILE_BT
77- return bluetoothSerial. isCongested ();
76+ return bluetoothSerial-> isCongested ();
7877#else // COMPILE_BT
7978 return false ;
8079#endif // COMPILE_BT
@@ -84,7 +83,7 @@ bool bluetoothIsCongested()
8483int bluetoothReadBytes (uint8_t * buffer, int length)
8584{
8685#ifdef COMPILE_BT
87- return bluetoothSerial. readBytes (buffer, length);
86+ return bluetoothSerial-> readBytes (buffer, length);
8887#else // COMPILE_BT
8988 return 0 ;
9089#endif // COMPILE_BT
@@ -94,7 +93,7 @@ int bluetoothReadBytes(uint8_t * buffer, int length)
9493bool bluetoothRxDataAvailable ()
9594{
9695#ifdef COMPILE_BT
97- return bluetoothSerial. available ();
96+ return bluetoothSerial-> available ();
9897#else // COMPILE_BT
9998 return false ;
10099#endif // COMPILE_BT
@@ -116,7 +115,15 @@ void bluetoothStart()
116115
117116 sprintf (deviceName, " %s %s%02X%02X" , platformPrefix, stateName, unitMACAddress[4 ], unitMACAddress[5 ]);
118117
119- if (bluetoothSerial.begin (deviceName, false , settings.sppRxQueueSize , settings.sppTxQueueSize ) == false ) // localName, isMaster, rxBufferSize, txBufferSize
118+ // BLE vs Bluetooth Classic
119+ if (settings.enableBLE )
120+ bluetoothSerial = new BTLESerial ();
121+ else
122+ {
123+ bluetoothSerial = new BTClassicSerial ();
124+ }
125+
126+ if (bluetoothSerial->begin (deviceName, false , settings.sppRxQueueSize , settings.sppTxQueueSize ) == false ) // localName, isMaster, rxBufferSize, txBufferSize
120127 {
121128 Serial.println (" An error occurred initializing Bluetooth" );
122129
@@ -145,8 +152,8 @@ void bluetoothStart()
145152 esp_bt_gap_set_pin (pin_type, 4 , pin_code);
146153 // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
147154
148- bluetoothSerial. register_callback (bluetoothCallback); // Controls BT Status LED on Surveyor
149- bluetoothSerial. setTimeout (250 );
155+ bluetoothSerial-> register_callback (bluetoothCallback); // Controls BT Status LED on Surveyor
156+ bluetoothSerial-> setTimeout (250 );
150157
151158 Serial.print (" Bluetooth broadcasting as: " );
152159 Serial.println (deviceName);
@@ -172,10 +179,10 @@ void bluetoothStop()
172179#ifdef COMPILE_BT
173180 if (bluetoothState == BT_NOTCONNECTED || bluetoothState == BT_CONNECTED)
174181 {
175- bluetoothSerial. register_callback (NULL );
176- bluetoothSerial. flush (); // Complete any transfers
177- bluetoothSerial. disconnect (); // Drop any clients
178- bluetoothSerial. end (); // bluetoothSerial. end() will release significant RAM (~100k!) but a bluetoothSerial. start will crash.
182+ bluetoothSerial-> register_callback (NULL );
183+ bluetoothSerial-> flush (); // Complete any transfers
184+ bluetoothSerial-> disconnect (); // Drop any clients
185+ bluetoothSerial-> end (); // bluetoothSerial-> end() will release significant RAM (~100k!) but a bluetoothSerial-> start will crash.
179186
180187 log_d (" Bluetooth turned off" );
181188
@@ -191,7 +198,7 @@ int bluetoothWriteBytes(const uint8_t * buffer, int length)
191198{
192199#ifdef COMPILE_BT
193200 // Push new data to BT SPP
194- return bluetoothSerial. write (buffer, length);
201+ return bluetoothSerial-> write (buffer, length);
195202#else // COMPILE_BT
196203 return 0 ;
197204#endif // COMPILE_BT
0 commit comments