Search in sources :

Example 1 with ActiveBluetoothDevice

use of com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice in project xDrip by NightscoutFoundation.

the class ShareTest method attemptConnection.

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...: ");
            }
        }
    }
}
Also used : ActiveBluetoothDevice(com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice) Select(com.activeandroid.query.Select)

Example 2 with ActiveBluetoothDevice

use of com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice in project xDrip by NightscoutFoundation.

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("Connected");
    } else {
        connection_status.setText("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("No bluetooth");
        }
    }
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) ActiveBluetoothDevice(com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice) Transmitter(com.eveningoutpost.dexdrip.G5Model.Transmitter)

Example 3 with ActiveBluetoothDevice

use of com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice in project xDrip by NightscoutFoundation.

the class SystemStatusFragment 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"));
        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)) {
                            current_device.setText(defaultTransmitter.transmitterId);
                        }
                    }
                }
            }
        } else {
            current_device.setText("No Bluetooth");
        }
    }
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) ActiveBluetoothDevice(com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice) Transmitter(com.eveningoutpost.dexdrip.G5Model.Transmitter)

Example 4 with ActiveBluetoothDevice

use of com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice in project xDrip by NightscoutFoundation.

the class SystemStatusFragment method setConnectionStatus.

private void setConnectionStatus() {
    boolean connected = false;
    if (mBluetoothManager != null && activeBluetoothDevice != null && (Build.VERSION.SDK_INT >= 18)) {
        for (BluetoothDevice bluetoothDevice : mBluetoothManager.getConnectedDevices(BluetoothProfile.GATT)) {
            if (bluetoothDevice.getAddress().compareTo(activeBluetoothDevice.address) == 0) {
                connected = true;
            }
        }
    }
    if (connected) {
        connection_status.setText("Connected");
    } else {
        connection_status.setText("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"));
        if (Build.VERSION.SDK_INT >= 18)
            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("No bluetooth");
        }
    }
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) ActiveBluetoothDevice(com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice) Transmitter(com.eveningoutpost.dexdrip.G5Model.Transmitter)

Example 5 with ActiveBluetoothDevice

use of com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice in project xDrip by NightscoutFoundation.

the class ListenerService method syncActiveBtDeviceData.

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);
        // ensure database has already been initialized
        Sensor.InitDb(context);
        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();
                }
            }
        }
    }
}
Also used : ActiveBluetoothDevice(com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice) SharedPreferences(android.content.SharedPreferences) Select(com.activeandroid.query.Select)

Aggregations

ActiveBluetoothDevice (com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice)22 BluetoothDevice (android.bluetooth.BluetoothDevice)16 Transmitter (com.eveningoutpost.dexdrip.G5Model.Transmitter)8 Select (com.activeandroid.query.Select)6 BluetoothManager (android.bluetooth.BluetoothManager)4 SharedPreferences (android.content.SharedPreferences)4 DataMap (com.google.android.gms.wearable.DataMap)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Date (java.util.Date)2