mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
WIP: iGPSport: add hard/soft version
This commit is contained in:
committed by
José Rebelo
parent
d70b2a0efe
commit
d66f52cd09
+6
@@ -2,7 +2,13 @@ package nodomain.freeyourgadget.gadgetbridge.devices.igpsport;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.GattService;
|
||||
|
||||
public class IGPSportConstants {
|
||||
|
||||
public static final UUID UUID_IGPSPORT_SERVICE_BATTERY = UUID.fromString("0000180a-0000-1000-8000-00805f9b34fb");
|
||||
public static final UUID UUID_IGPSPORT_BATTERY_INFO = UUID.fromString("00002a19-0000-1000-8000-00805f9b34fb");
|
||||
|
||||
public static final UUID UUID_IGPSPORT_SERVICE = UUID.fromString("6e400001-b5a3-f393-e0a9-e50e24dcca9e");
|
||||
public static final UUID UUID_IGPSPORT_CHARACTERISTIC_CONTROL = UUID.fromString("6e400002-b5a3-f393-e0a9-e50e24dcca9e");
|
||||
public static final UUID UUID_IGPSPORT_CHARACTERISTIC_REPORT = UUID.fromString("6e400003-b5a3-f393-e0a9-e50e24dcca9e");
|
||||
|
||||
+62
-4
@@ -1,34 +1,69 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.igpsport;
|
||||
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.fitpro.FitProConstants.UUID_CHARACTERISTIC_RX;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.fitpro.FitProConstants.UUID_CHARACTERISTIC_TX;
|
||||
|
||||
import android.bluetooth.BluetoothGatt;
|
||||
import android.bluetooth.BluetoothGattCharacteristic;
|
||||
import android.content.Intent;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.UUID;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.fitpro.FitProConstants;
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventBatteryInfo;
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventVersionInfo;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.igpsport.IGPSportConstants;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEDeviceSupport;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.GattService;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.makibeshr3.MakibesHR3DeviceSupport;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.IntentListener;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.battery.BatteryInfoProfile;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.deviceinfo.DeviceInfo;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.deviceinfo.DeviceInfoProfile;
|
||||
|
||||
public class IGPSportDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(IGPSportDeviceSupport.class);
|
||||
public BluetoothGattCharacteristic readCharacteristic;
|
||||
public BluetoothGattCharacteristic writeCharacteristic;
|
||||
public final GBDeviceEventBatteryInfo batteryCmd = new GBDeviceEventBatteryInfo();
|
||||
public final GBDeviceEventVersionInfo versionCmd = new GBDeviceEventVersionInfo();
|
||||
public final DeviceInfoProfile<IGPSportDeviceSupport> deviceInfoProfile;
|
||||
public final BatteryInfoProfile<IGPSportDeviceSupport> batteryInfoProfile;
|
||||
|
||||
|
||||
|
||||
public IGPSportDeviceSupport() {
|
||||
super(LOG);
|
||||
|
||||
addSupportedService(GattService.UUID_SERVICE_DEVICE_INFORMATION);
|
||||
addSupportedService(GattService.UUID_SERVICE_BATTERY_SERVICE);
|
||||
addSupportedService(IGPSportConstants.UUID_IGPSPORT_SERVICE);
|
||||
addSupportedService(IGPSportConstants.UUID_IGPSPORT_CHARACTERISTIC_REPORT);
|
||||
|
||||
IntentListener mListener = new IntentListener() {
|
||||
@Override
|
||||
public void notify(Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (DeviceInfoProfile.ACTION_DEVICE_INFO.equals(action)) {
|
||||
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);
|
||||
addSupportedProfile(deviceInfoProfile);
|
||||
|
||||
batteryInfoProfile = new BatteryInfoProfile<>(this);
|
||||
batteryInfoProfile.addListener(mListener);
|
||||
addSupportedProfile(batteryInfoProfile);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -36,12 +71,35 @@ public class IGPSportDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void handleDeviceInfo(DeviceInfo info) {
|
||||
LOG.debug("iGPSport device info: " + info);
|
||||
versionCmd.hwVersion = info.getHardwareRevision();
|
||||
versionCmd.fwVersion = info.getSoftwareRevision();
|
||||
handleGBDeviceEvent(versionCmd);
|
||||
}
|
||||
|
||||
|
||||
public void handleBatteryInfo(nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.battery.BatteryInfo info) {
|
||||
LOG.debug("iGPSport battery info: " + info);
|
||||
batteryCmd.level = (short) info.getPercentCharged();
|
||||
handleGBDeviceEvent(batteryCmd);
|
||||
}
|
||||
|
||||
protected TransactionBuilder initializeDevice(TransactionBuilder builder) {
|
||||
// mark the device as initializing
|
||||
builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZING, getContext()));
|
||||
readCharacteristic = getCharacteristic(IGPSportConstants.UUID_IGPSPORT_CHARACTERISTIC_REPORT);
|
||||
writeCharacteristic = getCharacteristic(IGPSportConstants.UUID_IGPSPORT_CHARACTERISTIC_CONTROL);
|
||||
|
||||
builder.notify(getCharacteristic(IGPSportConstants.UUID_IGPSPORT_CHARACTERISTIC_REPORT), true);
|
||||
builder.notify(getCharacteristic(GattService.UUID_SERVICE_BATTERY_SERVICE), true);
|
||||
builder.setCallback(this);
|
||||
|
||||
deviceInfoProfile.requestDeviceInfo(builder);
|
||||
batteryInfoProfile.requestBatteryInfo(builder);
|
||||
batteryInfoProfile.enableNotify(builder, true);
|
||||
deviceInfoProfile.enableNotify(builder, true);
|
||||
|
||||
// ... custom initialization logic ...
|
||||
|
||||
// set device firmware to prevent the following error when you (later) try to save data to database and
|
||||
|
||||
Reference in New Issue
Block a user