Search in sources :

Example 21 with TransactionBuilder

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

the class HPlusHandlerThread method sync.

public void sync() {
    mGetSleepTime.setTimeInMillis(0);
    mGetDaySlotsTime.setTimeInMillis(0);
    mGetDaySummaryTime.setTimeInMillis(0);
    mLastSleepDayReceived.setTimeInMillis(0);
    mSlotsInitialSync = true;
    mLastSlotReceived = -1;
    mLastSlotRequested = 0;
    mCurrentDaySlot = null;
    mDaySlotRecords.clear();
    TransactionBuilder builder = new TransactionBuilder("startSyncDayStats");
    builder.write(mHPlusSupport.ctrlCharacteristic, new byte[] { HPlusConstants.CMD_GET_DEVICE_ID });
    builder.write(mHPlusSupport.ctrlCharacteristic, new byte[] { HPlusConstants.CMD_GET_VERSION });
    builder.write(mHPlusSupport.ctrlCharacteristic, new byte[] { HPlusConstants.CMD_GET_CURR_DATA });
    builder.queue(mHPlusSupport.getQueue());
    synchronized (waitObject) {
        waitObject.notify();
    }
}
Also used : TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder)

Example 22 with TransactionBuilder

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

the class HPlusSupport method onFindDevice.

@Override
public void onFindDevice(boolean start) {
    try {
        TransactionBuilder builder = performInitialized("findMe");
        setFindMe(builder, start);
        builder.queue(getQueue());
    } catch (IOException e) {
        GB.toast(getContext(), "Error toggling Find Me: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
    }
}
Also used : TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder) IOException(java.io.IOException)

Example 23 with TransactionBuilder

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

the class HPlusSupport method showText.

private void showText(String title, String body) {
    LOG.debug("Show Notification: " + title + " --> " + body);
    try {
        TransactionBuilder builder = performInitialized("notification");
        String message = "";
        if (title != null && title.length() > 0) {
            //Limit title to top row
            message = StringUtils.pad(StringUtils.truncate(title, 16), 16);
        }
        if (body != null) {
            message += body;
        }
        byte[] messageBytes = encodeStringToDevice(message);
        int length = messageBytes.length / 17;
        builder.write(ctrlCharacteristic, new byte[] { HPlusConstants.CMD_SET_INCOMING_MESSAGE, HPlusConstants.ARG_INCOMING_MESSAGE });
        int remaining = Math.min(255, (messageBytes.length % 17 > 0) ? length + 1 : length);
        byte[] msg = new byte[20];
        msg[0] = HPlusConstants.CMD_ACTION_DISPLAY_TEXT;
        msg[1] = (byte) remaining;
        for (int i = 2; i < msg.length; i++) msg[i] = ' ';
        int message_index = 0;
        int i = 3;
        for (int j = 0; j < messageBytes.length; j++) {
            msg[i++] = messageBytes[j];
            if (i == msg.length) {
                message_index++;
                msg[2] = (byte) message_index;
                builder.write(ctrlCharacteristic, msg);
                msg = msg.clone();
                for (i = 3; i < msg.length; i++) msg[i] = ' ';
                if (message_index < remaining)
                    i = 3;
                else
                    break;
            }
        }
        msg[2] = (byte) remaining;
        builder.write(ctrlCharacteristic, msg);
        builder.queue(getQueue());
    } catch (IOException e) {
        GB.toast(getContext(), "Error showing device Notification: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
    }
}
Also used : TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder) IOException(java.io.IOException)

Example 24 with TransactionBuilder

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

the class HPlusSupport method onSetConstantVibration.

@Override
public void onSetConstantVibration(int intensity) {
    getQueue().clear();
    try {
        TransactionBuilder builder = performInitialized("vibration");
        byte[] msg = new byte[15];
        msg[0] = HPlusConstants.CMD_SET_INCOMING_CALL_NUMBER;
        for (int i = 0; i < msg.length - 1; i++) msg[i + 1] = (byte) "GadgetBridge".charAt(i);
        builder.write(ctrlCharacteristic, msg);
        builder.queue(getQueue());
    } catch (IOException e) {
        GB.toast(getContext(), "Error setting Vibration: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
    }
}
Also used : TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder) IOException(java.io.IOException)

Example 25 with TransactionBuilder

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

the class VibratissimoSupport method onSetConstantVibration.

@Override
public void onSetConstantVibration(int intensity) {
    getQueue().clear();
    BluetoothGattCharacteristic characteristic2 = getCharacteristic(UUID.fromString("00001526-1212-efde-1523-785feabcd123"));
    BluetoothGattCharacteristic characteristic1 = getCharacteristic(UUID.fromString("00001524-1212-efde-1523-785feabcd123"));
    TransactionBuilder builder = new TransactionBuilder("vibration");
    builder.write(characteristic1, new byte[] { 0x03, (byte) 0x80 });
    builder.write(characteristic2, new byte[] { (byte) intensity, 0x00 });
    builder.queue(getQueue());
}
Also used : TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder) BluetoothGattCharacteristic(android.bluetooth.BluetoothGattCharacteristic)

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