1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-26 02:25:50 +01:00

Add explicit support for GB-6900B, GB-X6900B and GB-5600B

This commit is contained in:
Andreas Böhler 2019-01-28 20:26:02 +01:00
parent df6547c287
commit fc17dec87b
3 changed files with 65 additions and 10 deletions

View File

@ -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
}
}

View File

@ -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();

View File

@ -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)