Search in sources :

Example 91 with TransactionBuilder

use of nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder in project Gadgetbridge by Freeyourgadget.

the class MiBandSupport method onEnableRealtimeHeartRateMeasurement.

@Override
public void onEnableRealtimeHeartRateMeasurement(boolean enable) {
    if (supportsHeartRate()) {
        try {
            TransactionBuilder builder = performInitialized("EnableRealtimeHeartRateMeasurement");
            if (enable) {
                builder.write(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_HEART_RATE_CONTROL_POINT), stopHeartMeasurementManual);
                builder.write(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_HEART_RATE_CONTROL_POINT), startHeartMeasurementContinuous);
            } else {
                builder.write(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_HEART_RATE_CONTROL_POINT), stopHeartMeasurementContinuous);
            }
            builder.queue(getQueue());
            enableRealtimeSamplesTimer(enable);
        } catch (IOException ex) {
            LOG.error("Unable to enable realtime heart rate measurement in  MI1S", ex);
        }
    }
}
Also used : TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder) IOException(java.io.IOException)

Example 92 with TransactionBuilder

use of nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder in project Gadgetbridge by Freeyourgadget.

the class MiBandSupport method onSetTime.

@Override
public void onSetTime() {
    try {
        TransactionBuilder builder = performInitialized("Set date and time");
        setCurrentTime(builder);
        builder.queue(getQueue());
    } catch (IOException ex) {
        LOG.error("Unable to set time on MI device", ex);
    }
    // TODO: once we have a common strategy for sending events (e.g. EventHandler), remove this call from here. Meanwhile it does no harm.
    sendCalendarEvents();
}
Also used : TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder) IOException(java.io.IOException)

Example 93 with TransactionBuilder

use of nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder in project Gadgetbridge by Freeyourgadget.

the class MiBandSupport method onReset.

@Override
public void onReset(int flags) {
    try {
        TransactionBuilder builder = performInitialized("reset");
        if ((flags & GBDeviceProtocol.RESET_FLAGS_FACTORY_RESET) != 0) {
            builder.write(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT), factoryReset);
        } else {
            builder.write(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT), reboot);
        }
        builder.queue(getQueue());
    } catch (IOException ex) {
        LOG.error("Unable to reset", ex);
    }
}
Also used : TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder) IOException(java.io.IOException)

Example 94 with TransactionBuilder

use of nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder in project Gadgetbridge by Freeyourgadget.

the class MiBandSupport method performPreferredNotification.

private void performPreferredNotification(String task, @Nullable SimpleNotification simpleNotification, String notificationOrigin, BtLEAction extraAction) {
    try {
        TransactionBuilder builder = performInitialized(task);
        Prefs prefs = GBApplication.getPrefs();
        int vibrateDuration = getPreferredVibrateDuration(notificationOrigin, prefs);
        int vibratePause = getPreferredVibratePause(notificationOrigin, prefs);
        short vibrateTimes = getPreferredVibrateCount(notificationOrigin, prefs);
        VibrationProfile profile = getPreferredVibrateProfile(notificationOrigin, prefs, vibrateTimes);
        int flashTimes = getPreferredFlashCount(notificationOrigin, prefs);
        int flashColour = getPreferredFlashColour(notificationOrigin, prefs);
        int originalColour = getPreferredOriginalColour(notificationOrigin, prefs);
        int flashDuration = getPreferredFlashDuration(notificationOrigin, prefs);
        // setLowLatency(builder);
        sendCustomNotification(profile, simpleNotification, flashTimes, flashColour, originalColour, flashDuration, extraAction, builder);
        // setHighLatency(builder);
        // sendCustomNotification(vibrateDuration, vibrateTimes, vibratePause, flashTimes, flashColour, originalColour, flashDuration, builder);
        builder.queue(getQueue());
    } catch (IOException ex) {
        LOG.error("Unable to send notification to MI device", ex);
    }
}
Also used : VibrationProfile(nodomain.freeyourgadget.gadgetbridge.devices.miband.VibrationProfile) TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder) IOException(java.io.IOException) Prefs(nodomain.freeyourgadget.gadgetbridge.util.Prefs)

Example 95 with TransactionBuilder

use of nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder in project Gadgetbridge by Freeyourgadget.

the class WatchXPlusDeviceSupport method getTime.

private void getTime() {
    try {
        TransactionBuilder builder = performInitialized("getTime");
        builder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE), buildCommand(WatchXPlusConstants.CMD_TIME_SETTINGS, WatchXPlusConstants.READ_VALUE));
        builder.queue(getQueue());
    } catch (IOException e) {
        LOG.warn(" Unable to get device time ", e);
    }
}
Also used : TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder) IOException(java.io.IOException)

Aggregations

TransactionBuilder (nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder)279 IOException (java.io.IOException)218 BluetoothGattCharacteristic (android.bluetooth.BluetoothGattCharacteristic)17 Alarm (nodomain.freeyourgadget.gadgetbridge.model.Alarm)16 UnsupportedEncodingException (java.io.UnsupportedEncodingException)12 GregorianCalendar (java.util.GregorianCalendar)11 UUID (java.util.UUID)11 Calendar (java.util.Calendar)10 SetDeviceBusyAction (nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceBusyAction)10 ByteBuffer (java.nio.ByteBuffer)8 Prefs (nodomain.freeyourgadget.gadgetbridge.util.Prefs)8 ServerTransactionBuilder (nodomain.freeyourgadget.gadgetbridge.service.btle.ServerTransactionBuilder)7 SetDeviceStateAction (nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction)7 GBException (nodomain.freeyourgadget.gadgetbridge.GBException)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 SetProgressAction (nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetProgressAction)4 AlertNotificationProfile (nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification.AlertNotificationProfile)4 NewAlert (nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification.NewAlert)4 GBPrefs (nodomain.freeyourgadget.gadgetbridge.util.GBPrefs)4 InvalidKeyException (java.security.InvalidKeyException)3