Search in sources :

Example 31 with BluetoothGattCharacteristic

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

the class WriteAction method run.

@Override
public boolean run(BluetoothGatt gatt) {
    BluetoothGattCharacteristic characteristic = getCharacteristic();
    int properties = characteristic.getProperties();
    //TODO: expectsResult should return false if PROPERTY_WRITE_NO_RESPONSE is true, but this leads to timing issues
    if ((properties & BluetoothGattCharacteristic.PROPERTY_WRITE) > 0 || ((properties & BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) > 0)) {
        return writeValue(gatt, characteristic, value);
    }
    return false;
}
Also used : BluetoothGattCharacteristic(android.bluetooth.BluetoothGattCharacteristic)

Example 32 with BluetoothGattCharacteristic

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

the class MiBandSupport method enableFurtherNotifications.

private MiBandSupport enableFurtherNotifications(TransactionBuilder builder, boolean enable) {
    builder.notify(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_REALTIME_STEPS), enable).notify(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_ACTIVITY_DATA), enable).notify(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_BATTERY), enable).notify(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_SENSOR_DATA), enable);
    // cannot use supportsHeartrate() here because we don't have that information yet
    BluetoothGattCharacteristic heartrateCharacteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_HEART_RATE_MEASUREMENT);
    if (heartrateCharacteristic != null) {
        builder.notify(heartrateCharacteristic, enable);
    }
    return this;
}
Also used : BluetoothGattCharacteristic(android.bluetooth.BluetoothGattCharacteristic)

Example 33 with BluetoothGattCharacteristic

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

the class MiBandSupport method onSetAlarms.

@Override
public void onSetAlarms(ArrayList<? extends Alarm> alarms) {
    try {
        BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT);
        TransactionBuilder builder = performInitialized("Set alarm");
        boolean anyAlarmEnabled = false;
        for (Alarm alarm : alarms) {
            anyAlarmEnabled |= alarm.isEnabled();
            queueAlarm(alarm, builder, characteristic);
        }
        builder.queue(getQueue());
        if (anyAlarmEnabled) {
            GB.toast(getContext(), getContext().getString(R.string.user_feedback_miband_set_alarms_ok), Toast.LENGTH_SHORT, GB.INFO);
        } else {
            GB.toast(getContext(), getContext().getString(R.string.user_feedback_all_alarms_disabled), Toast.LENGTH_SHORT, GB.INFO);
        }
    } catch (IOException ex) {
        GB.toast(getContext(), getContext().getString(R.string.user_feedback_miband_set_alarms_failed), Toast.LENGTH_LONG, GB.ERROR, ex);
    }
}
Also used : GBAlarm(nodomain.freeyourgadget.gadgetbridge.impl.GBAlarm) Alarm(nodomain.freeyourgadget.gadgetbridge.model.Alarm) TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder) IOException(java.io.IOException) BluetoothGattCharacteristic(android.bluetooth.BluetoothGattCharacteristic)

Example 34 with BluetoothGattCharacteristic

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

the class MiBandSupport method requestBatteryInfo.

private MiBandSupport requestBatteryInfo(TransactionBuilder builder) {
    LOG.debug("Requesting Battery Info!");
    BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_BATTERY);
    builder.read(characteristic);
    return this;
}
Also used : BluetoothGattCharacteristic(android.bluetooth.BluetoothGattCharacteristic)

Example 35 with BluetoothGattCharacteristic

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

the class MiBandSupport method sendCalendarEvents.

/**
     * Fetch the events from the android device calendars and set the alarms on the miband.
     */
private void sendCalendarEvents() {
    try {
        TransactionBuilder builder = performInitialized("Send upcoming events");
        BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT);
        Prefs prefs = GBApplication.getPrefs();
        int availableSlots = prefs.getInt(MiBandConst.PREF_MIBAND_RESERVE_ALARM_FOR_CALENDAR, 0);
        if (availableSlots > 0) {
            CalendarEvents upcomingEvents = new CalendarEvents();
            List<CalendarEvents.CalendarEvent> mEvents = upcomingEvents.getCalendarEventList(getContext());
            int iteration = 0;
            for (CalendarEvents.CalendarEvent mEvt : mEvents) {
                if (iteration >= availableSlots || iteration > 2) {
                    break;
                }
                int slotToUse = 2 - iteration;
                Calendar calendar = Calendar.getInstance();
                calendar.setTimeInMillis(mEvt.getBegin());
                Alarm alarm = GBAlarm.createSingleShot(slotToUse, false, calendar);
                queueAlarm(alarm, builder, characteristic);
                iteration++;
            }
            builder.queue(getQueue());
        }
    } catch (IOException ex) {
        LOG.error("Unable to send Events to MI device", ex);
    }
}
Also used : GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GBAlarm(nodomain.freeyourgadget.gadgetbridge.impl.GBAlarm) Alarm(nodomain.freeyourgadget.gadgetbridge.model.Alarm) TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder) CalendarEvents(nodomain.freeyourgadget.gadgetbridge.model.CalendarEvents) IOException(java.io.IOException) Prefs(nodomain.freeyourgadget.gadgetbridge.util.Prefs) 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