From 036e92ee64fb49817530181bf72f95cff32b4721 Mon Sep 17 00:00:00 2001 From: Daniele Gobbetti Date: Thu, 17 Dec 2015 18:02:21 +0100 Subject: [PATCH] Implement sending the upcoming events to the miband. The reserved alarm slots are used for storing the upcoming events. The method is not yet called anywhere. --- .../service/devices/miband/MiBandSupport.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java index 0f7f6676..65adefc8 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java @@ -18,6 +18,7 @@ import java.util.Arrays; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; +import java.util.List; import java.util.UUID; import nodomain.freeyourgadget.gadgetbridge.R; @@ -29,8 +30,10 @@ import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandDateConverter; import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandFWHelper; import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandService; import nodomain.freeyourgadget.gadgetbridge.devices.miband.VibrationProfile; +import nodomain.freeyourgadget.gadgetbridge.impl.GBAlarm; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice.State; import nodomain.freeyourgadget.gadgetbridge.model.Alarm; +import nodomain.freeyourgadget.gadgetbridge.model.CalendarEvents; import nodomain.freeyourgadget.gadgetbridge.model.DeviceService; import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec; import nodomain.freeyourgadget.gadgetbridge.model.ServiceCommand; @@ -792,4 +795,50 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport { } LOG.info("MI Band pairing result: " + value); } + + private void sendEvents() { + try { + TransactionBuilder builder = performInitialized("Send upcoming events"); + BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT); + + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); + int availableSlots = Integer.parseInt(prefs.getString(MiBandConst.PREF_MIBAND_RESERVE_ALARM_FOR_CALENDAR, "0")); + + if (availableSlots > 0) { + CalendarEvents upcomingEvents = new CalendarEvents(); + List mEvents = upcomingEvents.getCalendarEventList(getContext()); + + int iteration = 0; + ArrayList alarmList = new ArrayList<>(); + for(CalendarEvents.CalendarEvent mEvt : mEvents) { + if (iteration >= availableSlots) { + break; + } + Calendar calendar = Calendar.getInstance(); + calendar.setTimeInMillis(mEvt.getBegin()); + byte[] calBytes = MiBandDateConverter.calendarToRawBytes(calendar); + + byte[] alarmMessage = new byte[]{ + MiBandService.COMMAND_SET_TIMER, + (byte)(3-iteration), + (byte) 1, + calBytes[0], + calBytes[1], + calBytes[2], + calBytes[3], + calBytes[4], + calBytes[5], + (byte) 0, + (byte) 0 + }; + builder.write(characteristic, alarmMessage); + iteration++; + } + } + } catch (IOException ex) { + LOG.error("Unable to send Events to MI device", ex); + } + } + + }