From fc17dec87b08ec5415c8f46a1936cbb426a8697f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20B=C3=B6hler?= Date: Mon, 28 Jan 2019 20:26:02 +0100 Subject: [PATCH] Add explicit support for GB-6900B, GB-X6900B and GB-5600B --- .../casiogb6900/CasioGB6900Constants.java | 6 ++- .../devices/casiogb6900/CasioGATTServer.java | 54 +++++++++++++++---- .../casiogb6900/CasioGB6900DeviceSupport.java | 15 ++++++ 3 files changed, 65 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casiogb6900/CasioGB6900Constants.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casiogb6900/CasioGB6900Constants.java index b2b97d738..b701a6f0b 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casiogb6900/CasioGB6900Constants.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casiogb6900/CasioGB6900Constants.java @@ -88,5 +88,9 @@ public final class CasioGB6900Constants { public static final byte SNS_NOTIFICATION_ID = 13; public static final byte SMS_NOTIFICATION_ID = 5; - + public enum Model { + MODEL_CASIO_GENERIC, + MODEL_CASIO_6900B, + MODEL_CASIO_5600B + } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casiogb6900/CasioGATTServer.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casiogb6900/CasioGATTServer.java index 75ab2a7f1..4515f2553 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casiogb6900/CasioGATTServer.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casiogb6900/CasioGATTServer.java @@ -101,6 +101,40 @@ class CasioGATTServer extends BluetoothGattServerCallback { LOG.warn("error sending response"); } } + private GBDeviceEventMusicControl.Event parse3Button(int button) { + GBDeviceEventMusicControl.Event event; + switch(button) { + case 3: + event = GBDeviceEventMusicControl.Event.NEXT; + break; + case 2: + event = GBDeviceEventMusicControl.Event.PREVIOUS; + break; + case 1: + event = GBDeviceEventMusicControl.Event.PLAYPAUSE; + break; + default: + LOG.warn("Unhandled button received: " + button); + event = GBDeviceEventMusicControl.Event.UNKNOWN; + } + return event; + } + + private GBDeviceEventMusicControl.Event parse2Button(int button) { + GBDeviceEventMusicControl.Event event; + switch(button) { + case 2: + event = GBDeviceEventMusicControl.Event.PLAYPAUSE; + break; + case 1: + event = GBDeviceEventMusicControl.Event.NEXT; + break; + default: + LOG.warn("Unhandled button received: " + button); + event = GBDeviceEventMusicControl.Event.UNKNOWN; + } + return event; + } @Override public void onCharacteristicWriteRequest(BluetoothDevice device, int requestId, BluetoothGattCharacteristic characteristic, @@ -119,21 +153,23 @@ class CasioGATTServer extends BluetoothGattServerCallback { if((value[0] & 0x03) == 0) { int button = value[1] & 0x0f; LOG.info("Button pressed: " + button); - switch(button) { - case 3: - musicCmd.event = GBDeviceEventMusicControl.Event.NEXT; + switch(mDeviceSupport.getModel()) + { + case MODEL_CASIO_5600B: + musicCmd.event = parse2Button(button); break; - case 2: - musicCmd.event = GBDeviceEventMusicControl.Event.PREVIOUS; + case MODEL_CASIO_6900B: + musicCmd.event = parse3Button(button); break; - case 1: - musicCmd.event = GBDeviceEventMusicControl.Event.PLAYPAUSE; + case MODEL_CASIO_GENERIC: + musicCmd.event = parse3Button(button); break; default: - LOG.warn("Unhandled button received: " + button); + LOG.warn("Unhandled device"); return; } mDeviceSupport.evaluateGBDeviceEvent(musicCmd); + mDeviceSupport.evaluateGBDeviceEvent(musicCmd); } else { LOG.info("received from device: " + value.toString()); @@ -145,7 +181,7 @@ class CasioGATTServer extends BluetoothGattServerCallback { LOG.info("Connection state change for device: " + device.getAddress() + " status = " + status + " newState = " + newState); if (newState == BluetoothGattServer.STATE_DISCONNECTED) { - + LOG.info("CASIO GATT server noticed disconnect."); } if (newState == BluetoothGattServer.STATE_CONNECTED) { GBDevice.State devState = mDeviceSupport.getDevice().getState(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casiogb6900/CasioGB6900DeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casiogb6900/CasioGB6900DeviceSupport.java index 7870e0f5b..7fb879259 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casiogb6900/CasioGB6900DeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casiogb6900/CasioGB6900DeviceSupport.java @@ -60,6 +60,7 @@ public class CasioGB6900DeviceSupport extends AbstractBTLEDeviceSupport { private MusicSpec mBufferMusicSpec = null; private MusicStateSpec mBufferMusicStateSpec = null; private BluetoothGatt mBtGatt = null; + private CasioGB6900Constants.Model mModel = CasioGB6900Constants.Model.MODEL_CASIO_GENERIC; public CasioGB6900DeviceSupport() { super(LOG); @@ -117,6 +118,16 @@ public class CasioGB6900DeviceSupport extends AbstractBTLEDeviceSupport { protected TransactionBuilder initializeDevice(TransactionBuilder builder) { LOG.info("Initializing"); + String name = gbDevice.getName(); + + if(name.contains("5600B")) { + mModel = CasioGB6900Constants.Model.MODEL_CASIO_5600B; + } else if(name.contains("6900B")) { + mModel = CasioGB6900Constants.Model.MODEL_CASIO_6900B; + } else { + mModel = CasioGB6900Constants.Model.MODEL_CASIO_GENERIC; + } + gbDevice.setState(GBDevice.State.INITIALIZING); gbDevice.sendDeviceUpdateIntent(getContext()); @@ -133,6 +144,10 @@ public class CasioGB6900DeviceSupport extends AbstractBTLEDeviceSupport { return builder; } + CasioGB6900Constants.Model getModel() { + return mModel; + } + // FIXME: Replace hardcoded values by configuration private void configureWatch(TransactionBuilder builder) { if (mBtGatt == null)