1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-29 21:32:57 +01:00

InfiniTime: Implement call control and notification

This commit is contained in:
Andreas Shimokawa 2021-02-22 23:35:34 +01:00
parent 0118469c9f
commit 00e5f1caf2
2 changed files with 37 additions and 1 deletions

View File

@ -33,4 +33,6 @@ public class PineTimeJFConstants {
public static final UUID UUID_CHARACTERISTICS_MUSIC_PLAYBACK_SPEED = UUID.fromString("0000000a-78fc-48fe-8e23-433b3a1942d0"); public static final UUID UUID_CHARACTERISTICS_MUSIC_PLAYBACK_SPEED = UUID.fromString("0000000a-78fc-48fe-8e23-433b3a1942d0");
public static final UUID UUID_CHARACTERISTICS_MUSIC_REPEAT = UUID.fromString("0000000b-78fc-48fe-8e23-433b3a1942d0"); public static final UUID UUID_CHARACTERISTICS_MUSIC_REPEAT = UUID.fromString("0000000b-78fc-48fe-8e23-433b3a1942d0");
public static final UUID UUID_CHARACTERISTICS_MUSIC_SHUFFLE = UUID.fromString("0000000c-78fc-48fe-8e23-433b3a1942d0"); public static final UUID UUID_CHARACTERISTICS_MUSIC_SHUFFLE = UUID.fromString("0000000c-78fc-48fe-8e23-433b3a1942d0");
public static final UUID UUID_CHARACTERISTIC_ALERT_NOTIFICATION_EVENT = UUID.fromString("00020001-78fc-48fe-8e23-433b3a1942d0");
} }

View File

@ -42,6 +42,7 @@ import no.nordicsemi.android.dfu.DfuServiceController;
import no.nordicsemi.android.dfu.DfuServiceInitiator; import no.nordicsemi.android.dfu.DfuServiceInitiator;
import no.nordicsemi.android.dfu.DfuServiceListenerHelper; import no.nordicsemi.android.dfu.DfuServiceListenerHelper;
import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventCallControl;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventMusicControl; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventMusicControl;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventVersionInfo; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventVersionInfo;
import nodomain.freeyourgadget.gadgetbridge.devices.pinetime.PineTimeDFUService; import nodomain.freeyourgadget.gadgetbridge.devices.pinetime.PineTimeDFUService;
@ -211,6 +212,8 @@ public class PineTimeJFSupport extends AbstractBTLEDeviceSupport implements DfuL
addSupportedService(GattService.UUID_SERVICE_CURRENT_TIME); addSupportedService(GattService.UUID_SERVICE_CURRENT_TIME);
addSupportedService(GattService.UUID_SERVICE_DEVICE_INFORMATION); addSupportedService(GattService.UUID_SERVICE_DEVICE_INFORMATION);
addSupportedService(PineTimeJFConstants.UUID_SERVICE_MUSIC_CONTROL); addSupportedService(PineTimeJFConstants.UUID_SERVICE_MUSIC_CONTROL);
addSupportedService(PineTimeJFConstants.UUID_CHARACTERISTIC_ALERT_NOTIFICATION_EVENT);
deviceInfoProfile = new DeviceInfoProfile<>(this); deviceInfoProfile = new DeviceInfoProfile<>(this);
IntentListener mListener = new IntentListener() { IntentListener mListener = new IntentListener() {
@Override @Override
@ -277,7 +280,15 @@ public class PineTimeJFSupport extends AbstractBTLEDeviceSupport implements DfuL
@Override @Override
public void onSetCallState(CallSpec callSpec) { public void onSetCallState(CallSpec callSpec) {
if (callSpec.command == CallSpec.CALL_INCOMING) {
TransactionBuilder builder = new TransactionBuilder("incomingcall");
String message = (byte) 0x01 + callSpec.name;
NewAlert alert = new NewAlert(AlertCategory.IncomingCall, 1, message);
AlertNotificationProfile<?> profile = new AlertNotificationProfile<>(this);
profile.setMaxLength(MaxNotificationLength);
profile.newAlert(builder, alert, OverflowStrategy.TRUNCATE);
builder.queue(getQueue());
}
} }
@Override @Override
@ -415,6 +426,10 @@ public class PineTimeJFSupport extends AbstractBTLEDeviceSupport implements DfuL
requestDeviceInfo(builder); requestDeviceInfo(builder);
onSetTime(); onSetTime();
builder.notify(getCharacteristic(PineTimeJFConstants.UUID_CHARACTERISTICS_MUSIC_EVENT), true); builder.notify(getCharacteristic(PineTimeJFConstants.UUID_CHARACTERISTICS_MUSIC_EVENT), true);
BluetoothGattCharacteristic alertNotificationEventCharacteristic = getCharacteristic(PineTimeJFConstants.UUID_CHARACTERISTIC_ALERT_NOTIFICATION_EVENT);
if (alertNotificationEventCharacteristic != null) {
builder.notify(alertNotificationEventCharacteristic, true);
}
setInitialized(builder); setInitialized(builder);
return builder; return builder;
} }
@ -553,7 +568,26 @@ public class PineTimeJFSupport extends AbstractBTLEDeviceSupport implements DfuL
} }
evaluateGBDeviceEvent(deviceEventMusicControl); evaluateGBDeviceEvent(deviceEventMusicControl);
return true; return true;
} else if (characteristicUUID.equals(PineTimeJFConstants.UUID_CHARACTERISTIC_ALERT_NOTIFICATION_EVENT)) {
byte[] value = characteristic.getValue();
GBDeviceEventCallControl deviceEventCallControl = new GBDeviceEventCallControl();
switch (value[0]) {
case 0:
deviceEventCallControl.event = GBDeviceEventCallControl.Event.REJECT;
break;
case 1:
deviceEventCallControl.event = GBDeviceEventCallControl.Event.ACCEPT;
break;
case 2:
deviceEventCallControl.event = GBDeviceEventCallControl.Event.IGNORE;
break;
default:
return false;
} }
evaluateGBDeviceEvent(deviceEventCallControl);
return true;
}
LOG.info("Unhandled characteristic changed: " + characteristicUUID); LOG.info("Unhandled characteristic changed: " + characteristicUUID);
return false; return false;
} }