Search in sources :

Example 31 with TransactionBuilder

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

the class HPlusSupport method showIncomingCall.

private void showIncomingCall(String name, String rawNumber) {
    try {
        StringBuilder number = new StringBuilder();
        //Clean up number as the device only accepts digits
        for (char c : rawNumber.toCharArray()) {
            if (Character.isDigit(c)) {
                number.append(c);
            }
        }
        TransactionBuilder builder = performInitialized("incomingCall");
        //Enable call notifications
        builder.write(ctrlCharacteristic, new byte[] { HPlusConstants.CMD_ACTION_INCOMING_CALL, 1 });
        //Show Call Icon
        builder.write(ctrlCharacteristic, new byte[] { HPlusConstants.CMD_SET_INCOMING_CALL, HPlusConstants.ARG_INCOMING_CALL });
        byte[] msg = new byte[13];
        for (int i = 0; i < msg.length; i++) msg[i] = ' ';
        byte[] nameBytes = encodeStringToDevice(name);
        for (int i = 0; i < nameBytes.length && i < (msg.length - 1); i++) msg[i + 1] = nameBytes[i];
        msg[0] = HPlusConstants.CMD_ACTION_DISPLAY_TEXT_NAME;
        builder.write(ctrlCharacteristic, msg);
        msg[0] = HPlusConstants.CMD_ACTION_DISPLAY_TEXT_NAME_CN;
        builder.write(ctrlCharacteristic, msg);
        builder.wait(200);
        msg = msg.clone();
        //Show call number
        for (int i = 0; i < msg.length; i++) msg[i] = ' ';
        for (int i = 0; i < number.length() && i < (msg.length - 1); i++) msg[i + 1] = (byte) number.charAt(i);
        msg[0] = HPlusConstants.CMD_SET_INCOMING_CALL_NUMBER;
        builder.write(ctrlCharacteristic, msg);
        builder.queue(getQueue());
    } catch (IOException e) {
        GB.toast(getContext(), "Error showing incoming call: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
    }
}
Also used : TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder) IOException(java.io.IOException)

Example 32 with TransactionBuilder

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

the class HPlusSupport method onReboot.

@Override
public void onReboot() {
    getQueue().clear();
    TransactionBuilder builder = new TransactionBuilder("Shutdown");
    builder.write(ctrlCharacteristic, new byte[] { HPlusConstants.CMD_SHUTDOWN, HPlusConstants.ARG_SHUTDOWN_EN });
    builder.queue(getQueue());
}
Also used : TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder)

Example 33 with TransactionBuilder

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

the class HPlusSupport method onSetAlarms.

@Override
public void onSetAlarms(ArrayList<? extends Alarm> alarms) {
    TransactionBuilder builder = new TransactionBuilder("alarm");
    for (Alarm alarm : alarms) {
        if (!alarm.isEnabled())
            continue;
        if (//Not available
        alarm.isSmartWakeup())
            continue;
        Calendar t = alarm.getAlarmCal();
        setAlarm(builder, t);
        builder.queue(getQueue());
        GB.toast(getContext(), getContext().getString(R.string.user_feedback_miband_set_alarms_ok), Toast.LENGTH_SHORT, GB.INFO);
        //Only first alarm
        return;
    }
    setAlarm(builder, null);
    builder.queue(getQueue());
    GB.toast(getContext(), getContext().getString(R.string.user_feedback_all_alarms_disabled), Toast.LENGTH_SHORT, GB.INFO);
}
Also used : Alarm(nodomain.freeyourgadget.gadgetbridge.model.Alarm) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder)

Example 34 with TransactionBuilder

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

the class HPlusSupport method onEnableRealtimeHeartRateMeasurement.

@Override
public void onEnableRealtimeHeartRateMeasurement(boolean enable) {
    getQueue().clear();
    TransactionBuilder builder = new TransactionBuilder("realTimeHeartMeasurement");
    byte state;
    if (enable)
        state = HPlusConstants.ARG_HEARTRATE_ALLDAY_ON;
    else
        state = HPlusConstants.ARG_HEARTRATE_ALLDAY_OFF;
    builder.write(ctrlCharacteristic, new byte[] { HPlusConstants.CMD_SET_ALLDAY_HRM, state });
    builder.queue(getQueue());
}
Also used : TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder)

Example 35 with TransactionBuilder

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

the class HPlusSupport method onHeartRateTest.

@Override
public void onHeartRateTest() {
    getQueue().clear();
    TransactionBuilder builder = new TransactionBuilder("HeartRateTest");
    //Set Real Time... ?
    builder.write(ctrlCharacteristic, new byte[] { HPlusConstants.CMD_SET_HEARTRATE_STATE, HPlusConstants.ARG_HEARTRATE_MEASURE_ON });
    builder.queue(getQueue());
}
Also used : TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder)

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