mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-28 03:25:49 +01:00
InfiniTime: Add support for battery info
This commit is contained in:
parent
9aed3a6b25
commit
bb1df11650
@ -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.GBDeviceEventBatteryInfo;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventCallControl;
|
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;
|
||||||
@ -68,13 +69,18 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotificat
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification.AlertNotificationProfile;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification.AlertNotificationProfile;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification.NewAlert;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification.NewAlert;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification.OverflowStrategy;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification.OverflowStrategy;
|
||||||
|
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;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||||
|
|
||||||
public class PineTimeJFSupport extends AbstractBTLEDeviceSupport implements DfuLogListener {
|
public class PineTimeJFSupport extends AbstractBTLEDeviceSupport implements DfuLogListener {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(PineTimeJFSupport.class);
|
private static final Logger LOG = LoggerFactory.getLogger(PineTimeJFSupport.class);
|
||||||
private final GBDeviceEventVersionInfo versionCmd = new GBDeviceEventVersionInfo();
|
private final GBDeviceEventVersionInfo versionCmd = new GBDeviceEventVersionInfo();
|
||||||
|
private final GBDeviceEventBatteryInfo batteryCmd = new GBDeviceEventBatteryInfo();
|
||||||
|
|
||||||
private final DeviceInfoProfile<PineTimeJFSupport> deviceInfoProfile;
|
private final DeviceInfoProfile<PineTimeJFSupport> deviceInfoProfile;
|
||||||
|
private final BatteryInfoProfile<PineTimeJFSupport> batteryInfoProfile;
|
||||||
|
|
||||||
private final int MaxNotificationLength = 100;
|
private final int MaxNotificationLength = 100;
|
||||||
private int firmwareVersionMajor = 0;
|
private int firmwareVersionMajor = 0;
|
||||||
private int firmwareVersionMinor = 0;
|
private int firmwareVersionMinor = 0;
|
||||||
@ -211,23 +217,37 @@ public class PineTimeJFSupport extends AbstractBTLEDeviceSupport implements DfuL
|
|||||||
addSupportedService(GattService.UUID_SERVICE_ALERT_NOTIFICATION);
|
addSupportedService(GattService.UUID_SERVICE_ALERT_NOTIFICATION);
|
||||||
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(GattService.UUID_SERVICE_BATTERY_SERVICE);
|
||||||
addSupportedService(PineTimeJFConstants.UUID_SERVICE_MUSIC_CONTROL);
|
addSupportedService(PineTimeJFConstants.UUID_SERVICE_MUSIC_CONTROL);
|
||||||
addSupportedService(PineTimeJFConstants.UUID_CHARACTERISTIC_ALERT_NOTIFICATION_EVENT);
|
addSupportedService(PineTimeJFConstants.UUID_CHARACTERISTIC_ALERT_NOTIFICATION_EVENT);
|
||||||
|
|
||||||
deviceInfoProfile = new DeviceInfoProfile<>(this);
|
|
||||||
IntentListener mListener = new IntentListener() {
|
IntentListener mListener = new IntentListener() {
|
||||||
@Override
|
@Override
|
||||||
public void notify(Intent intent) {
|
public void notify(Intent intent) {
|
||||||
String action = intent.getAction();
|
String action = intent.getAction();
|
||||||
if (DeviceInfoProfile.ACTION_DEVICE_INFO.equals(action)) {
|
if (DeviceInfoProfile.ACTION_DEVICE_INFO.equals(action)) {
|
||||||
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 (BatteryInfoProfile.ACTION_BATTERY_INFO.equals(action)) {
|
||||||
|
handleBatteryInfo((nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.battery.BatteryInfo) intent.getParcelableExtra(BatteryInfoProfile.EXTRA_BATTERY_INFO));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
deviceInfoProfile = new DeviceInfoProfile<>(this);
|
||||||
deviceInfoProfile.addListener(mListener);
|
deviceInfoProfile.addListener(mListener);
|
||||||
|
addSupportedProfile(deviceInfoProfile);
|
||||||
|
|
||||||
AlertNotificationProfile<PineTimeJFSupport> alertNotificationProfile = new AlertNotificationProfile<>(this);
|
AlertNotificationProfile<PineTimeJFSupport> alertNotificationProfile = new AlertNotificationProfile<>(this);
|
||||||
addSupportedProfile(alertNotificationProfile);
|
addSupportedProfile(alertNotificationProfile);
|
||||||
addSupportedProfile(deviceInfoProfile);
|
|
||||||
|
batteryInfoProfile = new BatteryInfoProfile<>(this);
|
||||||
|
batteryInfoProfile.addListener(mListener);
|
||||||
|
addSupportedProfile(batteryInfoProfile);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleBatteryInfo(nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.battery.BatteryInfo info) {
|
||||||
|
batteryCmd.level = (short) info.getPercentCharged();
|
||||||
|
handleGBDeviceEvent(batteryCmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -431,6 +451,8 @@ public class PineTimeJFSupport extends AbstractBTLEDeviceSupport implements DfuL
|
|||||||
builder.notify(alertNotificationEventCharacteristic, true);
|
builder.notify(alertNotificationEventCharacteristic, true);
|
||||||
}
|
}
|
||||||
setInitialized(builder);
|
setInitialized(builder);
|
||||||
|
batteryInfoProfile.requestBatteryInfo(builder);
|
||||||
|
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user