mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-25 11:26:47 +01:00
Mi Band 2: use native notification patterns instead of manually timed ones
What we do now is: - Send a notification with the app icon - Send the vibration pattern right away (this causes the first unwanted vibration to be cancelled immediately and only the pattern is noticable, while the icon stays on screen during the vibration pattern) - (optional) send the text together with a generic sms icon This also fixes problems of text not appearing in newer firmwares when a notification pattern with repeat has been set in Mi Band settings.
This commit is contained in:
parent
4f246b3ed9
commit
669f4bcdd0
@ -37,24 +37,19 @@ public class Mi2NotificationStrategy extends V2NotificationStrategy<MiBand2Suppo
|
||||
|
||||
@Override
|
||||
protected void sendCustomNotification(VibrationProfile vibrationProfile, SimpleNotification simpleNotification, BtLEAction extraAction, TransactionBuilder builder) {
|
||||
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
|
||||
startNotify(builder, vibrationProfile.getAlertLevel(), simpleNotification);
|
||||
builder.wait(on);
|
||||
stopNotify(builder);
|
||||
startNotify(builder, vibrationProfile.getAlertLevel(), simpleNotification);
|
||||
BluetoothGattCharacteristic alert = getSupport().getCharacteristic(GattCharacteristic.UUID_CHARACTERISTIC_ALERT_LEVEL);
|
||||
byte repeat = (byte) (vibrationProfile.getRepeat() * (vibrationProfile.getOnOffSequence().length / 2));
|
||||
if (repeat > 0) {
|
||||
short vibration = (short) vibrationProfile.getOnOffSequence()[0];
|
||||
short pause = (short) vibrationProfile.getOnOffSequence()[1];
|
||||
int duration = (vibration + pause) * repeat;
|
||||
builder.write(alert, new byte[]{-1, (byte) (vibration & 255), (byte) (vibration >> 8 & 255), (byte) (pause & 255), (byte) (pause >> 8 & 255), repeat});
|
||||
builder.wait(duration);
|
||||
}
|
||||
|
||||
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 (extraAction != null) {
|
||||
builder.add(extraAction);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user