1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-29 05:16:51 +01:00

add heart rate measurment support for infinitime

This commit is contained in:
Patric Gruber 2023-03-31 10:17:57 +02:00 committed by José Rebelo
parent 42f35259fc
commit 70a8ca5067
3 changed files with 41 additions and 1 deletions

View File

@ -16,6 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. */ along with this program. If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.devices.pinetime; package nodomain.freeyourgadget.gadgetbridge.devices.pinetime;
import nodomain.freeyourgadget.gadgetbridge.service.btle.GattService;
import java.util.UUID; import java.util.UUID;
public class PineTimeJFConstants { public class PineTimeJFConstants {
@ -55,4 +56,7 @@ public class PineTimeJFConstants {
// since https://github.com/InfiniTimeOrg/InfiniTime/pull/1454 // since https://github.com/InfiniTimeOrg/InfiniTime/pull/1454
public static final UUID UUID_CHARACTERISTIC_WORLD_TIME = UUID.fromString("00050001-78fc-48fe-8e23-433b3a1942d0"); public static final UUID UUID_CHARACTERISTIC_WORLD_TIME = UUID.fromString("00050001-78fc-48fe-8e23-433b3a1942d0");
public static final UUID UUID_SERVICE_HEART_RATE = GattService.UUID_SERVICE_HEART_RATE;
public static final UUID UUID_CHARACTERISTIC_HEART_RATE_MEASUREMENT = UUID.fromString("00002a37-0000-1000-8000-00805f9b34fb");
} }

View File

@ -98,7 +98,7 @@ public class PineTimeJFCoordinator extends AbstractBLEDeviceCoordinator {
@Override @Override
public boolean supportsHeartRateMeasurement(GBDevice device) { public boolean supportsHeartRateMeasurement(GBDevice device) {
return false; return true;
} }
@Override @Override

View File

@ -262,6 +262,7 @@ public class PineTimeJFSupport extends AbstractBTLEDeviceSupport implements DfuL
addSupportedService(PineTimeJFConstants.UUID_SERVICE_NAVIGATION); addSupportedService(PineTimeJFConstants.UUID_SERVICE_NAVIGATION);
addSupportedService(PineTimeJFConstants.UUID_CHARACTERISTIC_ALERT_NOTIFICATION_EVENT); addSupportedService(PineTimeJFConstants.UUID_CHARACTERISTIC_ALERT_NOTIFICATION_EVENT);
addSupportedService(PineTimeJFConstants.UUID_SERVICE_MOTION); addSupportedService(PineTimeJFConstants.UUID_SERVICE_MOTION);
addSupportedService(PineTimeJFConstants.UUID_SERVICE_HEART_RATE);
IntentListener mListener = new IntentListener() { IntentListener mListener = new IntentListener() {
@Override @Override
@ -475,6 +476,8 @@ public class PineTimeJFSupport extends AbstractBTLEDeviceSupport implements DfuL
//builder.notify(getCharacteristic(PineTimeJFConstants.UUID_CHARACTERISTIC_MOTION_RAW_XYZ_VALUES), false); // issue #2527 //builder.notify(getCharacteristic(PineTimeJFConstants.UUID_CHARACTERISTIC_MOTION_RAW_XYZ_VALUES), false); // issue #2527
} }
builder.notify(getCharacteristic(PineTimeJFConstants.UUID_CHARACTERISTIC_HEART_RATE_MEASUREMENT), true);
setInitialized(builder); setInitialized(builder);
batteryInfoProfile.requestBatteryInfo(builder); batteryInfoProfile.requestBatteryInfo(builder);
batteryInfoProfile.enableNotify(builder, true); batteryInfoProfile.enableNotify(builder, true);
@ -681,6 +684,13 @@ public class PineTimeJFSupport extends AbstractBTLEDeviceSupport implements DfuL
} }
onReceiveStepsSample(steps); onReceiveStepsSample(steps);
return true; return true;
} else if (characteristicUUID.equals(PineTimeJFConstants.UUID_CHARACTERISTIC_HEART_RATE_MEASUREMENT)) {
int heartrate = Byte.toUnsignedInt(characteristic.getValue()[1]);
if (LOG.isDebugEnabled()) {
LOG.debug("onCharacteristicChanged: HeartRateMeasurement:HeartRate=" + heartrate);
}
onReceiveHeartRateMeasurement(heartrate);
return true;
} }
LOG.info("Unhandled characteristic changed: " + characteristicUUID); LOG.info("Unhandled characteristic changed: " + characteristicUUID);
@ -1041,6 +1051,32 @@ public class PineTimeJFSupport extends AbstractBTLEDeviceSupport implements DfuL
} }
} }
private void onReceiveHeartRateMeasurement(int heartrate) {
this.onReceiveHeartRateMeasurement((int) (Calendar.getInstance().getTimeInMillis() / 1000l), heartrate);
}
private void onReceiveHeartRateMeasurement(int timeStamp, int heartrate) {
PineTimeActivitySample sample = new PineTimeActivitySample();
logDebug(String.format("onReceiveHeartRateMeasurement: \nheartrate=%d", heartrate));
if (heartrate > 0) {
sample.setHeartRate((int)heartrate);
sample.setTimestamp(timeStamp);
// since it's a local timestamp, it should NOT be treated as Activity because it will spoil activity charts
sample.setRawKind(ActivityKind.TYPE_UNKNOWN);
this.addGBActivitySample(sample);
Intent intent = new Intent(DeviceService.ACTION_REALTIME_SAMPLES)
.putExtra(DeviceService.EXTRA_REALTIME_SAMPLE, sample)
.putExtra(DeviceService.EXTRA_TIMESTAMP, sample.getTimestamp());
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent);
} else {
logDebug("ignoring heartrate of 0");
}
}
/** /**
* @param timeStamp Time stamp (in seconds) at some point during the requested day. * @param timeStamp Time stamp (in seconds) at some point during the requested day.
*/ */