From 713989ef389069d6ac5775b6cd8fdc5a5d582909 Mon Sep 17 00:00:00 2001 From: cpfeiffer Date: Tue, 11 Oct 2016 23:06:59 +0200 Subject: [PATCH] Add event "test new function" for the debug screen --- .../freeyourgadget/gadgetbridge/devices/EventHandler.java | 2 ++ .../freeyourgadget/gadgetbridge/impl/GBDeviceService.java | 6 ++++++ .../freeyourgadget/gadgetbridge/model/DeviceService.java | 1 + .../gadgetbridge/service/DeviceCommunicationService.java | 5 +++++ .../gadgetbridge/service/ServiceDeviceSupport.java | 8 ++++++++ .../service/devices/miband/MiBand2Support.java | 4 +++- .../service/devices/miband/MiBandSupport.java | 4 +++- .../service/devices/pebble/PebbleSupport.java | 7 +++++++ .../service/devices/vibratissimo/VibratissimoSupport.java | 3 +++ .../service/serial/AbstractSerialDeviceSupport.java | 6 ++++++ .../gadgetbridge/service/serial/GBDeviceProtocol.java | 2 ++ .../gadgetbridge/service/TestDeviceSupport.java | 5 +++++ 12 files changed, 51 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/EventHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/EventHandler.java index 1310fee2a..a3af9b205 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/EventHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/EventHandler.java @@ -66,4 +66,6 @@ public interface EventHandler { void onAddCalendarEvent(CalendarEventSpec calendarEventSpec); void onDeleteCalendarEvent(byte type, long id); + + void onTestNewFunction(); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDeviceService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDeviceService.java index f1f3f3472..a46736550 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDeviceService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDeviceService.java @@ -280,4 +280,10 @@ public class GBDeviceService implements DeviceService { .putExtra(EXTRA_CALENDAREVENT_ID, id); invokeService(intent); } + + @Override + public void onTestNewFunction() { + Intent intent = createIntent().setAction(ACTION_TEST_NEW_FUNCTION); + invokeService(intent); + } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/DeviceService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/DeviceService.java index 6f75d01e8..6afa7e346 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/DeviceService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/DeviceService.java @@ -48,6 +48,7 @@ public interface DeviceService extends EventHandler { String ACTION_HEARTRATE_MEASUREMENT = PREFIX + ".action.hr_measurement"; String ACTION_ADD_CALENDAREVENT = PREFIX + ".action.add_calendarevent"; String ACTION_DELETE_CALENDAREVENT = PREFIX + ".action.delete_calendarevent"; + String ACTION_TEST_NEW_FUNCTION = PREFIX + ".action.test_new_function"; String EXTRA_DEVICE_ADDRESS = "device_address"; String EXTRA_NOTIFICATION_BODY = "notification_body"; String EXTRA_NOTIFICATION_FLAGS = "notification_flags"; 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 333c7f6a3..82222bcfe 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java @@ -80,6 +80,7 @@ import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_SE import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_SET_CONSTANT_VIBRATION; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_START; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_STARTAPP; +import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_TEST_NEW_FUNCTION; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_ALARMS; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_APP_CONFIG; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_APP_START; @@ -484,6 +485,10 @@ public class DeviceCommunicationService extends Service implements SharedPrefere mDeviceSupport.onEnableRealtimeHeartRateMeasurement(enable); break; } + case ACTION_TEST_NEW_FUNCTION: { + mDeviceSupport.onTestNewFunction(); + break; + } } return START_STICKY; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/ServiceDeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/ServiceDeviceSupport.java index 822b02d6c..0772633d7 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/ServiceDeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/ServiceDeviceSupport.java @@ -319,4 +319,12 @@ public class ServiceDeviceSupport implements DeviceSupport { } delegate.onDeleteCalendarEvent(type, id); } + + @Override + public void onTestNewFunction() { + if (checkBusy("test new function event")) { + return; + } + delegate.onTestNewFunction(); + } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBand2Support.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBand2Support.java index 35de683c2..159e61a7a 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBand2Support.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBand2Support.java @@ -1206,5 +1206,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport { } } - + @Override + public void onTestNewFunction() { + } } 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 49a90d92a..476d514c0 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 @@ -1212,5 +1212,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport { } } - + @Override + public void onTestNewFunction() { + } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleSupport.java index 5441decaf..a6beb9ffa 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleSupport.java @@ -147,4 +147,11 @@ public class PebbleSupport extends AbstractSerialDeviceSupport { super.onDeleteCalendarEvent(type, id); } } + + @Override + public void onTestNewFunction() { + if (reconnect()) { + super.onTestNewFunction(); + } + } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vibratissimo/VibratissimoSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vibratissimo/VibratissimoSupport.java index d72c144e3..cacd86587 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vibratissimo/VibratissimoSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/vibratissimo/VibratissimoSupport.java @@ -269,7 +269,10 @@ public class VibratissimoSupport extends AbstractBTLEDeviceSupport { LOG.info("Unhandled characteristic read: " + characteristicUUID); return false; + } + @Override + public void onTestNewFunction() { } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/serial/AbstractSerialDeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/serial/AbstractSerialDeviceSupport.java index 53e3593e8..71acbb87c 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/serial/AbstractSerialDeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/serial/AbstractSerialDeviceSupport.java @@ -214,4 +214,10 @@ public abstract class AbstractSerialDeviceSupport extends AbstractDeviceSupport byte[] bytes = gbDeviceProtocol.encodeDeleteCalendarEvent(type, id); sendToDevice(bytes); } + + @Override + public void onTestNewFunction() { + byte[] bytes = gbDeviceProtocol.encodeTestNewFunction(); + sendToDevice(bytes); + } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/serial/GBDeviceProtocol.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/serial/GBDeviceProtocol.java index e46c83b8f..55d4c10c6 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/serial/GBDeviceProtocol.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/serial/GBDeviceProtocol.java @@ -94,6 +94,8 @@ public abstract class GBDeviceProtocol { return null; } + public byte[] encodeTestNewFunction() { return null; } + public GBDeviceEvent[] decodeResponse(byte[] responseData) { return null; } diff --git a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/service/TestDeviceSupport.java b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/service/TestDeviceSupport.java index bc96f010b..7eacaa537 100644 --- a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/service/TestDeviceSupport.java +++ b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/service/TestDeviceSupport.java @@ -167,4 +167,9 @@ public class TestDeviceSupport extends AbstractDeviceSupport { public void onEnableRealtimeHeartRateMeasurement(boolean enable) { } + + @Override + public void onTestNewFunction() { + + } }