mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-29 03:55:49 +01:00
Xiaomi Watch S1 Pro: Enable charts for body temperature
This commit is contained in:
parent
9db60f16d1
commit
ae05f7fd42
@ -58,6 +58,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.PaiSample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.SleepRespiratoryRateSample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.Spo2Sample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.StressSample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.TemperatureSample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.DeviceSupport;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.xiaomi.XiaomiUuids;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.xiaomi.XiaomiPreferences;
|
||||
@ -125,6 +126,11 @@ public abstract class XiaomiCoordinator extends AbstractBLEDeviceCoordinator {
|
||||
return new int[]{1, 26, 51, 81};
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimeSampleProvider<? extends TemperatureSample> getTemperatureSampleProvider(final GBDevice device, final DaoSession session) {
|
||||
return new XiaomiTemperatureSampleProvider(device, session);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimeSampleProvider<? extends Spo2Sample> getSpo2SampleProvider(final GBDevice device, final DaoSession session) {
|
||||
return new XiaomiSpo2SampleProvider(device, session);
|
||||
|
@ -17,12 +17,19 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.devices.xiaomi;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import de.greenrobot.dao.AbstractDao;
|
||||
import de.greenrobot.dao.Property;
|
||||
import de.greenrobot.dao.query.QueryBuilder;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractTimeSampleProvider;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.XiaomiManualSample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.XiaomiManualSampleDao;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.XiaomiSleepStageSampleDao;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
|
||||
@ -58,4 +65,42 @@ public class XiaomiManualSampleProvider extends AbstractTimeSampleProvider<Xiaom
|
||||
public XiaomiManualSample createSample() {
|
||||
return new XiaomiManualSample();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public XiaomiManualSample getLatestSample(final int type) {
|
||||
final QueryBuilder<XiaomiManualSample> qb = getSampleDao().queryBuilder();
|
||||
final Device dbDevice = DBHelper.findDevice(getDevice(), getSession());
|
||||
if (dbDevice == null) {
|
||||
// no device, no sample
|
||||
return null;
|
||||
}
|
||||
final Property deviceProperty = getDeviceIdentifierSampleProperty();
|
||||
qb.where(deviceProperty.eq(dbDevice.getId()))
|
||||
.where(XiaomiManualSampleDao.Properties.Type.eq(type))
|
||||
.orderDesc(getTimestampSampleProperty()).limit(1);
|
||||
final List<XiaomiManualSample> samples = qb.build().list();
|
||||
if (samples.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return samples.get(0);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public XiaomiManualSample getFirstSample(final int type) {
|
||||
final QueryBuilder<XiaomiManualSample> qb = getSampleDao().queryBuilder();
|
||||
final Device dbDevice = DBHelper.findDevice(getDevice(), getSession());
|
||||
if (dbDevice == null) {
|
||||
// no device, no sample
|
||||
return null;
|
||||
}
|
||||
final Property deviceProperty = getDeviceIdentifierSampleProperty();
|
||||
qb.where(deviceProperty.eq(dbDevice.getId()))
|
||||
.where(XiaomiManualSampleDao.Properties.Type.eq(type))
|
||||
.orderAsc(getTimestampSampleProperty()).limit(1);
|
||||
final List<XiaomiManualSample> samples = qb.build().list();
|
||||
if (samples.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return samples.get(0);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,116 @@
|
||||
/* 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.XiaomiManualSample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.TemperatureSample;
|
||||
|
||||
public class XiaomiTemperatureSampleProvider implements TimeSampleProvider<TemperatureSample> {
|
||||
private final XiaomiManualSampleProvider manualSampleProvider;
|
||||
|
||||
public XiaomiTemperatureSampleProvider(final GBDevice device, final DaoSession session) {
|
||||
manualSampleProvider = new XiaomiManualSampleProvider(device, session);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public List<TemperatureSample> getAllSamples(final long timestampFrom, final long timestampTo) {
|
||||
final List<XiaomiManualSample> manualSamples = manualSampleProvider.getAllSamples(timestampFrom, timestampTo);
|
||||
|
||||
final List<TemperatureSample> temperatureSamples = new ArrayList<>();
|
||||
|
||||
for (final XiaomiManualSample manualSample : manualSamples) {
|
||||
if (XiaomiManualSampleProvider.TYPE_TEMPERATURE == manualSample.getType()) {
|
||||
temperatureSamples.add(new XiaomiTemperatureSample(manualSample));
|
||||
}
|
||||
}
|
||||
|
||||
return temperatureSamples;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSample(final TemperatureSample timeSample) {
|
||||
throw new UnsupportedOperationException("read-only sample provider");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSamples(final List<TemperatureSample> timeSamples) {
|
||||
throw new UnsupportedOperationException("read-only sample provider");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemperatureSample createSample() {
|
||||
throw new UnsupportedOperationException("read-only sample provider");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public TemperatureSample getLatestSample() {
|
||||
final XiaomiManualSample sample = manualSampleProvider.getLatestSample(XiaomiManualSampleProvider.TYPE_TEMPERATURE);
|
||||
if (sample != null) {
|
||||
return new XiaomiTemperatureSample(sample);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public TemperatureSample getFirstSample() {
|
||||
final XiaomiManualSample sample = manualSampleProvider.getFirstSample(XiaomiManualSampleProvider.TYPE_TEMPERATURE);
|
||||
if (sample != null) {
|
||||
return new XiaomiTemperatureSample(sample);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected static class XiaomiTemperatureSample implements TemperatureSample {
|
||||
private final long timestamp;
|
||||
private final float temperature;
|
||||
|
||||
public XiaomiTemperatureSample(final XiaomiManualSample sample) {
|
||||
this.timestamp = sample.getTimestamp();
|
||||
// first 2 bytes are body temperature
|
||||
// last 2 bytes are skin temperature
|
||||
// since the body temperature seems to always be 0, we only display skin temperature
|
||||
this.temperature = (sample.getValue() & 0xffff);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getTemperature() {
|
||||
return temperature;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTemperatureType() {
|
||||
return 0; // ?
|
||||
}
|
||||
}
|
||||
}
|
@ -58,4 +58,9 @@ public class XiaomiWatchS1ProCoordinator extends XiaomiCoordinator {
|
||||
public boolean supportsFindDevice() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsTemperatureMeasurement() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -67,6 +67,9 @@ public class ManualSamplesParser extends XiaomiActivityParser {
|
||||
final int type = buf.get() & 0xff;
|
||||
|
||||
final int value;
|
||||
// FIXME: This is incomplete - the type is actually composed of 2 nibbles that
|
||||
// define the data length + type
|
||||
// see https://codeberg.org/Freeyourgadget/Gadgetbridge/issues/3517#issuecomment-1516353
|
||||
switch (type) {
|
||||
case XiaomiManualSampleProvider.TYPE_HR:
|
||||
case XiaomiManualSampleProvider.TYPE_SPO2:
|
||||
@ -74,8 +77,10 @@ public class ManualSamplesParser extends XiaomiActivityParser {
|
||||
value = buf.get() & 0xff;
|
||||
break;
|
||||
case XiaomiManualSampleProvider.TYPE_TEMPERATURE:
|
||||
// FIXME: This is actually 2 2-byte values, see the comment linked above
|
||||
value = buf.getInt();
|
||||
break;
|
||||
// TODO blood pressure, see the comment linked above
|
||||
default:
|
||||
LOG.warn("Unknown sample type {}", type);
|
||||
// We need to abort parsing, as we don't know the sample size
|
||||
|
Loading…
Reference in New Issue
Block a user