Search in sources :

Example 6 with BluetoothGattCharacteristic

use of android.bluetooth.BluetoothGattCharacteristic in project Gadgetbridge by Freeyourgadget.

the class MiBandSupport method pair.

/* private MiBandSupport requestHRInfo(TransactionBuilder builder) {
        LOG.debug("Requesting HR Info!");
        BluetoothGattCharacteristic HRInfo = getCharacteristic(MiBandService.UUID_CHAR_HEART_RATE_MEASUREMENT);
        builder.read(HRInfo);
        BluetoothGattCharacteristic HR_Point = getCharacteristic(GattCharacteristic.UUID_CHARACTERISTIC_HEART_RATE_CONTROL_POINT);
        builder.read(HR_Point);
        return this;
    }
    */
/**
     * Part of HR test. Do not call manually.
     *
     * @param transaction
     * @return
     */
/*
    private MiBandSupport heartrate(TransactionBuilder transaction) {
        LOG.info("Attempting to read HR ...");
        BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandService.UUID_CHAR_HEART_RATE_MEASUREMENT);
        if (characteristic != null) {
            transaction.write(characteristic, new byte[]{MiBandService.COMMAND_SET__HR_CONTINUOUS});
        } else {
            LOG.info("Unable to read HR from  MI device -- characteristic not available");
        }
        return this;
    }*/
/**
     * Part of device initialization process. Do not call manually.
     *
     * @param transaction
     * @return
     */
private MiBandSupport pair(TransactionBuilder transaction) {
    // this is apparently only needed to get a more strict bond between mobile and mi band,
    // e.g. such that Mi Fit and Gadgetbridge can coexist without needing to re-pair (with
    // full device-data-reset).
    // Unfortunately this extra pairing causes problems when bonding is not used/does not work
    // so we only do this when configured to keep data on the device
    Prefs prefs = GBApplication.getPrefs();
    if (prefs.getBoolean(MiBandConst.PREF_MIBAND_DONT_ACK_TRANSFER, false)) {
        LOG.info("Attempting to pair MI device...");
        BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_PAIR);
        if (characteristic != null) {
            transaction.write(characteristic, new byte[] { 2 });
        } else {
            LOG.info("Unable to pair MI device -- characteristic not available");
        }
    }
    return this;
}
Also used : Prefs(nodomain.freeyourgadget.gadgetbridge.util.Prefs) BluetoothGattCharacteristic(android.bluetooth.BluetoothGattCharacteristic)

Example 7 with BluetoothGattCharacteristic

use of android.bluetooth.BluetoothGattCharacteristic in project Gadgetbridge by Freeyourgadget.

the class MiBandSupport method requestDeviceInfo.

private MiBandSupport requestDeviceInfo(TransactionBuilder builder) {
    LOG.debug("Requesting Device Info!");
    BluetoothGattCharacteristic deviceInfo = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_DEVICE_INFO);
    builder.read(deviceInfo);
    BluetoothGattCharacteristic deviceName = getCharacteristic(GattCharacteristic.UUID_CHARACTERISTIC_GAP_DEVICE_NAME);
    builder.read(deviceName);
    return this;
}
Also used : BluetoothGattCharacteristic(android.bluetooth.BluetoothGattCharacteristic)

Example 8 with BluetoothGattCharacteristic

use of android.bluetooth.BluetoothGattCharacteristic in project Gadgetbridge by Freeyourgadget.

the class FetchActivityOperation method doPerform.

@Override
protected void doPerform() throws IOException {
    TransactionBuilder builder = performInitialized("fetching activity data");
    getSupport().setLowLatency(builder);
    builder.add(new SetDeviceBusyAction(getDevice(), getContext().getString(R.string.busy_task_fetch_activity_data), getContext()));
    BluetoothGattCharacteristic characteristicFetch = getCharacteristic(MiBand2Service.UUID_UNKNOWN_CHARACTERISTIC4);
    builder.notify(characteristicFetch, true);
    BluetoothGattCharacteristic characteristicActivityData = getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_5_ACTIVITY_DATA);
    GregorianCalendar sinceWhen = getLastSuccessfulSyncTime();
    builder.write(characteristicFetch, BLETypeConversions.join(new byte[] { MiBand2Service.COMMAND_ACTIVITY_DATA_START_DATE, 0x01 }, getSupport().getTimeBytes(sinceWhen, TimeUnit.MINUTES)));
    // TODO: actually wait for the success-reply
    builder.add(new WaitAction(1000));
    builder.notify(characteristicActivityData, true);
    builder.write(characteristicFetch, new byte[] { MiBand2Service.COMMAND_FETCH_ACTIVITY_DATA });
    builder.queue(getQueue());
}
Also used : GregorianCalendar(java.util.GregorianCalendar) TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder) SetDeviceBusyAction(nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceBusyAction) BluetoothGattCharacteristic(android.bluetooth.BluetoothGattCharacteristic) WaitAction(nodomain.freeyourgadget.gadgetbridge.service.btle.actions.WaitAction)

Example 9 with BluetoothGattCharacteristic

use of android.bluetooth.BluetoothGattCharacteristic in project Gadgetbridge by Freeyourgadget.

the class PebbleGATTClient method onServicesDiscovered.

public void onServicesDiscovered(BluetoothGatt gatt, int status) {
    if (!mPebbleLESupport.isExpectedDevice(gatt.getDevice())) {
        return;
    }
    LOG.info("onServicesDiscovered() status = " + status);
    if (status == BluetoothGatt.GATT_SUCCESS) {
        BluetoothGattCharacteristic connectionPararmharacteristic = gatt.getService(SERVICE_UUID).getCharacteristic(CONNECTION_PARAMETERS_CHARACTERISTIC);
        oldPebble = connectionPararmharacteristic == null;
        if (oldPebble) {
            LOG.info("This seems to be an older le enabled pebble");
        }
        if (doPairing) {
            BluetoothGattCharacteristic characteristic = gatt.getService(SERVICE_UUID).getCharacteristic(PAIRING_TRIGGER_CHARACTERISTIC);
            if ((characteristic.getProperties() & PROPERTY_WRITE) != 0) {
                characteristic.setValue(new byte[] { 1 });
                gatt.writeCharacteristic(characteristic);
            } else {
                LOG.info("This seems to be some <4.0 FW Pebble, reading pairing trigger");
                gatt.readCharacteristic(characteristic);
            }
        } else {
            if (oldPebble) {
                subscribeToConnectivity(gatt);
            } else {
                subscribeToConnectionParams(gatt);
            }
        }
    }
}
Also used : BluetoothGattCharacteristic(android.bluetooth.BluetoothGattCharacteristic)

Example 10 with BluetoothGattCharacteristic

use of android.bluetooth.BluetoothGattCharacteristic in project Gadgetbridge by Freeyourgadget.

the class PebbleGATTServer method onServiceAdded.

public void onServiceAdded(int status, BluetoothGattService service) {
    LOG.info("onServiceAdded() status = " + status + " service = " + service.getUuid());
    if (status == BluetoothGatt.GATT_SUCCESS && service.getUuid().equals(SERVER_SERVICE)) {
        final BluetoothGattService badbadService = new BluetoothGattService(SERVER_SERVICE_BADBAD, BluetoothGattService.SERVICE_TYPE_PRIMARY);
        badbadService.addCharacteristic(new BluetoothGattCharacteristic(SERVER_SERVICE_BADBAD, BluetoothGattCharacteristic.PROPERTY_READ, BluetoothGattCharacteristic.PERMISSION_READ));
        mBluetoothGattServer.addService(badbadService);
    }
}
Also used : BluetoothGattService(android.bluetooth.BluetoothGattService) BluetoothGattCharacteristic(android.bluetooth.BluetoothGattCharacteristic)

Aggregations

BluetoothGattCharacteristic (android.bluetooth.BluetoothGattCharacteristic)42 BluetoothGattService (android.bluetooth.BluetoothGattService)8 TransactionBuilder (nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder)7 IOException (java.io.IOException)6 BluetoothGattDescriptor (android.bluetooth.BluetoothGattDescriptor)5 GregorianCalendar (java.util.GregorianCalendar)4 GBAlarm (nodomain.freeyourgadget.gadgetbridge.impl.GBAlarm)4 Alarm (nodomain.freeyourgadget.gadgetbridge.model.Alarm)4 Calendar (java.util.Calendar)3 HashMap (java.util.HashMap)3 Prefs (nodomain.freeyourgadget.gadgetbridge.util.Prefs)3 UUID (java.util.UUID)2 CalendarEvents (nodomain.freeyourgadget.gadgetbridge.model.CalendarEvents)2 BaseSensor (sample.ble.sensortag.sensor.BaseSensor)2 TiPeriodicalSensor (sample.ble.sensortag.sensor.ti.TiPeriodicalSensor)2 BluetoothAdapter (android.bluetooth.BluetoothAdapter)1 BluetoothDevice (android.bluetooth.BluetoothDevice)1 BluetoothGatt (android.bluetooth.BluetoothGatt)1 BluetoothManager (android.bluetooth.BluetoothManager)1 Context (android.content.Context)1