Search in sources :

Example 76 with TransactionBuilder

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

the class ITagSupport method onSetConstantVibration.

@Override
public void onSetConstantVibration(int intensity) {
    getQueue().clear();
    BluetoothGattCharacteristic characteristic = getCharacteristic(ITagConstants.UUID_LINK_LOSS_ALERT_LEVEL);
    TransactionBuilder builder = new TransactionBuilder("beeping");
    builder.write(characteristic, new byte[] { (byte) intensity });
    builder.queue(getQueue());
}
Also used : TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder) BluetoothGattCharacteristic(android.bluetooth.BluetoothGattCharacteristic)

Example 77 with TransactionBuilder

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

the class JYouSupport method showNotification.

private void showNotification(byte icon, String title, String message) {
    try {
        TransactionBuilder builder = performInitialized("ShowNotification");
        byte[] titleBytes = stringToUTF8Bytes(title, 16);
        byte[] messageBytes = stringToUTF8Bytes(message, 80);
        for (int i = 1; i <= 7; i++) {
            byte[] currentPacket = new byte[20];
            currentPacket[0] = JYouConstants.CMD_ACTION_SHOW_NOTIFICATION;
            currentPacket[1] = 7;
            currentPacket[2] = (byte) i;
            switch(i) {
                case 1:
                    currentPacket[4] = icon;
                    break;
                case 2:
                    if (titleBytes != null) {
                        System.arraycopy(titleBytes, 0, currentPacket, 3, 6);
                        System.arraycopy(titleBytes, 6, currentPacket, 10, 10);
                    }
                    break;
                default:
                    if (messageBytes != null) {
                        System.arraycopy(messageBytes, 16 * (i - 3), currentPacket, 3, 6);
                        System.arraycopy(messageBytes, 6 + 16 * (i - 3), currentPacket, 10, 10);
                    }
                    break;
            }
            builder.write(ctrlCharacteristic, currentPacket);
        }
        performConnected(builder.getTransaction());
    } catch (IOException e) {
        logger.warn(e.getMessage());
    }
}
Also used : TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder) IOException(java.io.IOException)

Example 78 with TransactionBuilder

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

the class JYouSupport method onSetAlarms.

@Override
public void onSetAlarms(ArrayList<? extends Alarm> alarms) {
    try {
        TransactionBuilder builder = performInitialized("SetAlarms");
        for (int i = 0; i < alarms.size(); i++) {
            byte cmd;
            switch(i) {
                case 0:
                    cmd = JYouConstants.CMD_SET_ALARM_1;
                    break;
                case 1:
                    cmd = JYouConstants.CMD_SET_ALARM_2;
                    break;
                case 2:
                    cmd = JYouConstants.CMD_SET_ALARM_3;
                    break;
                default:
                    return;
            }
            Calendar cal = AlarmUtils.toCalendar(alarms.get(i));
            builder.write(ctrlCharacteristic, commandWithChecksum(cmd, alarms.get(i).getEnabled() ? cal.get(Calendar.HOUR_OF_DAY) : -1, alarms.get(i).getEnabled() ? cal.get(Calendar.MINUTE) : -1));
        }
        performConnected(builder.getTransaction());
        GB.toast(getContext(), "Alarm settings applied - do note that the current device does not support day specification", Toast.LENGTH_LONG, GB.INFO);
    } catch (IOException e) {
        logger.warn(e.getMessage());
    }
}
Also used : Calendar(java.util.Calendar) TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder) IOException(java.io.IOException)

Example 79 with TransactionBuilder

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

the class JYouSupport method onEnableRealtimeHeartRateMeasurement.

@Override
public void onEnableRealtimeHeartRateMeasurement(boolean enable) {
    try {
        TransactionBuilder builder = performInitialized("RealTimeHeartMeasurement");
        builder.write(ctrlCharacteristic, commandWithChecksum(JYouConstants.CMD_SET_HEARTRATE_AUTO, 0, enable ? 1 : 0));
        builder.queue(getQueue());
    } catch (Exception e) {
        logger.warn(e.getMessage());
    }
}
Also used : TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 80 with TransactionBuilder

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

the class JYouSupport method onSetTime.

@Override
public void onSetTime() {
    try {
        TransactionBuilder builder = performInitialized("SetTime");
        syncDateAndTime(builder);
        performConnected(builder.getTransaction());
    } catch (IOException e) {
        logger.warn(e.getMessage());
    }
}
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