From 4cad3b3837e6e83d245c7f281d2a0c57a9e142ef Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Thu, 21 Oct 2021 18:39:01 +0200 Subject: [PATCH] InfiniTime: support navigation app --- .../devices/pinetime/PineTimeJFConstants.java | 5 ++ .../service/DeviceCommunicationService.java | 10 +-- .../devices/pinetime/PineTimeJFSupport.java | 65 +++++++++++++++++++ 3 files changed, 75 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pinetime/PineTimeJFConstants.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pinetime/PineTimeJFConstants.java index 8db0a749e..9bd600586 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pinetime/PineTimeJFConstants.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pinetime/PineTimeJFConstants.java @@ -36,6 +36,11 @@ public class PineTimeJFConstants { public static final UUID UUID_SERVICE_NAVIGATION = UUID.fromString("00010000-78fc-48fe-8e23-433b3a1942d0"); + public static final UUID UUID_CHARACTERISTICS_NAVIGATION_FLAGS = UUID.fromString("00010001-78fc-48fe-8e23-433b3a1942d0"); + public static final UUID UUID_CHARACTERISTICS_NAVIGATION_NARRATIVE = UUID.fromString("00010002-78fc-48fe-8e23-433b3a1942d0"); + public static final UUID UUID_CHARACTERISTICS_NAVIGATION_MAN_DISTANCE = UUID.fromString("00010003-78fc-48fe-8e23-433b3a1942d0"); + public static final UUID UUID_CHARACTERISTICS_NAVIGATION_PROGRESS = UUID.fromString("00010004-78fc-48fe-8e23-433b3a1942d0"); + public static final UUID UUID_CHARACTERISTIC_ALERT_NOTIFICATION_EVENT = UUID.fromString("00020001-78fc-48fe-8e23-433b3a1942d0"); public static final UUID UUID_SERVICE_WEATHER = UUID.fromString("00040000-78fc-48fe-8e23-433b3a1942d0"); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java index 6c83c65aa..76c3c1d6f 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java @@ -1238,6 +1238,10 @@ public class DeviceCommunicationService extends Service implements SharedPrefere registerReceiver(mAlarmClockReceiver, filter); } + if (mOsmandAidlHelper == null) { + mOsmandAidlHelper = new OsmandEventReceiver(this.getApplication()); + } + // Weather receivers if (features.supportsWeather()) { if (GBApplication.isRunningOreoOrLater()) { @@ -1245,8 +1249,7 @@ public class DeviceCommunicationService extends Service implements SharedPrefere mLineageOsWeatherReceiver = new LineageOsWeatherReceiver(); registerReceiver(mLineageOsWeatherReceiver, new IntentFilter("GB_UPDATE_WEATHER")); } - } - else { + } else { if (mCMWeatherReceiver == null) { mCMWeatherReceiver = new CMWeatherReceiver(); registerReceiver(mCMWeatherReceiver, new IntentFilter("GB_UPDATE_WEATHER")); @@ -1268,9 +1271,6 @@ public class DeviceCommunicationService extends Service implements SharedPrefere //Nothing wrong, it just means we're not running on omnirom. } } - if (mOsmandAidlHelper == null) { - mOsmandAidlHelper = new OsmandEventReceiver(this.getApplication()); - } } if (GBApplication.getPrefs().getBoolean("auto_fetch_enabled", false) && diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pinetime/PineTimeJFSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pinetime/PineTimeJFSupport.java index 41b4c668c..bcca4401e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pinetime/PineTimeJFSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pinetime/PineTimeJFSupport.java @@ -38,6 +38,7 @@ import org.slf4j.LoggerFactory; import java.io.ByteArrayOutputStream; import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Calendar; import java.util.GregorianCalendar; @@ -87,6 +88,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.CannedMessagesSpec; import nodomain.freeyourgadget.gadgetbridge.model.DeviceService; import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec; import nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec; +import nodomain.freeyourgadget.gadgetbridge.model.NavigationInfoSpec; import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec; import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec; import nodomain.freeyourgadget.gadgetbridge.model.WorldClock; @@ -257,6 +259,7 @@ public class PineTimeJFSupport extends AbstractBTLEDeviceSupport implements DfuL addSupportedService(GattService.UUID_SERVICE_BATTERY_SERVICE); addSupportedService(PineTimeJFConstants.UUID_SERVICE_MUSIC_CONTROL); addSupportedService(PineTimeJFConstants.UUID_SERVICE_WEATHER); + addSupportedService(PineTimeJFConstants.UUID_SERVICE_NAVIGATION); addSupportedService(PineTimeJFConstants.UUID_CHARACTERISTIC_ALERT_NOTIFICATION_EVENT); addSupportedService(PineTimeJFConstants.UUID_SERVICE_MOTION); @@ -317,6 +320,68 @@ public class PineTimeJFSupport extends AbstractBTLEDeviceSupport implements DfuL builder.queue(getQueue()); } + @Override + public void onSetNavigationInfo(NavigationInfoSpec navigationInfoSpec) { + TransactionBuilder builder = new TransactionBuilder("navigation info"); + if (navigationInfoSpec.instruction == null) { + navigationInfoSpec.instruction = ""; + } + + safeWriteToCharacteristic(builder, PineTimeJFConstants.UUID_CHARACTERISTICS_NAVIGATION_NARRATIVE, navigationInfoSpec.instruction.getBytes(StandardCharsets.UTF_8)); + safeWriteToCharacteristic(builder, PineTimeJFConstants.UUID_CHARACTERISTICS_NAVIGATION_MAN_DISTANCE, (navigationInfoSpec.distanceToTurn + "m").getBytes(StandardCharsets.UTF_8)); + String iconname; + switch (navigationInfoSpec.nextAction) { + case NavigationInfoSpec.ACTION_CONTINUE: + iconname = "contine"; + break; + case NavigationInfoSpec.ACTION_TURN_LEFT: + iconname = "turn-left"; + break; + case NavigationInfoSpec.ACTION_TURN_LEFT_SLIGHTLY: + iconname = "turn-slight-left"; + break; + case NavigationInfoSpec.ACTION_TURN_LEFT_SHARPLY: + iconname = "turn-sharp-left"; + break; + case NavigationInfoSpec.ACTION_TURN_RIGHT: + iconname = "turn-right"; + break; + case NavigationInfoSpec.ACTION_TURN_RIGHT_SLIGHTLY: + iconname = "turn-slight-right"; + break; + case NavigationInfoSpec.ACTION_TURN_RIGHT_SHARPLY: + iconname = "turn-sharp-right"; + break; + case NavigationInfoSpec.ACTION_KEEP_LEFT: + iconname = "continue-left"; + break; + case NavigationInfoSpec.ACTION_KEEP_RIGHT: + iconname = "continue-right"; + break; + case NavigationInfoSpec.ACTION_UTURN_LEFT: + case NavigationInfoSpec.ACTION_UTURN_RIGHT: + iconname = "iturn"; + break; + case NavigationInfoSpec.ACTION_ROUNDABOUT_RIGHT: + iconname = "roundabout-right"; + break; + case NavigationInfoSpec.ACTION_ROUNDABOUT_LEFT: + iconname = "roundabout-left"; + break; + default: + iconname = "invalid"; + break; + } + + safeWriteToCharacteristic(builder, PineTimeJFConstants.UUID_CHARACTERISTICS_NAVIGATION_FLAGS, iconname.getBytes(StandardCharsets.UTF_8)); + builder.queue(getQueue()); + } + + @Override + public void onDeleteNotification(int id) { + + } + @Override public void onSetTime() { // Since this is a standard we should generalize this in Gadgetbridge (properly)