Skip to content
This repository has been archived by the owner on Dec 23, 2024. It is now read-only.

Mi Band 2: Vibrate-only notifications, find lost device while in DND #824

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public enum AlertCategory {
// 251-255 defined by service specification
Any(255),
Custom(-1),
CustomVibrateOnly(-2),
CustomMiBand2(-6);

private final int id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
import android.bluetooth.BluetoothGattCharacteristic;
import android.support.annotation.Nullable;

import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBand2Service;
import nodomain.freeyourgadget.gadgetbridge.devices.miband.VibrationProfile;
import nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEAction;
import nodomain.freeyourgadget.gadgetbridge.service.btle.GattCharacteristic;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification.AlertCategory;
import nodomain.freeyourgadget.gadgetbridge.service.devices.common.SimpleNotification;
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.V2NotificationStrategy;

Expand All @@ -35,6 +37,16 @@ public Mi2NotificationStrategy(MiBand2Support support) {
alertLevelCharacteristic = support.getCharacteristic(GattCharacteristic.UUID_CHARACTERISTIC_ALERT_LEVEL);
}

@Override
public void sendDefaultNotification(TransactionBuilder builder, SimpleNotification simpleNotification, BtLEAction extraAction) {
VibrationProfile profile = VibrationProfile.getProfile(VibrationProfile.ID_MEDIUM, (short) 3);
if (simpleNotification.getAlertCategory() == AlertCategory.CustomVibrateOnly) {
profile.setAlertLevel(MiBand2Service.ALERT_LEVEL_VIBRATE_ONLY);
}
sendCustomNotification(profile, simpleNotification, extraAction, builder);
}


@Override
protected void sendCustomNotification(VibrationProfile vibrationProfile, SimpleNotification simpleNotification, BtLEAction extraAction, TransactionBuilder builder) {
for (short i = 0; i < vibrationProfile.getRepeat(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ protected void sendCustomNotification(VibrationProfile vibrationProfile, SimpleN

@Override
protected void startNotify(TransactionBuilder builder, int alertLevel, SimpleNotification simpleNotification) {
builder.write(newAlertCharacteristic, getNotifyMessage(simpleNotification));
if (alertLevel == MiBand2Service.ALERT_LEVEL_VIBRATE_ONLY) {
super.startNotify(builder, alertLevel, simpleNotification);
} else {
builder.write(newAlertCharacteristic, getNotifyMessage(simpleNotification));
}
}

protected byte[] getNotifyMessage(SimpleNotification simpleNotification) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ protected boolean shouldAbort() {
return !isLocatingDevice;
}
};
SimpleNotification simpleNotification = new SimpleNotification(getContext().getString(R.string.find_device_you_found_it), AlertCategory.HighPriorityAlert);
SimpleNotification simpleNotification = new SimpleNotification(getContext().getString(R.string.find_device_you_found_it), AlertCategory.CustomVibrateOnly);
performDefaultNotification("locating device", simpleNotification, (short) 255, abortAction);
}
}
Expand Down