0% found this document useful (0 votes)
32 views4 pages

Bluetooth Connection and Scanning Logic

This method handles different connection methods for Bluetooth based on the scan method preference. It checks for required permissions, then either starts a QR code scanner, RFID tag scanner, or connects to Bluetooth. For Bluetooth connection, it determines the scan method from preferences and calls the appropriate startBluetooth method, passing required parameters.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views4 pages

Bluetooth Connection and Scanning Logic

This method handles different connection methods for Bluetooth based on the scan method preference. It checks for required permissions, then either starts a QR code scanner, RFID tag scanner, or connects to Bluetooth. For Bluetooth connection, it determines the scan method from preferences and calls the appropriate startBluetooth method, passing required parameters.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

public void connectClicked(View view) {

connectStart = 0;
String bleScanMethod = [Link]("bleScanMethod", "Basic");
if ([Link]("QR_Code")) {
if ([Link](this, [Link])
!= PackageManager.PERMISSION_GRANTED) {
// Permission is not granted
log("Requesting camera permission");
[Link](this, new String[]
{[Link]}, CAMERA_PERMISSION_RESULT);
return;
}
connectStart = [Link]();
log("Starting scan");
startQRCodeScanner();
} else if ([Link]("RFID_Tag") && !isPlayerCarded) {
if ([Link](this, [Link])
!= PackageManager.PERMISSION_GRANTED) {
// Permission is not granted
log("Requesting nfc permission");
[Link](this, new String[]
{[Link]}, NFC_PERMISSION_RESULT);
return;
}
connectStart = [Link]();
log("Starting RFID Scan Activity");
startRFIDTagScanner();
} else {
connectBluetooth();
}
}

-------------------------------
private void connectBluetooth() {
configureProcessor();
Log.d("Hoang", "connectClicked: 123");
connectStart = [Link]();
String selected = (String)[Link]();
BaseOptions options = [Link](selected);
String serviceId = [Link]([Link]);

SERVICE_ID = serviceId == null ? SERVICE_ID : serviceId;


Log.d("HoangHoang", SERVICE_ID);
String bleScanMethod = [Link]("bleScanMethod",
"Auto_Calibration");
log("BLE Scan Method: " + [Link]("_", " "));
log("Starting bluetooth scan");

if ([Link]("Incremental")) {
Log.d("Hoang", "connectClicked: Incremental");
int bleScanTimerPeriodMilliSecs =
[Link]([Link]("bleScanTimerPeriodMilliSecs", "250"));
int startScanThreshold =
[Link]([Link]("startScanThreshold", "-45"));
int minScanThreshold =
[Link]([Link]("connectThreshold", "-55"));
int incrementStepSize =
[Link]([Link]("incrementStepSize", "1"));
[Link](bleScanTimerPeriodMilliSecs,
incrementStepSize,
startScanThreshold, minScanThreshold);
} else if ([Link]("Auto_Calibration")) {
Log.d("Hoang", "connectClicked: Auto_Calibration");
int calibrationDiff =
[Link]([Link]("calibrationDiff", "20"));
Log.d("Hoang", "calibrationDiff: " +calibrationDiff);
[Link](calibrationDiff);
} else {
Log.d("Hoang", "connectClicked: Basic");
[Link](SERVICE_ID);
}
runOnUiThread(new Runnable() {
@Override
public void run() {
[Link](false);
[Link](true);
[Link](false);
}
});
}

-----------------------
public void startBluetoothWithCalibration(int calibrationDiff) {
clearSessionData();
startBluetooth(null, calibrationDiff);
}
--------------------------------
private void startBluetooth(String serviceId, Integer calibrationDiff) {

_serviceId = null;
if (serviceId != null && ![Link]().isEmpty()) {
_serviceId = [Link]();
_isPolling = true;
} else {
_isPolling = false;
}

if (_commandListener == null || _config == null) {


throw new IllegalStateException("The listener and configuration have
not been set yet.");
}

_lastHostSequence = 0;
if (_serviceConnection == null) {
_serviceConnection = new BLEService(context, this, encryptionManager);
}
if (_serviceConnection instanceof BLEService) {
((BLEService)_serviceConnection).resetThresholds(_config);
if (_config.getTunerListener() != null) {

((BLEService)_serviceConnection).setListener(_config.getTunerListener());
}
_serviceConnection.connect(_serviceId, calibrationDiff);
}
}

--------------------------------
@Override
public void connect(String serviceId, Integer calibrationDiff) {
_serviceId = null;
if (serviceId != null && ![Link]().isEmpty()) {
_serviceId = serviceId;
}

_calibrationDiff = calibrationDiff;
startScan();
}
------------------------------
private void startScan() {
synchronized (this) {
if (_connectionState != [Link]) {
return;
}
setState([Link]);
resetDevices();
final UUID[] deviceFilter = new UUID[]{[Link](DEVICE_ID)};
[Link](deviceFilter, this);
if (_scanTimer == null) {
_scanTimer = new Timer();
_scanTimer.schedule(new TimerTask() {
@Override
public void run() {
if ([Link]() - _lastScanTime > 1000) {
Log.d("cc", "NO SCAN! Restarting!");
[Link]([Link]);
[Link](deviceFilter,
[Link]);
}
}
}, 1000, 1000);
}
}

------------------------------------
@Override
public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) {
_lastScanTime = [Link]();
String deviceName = [Link]();
if (deviceName == null) {
return;
}
String cardReaderName = _processor.getConfiguration().getCardReaderName();
if (matchNameStart) {
if (![Link](cardReaderName)) {
return;
}
} else {
if (![Link](cardReaderName)) {
return;
}
}
BLEAdvertisement ad = new BLEAdvertisement(scanRecord);
synchronized (this) {
if (_connectionState != [Link]) {
return;
}
DeviceInfo deviceInfo = [Link]([Link]());
if (deviceInfo == null) {
deviceInfo = new DeviceInfo(device, ad);
[Link]([Link](), deviceInfo);
} else {
[Link] = ad;
}
boolean shouldConnect = false;
if (_serviceId != null) {
//check for matching service Id
if ([Link]() == null || !
isServiceIdMatching([Link]())) {
return;
}
//check for polled connection support in appearance bitfield
byte[] appearance = [Link]();
if (![Link](appearance[0],
POLLED_CONNECTION_MODE_SUPPORTED_BIT)) {
return;
}
shouldConnect = true;
} else {
shouldConnect = _signalAnalyzer.shouldConnect([Link](),
rssi, ad, _calibrationDiff );
}
if (!shouldConnect) {
return;
}
setState([Link]);
stopScanTimer();
[Link]();
[Link](this);
connectingDevice = deviceInfo;
bluetoothGatt = [Link](_context, false, new
BLEGattCallback());
}
}

You might also like