mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-27 11:05:49 +01:00
Refactored the iTag support class
This commit is contained in:
parent
1c93f579b5
commit
ed8323ad2e
@ -20,4 +20,5 @@ import java.util.UUID;
|
|||||||
|
|
||||||
public final class ITagConstants {
|
public final class ITagConstants {
|
||||||
public static final UUID UUID_SERVICE_BUTTON = UUID.fromString("0000ffe1-0000-1000-8000-00805f9b34fb"); // Contains information about the button state
|
public static final UUID UUID_SERVICE_BUTTON = UUID.fromString("0000ffe1-0000-1000-8000-00805f9b34fb"); // Contains information about the button state
|
||||||
|
public static final UUID UUID_LINK_LOSS_ALERT_LEVEL = UUID.fromString("00002a06-0000-1000-8000-00805f9b34fb"); // Contains information about the button state
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEDeviceSuppo
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.GattService;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.GattService;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.IntentListener;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.battery.BatteryInfoProfile;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.battery.BatteryInfoProfile;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.deviceinfo.DeviceInfoProfile;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.deviceinfo.DeviceInfoProfile;
|
||||||
|
|
||||||
@ -57,44 +58,35 @@ public class ITagSupport extends AbstractBTLEDeviceSupport {
|
|||||||
private final DeviceInfoProfile<ITagSupport> deviceInfoProfile;
|
private final DeviceInfoProfile<ITagSupport> deviceInfoProfile;
|
||||||
private final BatteryInfoProfile<ITagSupport> batteryInfoProfile;
|
private final BatteryInfoProfile<ITagSupport> batteryInfoProfile;
|
||||||
|
|
||||||
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
private final IntentListener mListener = new IntentListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void notify(Intent intent) {
|
||||||
String intentAction = intent.getAction();
|
String s = intent.getAction();
|
||||||
if(intentAction != null) {
|
if (s.equals(DeviceInfoProfile.ACTION_DEVICE_INFO)) {
|
||||||
if (intentAction.equals(DeviceInfoProfile.ACTION_DEVICE_INFO)) {
|
|
||||||
handleDeviceInfo((nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.deviceinfo.DeviceInfo) intent.getParcelableExtra(DeviceInfoProfile.EXTRA_DEVICE_INFO));
|
handleDeviceInfo((nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.deviceinfo.DeviceInfo) intent.getParcelableExtra(DeviceInfoProfile.EXTRA_DEVICE_INFO));
|
||||||
} else if (intentAction.equals(BatteryInfoProfile.ACTION_BATTERY_INFO)) {
|
} else if (s.equals(BatteryInfoProfile.ACTION_BATTERY_INFO)) {
|
||||||
handleBatteryInfo((nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.battery.BatteryInfo) intent.getParcelableExtra(BatteryInfoProfile.EXTRA_BATTERY_INFO));
|
handleBatteryInfo((nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.battery.BatteryInfo) intent.getParcelableExtra(BatteryInfoProfile.EXTRA_BATTERY_INFO));
|
||||||
}
|
}
|
||||||
} else{
|
|
||||||
LOG.warn("ITagSupport", "Error reading intent action");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public ITagSupport() {
|
public ITagSupport() {
|
||||||
super(LOG);
|
super(LOG);
|
||||||
addSupportedService(GattService.UUID_SERVICE_GENERIC_ACCESS);
|
addSupportedService(GattService.UUID_SERVICE_GENERIC_ACCESS);
|
||||||
//TODO: Might not exist! Enabling on unsupported devices causes reconnection loops that
|
addSupportedService(GattService.UUID_SERVICE_GENERIC_ATTRIBUTE);
|
||||||
// might cause the device to become unresponsive and drain its battery
|
addSupportedService(GattService.UUID_SERVICE_BATTERY_SERVICE);
|
||||||
//addSupportedService(GattService.UUID_SERVICE_GENERIC_ATTRIBUTE);
|
|
||||||
//addSupportedService(GattService.UUID_SERVICE_BATTERY_SERVICE);
|
|
||||||
|
|
||||||
addSupportedService(GattService.UUID_SERVICE_IMMEDIATE_ALERT);
|
addSupportedService(GattService.UUID_SERVICE_IMMEDIATE_ALERT);
|
||||||
addSupportedService(ITagConstants.UUID_SERVICE_BUTTON);
|
addSupportedService(ITagConstants.UUID_SERVICE_BUTTON);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
deviceInfoProfile = new DeviceInfoProfile<>(this);
|
deviceInfoProfile = new DeviceInfoProfile<>(this);
|
||||||
|
deviceInfoProfile.addListener(mListener);
|
||||||
batteryInfoProfile = new BatteryInfoProfile<>(this);
|
batteryInfoProfile = new BatteryInfoProfile<>(this);
|
||||||
|
batteryInfoProfile.addListener(mListener);
|
||||||
|
|
||||||
addSupportedProfile(deviceInfoProfile);
|
addSupportedProfile(deviceInfoProfile);
|
||||||
addSupportedProfile(batteryInfoProfile);
|
addSupportedProfile(batteryInfoProfile);
|
||||||
|
|
||||||
LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(getContext());
|
|
||||||
IntentFilter intentFilter = new IntentFilter();
|
|
||||||
intentFilter.addAction(BatteryInfoProfile.ACTION_BATTERY_INFO);
|
|
||||||
broadcastManager.registerReceiver(mReceiver, intentFilter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleBatteryInfo(nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.battery.BatteryInfo info) {
|
private void handleBatteryInfo(nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.battery.BatteryInfo info) {
|
||||||
@ -102,13 +94,6 @@ public class ITagSupport extends AbstractBTLEDeviceSupport {
|
|||||||
handleGBDeviceEvent(batteryCmd);
|
handleGBDeviceEvent(batteryCmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void dispose() {
|
|
||||||
LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(getContext());
|
|
||||||
broadcastManager.unregisterReceiver(mReceiver);
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected TransactionBuilder initializeDevice(TransactionBuilder builder) {
|
protected TransactionBuilder initializeDevice(TransactionBuilder builder) {
|
||||||
builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZING, getContext()));
|
builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZING, getContext()));
|
||||||
@ -134,7 +119,7 @@ public class ITagSupport extends AbstractBTLEDeviceSupport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handleDeviceInfo(nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.deviceinfo.DeviceInfo info) {
|
private void handleDeviceInfo(nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.deviceinfo.DeviceInfo info) {
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -239,7 +224,7 @@ public class ITagSupport extends AbstractBTLEDeviceSupport {
|
|||||||
@Override
|
@Override
|
||||||
public void onSetConstantVibration(int intensity) {
|
public void onSetConstantVibration(int intensity) {
|
||||||
getQueue().clear();
|
getQueue().clear();
|
||||||
BluetoothGattCharacteristic characteristic = getCharacteristic(UUID.fromString("00002a06-0000-1000-8000-00805f9b34fb"));
|
BluetoothGattCharacteristic characteristic = getCharacteristic(ITagConstants.UUID_LINK_LOSS_ALERT_LEVEL);
|
||||||
|
|
||||||
TransactionBuilder builder = new TransactionBuilder("beeping");
|
TransactionBuilder builder = new TransactionBuilder("beeping");
|
||||||
builder.write(characteristic, new byte[]{(byte) intensity});
|
builder.write(characteristic, new byte[]{(byte) intensity});
|
||||||
|
Loading…
Reference in New Issue
Block a user