Search in sources :

Example 41 with TransactionBuilder

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

the class MiBandSupport method performDefaultNotification.

private void performDefaultNotification(String task, SimpleNotification simpleNotification, short repeat, BtLEAction extraAction) {
    try {
        TransactionBuilder builder = performInitialized(task);
        sendDefaultNotification(builder, simpleNotification, repeat, extraAction);
        builder.queue(getQueue());
    } catch (IOException ex) {
        LOG.error("Unable to send notification to MI device", ex);
    }
}
Also used : TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder) IOException(java.io.IOException)

Example 42 with TransactionBuilder

use of nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder 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 43 with TransactionBuilder

use of nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder 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)

Example 44 with TransactionBuilder

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

the class MiBand2Support method onReboot.

@Override
public void onReboot() {
    try {
        TransactionBuilder builder = performInitialized("Reboot");
        builder.write(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_FIRMWARE), new byte[] { MiBand2Service.COMMAND_FIRMWARE_REBOOT });
        builder.queue(getQueue());
    } catch (IOException ex) {
        LOG.error("Unable to reboot MI", ex);
    }
}
Also used : TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder) IOException(java.io.IOException)

Example 45 with TransactionBuilder

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

the class MiBand2Support method onHeartRateTest.

@Override
public void onHeartRateTest() {
    try {
        TransactionBuilder builder = performInitialized("HeartRateTest");
        builder.write(getCharacteristic(GattCharacteristic.UUID_CHARACTERISTIC_HEART_RATE_CONTROL_POINT), stopHeartMeasurementContinuous);
        builder.write(getCharacteristic(GattCharacteristic.UUID_CHARACTERISTIC_HEART_RATE_CONTROL_POINT), stopHeartMeasurementManual);
        builder.write(getCharacteristic(GattCharacteristic.UUID_CHARACTERISTIC_HEART_RATE_CONTROL_POINT), startHeartMeasurementManual);
        builder.queue(getQueue());
    } catch (IOException ex) {
        LOG.error("Unable to read HearRate with MI2", ex);
    }
}
Also used : TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder) IOException(java.io.IOException)

Aggregations

TransactionBuilder (nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder)50 IOException (java.io.IOException)34 BluetoothGattCharacteristic (android.bluetooth.BluetoothGattCharacteristic)7 GregorianCalendar (java.util.GregorianCalendar)4 Alarm (nodomain.freeyourgadget.gadgetbridge.model.Alarm)4 Prefs (nodomain.freeyourgadget.gadgetbridge.util.Prefs)4 Calendar (java.util.Calendar)3 GBAlarm (nodomain.freeyourgadget.gadgetbridge.impl.GBAlarm)3 SetDeviceBusyAction (nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceBusyAction)3 VibrationProfile (nodomain.freeyourgadget.gadgetbridge.devices.miband.VibrationProfile)2 SetProgressAction (nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetProgressAction)2 InvalidKeyException (java.security.InvalidKeyException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 UUID (java.util.UUID)1 BadPaddingException (javax.crypto.BadPaddingException)1 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)1 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)1 CalendarEvents (nodomain.freeyourgadget.gadgetbridge.model.CalendarEvents)1 SetDeviceStateAction (nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction)1 WaitAction (nodomain.freeyourgadget.gadgetbridge.service.btle.actions.WaitAction)1