Mi2: attempt to enable text notifications #560

This commit is contained in:
cpfeiffer 2017-03-05 12:08:03 +01:00
parent c56b655b48
commit 1c06aaace1

View File

@ -2,6 +2,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.miband2;
import android.bluetooth.BluetoothGattCharacteristic;
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBand2Service;
import nodomain.freeyourgadget.gadgetbridge.devices.miband.VibrationProfile;
import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEDeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEAction;
@ -19,27 +20,34 @@ public class Mi2NotificationStrategy extends V2NotificationStrategy {
@Override
protected void sendCustomNotification(VibrationProfile vibrationProfile, SimpleNotification simpleNotification, BtLEAction extraAction, TransactionBuilder builder) {
// for testing
//use the new alert characteristic
BluetoothGattCharacteristic alert = getSupport().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];
on = Math.min(500, on); // longer than 500ms is not possible
builder.write(alert, new byte[]{(byte) vibrationProfile.getAlertLevel()});
builder.wait(on);
builder.write(alert, new byte[]{GattCharacteristic.NO_ALERT});
// BluetoothGattCharacteristic alert = getSupport().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];
// on = Math.min(500, on); // longer than 500ms is not possible
// builder.write(alert, new byte[]{(byte) vibrationProfile.getAlertLevel()});
// builder.wait(on);
// builder.write(alert, new byte[]{GattCharacteristic.NO_ALERT});
//
// if (++j < onOffSequence.length) {
// int off = Math.max(onOffSequence[j], 25); // wait at least 25ms
// builder.wait(off);
// }
//
// if (extraAction != null) {
// builder.add(extraAction);
// }
// }
// }
if (++j < onOffSequence.length) {
int off = Math.max(onOffSequence[j], 25); // wait at least 25ms
builder.wait(off);
}
if (extraAction != null) {
builder.add(extraAction);
}
}
}
BluetoothGattCharacteristic config = getSupport().getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_3_CONFIGURATION);
builder.write(config, new byte[] {MiBand2Service.ENDPOINT_DISPLAY, 0x10, 0x00, 0x01, 0x01});
builder.wait(500);
// end for testing
sendAlert(simpleNotification, builder);
}