use of android.bluetooth.BluetoothGattCharacteristic in project Gadgetbridge by Freeyourgadget.
the class V1NotificationStrategy method sendCustomNotification.
/**
* Adds a custom notification to the given transaction builder
* @param vibrationProfile specifies how and how often the Band shall vibrate.
* @param simpleNotification
* @param flashTimes
* @param flashColour
* @param originalColour
* @param flashDuration
* @param extraAction an extra action to be executed after every vibration and flash sequence. Allows to abort the repetition, for example.
* @param builder
*/
@Override
public void sendCustomNotification(VibrationProfile vibrationProfile, SimpleNotification simpleNotification, int flashTimes, int flashColour, int originalColour, long flashDuration, BtLEAction extraAction, TransactionBuilder builder) {
BluetoothGattCharacteristic controlPoint = support.getCharacteristic(MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT);
for (short i = 0; i < vibrationProfile.getRepeat(); i++) {
int[] onOffSequence = vibrationProfile.getOnOffSequence();
for (int j = 0; j < onOffSequence.length; j++) {
int on = onOffSequence[j];
// longer than 500ms is not possible
on = Math.min(500, on);
builder.write(controlPoint, startVibrate);
builder.wait(on);
builder.write(controlPoint, stopVibrate);
if (++j < onOffSequence.length) {
// wait at least 25ms
int off = Math.max(onOffSequence[j], 25);
builder.wait(off);
}
if (extraAction != null) {
builder.add(extraAction);
}
}
}
}
use of android.bluetooth.BluetoothGattCharacteristic in project Gadgetbridge by Freeyourgadget.
the class V1NotificationStrategy method stopCurrentNotification.
@Override
public void stopCurrentNotification(TransactionBuilder builder) {
BluetoothGattCharacteristic controlPoint = support.getCharacteristic(MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT);
builder.write(controlPoint, stopVibrate);
}
use of android.bluetooth.BluetoothGattCharacteristic in project Gadgetbridge by Freeyourgadget.
the class V2NotificationStrategy method sendCustomNotification.
protected void sendCustomNotification(VibrationProfile vibrationProfile, @Nullable SimpleNotification simpleNotification, BtLEAction extraAction, TransactionBuilder builder) {
//use the new alert characteristic
BluetoothGattCharacteristic alert = support.getCharacteristic(GattCharacteristic.UUID_CHARACTERISTIC_ALERT_LEVEL);
for (short i = 0; i < vibrationProfile.getRepeat(); i++) {
int[] onOffSequence = vibrationProfile.getOnOffSequence();
for (int j = 0; j < onOffSequence.length; j++) {
int on = onOffSequence[j];
// longer than 500ms is not possible
on = Math.min(500, on);
//MILD_ALERT lights up GREEN leds, HIGH_ALERT lights up RED leds
builder.write(alert, new byte[] { GattCharacteristic.MILD_ALERT });
// builder.wait(on);
// builder.write(alert, new byte[]{GattCharacteristic.HIGH_ALERT});
builder.wait(on);
builder.write(alert, new byte[] { GattCharacteristic.NO_ALERT });
if (++j < onOffSequence.length) {
// wait at least 25ms
int off = Math.max(onOffSequence[j], 25);
builder.wait(off);
}
if (extraAction != null) {
builder.add(extraAction);
}
}
}
}
use of android.bluetooth.BluetoothGattCharacteristic in project Gadgetbridge by Freeyourgadget.
the class V2NotificationStrategy method stopCurrentNotification.
@Override
public void stopCurrentNotification(TransactionBuilder builder) {
BluetoothGattCharacteristic alert = support.getCharacteristic(GattCharacteristic.UUID_CHARACTERISTIC_ALERT_LEVEL);
builder.write(alert, new byte[] { GattCharacteristic.NO_ALERT });
}
use of android.bluetooth.BluetoothGattCharacteristic in project Gadgetbridge by Freeyourgadget.
the class MiBandSupport method setCurrentTime.
/**
* Sets the current time to the Mi device using the given builder.
*
* @param builder
*/
private MiBandSupport setCurrentTime(TransactionBuilder builder) {
Calendar now = GregorianCalendar.getInstance();
Date date = now.getTime();
LOG.info("Sending current time to Mi Band: " + DateTimeUtils.formatDate(date) + " (" + date.toGMTString() + ")");
byte[] nowBytes = MiBandDateConverter.calendarToRawBytes(now);
byte[] time = new byte[] { nowBytes[0], nowBytes[1], nowBytes[2], nowBytes[3], nowBytes[4], nowBytes[5], (byte) 0x0f, (byte) 0x0f, (byte) 0x0f, (byte) 0x0f, (byte) 0x0f, (byte) 0x0f };
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_DATE_TIME);
if (characteristic != null) {
builder.write(characteristic, time);
} else {
LOG.info("Unable to set time -- characteristic not available");
}
return this;
}
Aggregations