use of nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder in project Gadgetbridge by Freeyourgadget.
the class WatchXPlusDeviceSupport method getUnitsSettings.
/**
* request watch units
* for testing purposes only
*/
private WatchXPlusDeviceSupport getUnitsSettings() {
LOG.info(" Get units from watch... ");
try {
TransactionBuilder builder = performInitialized("getUnits");
builder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE), buildCommand(WatchXPlusConstants.CMD_SET_UNITS, WatchXPlusConstants.READ_VALUE));
builder.queue(getQueue());
} catch (IOException e) {
LOG.warn(" Unable to get units ", e);
}
return this;
}
use of nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder in project Gadgetbridge by Freeyourgadget.
the class WatchXPlusDeviceSupport method setTime.
// set only digital time
private void setTime(Calendar calendar) {
try {
TransactionBuilder builder = performInitialized("setTime");
int timezoneOffsetMinutes = (calendar.get(Calendar.ZONE_OFFSET) + calendar.get(Calendar.DST_OFFSET)) / (60 * 1000);
int timezoneOffsetIndustrialMinutes = Math.round((Math.abs(timezoneOffsetMinutes) % 60) * 100f / 60f);
byte[] time = new byte[] { BcdUtil.toBcd8(calendar.get(Calendar.YEAR) % 100), BcdUtil.toBcd8(calendar.get(Calendar.MONTH) + 1), BcdUtil.toBcd8(calendar.get(Calendar.DAY_OF_MONTH)), BcdUtil.toBcd8(calendar.get(Calendar.HOUR_OF_DAY)), BcdUtil.toBcd8(calendar.get(Calendar.MINUTE)), BcdUtil.toBcd8(calendar.get(Calendar.SECOND)), (byte) (timezoneOffsetMinutes / 60), (byte) timezoneOffsetIndustrialMinutes, (byte) (calendar.get(Calendar.DAY_OF_WEEK) - 1) };
builder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE), buildCommand(WatchXPlusConstants.CMD_TIME_SETTINGS, WatchXPlusConstants.WRITE_VALUE, time));
builder.queue(getQueue());
} catch (IOException e) {
LOG.warn(" Unable to set time ", e);
}
}
use of nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder in project Gadgetbridge by Freeyourgadget.
the class WatchXPlusDeviceSupport method onFetchRecordedData.
@Override
public void onFetchRecordedData(int dataTypes) {
TransactionBuilder builder;
// get battery state
try {
builder = performInitialized("getBatteryInfo");
builder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE), buildCommand(WatchXPlusConstants.CMD_BATTERY_INFO, WatchXPlusConstants.READ_VALUE));
builder.queue(getQueue());
} catch (IOException e) {
LOG.warn(" Unable to retrieve battery data ", e);
}
try {
builder = performInitialized("fetchData");
builder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE), buildCommand(WatchXPlusConstants.CMD_DAY_STEPS_INFO, WatchXPlusConstants.READ_VALUE));
// Fetch heart rate data samples count
requestDataCount(DataType.HEART_RATE);
builder.queue(getQueue());
} catch (IOException e) {
LOG.warn(" Unable to retrieve recorded data ", e);
}
}
use of nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder in project Gadgetbridge by Freeyourgadget.
the class WatchXPlusDeviceSupport method requestDataContentForTimestamp.
private void requestDataContentForTimestamp(int timestamp, DataType dataType) {
byte[] command = WatchXPlusConstants.CMD_RETRIEVE_DATA_CONTENT;
try {
TransactionBuilder builder = performInitialized("requestDataContentForTimestamp");
byte[] ts = Conversion.toByteArr32(timestamp);
byte[] req = BLETypeConversions.join(dataType.getValue(), ts);
req = BLETypeConversions.join(req, Conversion.toByteArr16(0));
requestedDataTimestamp = timestamp;
builder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE), buildCommand(command, WatchXPlusConstants.READ_VALUE, req));
builder.queue(getQueue());
} catch (IOException e) {
LOG.warn(" Unable to request data content ", e);
}
}
use of nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder in project Gadgetbridge by Freeyourgadget.
the class WatchXPlusDeviceSupport method handleAck.
private void handleAck() {
try {
TransactionBuilder builder = performInitialized("handleAck");
builder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE), buildCommand());
builder.queue(getQueue());
} catch (IOException e) {
LOG.warn(" Unable to response to ACK ", e);
}
}
Aggregations