1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-09 11:47:04 +01:00

Mi Band 8: Overlay sleep on activity data

This commit is contained in:
José Rebelo 2023-12-02 10:56:36 +00:00
parent 84692e5432
commit 216dc93986
2 changed files with 36 additions and 3 deletions

View File

@ -287,7 +287,8 @@ public abstract class XiaomiCoordinator extends AbstractBLEDeviceCoordinator {
@Override @Override
public boolean supportsRemSleep() { public boolean supportsRemSleep() {
return true; // TODO it does, but we don't know how to parse it yet
return false;
} }
@Override @Override

View File

@ -19,15 +19,24 @@ package nodomain.freeyourgadget.gadgetbridge.devices.xiaomi;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import de.greenrobot.dao.AbstractDao; import de.greenrobot.dao.AbstractDao;
import de.greenrobot.dao.Property; import de.greenrobot.dao.Property;
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractSampleProvider; import nodomain.freeyourgadget.gadgetbridge.devices.AbstractSampleProvider;
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession; import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
import nodomain.freeyourgadget.gadgetbridge.entities.XiaomiActivitySample; import nodomain.freeyourgadget.gadgetbridge.entities.XiaomiActivitySample;
import nodomain.freeyourgadget.gadgetbridge.entities.XiaomiActivitySampleDao; import nodomain.freeyourgadget.gadgetbridge.entities.XiaomiActivitySampleDao;
import nodomain.freeyourgadget.gadgetbridge.entities.XiaomiSleepTimeSample;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
public class XiaomiSampleProvider extends AbstractSampleProvider<XiaomiActivitySample> { public class XiaomiSampleProvider extends AbstractSampleProvider<XiaomiActivitySample> {
private static final Logger LOG = LoggerFactory.getLogger(XiaomiSampleProvider.class);
public XiaomiSampleProvider(final GBDevice device, final DaoSession session) { public XiaomiSampleProvider(final GBDevice device, final DaoSession session) {
super(device, session); super(device, session);
} }
@ -69,12 +78,35 @@ public class XiaomiSampleProvider extends AbstractSampleProvider<XiaomiActivityS
@Override @Override
public float normalizeIntensity(final int rawIntensity) { public float normalizeIntensity(final int rawIntensity) {
// TODO return rawIntensity / 100f;
return rawIntensity;
} }
@Override @Override
public XiaomiActivitySample createActivitySample() { public XiaomiActivitySample createActivitySample() {
return new XiaomiActivitySample(); return new XiaomiActivitySample();
} }
@Override
protected List<XiaomiActivitySample> getGBActivitySamples(final int timestamp_from, final int timestamp_to, final int activityType) {
final List<XiaomiActivitySample> samples = super.getGBActivitySamples(timestamp_from, timestamp_to, activityType);
// Fetch bed and wakeup times and overlay them on the activity
final XiaomiSleepTimeSampleProvider sleepTimeSampleProvider = new XiaomiSleepTimeSampleProvider(getDevice(), getSession());
final List<XiaomiSleepTimeSample> sleepSamples = sleepTimeSampleProvider.getAllSamples(timestamp_from * 1000L, timestamp_to * 1000L);
if (!sleepSamples.isEmpty()) {
LOG.debug("Found {} sleep samples between {} and {}", sleepSamples.size(), timestamp_from, timestamp_to);
for (final XiaomiActivitySample sample : samples) {
final long ts = sample.getTimestamp() * 1000L;
for (final XiaomiSleepTimeSample sleepSample : sleepSamples) {
if (ts >= sleepSample.getTimestamp() && ts <= sleepSample.getWakeupTime()) {
sample.setRawKind(ActivityKind.TYPE_LIGHT_SLEEP);
sample.setRawIntensity(30);
}
}
}
}
return samples;
}
} }