mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-28 04:46:51 +01:00
Mi2/Bip: Various sleep fixes
- Long standing bug fixed in determinePreviousValidActivityType() it always got the very fist valid sample, not the nearest in the past (for me that was light sleep, so every timespan queried began with light sleep) - Support type 2 (running) and 12 (wakeup(?)) - Support new firmwares (Mi2 and Bip) by masking only the last 4 bits (0xf), takes some ugly query hack in determinePreviousValidActivityType() since greenDAO does not support the & operator (even though sqlite does)
This commit is contained in:
parent
0ffa2ce45a
commit
9f05aff11b
@ -50,13 +50,13 @@ public class MiBand2SampleProvider extends AbstractMiBandSampleProvider {
|
||||
public static final int TYPE_UNSET = -1;
|
||||
public static final int TYPE_NO_CHANGE = 0;
|
||||
public static final int TYPE_ACTIVITY = 1;
|
||||
public static final int TYPE_RUNNING = 2;
|
||||
public static final int TYPE_NONWEAR = 3;
|
||||
public static final int TYPE_CHARGING = 6;
|
||||
public static final int TYPE_LIGHT_SLEEP = 9;
|
||||
public static final int TYPE_IGNORE = 10;
|
||||
public static final int TYPE_DEEP_SLEEP = 11;
|
||||
public static final int TYPE_WAKE_UP = 12;
|
||||
// appears to be a measurement problem resulting in type = 10 and intensity = 20, at least with fw 1.0.0.39
|
||||
public static final int TYPE_IGNORE = 10;
|
||||
|
||||
public MiBand2SampleProvider(GBDevice device, DaoSession session) {
|
||||
super(device, session);
|
||||
@ -81,6 +81,11 @@ public class MiBand2SampleProvider extends AbstractMiBandSampleProvider {
|
||||
int lastValidKind = determinePreviousValidActivityType(samples.get(0));
|
||||
for (MiBandActivitySample sample : samples) {
|
||||
int rawKind = sample.getRawKind();
|
||||
if (rawKind != TYPE_UNSET) {
|
||||
rawKind &= 0xf;
|
||||
sample.setRawKind(rawKind);
|
||||
}
|
||||
|
||||
switch (rawKind) {
|
||||
case TYPE_IGNORE:
|
||||
case TYPE_NO_CHANGE:
|
||||
@ -100,11 +105,12 @@ public class MiBand2SampleProvider extends AbstractMiBandSampleProvider {
|
||||
qb.where(MiBandActivitySampleDao.Properties.DeviceId.eq(sample.getDeviceId()),
|
||||
MiBandActivitySampleDao.Properties.UserId.eq(sample.getUserId()),
|
||||
MiBandActivitySampleDao.Properties.Timestamp.lt(sample.getTimestamp()),
|
||||
MiBandActivitySampleDao.Properties.RawKind.notIn(TYPE_IGNORE, TYPE_NO_CHANGE));
|
||||
MiBandActivitySampleDao.Properties.RawKind.notIn(TYPE_NO_CHANGE, TYPE_IGNORE, TYPE_UNSET, 16, 80, 96, 112)); // all I ever had that are 0 when doing &=0xf
|
||||
qb.orderDesc(MiBandActivitySampleDao.Properties.Timestamp);
|
||||
qb.limit(1);
|
||||
List<MiBandActivitySample> result = qb.build().list();
|
||||
if (result.size() > 0) {
|
||||
return result.get(0).getRawKind();
|
||||
return result.get(0).getRawKind() & 0xf;
|
||||
}
|
||||
return TYPE_UNSET;
|
||||
}
|
||||
@ -117,12 +123,13 @@ public class MiBand2SampleProvider extends AbstractMiBandSampleProvider {
|
||||
case TYPE_LIGHT_SLEEP:
|
||||
return ActivityKind.TYPE_LIGHT_SLEEP;
|
||||
case TYPE_ACTIVITY:
|
||||
case TYPE_RUNNING:
|
||||
case TYPE_WAKE_UP:
|
||||
return ActivityKind.TYPE_ACTIVITY;
|
||||
case TYPE_NONWEAR:
|
||||
return ActivityKind.TYPE_NOT_WORN;
|
||||
case TYPE_CHARGING:
|
||||
return ActivityKind.TYPE_NOT_WORN; //I believe it's a safe assumption
|
||||
case TYPE_IGNORE:
|
||||
default:
|
||||
case TYPE_UNSET: // fall through
|
||||
return ActivityKind.TYPE_UNKNOWN;
|
||||
|
Loading…
Reference in New Issue
Block a user