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 b48e2c83f..62f50dc69 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 @@ -68,21 +68,28 @@ public class PineTimeJFSupport extends AbstractBTLEDeviceSupport { */ String lastAlbum; String lastTrack; + String lastArtist; - private void setInitialized(TransactionBuilder builder) { - builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZED, getContext())); - } - - private void requestDeviceInfo(TransactionBuilder builder) { - LOG.debug("Requesting Device Info!"); - deviceInfoProfile.requestDeviceInfo(builder); - } - - private void handleDeviceInfo(nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.deviceinfo.DeviceInfo info) { - LOG.warn("Device info: " + info); - versionCmd.hwVersion = info.getHardwareRevision(); - versionCmd.fwVersion = info.getFirmwareRevision(); - handleGBDeviceEvent(versionCmd); + public PineTimeJFSupport() { + super(LOG); + addSupportedService(GattService.UUID_SERVICE_ALERT_NOTIFICATION); + addSupportedService(GattService.UUID_SERVICE_CURRENT_TIME); + addSupportedService(GattService.UUID_SERVICE_DEVICE_INFORMATION); + addSupportedService(PineTimeJFConstants.UUID_SERVICE_MUSIC_CONTROL); + deviceInfoProfile = new DeviceInfoProfile<>(this); + IntentListener mListener = new IntentListener() { + @Override + public void notify(Intent intent) { + String action = intent.getAction(); + if (DeviceInfoProfile.ACTION_DEVICE_INFO.equals(action)) { + handleDeviceInfo((nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.deviceinfo.DeviceInfo) intent.getParcelableExtra(DeviceInfoProfile.EXTRA_DEVICE_INFO)); + } + } + }; + deviceInfoProfile.addListener(mListener); + AlertNotificationProfile alertNotificationProfile = new AlertNotificationProfile<>(this); + addSupportedProfile(alertNotificationProfile); + addSupportedProfile(deviceInfoProfile); } @Override @@ -221,37 +228,6 @@ public class PineTimeJFSupport extends AbstractBTLEDeviceSupport { } - String lastArtist; - - public PineTimeJFSupport() { - super(LOG); - addSupportedService(GattService.UUID_SERVICE_ALERT_NOTIFICATION); - addSupportedService(GattService.UUID_SERVICE_CURRENT_TIME); - addSupportedService(GattService.UUID_SERVICE_DEVICE_INFORMATION); - addSupportedService(PineTimeJFConstants.UUID_SERVICE_MUSIC_CONTROL); - deviceInfoProfile = new DeviceInfoProfile<>(this); - IntentListener mListener = new IntentListener() { - @Override - public void notify(Intent intent) { - String action = intent.getAction(); - if (DeviceInfoProfile.ACTION_DEVICE_INFO.equals(action)) { - handleDeviceInfo((nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.deviceinfo.DeviceInfo) intent.getParcelableExtra(DeviceInfoProfile.EXTRA_DEVICE_INFO)); - } - } - }; - deviceInfoProfile.addListener(mListener); - AlertNotificationProfile alertNotificationProfile = new AlertNotificationProfile<>(this); - addSupportedProfile(alertNotificationProfile); - addSupportedProfile(deviceInfoProfile); - } - - /** - * Helper function that ust converts an integer into a byte array - */ - private static byte[] intToBytes(int source) { - return ByteBuffer.allocate(4).putInt(source).array(); - } - @Override protected TransactionBuilder initializeDevice(TransactionBuilder builder) { builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZING, getContext())); @@ -406,6 +382,13 @@ public class PineTimeJFSupport extends AbstractBTLEDeviceSupport { } + /** + * Helper function that just converts an integer into a byte array + */ + private static byte[] intToBytes(int source) { + return ByteBuffer.allocate(4).putInt(source).array(); + } + /** * This will check if the characteristic exists and can be written *

@@ -418,4 +401,20 @@ public class PineTimeJFSupport extends AbstractBTLEDeviceSupport { builder.write(characteristic, data); } } + + private void setInitialized(TransactionBuilder builder) { + builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZED, getContext())); + } + + private void requestDeviceInfo(TransactionBuilder builder) { + LOG.debug("Requesting Device Info!"); + deviceInfoProfile.requestDeviceInfo(builder); + } + + private void handleDeviceInfo(nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.deviceinfo.DeviceInfo info) { + LOG.warn("Device info: " + info); + versionCmd.hwVersion = info.getHardwareRevision(); + versionCmd.fwVersion = info.getFirmwareRevision(); + handleGBDeviceEvent(versionCmd); + } }