Search in sources :

Example 26 with ActiveBluetoothDevice

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

Example 27 with ActiveBluetoothDevice

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));
        }
    }
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) ActiveBluetoothDevice(com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice) Transmitter(com.eveningoutpost.dexdrip.G5Model.Transmitter)

Example 28 with ActiveBluetoothDevice

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;
    }
}
Also used : ActiveBluetoothDevice(com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice) BluetoothDevice(android.bluetooth.BluetoothDevice) ActiveBluetoothDevice(com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice)

Aggregations

ActiveBluetoothDevice (com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice)28 BluetoothDevice (android.bluetooth.BluetoothDevice)18 Transmitter (com.eveningoutpost.dexdrip.G5Model.Transmitter)10 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 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2