Search in sources :

Example 26 with BluetoothGattCharacteristic

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

the class V1NotificationStrategy method sendCustomNotification.

/**
     * Adds a custom notification to the given transaction builder
     * @param vibrationProfile specifies how and how often the Band shall vibrate.
     * @param simpleNotification
     * @param flashTimes
     * @param flashColour
     * @param originalColour
     * @param flashDuration
     * @param extraAction      an extra action to be executed after every vibration and flash sequence. Allows to abort the repetition, for example.
     * @param builder
     */
@Override
public void sendCustomNotification(VibrationProfile vibrationProfile, SimpleNotification simpleNotification, int flashTimes, int flashColour, int originalColour, long flashDuration, BtLEAction extraAction, TransactionBuilder builder) {
    BluetoothGattCharacteristic controlPoint = support.getCharacteristic(MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT);
    for (short i = 0; i < vibrationProfile.getRepeat(); i++) {
        int[] onOffSequence = vibrationProfile.getOnOffSequence();
        for (int j = 0; j < onOffSequence.length; j++) {
            int on = onOffSequence[j];
            // longer than 500ms is not possible
            on = Math.min(500, on);
            builder.write(controlPoint, startVibrate);
            builder.wait(on);
            builder.write(controlPoint, stopVibrate);
            if (++j < onOffSequence.length) {
                // wait at least 25ms
                int off = Math.max(onOffSequence[j], 25);
                builder.wait(off);
            }
            if (extraAction != null) {
                builder.add(extraAction);
            }
        }
    }
}
Also used : BluetoothGattCharacteristic(android.bluetooth.BluetoothGattCharacteristic)

Example 27 with BluetoothGattCharacteristic

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

the class V1NotificationStrategy method stopCurrentNotification.

@Override
public void stopCurrentNotification(TransactionBuilder builder) {
    BluetoothGattCharacteristic controlPoint = support.getCharacteristic(MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT);
    builder.write(controlPoint, stopVibrate);
}
Also used : BluetoothGattCharacteristic(android.bluetooth.BluetoothGattCharacteristic)

Example 28 with BluetoothGattCharacteristic

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

the class V2NotificationStrategy method sendCustomNotification.

protected void sendCustomNotification(VibrationProfile vibrationProfile, @Nullable SimpleNotification simpleNotification, BtLEAction extraAction, TransactionBuilder builder) {
    //use the new alert characteristic
    BluetoothGattCharacteristic alert = support.getCharacteristic(GattCharacteristic.UUID_CHARACTERISTIC_ALERT_LEVEL);
    for (short i = 0; i < vibrationProfile.getRepeat(); i++) {
        int[] onOffSequence = vibrationProfile.getOnOffSequence();
        for (int j = 0; j < onOffSequence.length; j++) {
            int on = onOffSequence[j];
            // longer than 500ms is not possible
            on = Math.min(500, on);
            //MILD_ALERT lights up GREEN leds, HIGH_ALERT lights up RED leds
            builder.write(alert, new byte[] { GattCharacteristic.MILD_ALERT });
            //                builder.wait(on);
            //                builder.write(alert, new byte[]{GattCharacteristic.HIGH_ALERT});
            builder.wait(on);
            builder.write(alert, new byte[] { GattCharacteristic.NO_ALERT });
            if (++j < onOffSequence.length) {
                // wait at least 25ms
                int off = Math.max(onOffSequence[j], 25);
                builder.wait(off);
            }
            if (extraAction != null) {
                builder.add(extraAction);
            }
        }
    }
}
Also used : BluetoothGattCharacteristic(android.bluetooth.BluetoothGattCharacteristic)

Example 29 with BluetoothGattCharacteristic

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

the class V2NotificationStrategy method stopCurrentNotification.

@Override
public void stopCurrentNotification(TransactionBuilder builder) {
    BluetoothGattCharacteristic alert = support.getCharacteristic(GattCharacteristic.UUID_CHARACTERISTIC_ALERT_LEVEL);
    builder.write(alert, new byte[] { GattCharacteristic.NO_ALERT });
}
Also used : BluetoothGattCharacteristic(android.bluetooth.BluetoothGattCharacteristic)

Example 30 with BluetoothGattCharacteristic

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

the class MiBandSupport method setCurrentTime.

/**
     * Sets the current time to the Mi device using the given builder.
     *
     * @param builder
     */
private MiBandSupport setCurrentTime(TransactionBuilder builder) {
    Calendar now = GregorianCalendar.getInstance();
    Date date = now.getTime();
    LOG.info("Sending current time to Mi Band: " + DateTimeUtils.formatDate(date) + " (" + date.toGMTString() + ")");
    byte[] nowBytes = MiBandDateConverter.calendarToRawBytes(now);
    byte[] time = new byte[] { nowBytes[0], nowBytes[1], nowBytes[2], nowBytes[3], nowBytes[4], nowBytes[5], (byte) 0x0f, (byte) 0x0f, (byte) 0x0f, (byte) 0x0f, (byte) 0x0f, (byte) 0x0f };
    BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_DATE_TIME);
    if (characteristic != null) {
        builder.write(characteristic, time);
    } else {
        LOG.info("Unable to set time -- characteristic not available");
    }
    return this;
}
Also used : GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) BluetoothGattCharacteristic(android.bluetooth.BluetoothGattCharacteristic) Date(java.util.Date)

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