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();
}
}
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);
}
}
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);
}
}
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);
}
}
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());
}
Aggregations