1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-04 09:17:29 +01:00

Initial support for alarms (one, atm) #323

(repetitinos not tested yet)
This commit is contained in:
cpfeiffer 2016-10-21 00:49:42 +02:00
parent 839da4f06a
commit 15954d4561

View File

@ -228,6 +228,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
builder.notify(getCharacteristic(GattService.UUID_SERVICE_CURRENT_TIME), enable);
// Notify CHARACTERISTIC9 to receive random auth code
builder.notify(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_AUTH), enable);
builder.notify(getCharacteristic(MiBand2Service.UUID_UNKNOWN_CHARACTERISTIC3), enable);
builder.notify(getCharacteristic(MiBand2Service.UUID_UNKNOWN_CHARACTERISTIC4), enable);
return this;
}
@ -535,7 +536,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
@Override
public void onSetAlarms(ArrayList<? extends Alarm> alarms) {
try {
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBand2Service.UUID_UNKNOWN_CHARACTERISTIC4);
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBand2Service.UUID_UNKNOWN_CHARACTERISTIC3);
TransactionBuilder builder = performInitialized("Set alarm");
boolean anyAlarmEnabled = false;
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
* builder queue as a write message for the passed characteristic
@ -1054,22 +1053,43 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
* @param 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[]{
// MiBandService.COMMAND_SET_TIMER,
(byte) (alarm.isEnabled() ? 1 : 0),
(byte) alarm.getIndex(),
alarmCalBytes[0],
alarmCalBytes[1],
alarmCalBytes[2],
alarmCalBytes[3],
alarmCalBytes[4],
alarmCalBytes[5],
(byte) (alarm.isSmartWakeup() ? 38 : 0),
(byte) alarm.getRepetitionMask()
if (alarm.isEnabled()) {
if (alarm.getRepetition(Alarm.ALARM_MON)) {
daysMask |= 1;
}
if (alarm.getRepetition(Alarm.ALARM_TUE)) {
daysMask |= 2;
}
if (alarm.getRepetition(Alarm.ALARM_WED)) {
daysMask |= 4;
}
if (alarm.getRepetition(Alarm.ALARM_THU)) {
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) {
@ -1155,7 +1175,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
private void sendCalendarEvents() {
try {
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();
int availableSlots = prefs.getInt(MiBandConst.PREF_MIBAND_RESERVE_ALARM_FOR_CALENDAR, 0);