use of com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice in project xDrip-plus by jamorham.
the class SystemStatus method setCurrentDevice.
public void setCurrentDevice() {
if (activeBluetoothDevice != null) {
current_device.setText(activeBluetoothDevice.name);
} else {
current_device.setText("None Set");
}
String collection_method = prefs.getString("dex_collection_method", "BluetoothWixel");
if (collection_method.compareTo("DexcomG5") == 0) {
Transmitter defaultTransmitter = new Transmitter(prefs.getString("dex_txid", "ABCDEF"));
mBluetoothAdapter = mBluetoothManager.getAdapter();
if (mBluetoothAdapter != null) {
Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
if ((pairedDevices != null) && (pairedDevices.size() > 0)) {
for (BluetoothDevice device : pairedDevices) {
if (device.getName() != null) {
String transmitterIdLastTwo = Extensions.lastTwoCharactersOfString(defaultTransmitter.transmitterId);
String deviceNameLastTwo = Extensions.lastTwoCharactersOfString(device.getName());
if (transmitterIdLastTwo.equals(deviceNameLastTwo)) {
current_device.setText(defaultTransmitter.transmitterId);
}
}
}
}
} else {
current_device.setText("No Bluetooth");
}
}
}
use of com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice in project xDrip-plus by jamorham.
the class SystemStatus method setConnectionStatus.
private void setConnectionStatus() {
boolean connected = false;
if (mBluetoothManager != null && activeBluetoothDevice != null) {
for (BluetoothDevice bluetoothDevice : mBluetoothManager.getConnectedDevices(BluetoothProfile.GATT)) {
if (bluetoothDevice.getAddress().compareTo(activeBluetoothDevice.address) == 0) {
connected = true;
}
}
}
if (connected) {
connection_status.setText(getApplicationContext().getString(R.string.connected));
} else {
connection_status.setText(getApplicationContext().getString(R.string.not_connected));
}
String collection_method = prefs.getString("dex_collection_method", "BluetoothWixel");
if (collection_method.compareTo("DexcomG5") == 0) {
Transmitter defaultTransmitter = new Transmitter(prefs.getString("dex_txid", "ABCDEF"));
mBluetoothAdapter = mBluetoothManager.getAdapter();
if (mBluetoothAdapter != null) {
Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
if (pairedDevices.size() > 0) {
for (BluetoothDevice device : pairedDevices) {
if (device.getName() != null) {
String transmitterIdLastTwo = Extensions.lastTwoCharactersOfString(defaultTransmitter.transmitterId);
String deviceNameLastTwo = Extensions.lastTwoCharactersOfString(device.getName());
if (transmitterIdLastTwo.equals(deviceNameLastTwo)) {
final String fw = G5CollectionService.getFirmwareVersionString(defaultTransmitter.transmitterId);
connection_status.setText(device.getName() + " Authed" + ((fw != null) ? ("\n" + fw) : ""));
break;
}
}
}
}
} else {
connection_status.setText(getApplicationContext().getString(R.string.no_bluetooth));
}
}
}
use of com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice in project xDrip-plus by jamorham.
the class DexShareCollectionService method attemptConnection.
public void attemptConnection() {
mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
if (mBluetoothManager != null) {
if (device != null) {
mConnectionState = STATE_DISCONNECTED;
for (BluetoothDevice bluetoothDevice : mBluetoothManager.getConnectedDevices(BluetoothProfile.GATT)) {
if (bluetoothDevice.getAddress().compareTo(device.getAddress()) == 0) {
mConnectionState = STATE_CONNECTED;
}
}
}
Log.i(TAG, "Connection state: " + mConnectionState);
if (mConnectionState == STATE_DISCONNECTED || mConnectionState == STATE_DISCONNECTING) {
ActiveBluetoothDevice btDevice = ActiveBluetoothDevice.first();
if (btDevice != null) {
mDeviceName = btDevice.name;
mDeviceAddress = btDevice.address;
mBluetoothAdapter = mBluetoothManager.getAdapter();
try {
if (mBluetoothAdapter.isEnabled() && mBluetoothAdapter.getRemoteDevice(mDeviceAddress) != null) {
connect(mDeviceAddress);
return;
} else {
Log.w(TAG, "Bluetooth is disabled or BT device cant be found");
setRetryTimer();
return;
}
} catch (IllegalArgumentException e) {
if (JoH.ratelimit("dex-share-error-log", 180)) {
Log.wtf(TAG, "Error connecting: " + e);
}
}
} else {
Log.w(TAG, "No bluetooth device to try and connect to");
setRetryTimer();
return;
}
} else if (mConnectionState == STATE_CONNECTED) {
Log.i(TAG, "Looks like we are already connected, going to read!");
attemptRead();
return;
} else {
setRetryTimer();
return;
}
} else {
setRetryTimer();
return;
}
}
Aggregations