Huami: Fix weekly reminders

This commit is contained in:
José Rebelo
2021-12-12 22:58:52 +00:00
committed by Gitea
parent 45647ccbf7
commit 2e8f44cd85
2 changed files with 13 additions and 11 deletions

View File

@@ -89,7 +89,7 @@ public class BLETypeConversions {
return rawOffset; return rawOffset;
} }
private static byte dayOfWeekToRawBytes(Calendar cal) { public static byte dayOfWeekToRawBytes(Calendar cal) {
int calValue = cal.get(Calendar.DAY_OF_WEEK); int calValue = cal.get(Calendar.DAY_OF_WEEK);
switch (calValue) { switch (calValue) {
case Calendar.SUNDAY: case Calendar.SUNDAY:

View File

@@ -848,31 +848,33 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
buf.put((byte) 0x0B); buf.put((byte) 0x0B);
buf.put((byte) (position & 0xFF)); buf.put((byte) (position & 0xFF));
final Calendar cal = Calendar.getInstance();
cal.setTime(reminder.getDate());
int eventConfig = 0x01 | 0x08; // flags 0x01 = enable, 0x04 = end date present (not on reminders), 0x08 = has text
switch(reminder.getRepetition()) { switch(reminder.getRepetition()) {
case Reminder.ONCE: case Reminder.ONCE:
buf.put(new byte[]{0x09, 0x00}); // Default is once, nothing to do
break; break;
case Reminder.EVERY_DAY: case Reminder.EVERY_DAY:
buf.put(new byte[]{(byte) 0xE9, 0x0F}); eventConfig |= 0x0fe0; // all week day bits set
break; break;
case Reminder.EVERY_WEEK: case Reminder.EVERY_WEEK:
buf.put(new byte[]{0x09, 0x01}); int dayOfWeek = BLETypeConversions.dayOfWeekToRawBytes(cal) - 1; // Monday = 0
eventConfig |= 0x20 << dayOfWeek;
break; break;
case Reminder.EVERY_MONTH: case Reminder.EVERY_MONTH:
buf.put(new byte[]{0x09, 0x10}); eventConfig |= 0x1000;
break; break;
case Reminder.EVERY_YEAR: case Reminder.EVERY_YEAR:
buf.put(new byte[]{0x09, 0x20}); eventConfig |= 0x2000;
break; break;
default: default:
LOG.warn("Unknown repetition for reminder in position {}, defaulting to once", position); LOG.warn("Unknown repetition for reminder in position {}, defaulting to once", position);
buf.put(new byte[]{0x09, 0x00});
} }
buf.put(new byte[]{0x00, 0x00}); // unknown buf.putInt(eventConfig);
final Calendar cal = Calendar.getInstance();
cal.setTime(reminder.getDate());
buf.put(BLETypeConversions.shortCalendarToRawBytes(cal)); buf.put(BLETypeConversions.shortCalendarToRawBytes(cal));
buf.put((byte) 0x00); buf.put((byte) 0x00);