From 6a18d90fee1691afeedcd7bcc00f3c8929fe96ee Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Tue, 20 Sep 2016 20:28:52 +0200 Subject: [PATCH] Vibratissimo: add simple and buggy activity with a slider for vibration control Also includes some fixes and "find your device" support ;) --- app/src/main/AndroidManifest.xml | 4 ++ .../activities/VibrationActivity.java | 69 +++++++++++++++++++ .../gadgetbridge/devices/EventHandler.java | 2 + .../vibratissimo/VibratissimoCoordinator.java | 9 +-- .../gadgetbridge/impl/GBDeviceService.java | 7 ++ .../gadgetbridge/model/DeviceService.java | 2 + .../service/DeviceCommunicationService.java | 7 ++ .../service/ServiceDeviceSupport.java | 8 +++ .../devices/miband/MiBand2Support.java | 5 ++ .../service/devices/miband/MiBandSupport.java | 5 ++ .../service/devices/pebble/PebbleSupport.java | 5 ++ .../vibratissimo/VibratissimoSupport.java | 27 ++++---- .../main/res/layout/activity_vibration.xml | 16 +++++ app/src/main/res/values/strings.xml | 4 ++ .../service/TestDeviceSupport.java | 5 ++ 15 files changed, 156 insertions(+), 19 deletions(-) create mode 100644 app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/VibrationActivity.java create mode 100644 app/src/main/res/layout/activity_vibration.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 7a56cbf5..3c3c718a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -259,6 +259,10 @@ android:name=".activities.AlarmDetails" android:label="@string/title_activity_alarm_details" android:parentActivityName=".activities.ConfigureAlarms" /> + getPrimaryActivity() { - return null; + return VibrationActivity.class; } - @Override public InstallHandler findInstallHandler(Uri uri, Context context) { return null; @@ -53,7 +54,7 @@ public class VibratissimoCoordinator extends AbstractDeviceCoordinator { @Override public boolean supportsScreenshots() { - return true; + return false; } @Override @@ -68,7 +69,7 @@ public class VibratissimoCoordinator extends AbstractDeviceCoordinator { @Override public int getTapString() { - return R.string.tap_connected_device_for_activity; + return R.string.tap_connected_device_for_vibration; } @Override 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 bc458c81..f1f3f347 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDeviceService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDeviceService.java @@ -227,6 +227,13 @@ public class GBDeviceService implements DeviceService { invokeService(intent); } + @Override + public void onSetConstantVibration(int intensity) { + Intent intent = createIntent().setAction(ACTION_SET_CONSTANT_VIBRATION) + .putExtra(EXTRA_VIBRATION_INTENSITY, intensity); + invokeService(intent); + } + @Override public void onScreenshotReq() { Intent intent = createIntent().setAction(ACTION_REQUEST_SCREENSHOT); 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 6db9f4a8..0b664fcf 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/DeviceService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/DeviceService.java @@ -34,6 +34,7 @@ public interface DeviceService extends EventHandler { String ACTION_FETCH_ACTIVITY_DATA = PREFIX + ".action.fetch_activity_data"; String ACTION_DISCONNECT = PREFIX + ".action.disconnect"; String ACTION_FIND_DEVICE = PREFIX + ".action.find_device"; + String ACTION_SET_CONSTANT_VIBRATION = PREFIX + ".action.set_constant_vibration"; String ACTION_SET_ALARMS = PREFIX + ".action.set_alarms"; String ACTION_ENABLE_REALTIME_STEPS = PREFIX + ".action.enable_realtime_steps"; String ACTION_REALTIME_STEPS = PREFIX + ".action.realtime_steps"; @@ -53,6 +54,7 @@ public interface DeviceService extends EventHandler { String EXTRA_NOTIFICATION_TITLE = "notification_title"; String EXTRA_NOTIFICATION_TYPE = "notification_type"; String EXTRA_FIND_START = "find_start"; + String EXTRA_VIBRATION_INTENSITY = "vibration_intensity"; String EXTRA_CALL_COMMAND = "call_command"; String EXTRA_CALL_PHONENUMBER = "call_phonenumber"; String EXTRA_CANNEDMESSAGES = "cannedmessages"; 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 118ca276..db8f2a47 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java @@ -76,6 +76,7 @@ import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_SE import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_SETMUSICSTATE; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_SETTIME; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_SET_ALARMS; +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.EXTRA_ALARMS; @@ -117,6 +118,7 @@ import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_NOT import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_NOTIFICATION_TYPE; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_PERFORM_PAIR; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_URI; +import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_VIBRATION_INTENSITY; public class DeviceCommunicationService extends Service implements SharedPreferences.OnSharedPreferenceChangeListener { private static final Logger LOG = LoggerFactory.getLogger(DeviceCommunicationService.class); @@ -377,6 +379,11 @@ public class DeviceCommunicationService extends Service implements SharedPrefere mDeviceSupport.onFindDevice(start); break; } + case ACTION_SET_CONSTANT_VIBRATION: { + int intensity = intent.getIntExtra(EXTRA_VIBRATION_INTENSITY, 0); + mDeviceSupport.onSetConstantVibration(intensity); + break; + } case ACTION_CALLSTATE: int command = intent.getIntExtra(EXTRA_CALL_COMMAND, CallSpec.CALL_UNDEFINED); 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 7c509984..822b02d6 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/ServiceDeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/ServiceDeviceSupport.java @@ -256,6 +256,14 @@ public class ServiceDeviceSupport implements DeviceSupport { delegate.onFindDevice(start); } + @Override + public void onSetConstantVibration(int intensity) { + if (checkBusy("set constant vibration")) { + return; + } + delegate.onSetConstantVibration(intensity); + } + @Override public void onScreenshotReq() { if (checkBusy("request screenshot")) { 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 3aeae72a..4c372b97 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 @@ -774,6 +774,11 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport { } } + @Override + public void onSetConstantVibration(int intensity) { + + } + @Override public void onFetchActivityData() { // TODO: onFetchActivityData 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 e7f3667f..cfbdf14e 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 @@ -681,6 +681,11 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport { } } + @Override + public void onSetConstantVibration(int intensity) { + + } + @Override public void onFetchActivityData() { try { 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 9bf905b2..5441deca 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 @@ -72,6 +72,11 @@ public class PebbleSupport extends AbstractSerialDeviceSupport { } + @Override + public void onSetConstantVibration(int intensity) { + + } + @Override public synchronized PebbleIoThread getDeviceIOThread() { return (PebbleIoThread) super.getDeviceIOThread(); 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 cb609c8d..ebe1d5e1 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 @@ -51,7 +51,6 @@ public class VibratissimoSupport extends AbstractBTLEDeviceSupport { } } }; - private BtLEQueue mQueue; public VibratissimoSupport() { addSupportedService(GattService.UUID_SERVICE_GENERIC_ACCESS); @@ -136,21 +135,7 @@ public class VibratissimoSupport extends AbstractBTLEDeviceSupport { @Override public void onSetCallState(CallSpec callSpec) { - BluetoothGattCharacteristic characteristic2 = getCharacteristic(UUID.fromString("00001526-1212-efde-1523-785feabcd123")); - BluetoothGattCharacteristic characteristic1 = getCharacteristic(UUID.fromString("00001524-1212-efde-1523-785feabcd123")); - TransactionBuilder builder = new TransactionBuilder("phonetest"); - builder.write(characteristic1, new byte[]{0x03, (byte) 0x80}); - - byte intensity; - if (callSpec.command == CallSpec.CALL_INCOMING) { - intensity = 0x65; - builder.write(characteristic2, new byte[]{0x65, 0x00}); - } else { - intensity = 0; - } - builder.write(characteristic2, new byte[]{intensity, 0x00}); - builder.queue(getQueue()); } @Override @@ -225,7 +210,19 @@ public class VibratissimoSupport extends AbstractBTLEDeviceSupport { @Override public void onFindDevice(boolean start) { + onSetConstantVibration(start ? 0xff : 0x00); + } + @Override + public void onSetConstantVibration(int intensity) { + BluetoothGattCharacteristic characteristic2 = getCharacteristic(UUID.fromString("00001526-1212-efde-1523-785feabcd123")); + BluetoothGattCharacteristic characteristic1 = getCharacteristic(UUID.fromString("00001524-1212-efde-1523-785feabcd123")); + + TransactionBuilder builder = new TransactionBuilder("vibration"); + builder.write(characteristic1, new byte[]{0x03, (byte) 0x80}); + + builder.write(characteristic2, new byte[]{(byte) intensity, 0x00}); + builder.queue(getQueue()); } @Override diff --git a/app/src/main/res/layout/activity_vibration.xml b/app/src/main/res/layout/activity_vibration.xml new file mode 100644 index 00000000..c8e3ee04 --- /dev/null +++ b/app/src/main/res/layout/activity_vibration.xml @@ -0,0 +1,16 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 84ea525b..1b787899 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -126,6 +126,7 @@ Bluetooth is disabled. Tap connected device for App Manager Tap connected device for Activity + Tap connected device for Vibration Tap a device to connect Cannot connect. BT address invalid? Gadgetbridge running @@ -326,4 +327,7 @@ Overwrite Cancel Delete + + + Vibration 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 ba888273..bc96f010 100644 --- a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/service/TestDeviceSupport.java +++ b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/service/TestDeviceSupport.java @@ -133,6 +133,11 @@ public class TestDeviceSupport extends AbstractDeviceSupport { } + @Override + public void onSetConstantVibration(int intensity) { + + } + @Override public void onScreenshotReq() {