Fix bluetooth scan loop bug and add robust device matching
This commit is contained in:
parent
5e2b27f3a0
commit
2fecf43275
1 changed files with 16 additions and 3 deletions
|
|
@ -57,8 +57,19 @@ void scanBTdevice() {//scan bluetooth device
|
||||||
Terminal(txt,0,48,320,191);//list devices
|
Terminal(txt,0,48,320,191);//list devices
|
||||||
delay(100) ;
|
delay(100) ;
|
||||||
|
|
||||||
if (deviceName[i] == client_name || deviceName[i] == "debian" || deviceName[i].indexOf("OBD") != -1 || deviceAddr[i] == "e8:48:b8:c8:20:00") {//match name.
|
String dName = deviceName[i];
|
||||||
//found device name "OBDII"
|
dName.toUpperCase();
|
||||||
|
String dAddr = deviceAddr[i];
|
||||||
|
dAddr.toLowerCase();
|
||||||
|
|
||||||
|
bool isMatch = (dName == "OBDII") ||
|
||||||
|
(dName.indexOf("OBD") != -1) ||
|
||||||
|
(dName.indexOf("ELM") != -1) ||
|
||||||
|
(dName == "DEBIAN") ||
|
||||||
|
(dAddr == "e8:48:b8:c8:20:00");
|
||||||
|
|
||||||
|
if (isMatch) {//match name.
|
||||||
|
//found device name "OBDII" or emulator
|
||||||
foundOBD2 = true;
|
foundOBD2 = true;
|
||||||
//00:1d:a5:00:12:92 -> {0x00,0x1d,0xa5,0x00,0x12,0x92};
|
//00:1d:a5:00:12:92 -> {0x00,0x1d,0xa5,0x00,0x12,0x92};
|
||||||
//copy match bt mac address to client_name to connect
|
//copy match bt mac address to client_name to connect
|
||||||
|
|
@ -80,8 +91,10 @@ void scanBTdevice() {//scan bluetooth device
|
||||||
pref.putBytes("recent_client",client_addr,sizeof(client_addr));//save new bt addr to pref.
|
pref.putBytes("recent_client",client_addr,sizeof(client_addr));//save new bt addr to pref.
|
||||||
Serial.println(F("Save a new BT client address"));
|
Serial.println(F("Save a new BT client address"));
|
||||||
}
|
}
|
||||||
} else //not match
|
break; // Stop scanning once a matching device is found!
|
||||||
|
} else {
|
||||||
foundOBD2 = false;
|
foundOBD2 = false;
|
||||||
|
}
|
||||||
|
|
||||||
}//for loop list device
|
}//for loop list device
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue