mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-25 11:26:47 +01:00
Xiaomi: Fix SpO2
This commit is contained in:
parent
11ccf86056
commit
e53c67e8bf
@ -41,6 +41,7 @@ public abstract class AbstractSampleToTimeSampleProvider<T extends TimeSample, S
|
||||
mSession = session;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected abstract T convertSample(final S sample);
|
||||
|
||||
public GBDevice getDevice() {
|
||||
@ -57,7 +58,10 @@ public abstract class AbstractSampleToTimeSampleProvider<T extends TimeSample, S
|
||||
final List<S> upstreamSamples = mSampleProvider.getAllActivitySamples((int) (timestampFrom / 1000L), (int) (timestampTo / 1000L));
|
||||
final List<T> ret = new ArrayList<>();
|
||||
for (final S sample : upstreamSamples) {
|
||||
ret.add(convertSample(sample));
|
||||
final T converted = convertSample(sample);
|
||||
if (converted != null) {
|
||||
ret.add(converted);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -76,8 +76,7 @@ public abstract class XiaomiCoordinator extends AbstractBLEDeviceCoordinator {
|
||||
|
||||
@Override
|
||||
public TimeSampleProvider<? extends Spo2Sample> getSpo2SampleProvider(final GBDevice device, final DaoSession session) {
|
||||
// TODO XiaomiSpo2SampleProvider
|
||||
return super.getSpo2SampleProvider(device, session);
|
||||
return new XiaomiSpo2SampleProvider(device, session);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -156,24 +155,6 @@ public abstract class XiaomiCoordinator extends AbstractBLEDeviceCoordinator {
|
||||
return AppManagerActivity.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getAppCacheDir() throws IOException {
|
||||
// TODO we don't need this
|
||||
return new File(FileUtils.getExternalFilesDir(), "xiaomi-app-cache");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAppCacheSortFilename() {
|
||||
// TODO we don't need this
|
||||
return "xiaomi-app-cache-order.txt";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAppFileExtension() {
|
||||
// TODO we don't need this
|
||||
return ".bin";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsAppListFetching() {
|
||||
return true;
|
||||
@ -217,8 +198,7 @@ public abstract class XiaomiCoordinator extends AbstractBLEDeviceCoordinator {
|
||||
|
||||
@Override
|
||||
public boolean supportsSpo2() {
|
||||
// TODO it does, but not yet implemented, so let's not crash
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,66 @@
|
||||
/* Copyright (C) 2023 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 <http://www.gnu.org/licenses/>. */
|
||||
package nodomain.freeyourgadget.gadgetbridge.devices.xiaomi;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractSampleToTimeSampleProvider;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.XiaomiActivitySample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.Spo2Sample;
|
||||
|
||||
public class XiaomiSpo2SampleProvider extends AbstractSampleToTimeSampleProvider<Spo2Sample, XiaomiActivitySample> {
|
||||
public XiaomiSpo2SampleProvider(final GBDevice device, final DaoSession session) {
|
||||
super(new XiaomiSampleProvider(device, session), device, session);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Spo2Sample convertSample(final XiaomiActivitySample sample) {
|
||||
if (sample.getSpo2() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new XiaomiSpo2Sample(
|
||||
sample.getTimestamp() * 1000L,
|
||||
sample.getSpo2()
|
||||
);
|
||||
}
|
||||
|
||||
protected static class XiaomiSpo2Sample implements Spo2Sample {
|
||||
private final long timestamp;
|
||||
private final int spo2;
|
||||
|
||||
public XiaomiSpo2Sample(final long timestamp, final int spo2) {
|
||||
this.timestamp = timestamp;
|
||||
this.spo2 = spo2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getType() {
|
||||
return Type.UNKNOWN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSpo2() {
|
||||
return spo2;
|
||||
}
|
||||
}
|
||||
}
|
@ -20,6 +20,7 @@ public interface Spo2Sample extends TimeSample {
|
||||
enum Type {
|
||||
MANUAL(0),
|
||||
AUTOMATIC(1),
|
||||
UNKNOWN(2),
|
||||
;
|
||||
|
||||
private final int num;
|
||||
|
Loading…
Reference in New Issue
Block a user