mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-26 16:41:43 +01:00
Initial support for alarms (one, atm) #323
(repetitinos not tested yet)
This commit is contained in:
parent
839da4f06a
commit
15954d4561
@ -228,6 +228,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
|||||||
builder.notify(getCharacteristic(GattService.UUID_SERVICE_CURRENT_TIME), enable);
|
builder.notify(getCharacteristic(GattService.UUID_SERVICE_CURRENT_TIME), enable);
|
||||||
// Notify CHARACTERISTIC9 to receive random auth code
|
// Notify CHARACTERISTIC9 to receive random auth code
|
||||||
builder.notify(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_AUTH), enable);
|
builder.notify(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_AUTH), enable);
|
||||||
|
builder.notify(getCharacteristic(MiBand2Service.UUID_UNKNOWN_CHARACTERISTIC3), enable);
|
||||||
builder.notify(getCharacteristic(MiBand2Service.UUID_UNKNOWN_CHARACTERISTIC4), enable);
|
builder.notify(getCharacteristic(MiBand2Service.UUID_UNKNOWN_CHARACTERISTIC4), enable);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -535,7 +536,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
|||||||
@Override
|
@Override
|
||||||
public void onSetAlarms(ArrayList<? extends Alarm> alarms) {
|
public void onSetAlarms(ArrayList<? extends Alarm> alarms) {
|
||||||
try {
|
try {
|
||||||
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBand2Service.UUID_UNKNOWN_CHARACTERISTIC4);
|
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBand2Service.UUID_UNKNOWN_CHARACTERISTIC3);
|
||||||
TransactionBuilder builder = performInitialized("Set alarm");
|
TransactionBuilder builder = performInitialized("Set alarm");
|
||||||
boolean anyAlarmEnabled = false;
|
boolean anyAlarmEnabled = false;
|
||||||
for (Alarm alarm : alarms) {
|
for (Alarm alarm : alarms) {
|
||||||
@ -1043,8 +1044,6 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
private void queueAlarm(Calendar calender, boolean enabled, boolean smartWakeup, TransactionBuilder builder, BluetoothGattCharacteristic characteristic) {
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* Convert an alarm from the GB internal structure to a Mi Band message and put on the specified
|
* Convert an alarm from the GB internal structure to a Mi Band message and put on the specified
|
||||||
* builder queue as a write message for the passed characteristic
|
* builder queue as a write message for the passed characteristic
|
||||||
@ -1054,22 +1053,43 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
|||||||
* @param characteristic
|
* @param characteristic
|
||||||
*/
|
*/
|
||||||
private void queueAlarm(Alarm alarm, TransactionBuilder builder, BluetoothGattCharacteristic characteristic) {
|
private void queueAlarm(Alarm alarm, TransactionBuilder builder, BluetoothGattCharacteristic characteristic) {
|
||||||
byte[] alarmCalBytes = MiBandDateConverter.calendarToRawBytes(alarm.getAlarmCal());
|
Calendar calendar = alarm.getAlarmCal();
|
||||||
|
int daysMask = 0;
|
||||||
|
|
||||||
byte[] alarmMessage = new byte[]{
|
if (alarm.isEnabled()) {
|
||||||
// MiBandService.COMMAND_SET_TIMER,
|
if (alarm.getRepetition(Alarm.ALARM_MON)) {
|
||||||
(byte) (alarm.isEnabled() ? 1 : 0),
|
daysMask |= 1;
|
||||||
(byte) alarm.getIndex(),
|
}
|
||||||
alarmCalBytes[0],
|
if (alarm.getRepetition(Alarm.ALARM_TUE)) {
|
||||||
alarmCalBytes[1],
|
daysMask |= 2;
|
||||||
alarmCalBytes[2],
|
}
|
||||||
alarmCalBytes[3],
|
if (alarm.getRepetition(Alarm.ALARM_WED)) {
|
||||||
alarmCalBytes[4],
|
daysMask |= 4;
|
||||||
alarmCalBytes[5],
|
}
|
||||||
(byte) (alarm.isSmartWakeup() ? 38 : 0),
|
if (alarm.getRepetition(Alarm.ALARM_THU)) {
|
||||||
(byte) alarm.getRepetitionMask()
|
daysMask |= 8;
|
||||||
|
}
|
||||||
|
if (alarm.getRepetition(Alarm.ALARM_FRI)) {
|
||||||
|
daysMask |= 16;
|
||||||
|
}
|
||||||
|
if (alarm.getRepetition(Alarm.ALARM_SAT)) {
|
||||||
|
daysMask |= 32;
|
||||||
|
}
|
||||||
|
if (alarm.getRepetition(Alarm.ALARM_SUN)) {
|
||||||
|
daysMask |= 64;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] alarmMessage = new byte[] {
|
||||||
|
(byte) 0x2, // TODO what is this? 0x1 does not work
|
||||||
|
(byte) 128, // TODO: what is this?
|
||||||
|
(byte) calendar.get(Calendar.HOUR_OF_DAY),
|
||||||
|
(byte) calendar.get(Calendar.MINUTE),
|
||||||
|
(byte) daysMask,
|
||||||
};
|
};
|
||||||
builder.write(characteristic, alarmMessage);
|
if (alarm.isEnabled()) {
|
||||||
|
builder.write(characteristic, alarmMessage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleControlPointResult(byte[] value, int status) {
|
private void handleControlPointResult(byte[] value, int status) {
|
||||||
@ -1155,7 +1175,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
|||||||
private void sendCalendarEvents() {
|
private void sendCalendarEvents() {
|
||||||
try {
|
try {
|
||||||
TransactionBuilder builder = performInitialized("Send upcoming events");
|
TransactionBuilder builder = performInitialized("Send upcoming events");
|
||||||
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT);
|
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBand2Service.UUID_UNKNOWN_CHARACTERISTIC3);
|
||||||
|
|
||||||
Prefs prefs = GBApplication.getPrefs();
|
Prefs prefs = GBApplication.getPrefs();
|
||||||
int availableSlots = prefs.getInt(MiBandConst.PREF_MIBAND_RESERVE_ALARM_FOR_CALENDAR, 0);
|
int availableSlots = prefs.getInt(MiBandConst.PREF_MIBAND_RESERVE_ALARM_FOR_CALENDAR, 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user