diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/HPlusConstants.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/HPlusConstants.java index 2fe12b9dc..d158a0af6 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/HPlusConstants.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/HPlusConstants.java @@ -36,6 +36,8 @@ public final class HPlusConstants { public static final byte INCOMING_CALL_STATE_DISABLED_THRESHOLD = 0x7B; public static final byte INCOMING_CALL_STATE_ENABLED = (byte) 0xAA; + public static final byte ARG_ALARM_DISABLE = (byte) -1; + public static final byte[] CMD_SET_PREF_START = new byte[]{0x4f, 0x5a}; public static final byte[] CMD_SET_PREF_START1 = new byte[]{0x4d}; //public static final byte CMD_SET_ALARM = 0x4c; Unknown diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusSupport.java index 6ddffffb8..b399b11f7 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusSupport.java @@ -355,9 +355,17 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport { private HPlusSupport setAlarm(TransactionBuilder transaction, Calendar t) { + byte hour = HPlusConstants.ARG_ALARM_DISABLE; + byte minute = HPlusConstants.ARG_ALARM_DISABLE; + + if(t != null){ + hour = (byte) t.get(Calendar.HOUR_OF_DAY); + minute = (byte) t.get(Calendar.MINUTE); + } + transaction.write(ctrlCharacteristic, new byte[]{HPlusConstants.CMD_SET_ALARM, - (byte) t.get(Calendar.HOUR_OF_DAY), - (byte) t.get(Calendar.MINUTE)}); + hour, + minute}); return this; } @@ -429,8 +437,8 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport { @Override public void onSetAlarms(ArrayList alarms) { - if (alarms.size() == 0) - return; + + TransactionBuilder builder = new TransactionBuilder("alarm"); for (Alarm alarm : alarms) { @@ -441,7 +449,6 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport { continue; Calendar t = alarm.getAlarmCal(); - TransactionBuilder builder = new TransactionBuilder("alarm"); setAlarm(builder, t); builder.queue(getQueue()); @@ -449,6 +456,10 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport { return; //Only first alarm } + + setAlarm(builder, null); + builder.queue(getQueue()); + GB.toast(getContext(), getContext().getString(R.string.user_feedback_all_alarms_disabled), Toast.LENGTH_SHORT, GB.INFO); }