Bluetooth reconnect improvement.
This commit is contained in:
parent
32062947a9
commit
c82a235a82
|
@ -39,6 +39,7 @@ BluetoothSerial SerialBT;
|
|||
esp_spp_sec_t sec_mask=ESP_SPP_SEC_NONE;
|
||||
esp_spp_role_t role=ESP_SPP_ROLE_SLAVE;
|
||||
boolean isConnected = false;
|
||||
boolean wasConnected = false;
|
||||
|
||||
// checksum variables
|
||||
byte generatedChecksum = 0;
|
||||
|
@ -86,9 +87,6 @@ void setup(){
|
|||
restartButton.addHandler(restartHandler, E_TOUCH);
|
||||
powerOffButton.addHandler(powerOffHandler, E_TOUCH);
|
||||
|
||||
drawBluetoothLoading();
|
||||
connectBluetooth();
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -113,6 +111,11 @@ byte ReadOneByte() {
|
|||
//MAIN LOOP//
|
||||
/////////////
|
||||
void loop() {
|
||||
if (!isConnected) {
|
||||
drawBluetoothLoading();
|
||||
connectBluetooth();
|
||||
}
|
||||
|
||||
M5.update();
|
||||
drawBattery();
|
||||
if (!SerialBT.connected() && isConnected == true) {
|
||||
|
@ -231,11 +234,14 @@ void loop() {
|
|||
}
|
||||
} else {
|
||||
delay(5000);
|
||||
M5.shutdown(1);
|
||||
if (wasConnected) {
|
||||
M5.shutdown(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void connectBluetooth() {
|
||||
connectingBluetooth = true;
|
||||
if(! SerialBT.begin("ESP32test", true) ) {
|
||||
Serial.println("========== serialBT failed!");
|
||||
}
|
||||
|
@ -272,6 +278,7 @@ void connectBluetooth() {
|
|||
Serial.printf("connecting to %s - %d\n", addr.toString().c_str(), channel);
|
||||
SerialBT.connect(addr, channel, sec_mask, role);
|
||||
isConnected = true;
|
||||
wasConnected = true;
|
||||
drawGui(COLOR_MODE);
|
||||
}
|
||||
} else {
|
||||
|
@ -345,12 +352,16 @@ void drawBluetoothLoading() {
|
|||
M5.Lcd.drawString("Connecting bluetooth", 35, 110, 4);
|
||||
|
||||
M5.Lcd.drawLine(0, 180, 320, 180, COLORS[COLOR_MODE]);
|
||||
|
||||
drawBattery();
|
||||
}
|
||||
|
||||
void task1(void *pvParameters) {
|
||||
while (1) {
|
||||
bluetoothLoading();
|
||||
vTaskDelete(TaskHandle_1);
|
||||
delay(500);
|
||||
if (connectingBluetooth) {
|
||||
bluetoothLoading();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue