mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
Xiaomi-protobuf: Add resting HR
This commit is contained in:
+7
-3
@@ -153,9 +153,8 @@ public abstract class XiaomiCoordinator extends AbstractBLEDeviceCoordinator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimeSampleProvider<? extends HeartRateSample> getHeartRateRestingSampleProvider(final GBDevice device, final DaoSession session) {
|
||||
// TODO XiaomiHeartRateRestingSampleProvider
|
||||
return super.getHeartRateRestingSampleProvider(device, session);
|
||||
public TimeSampleProvider<? extends HeartRateSample> getHeartRateRestingSampleProvider(GBDevice device, DaoSession session) {
|
||||
return new XiaomiHeartRateRestingSampleProvider(device, session);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -271,6 +270,11 @@ public abstract class XiaomiCoordinator extends AbstractBLEDeviceCoordinator {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsHeartRateRestingMeasurement(GBDevice device) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsPai() {
|
||||
// Vitality Score
|
||||
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
/* Copyright (C) 2024 José Rebelo
|
||||
|
||||
This file is part of Gadgetbridge.
|
||||
|
||||
Gadgetbridge is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published
|
||||
by the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Gadgetbridge is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
package nodomain.freeyourgadget.gadgetbridge.devices.xiaomi;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.TimeSampleProvider;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.XiaomiDailySummarySample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.HeartRateSample;
|
||||
|
||||
public class XiaomiHeartRateRestingSampleProvider implements TimeSampleProvider<HeartRateSample> {
|
||||
private final XiaomiDailySummarySampleProvider dailySummarySampleProvider;
|
||||
|
||||
public XiaomiHeartRateRestingSampleProvider(final GBDevice device, final DaoSession session) {
|
||||
this.dailySummarySampleProvider = new XiaomiDailySummarySampleProvider(device, session);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public List<HeartRateSample> getAllSamples(final long timestampFrom, final long timestampTo) {
|
||||
final List<XiaomiDailySummarySample> allSamples = dailySummarySampleProvider.getAllSamples(timestampFrom, timestampTo);
|
||||
final List<HeartRateSample> ret = new ArrayList<>(allSamples.size());
|
||||
for (final XiaomiDailySummarySample sample : allSamples) {
|
||||
ret.add(new XiaomiHeartRateRestingSample(sample));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSample(final HeartRateSample timeSample) {
|
||||
throw new UnsupportedOperationException("This sample provider is read-only!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSamples(final List<HeartRateSample> timeSamples) {
|
||||
throw new UnsupportedOperationException("This sample provider is read-only!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public HeartRateSample createSample() {
|
||||
throw new UnsupportedOperationException("This sample provider is read-only!");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public HeartRateSample getLatestSample() {
|
||||
final XiaomiDailySummarySample sample = dailySummarySampleProvider.getLatestSample();
|
||||
if (sample != null) {
|
||||
return new XiaomiHeartRateRestingSample(sample);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public HeartRateSample getFirstSample() {
|
||||
final XiaomiDailySummarySample sample = dailySummarySampleProvider.getFirstSample();
|
||||
if (sample != null) {
|
||||
return new XiaomiHeartRateRestingSample(sample);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class XiaomiHeartRateRestingSample implements HeartRateSample {
|
||||
private final long timestamp;
|
||||
private final int heartRate;
|
||||
|
||||
public XiaomiHeartRateRestingSample(final XiaomiDailySummarySample sample) {
|
||||
this.timestamp = sample.getTimestamp();
|
||||
this.heartRate = sample.getHrResting();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeartRate() {
|
||||
return heartRate;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user