Java Code Examples for com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice
The following examples show how to use
com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice.
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: xDrip Author: NightscoutFoundation File: ShareTest.java License: GNU General Public License v3.0 | 6 votes |
@Override public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { if (newState == BluetoothProfile.STATE_CONNECTED) { mBluetoothGatt = gatt; mConnectionState = STATE_CONNECTED; ActiveBluetoothDevice.connected(); Log.i(TAG, "Connected to GATT server."); Log.i(TAG, "Connection state: Bonded - " + device.getBondState()); if (device.getBondState() == BluetoothDevice.BOND_BONDED) { currentGattTask = GATT_SETUP; mBluetoothGatt.discoverServices(); } else { device.setPin("000000".getBytes()); device.createBond(); } } else if (newState == BluetoothProfile.STATE_DISCONNECTED) { mConnectionState = STATE_DISCONNECTED; ActiveBluetoothDevice.disconnected(); Log.w(TAG, "Disconnected from GATT server."); } }
Example #2
Source Project: xDrip Author: NightscoutFoundation File: ShareTest.java License: GNU General Public License v3.0 | 6 votes |
public void attemptConnection() { mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); if (device != null) { details.append("\nConnection state: " + " Device is not null"); mConnectionState = mBluetoothManager.getConnectionState(device, BluetoothProfile.GATT); } Log.i(TAG, "Connection state: " + mConnectionState); details.append("\nConnection state: " + mConnectionState); if (mConnectionState == STATE_DISCONNECTED || mConnectionState == STATE_DISCONNECTING) { ActiveBluetoothDevice btDevice = new Select().from(ActiveBluetoothDevice.class) .orderBy("_ID desc") .executeSingle(); if (btDevice != null) { details.append("\nBT Device: " + btDevice.name); mDeviceName = btDevice.name; mDeviceAddress = btDevice.address; mBluetoothAdapter = mBluetoothManager.getAdapter(); boolean newConnection = true; if(newConnection) { is_connected = connect(mDeviceAddress); details.append("\nConnecting...: "); } } } }
Example #3
Source Project: xDrip Author: NightscoutFoundation File: SystemStatus.java License: GNU General Public License v3.0 | 6 votes |
private void set_current_values() { activeBluetoothDevice = ActiveBluetoothDevice.first(); mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); setVersionName(); setCollectionMethod(); setCurrentDevice(); if (Home.get_follower()) { setConnectionStatusFollower(); } else if (prefs.getString("dex_collection_method", "bogus").equals("WifiWixel")) { setConnectionStatusWifiWixel(); } else { setConnectionStatus(); } setSensorStatus(); setTransmitterStatus(); setNotes(); futureDataCheck(); }
Example #4
Source Project: xDrip Author: NightscoutFoundation File: SystemStatusFragment.java License: GNU General Public License v3.0 | 6 votes |
private void set_current_values() { notes.setText(""); activeBluetoothDevice = ActiveBluetoothDevice.first(); if (Build.VERSION.SDK_INT >= 18) { mBluetoothManager = (BluetoothManager) safeGetContext().getSystemService(Context.BLUETOOTH_SERVICE); } setVersionName(); //setCollectionMethod(); setCurrentDevice(); if (Home.get_follower()) { setConnectionStatusFollower(); } else if (prefs.getString("dex_collection_method", "bogus").equals("WifiWixel")) { setConnectionStatusWifiWixel(); } else { setConnectionStatus(); } setSensorStatus(); setTransmitterStatus(); setNotes(); futureDataCheck(); /* if (notes.getText().length()==0) { notes.setText("Swipe for more status pages!"); }*/ }
Example #5
Source Project: xDrip Author: NightscoutFoundation File: WatchUpdaterService.java License: GNU General Public License v3.0 | 6 votes |
private void sendActiveBtDeviceData() {//KS if (is_using_bt) {//only required for Collector running on watch forceGoogleApiConnect(); ActiveBluetoothDevice btDevice = ActiveBluetoothDevice.first(); if (btDevice != null) { if (wear_integration) { DataMap dataMap = new DataMap(); Log.d(TAG, "sendActiveBtDeviceData name=" + btDevice.name + " address=" + btDevice.address + " connected=" + btDevice.connected); dataMap.putLong("time", new Date().getTime()); // MOST IMPORTANT LINE FOR TIMESTAMP dataMap.putString("name", btDevice.name); dataMap.putString("address", btDevice.address); dataMap.putBoolean("connected", btDevice.connected); new SendToDataLayerThread(WEARABLE_ACTIVEBTDEVICE_DATA_PATH, googleApiClient).executeOnExecutor(xdrip.executor, dataMap); } } } else { Log.d(TAG, "Not sending activebluetoothdevice data as we are not using bt"); } }
Example #6
Source Project: xDrip-plus Author: jamorham File: ShareTest.java License: GNU General Public License v3.0 | 6 votes |
@Override public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { if (newState == BluetoothProfile.STATE_CONNECTED) { mBluetoothGatt = gatt; mConnectionState = STATE_CONNECTED; ActiveBluetoothDevice.connected(); Log.i(TAG, "Connected to GATT server."); Log.i(TAG, "Connection state: Bonded - " + device.getBondState()); if (device.getBondState() == BluetoothDevice.BOND_BONDED) { currentGattTask = GATT_SETUP; mBluetoothGatt.discoverServices(); } else { device.setPin("000000".getBytes()); device.createBond(); } } else if (newState == BluetoothProfile.STATE_DISCONNECTED) { mConnectionState = STATE_DISCONNECTED; ActiveBluetoothDevice.disconnected(); Log.w(TAG, "Disconnected from GATT server."); } }
Example #7
Source Project: xDrip-plus Author: jamorham File: ShareTest.java License: GNU General Public License v3.0 | 6 votes |
public void attemptConnection() { mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); if (device != null) { details.append("\nConnection state: " + " Device is not null"); mConnectionState = mBluetoothManager.getConnectionState(device, BluetoothProfile.GATT); } Log.i(TAG, "Connection state: " + mConnectionState); details.append("\nConnection state: " + mConnectionState); if (mConnectionState == STATE_DISCONNECTED || mConnectionState == STATE_DISCONNECTING) { ActiveBluetoothDevice btDevice = new Select().from(ActiveBluetoothDevice.class) .orderBy("_ID desc") .executeSingle(); if (btDevice != null) { details.append("\nBT Device: " + btDevice.name); mDeviceName = btDevice.name; mDeviceAddress = btDevice.address; mBluetoothAdapter = mBluetoothManager.getAdapter(); boolean newConnection = true; if(newConnection) { is_connected = connect(mDeviceAddress); details.append("\nConnecting...: "); } } } }
Example #8
Source Project: xDrip-plus Author: jamorham File: SystemStatus.java License: GNU General Public License v3.0 | 6 votes |
private void set_current_values() { activeBluetoothDevice = ActiveBluetoothDevice.first(); mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); setVersionName(); setCollectionMethod(); setCurrentDevice(); if (Home.get_follower()) { setConnectionStatusFollower(); } else if (prefs.getString("dex_collection_method", "bogus").equals("WifiWixel")) { setConnectionStatusWifiWixel(); } else { setConnectionStatus(); } setSensorStatus(); setTransmitterStatus(); setNotes(); futureDataCheck(); }
Example #9
Source Project: xDrip-plus Author: jamorham File: SystemStatusFragment.java License: GNU General Public License v3.0 | 6 votes |
private void set_current_values() { notes.setText(""); activeBluetoothDevice = ActiveBluetoothDevice.first(); if (Build.VERSION.SDK_INT >= 18) { mBluetoothManager = (BluetoothManager) safeGetContext().getSystemService(Context.BLUETOOTH_SERVICE); } setVersionName(); //setCollectionMethod(); setCurrentDevice(); if (Home.get_follower()) { setConnectionStatusFollower(); } else if (prefs.getString("dex_collection_method", "bogus").equals("WifiWixel")) { setConnectionStatusWifiWixel(); } else { setConnectionStatus(); } setSensorStatus(); setTransmitterStatus(); setNotes(); futureDataCheck(); /* if (notes.getText().length()==0) { notes.setText("Swipe for more status pages!"); }*/ }
Example #10
Source Project: xDrip-plus Author: jamorham File: WatchUpdaterService.java License: GNU General Public License v3.0 | 6 votes |
private void sendActiveBtDeviceData() {//KS if (is_using_bt) {//only required for Collector running on watch forceGoogleApiConnect(); ActiveBluetoothDevice btDevice = ActiveBluetoothDevice.first(); if (btDevice != null) { if (wear_integration) { DataMap dataMap = new DataMap(); Log.d(TAG, "sendActiveBtDeviceData name=" + btDevice.name + " address=" + btDevice.address + " connected=" + btDevice.connected); dataMap.putLong("time", new Date().getTime()); // MOST IMPORTANT LINE FOR TIMESTAMP dataMap.putString("name", btDevice.name); dataMap.putString("address", btDevice.address); dataMap.putBoolean("connected", btDevice.connected); new SendToDataLayerThread(WEARABLE_ACTIVEBTDEVICE_DATA_PATH, googleApiClient).executeOnExecutor(xdrip.executor, dataMap); } } } else { Log.d(TAG, "Not sending activebluetoothdevice data as we are not using bt"); } }
Example #11
Source Project: xDrip-Experimental Author: StephenBlackWasAlreadyTaken File: ShareTest.java License: GNU General Public License v3.0 | 6 votes |
@Override public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { if (newState == BluetoothProfile.STATE_CONNECTED) { mBluetoothGatt = gatt; mConnectionState = STATE_CONNECTED; ActiveBluetoothDevice.connected(); Log.i(TAG, "Connected to GATT server."); Log.i(TAG, "Connection state: Bonded - " + device.getBondState()); if (device.getBondState() == BluetoothDevice.BOND_BONDED) { currentGattTask = GATT_SETUP; mBluetoothGatt.discoverServices(); } else { device.setPin("000000".getBytes()); device.createBond(); } } else if (newState == BluetoothProfile.STATE_DISCONNECTED) { mConnectionState = STATE_DISCONNECTED; ActiveBluetoothDevice.disconnected(); Log.w(TAG, "Disconnected from GATT server."); } }
Example #12
Source Project: xDrip-Experimental Author: StephenBlackWasAlreadyTaken File: ShareTest.java License: GNU General Public License v3.0 | 6 votes |
public void attemptConnection() { mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); if (device != null) { details.append("\nConnection state: " + " Device is not null"); mConnectionState = mBluetoothManager.getConnectionState(device, BluetoothProfile.GATT); } Log.i(TAG, "Connection state: " + mConnectionState); details.append("\nConnection state: " + mConnectionState); if (mConnectionState == STATE_DISCONNECTED || mConnectionState == STATE_DISCONNECTING) { ActiveBluetoothDevice btDevice = new Select().from(ActiveBluetoothDevice.class) .orderBy("_ID desc") .executeSingle(); if (btDevice != null) { details.append("\nBT Device: " + btDevice.name); mDeviceName = btDevice.name; mDeviceAddress = btDevice.address; mBluetoothAdapter = mBluetoothManager.getAdapter(); boolean newConnection = true; if(newConnection) { is_connected = connect(mDeviceAddress); details.append("\nConnecting...: "); } } } }
Example #13
Source Project: xDrip Author: StephenBlackWasAlreadyTaken File: ShareTest.java License: GNU General Public License v3.0 | 6 votes |
@Override public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { if (newState == BluetoothProfile.STATE_CONNECTED) { mBluetoothGatt = gatt; mConnectionState = STATE_CONNECTED; ActiveBluetoothDevice.connected(); Log.w(TAG, "Connected to GATT server."); Log.w(TAG, "Connection state: Bonded - " + device.getBondState()); if (device.getBondState() == BluetoothDevice.BOND_BONDED) { currentGattTask = GATT_SETUP; mBluetoothGatt.discoverServices(); } else { device.setPin("000000".getBytes()); device.createBond(); } } else if (newState == BluetoothProfile.STATE_DISCONNECTED) { mConnectionState = STATE_DISCONNECTED; ActiveBluetoothDevice.disconnected(); Log.w(TAG, "Disconnected from GATT server."); } }
Example #14
Source Project: xDrip Author: StephenBlackWasAlreadyTaken File: ShareTest.java License: GNU General Public License v3.0 | 6 votes |
public void attemptConnection() { mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); if (device != null) { details.append("\nConnection state: " + " Device is not null"); mConnectionState = mBluetoothManager.getConnectionState(device, BluetoothProfile.GATT); } Log.w(TAG, "Connection state: " + mConnectionState); details.append("\nConnection state: " + mConnectionState); if (mConnectionState == STATE_DISCONNECTED || mConnectionState == STATE_DISCONNECTING) { ActiveBluetoothDevice btDevice = new Select().from(ActiveBluetoothDevice.class) .orderBy("_ID desc") .executeSingle(); if (btDevice != null) { details.append("\nBT Device: " + btDevice.name); mDeviceName = btDevice.name; mDeviceAddress = btDevice.address; mBluetoothAdapter = mBluetoothManager.getAdapter(); boolean newConnection = true; if(newConnection) { is_connected = connect(mDeviceAddress); details.append("\nConnecting...: "); } } } }
Example #15
Source Project: xDrip Author: NightscoutFoundation File: ListenerService.java License: GNU General Public License v3.0 | 5 votes |
private void syncActiveBtDeviceData(DataMap dataMap, Context context) {//KS Log.d(TAG, "syncActiveBtDeviceData"); if (dataMap != null) { String name = dataMap.getString("name", ""); String address = dataMap.getString("address", ""); Boolean connected = dataMap.getBoolean("connected", false); Log.d(TAG, "syncActiveBtDeviceData add ActiveBluetoothDevice for name=" + name + " address=" + address + " connected=" + connected); Sensor.InitDb(context);//ensure database has already been initialized if (name != null && !name.isEmpty() && address != null && !address.isEmpty()) { final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); synchronized (ActiveBluetoothDevice.table_lock) { ActiveBluetoothDevice btDevice = new Select().from(ActiveBluetoothDevice.class) .orderBy("_ID desc") .executeSingle(); prefs.edit().putString("last_connected_device_address", address).apply(); if (btDevice == null) { ActiveBluetoothDevice newBtDevice = new ActiveBluetoothDevice(); newBtDevice.name = name; newBtDevice.address = address; newBtDevice.connected = connected; newBtDevice.save(); } else { btDevice.name = name; btDevice.address = address; btDevice.connected = connected; btDevice.save(); } } } } }
Example #16
Source Project: xDrip Author: NightscoutFoundation File: DexCollectionService.java License: GNU General Public License v3.0 | 5 votes |
private synchronized void handleConnectedStateChange() { mConnectionState = STATE_CONNECTED; scanMeister.stop(); if ((servicesDiscovered == DISCOVERED.NULL) || Pref.getBoolean("always_discover_services", true)) { Log.d(TAG, "Requesting to discover services: previous: " + servicesDiscovered); servicesDiscovered = DISCOVERED.PENDING; } ActiveBluetoothDevice.connected(); if (JoH.ratelimit("attempt-connection", 30)) { checkConnection(); // refresh status info } if (servicesDiscovered != DISCOVERED.COMPLETE) { if (mBluetoothGatt != null) { if (JoH.ratelimit("dexcollect-discover-services", 1)) { Log.d(TAG, "Calling discoverServices"); mBluetoothGatt.discoverServices(); } else { Log.d(TAG, "Discover services duplicate blocked by rate limit"); } } else { UserError.Log.d(TAG, "Wanted to discover services but gatt was null!"); } } else { Log.d(TAG, "Services already discovered"); checkImmediateSend(); } if (mBluetoothGatt == null) { //gregorybel: no needs to continue if Gatt is null! UserError.Log.e(TAG, "gregorybel: force disconnect!"); handleDisconnectedStateChange(); } }
Example #17
Source Project: xDrip Author: NightscoutFoundation File: DexCollectionService.java License: GNU General Public License v3.0 | 5 votes |
private synchronized void handleDisconnectedStateChange() { if (JoH.ratelimit("handle-disconnected-state-change", 2)) { mConnectionState = STATE_DISCONNECTED; ActiveBluetoothDevice.disconnected(); if (!getTrustAutoConnect()) { if (mBluetoothGatt != null) { UserError.Log.d(TAG, "Sending disconnection"); try { mBluetoothGatt.disconnect(); } catch (Exception e) { // } } } // TODO should we allow close when trusting auto-connect? if (prefs.getBoolean("close_gatt_on_ble_disconnect", true)) { if (mBluetoothGatt != null) { Log.i(TAG, "onConnectionStateChange: mBluetoothGatt is not null, closing."); if (JoH.ratelimit("refresh-gatt", 60)) { Log.d(TAG, "Refresh result state close: " + JoH.refreshDeviceCache(TAG, mBluetoothGatt)); } mBluetoothGatt.close(); mBluetoothGatt = null; mCharacteristic = null; servicesDiscovered = DISCOVERED.NULL; } else { Log.d(TAG, "mBluetoothGatt is null so not closing"); } lastdata = null; } else { UserError.Log.d(TAG, "Not closing gatt on bluetooth disconnect"); } Log.i(TAG, "onConnectionStateChange: Disconnected from GATT server."); setRetryTimer(); } else { UserError.Log.d(TAG, "Ignoring duplicate disconnected state change"); } }
Example #18
Source Project: xDrip Author: NightscoutFoundation File: Blukon.java License: GNU General Public License v3.0 | 5 votes |
public static boolean expectingBlukonDevice() { try { final ActiveBluetoothDevice btDevice = ActiveBluetoothDevice.first(); if (btDevice.name.startsWith("BLU")) return true; } catch (Exception e) { // } return false; }
Example #19
Source Project: xDrip Author: NightscoutFoundation File: Blukon.java License: GNU General Public License v3.0 | 5 votes |
public static void unBondIfBlukonAtInit() { try { if (Blukon.expectingBlukonDevice() && Pref.getBooleanDefaultFalse("blukon_unbonding")) { final ActiveBluetoothDevice btDevice = ActiveBluetoothDevice.first(); if (btDevice != null) { UserError.Log.d(TAG, "Unbonding blukon at initialization"); JoH.unBond(btDevice.address); } } } catch (Exception e) { UserError.Log.e(TAG, "Got exception trying to unbond blukon at init"); } }
Example #20
Source Project: xDrip Author: NightscoutFoundation File: DexCollectionService.java License: GNU General Public License v3.0 | 5 votes |
private synchronized void handleConnectedStateChange() { mConnectionState = STATE_CONNECTED; scanMeister.stop(); if ((servicesDiscovered == DISCOVERED.NULL) || Pref.getBoolean("always_discover_services", true)) { Log.d(TAG, "Requesting to discover services: previous: " + servicesDiscovered); servicesDiscovered = DISCOVERED.PENDING; } ActiveBluetoothDevice.connected(); if (JoH.ratelimit("attempt-connection", 30)) { checkConnection(); // refresh status info } if (servicesDiscovered != DISCOVERED.COMPLETE) { if (mBluetoothGatt != null) { if (JoH.ratelimit("dexcollect-discover-services", 1)) { Log.d(TAG, "Calling discoverServices"); mBluetoothGatt.discoverServices(); } else { Log.d(TAG, "Discover services duplicate blocked by rate limit"); } } else { UserError.Log.d(TAG, "Wanted to discover services but gatt was null!"); } } else { Log.d(TAG, "Services already discovered"); checkImmediateSend(); } if (mBluetoothGatt == null) { //gregorybel: no needs to continue if Gatt is null! UserError.Log.e(TAG, "gregorybel: force disconnect!"); handleDisconnectedStateChange(); } }
Example #21
Source Project: xDrip Author: NightscoutFoundation File: DexCollectionService.java License: GNU General Public License v3.0 | 5 votes |
private synchronized void handleDisconnectedStateChange() { if (JoH.ratelimit("handle-disconnected-state-change", 2)) { mConnectionState = STATE_DISCONNECTED; ActiveBluetoothDevice.disconnected(); if (!getTrustAutoConnect()) { if (mBluetoothGatt != null) { UserError.Log.d(TAG, "Sending disconnection"); try { mBluetoothGatt.disconnect(); } catch (Exception e) { // } } } // TODO should we allow close when trusting auto-connect? if (prefs.getBoolean("close_gatt_on_ble_disconnect", true)) { if (mBluetoothGatt != null) { Log.i(TAG, "onConnectionStateChange: mBluetoothGatt is not null, closing."); if (JoH.ratelimit("refresh-gatt", 60)) { Log.d(TAG, "Refresh result state close: " + JoH.refreshDeviceCache(TAG, mBluetoothGatt)); } mBluetoothGatt.close(); mBluetoothGatt = null; mCharacteristic = null; servicesDiscovered = DISCOVERED.NULL; } else { Log.d(TAG, "mBluetoothGatt is null so not closing"); } lastdata = null; } else { UserError.Log.d(TAG, "Not closing gatt on bluetooth disconnect"); } Log.i(TAG, "onConnectionStateChange: Disconnected from GATT server."); setRetryTimer(); } else { UserError.Log.d(TAG, "Ignoring duplicate disconnected state change"); } }
Example #22
Source Project: xDrip Author: NightscoutFoundation File: Blukon.java License: GNU General Public License v3.0 | 5 votes |
public static boolean expectingBlukonDevice() { try { final ActiveBluetoothDevice btDevice = ActiveBluetoothDevice.first(); if (btDevice.name.startsWith("BLU")) return true; } catch (Exception e) { // } return false; }
Example #23
Source Project: xDrip Author: NightscoutFoundation File: Blukon.java License: GNU General Public License v3.0 | 5 votes |
public static void unBondIfBlukonAtInit() { try { if (Blukon.expectingBlukonDevice() && Pref.getBooleanDefaultFalse("blukon_unbonding")) { final ActiveBluetoothDevice btDevice = ActiveBluetoothDevice.first(); if (btDevice != null) { Log.d(TAG, "Unbonding blukon at initialization"); JoH.unBond(btDevice.address); } } } catch (Exception e) { Log.e(TAG, "Got exception trying to unbond blukon at init"); } }
Example #24
Source Project: xDrip Author: NightscoutFoundation File: Home.java License: GNU General Public License v3.0 | 5 votes |
private void updateCurrentBgInfoForBtBasedWixel(DexCollectionType collector, TextView notificationText) { if ((android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR2)) { notificationText.setText(R.string.unfortunately_andoird_version_no_blueooth_low_energy); return; } if (ActiveBluetoothDevice.first() == null) { notificationText.setText(R.string.first_use_menu_to_scan); return; } updateCurrentBgInfoCommon(collector, notificationText); }
Example #25
Source Project: xDrip Author: NightscoutFoundation File: Home.java License: GNU General Public License v3.0 | 5 votes |
private void updateCurrentBgInfoForBtShare(TextView notificationText) { if ((android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR2)) { notificationText.setText(R.string.unfortunately_andoird_version_no_blueooth_low_energy); return; } String receiverSn = Pref.getString("share_key", "SM00000000").toUpperCase(); if (receiverSn.compareTo("SM00000000") == 0 || receiverSn.length() == 0) { notificationText.setText(R.string.please_set_dex_receiver_serial_number); return; } if (receiverSn.length() < 10) { notificationText.setText(R.string.double_check_dex_receiver_serial_number); return; } if (ActiveBluetoothDevice.first() == null) { notificationText.setText(R.string.now_pair_with_your_dexcom_share); return; } if (!Sensor.isActive()) { notificationText.setText(R.string.now_choose_start_sensor_in_settings); return; } displayCurrentInfo(); }
Example #26
Source Project: xDrip Author: NightscoutFoundation File: Amazfitservice.java License: GNU General Public License v3.0 | 5 votes |
public String getCurrentDevice() { activeBluetoothDevice = ActiveBluetoothDevice.first(); mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); String currentdevice; if (activeBluetoothDevice != null) { currentdevice = activeBluetoothDevice.name; } else { currentdevice = "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")); if (Build.VERSION.SDK_INT >= 18) { 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)) { currentdevice = defaultTransmitter.transmitterId; } } } } } else { currentdevice = "No Bluetooth"; } } return currentdevice; }
Example #27
Source Project: xDrip-plus Author: jamorham File: ListenerService.java License: GNU General Public License v3.0 | 5 votes |
private void syncActiveBtDeviceData(DataMap dataMap, Context context) {//KS Log.d(TAG, "syncActiveBtDeviceData"); if (dataMap != null) { String name = dataMap.getString("name", ""); String address = dataMap.getString("address", ""); Boolean connected = dataMap.getBoolean("connected", false); Log.d(TAG, "syncActiveBtDeviceData add ActiveBluetoothDevice for name=" + name + " address=" + address + " connected=" + connected); Sensor.InitDb(context);//ensure database has already been initialized if (name != null && !name.isEmpty() && address != null && !address.isEmpty()) { final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); synchronized (ActiveBluetoothDevice.table_lock) { ActiveBluetoothDevice btDevice = new Select().from(ActiveBluetoothDevice.class) .orderBy("_ID desc") .executeSingle(); prefs.edit().putString("last_connected_device_address", address).apply(); if (btDevice == null) { ActiveBluetoothDevice newBtDevice = new ActiveBluetoothDevice(); newBtDevice.name = name; newBtDevice.address = address; newBtDevice.connected = connected; newBtDevice.save(); } else { btDevice.name = name; btDevice.address = address; btDevice.connected = connected; btDevice.save(); } } } } }
Example #28
Source Project: xDrip-plus Author: jamorham File: DexCollectionService.java License: GNU General Public License v3.0 | 5 votes |
private synchronized void handleConnectedStateChange() { mConnectionState = STATE_CONNECTED; scanMeister.stop(); if ((servicesDiscovered == DISCOVERED.NULL) || Pref.getBoolean("always_discover_services", true)) { Log.d(TAG, "Requesting to discover services: previous: " + servicesDiscovered); servicesDiscovered = DISCOVERED.PENDING; } ActiveBluetoothDevice.connected(); if (JoH.ratelimit("attempt-connection", 30)) { checkConnection(); // refresh status info } if (servicesDiscovered != DISCOVERED.COMPLETE) { if (mBluetoothGatt != null) { if (JoH.ratelimit("dexcollect-discover-services", 1)) { Log.d(TAG, "Calling discoverServices"); mBluetoothGatt.discoverServices(); } else { Log.d(TAG, "Discover services duplicate blocked by rate limit"); } } else { UserError.Log.d(TAG, "Wanted to discover services but gatt was null!"); } } else { Log.d(TAG, "Services already discovered"); checkImmediateSend(); } if (mBluetoothGatt == null) { //gregorybel: no needs to continue if Gatt is null! UserError.Log.e(TAG, "gregorybel: force disconnect!"); handleDisconnectedStateChange(); } }
Example #29
Source Project: xDrip-plus Author: jamorham File: DexCollectionService.java License: GNU General Public License v3.0 | 5 votes |
private synchronized void handleDisconnectedStateChange() { if (JoH.ratelimit("handle-disconnected-state-change", 2)) { mConnectionState = STATE_DISCONNECTED; ActiveBluetoothDevice.disconnected(); if (!getTrustAutoConnect()) { if (mBluetoothGatt != null) { UserError.Log.d(TAG, "Sending disconnection"); try { mBluetoothGatt.disconnect(); } catch (Exception e) { // } } } // TODO should we allow close when trusting auto-connect? if (prefs.getBoolean("close_gatt_on_ble_disconnect", true)) { if (mBluetoothGatt != null) { Log.i(TAG, "onConnectionStateChange: mBluetoothGatt is not null, closing."); if (JoH.ratelimit("refresh-gatt", 60)) { Log.d(TAG, "Refresh result state close: " + JoH.refreshDeviceCache(TAG, mBluetoothGatt)); } mBluetoothGatt.close(); mBluetoothGatt = null; mCharacteristic = null; servicesDiscovered = DISCOVERED.NULL; } else { Log.d(TAG, "mBluetoothGatt is null so not closing"); } lastdata = null; } else { UserError.Log.d(TAG, "Not closing gatt on bluetooth disconnect"); } Log.i(TAG, "onConnectionStateChange: Disconnected from GATT server."); setRetryTimer(); } else { UserError.Log.d(TAG, "Ignoring duplicate disconnected state change"); } }
Example #30
Source Project: xDrip-plus Author: jamorham File: Blukon.java License: GNU General Public License v3.0 | 5 votes |
public static boolean expectingBlukonDevice() { try { final ActiveBluetoothDevice btDevice = ActiveBluetoothDevice.first(); if (btDevice.name.startsWith("BLU")) return true; } catch (Exception e) { // } return false; }