mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-08-16 20:31:00 +02:00
Bip: activity types are different from samples' activity kind
This commit is contained in:
parent
f5318287c4
commit
7b3556756a
@ -42,7 +42,7 @@ public class MiBand2Const {
|
|||||||
case TYPE_CHARGING:
|
case TYPE_CHARGING:
|
||||||
return ActivityKind.TYPE_NOT_WORN; //I believe it's a safe assumption
|
return ActivityKind.TYPE_NOT_WORN; //I believe it's a safe assumption
|
||||||
case TYPE_RIDE_BIKE:
|
case TYPE_RIDE_BIKE:
|
||||||
return ActivityKind.TYPE_BIKING;
|
return ActivityKind.TYPE_CYCLING;
|
||||||
default:
|
default:
|
||||||
case TYPE_UNSET: // fall through
|
case TYPE_UNSET: // fall through
|
||||||
return ActivityKind.TYPE_UNKNOWN;
|
return ActivityKind.TYPE_UNKNOWN;
|
||||||
|
@ -35,10 +35,11 @@ public class ActivityKind {
|
|||||||
public static final int TYPE_RUNNING = 16;
|
public static final int TYPE_RUNNING = 16;
|
||||||
public static final int TYPE_WALKING = 32;
|
public static final int TYPE_WALKING = 32;
|
||||||
public static final int TYPE_SWIMMING = 64;
|
public static final int TYPE_SWIMMING = 64;
|
||||||
|
public static final int TYPE_CYCLING = 128;
|
||||||
|
public static final int TYPE_TREADMILL = 256;
|
||||||
|
|
||||||
public static final int TYPE_SLEEP = TYPE_LIGHT_SLEEP | TYPE_DEEP_SLEEP;
|
public static final int TYPE_SLEEP = TYPE_LIGHT_SLEEP | TYPE_DEEP_SLEEP;
|
||||||
public static final int TYPE_ALL = TYPE_ACTIVITY | TYPE_SLEEP | TYPE_NOT_WORN;
|
public static final int TYPE_ALL = TYPE_ACTIVITY | TYPE_SLEEP | TYPE_NOT_WORN;
|
||||||
public static final int TYPE_BIKING = 128;
|
|
||||||
|
|
||||||
public static int[] mapToDBActivityTypes(int types, SampleProvider provider) {
|
public static int[] mapToDBActivityTypes(int types, SampleProvider provider) {
|
||||||
int[] result = new int[3];
|
int[] result = new int[3];
|
||||||
@ -64,8 +65,8 @@ public class ActivityKind {
|
|||||||
if ((types & ActivityKind.TYPE_SWIMMING) != 0) {
|
if ((types & ActivityKind.TYPE_SWIMMING) != 0) {
|
||||||
result[i++] = provider.toRawActivityKind(TYPE_SWIMMING);
|
result[i++] = provider.toRawActivityKind(TYPE_SWIMMING);
|
||||||
}
|
}
|
||||||
if ((types & ActivityKind.TYPE_BIKING) != 0) {
|
if ((types & ActivityKind.TYPE_CYCLING) != 0) {
|
||||||
result[i++] = provider.toRawActivityKind(TYPE_BIKING);
|
result[i++] = provider.toRawActivityKind(TYPE_CYCLING);
|
||||||
}
|
}
|
||||||
return Arrays.copyOf(result, i);
|
return Arrays.copyOf(result, i);
|
||||||
}
|
}
|
||||||
@ -88,7 +89,7 @@ public class ActivityKind {
|
|||||||
return context.getString(R.string.activity_type_walking);
|
return context.getString(R.string.activity_type_walking);
|
||||||
case TYPE_SWIMMING:
|
case TYPE_SWIMMING:
|
||||||
return context.getString(R.string.activity_type_swimming);
|
return context.getString(R.string.activity_type_swimming);
|
||||||
case TYPE_BIKING:
|
case TYPE_CYCLING:
|
||||||
return context.getString(R.string.activity_type_biking);
|
return context.getString(R.string.activity_type_biking);
|
||||||
case TYPE_UNKNOWN:
|
case TYPE_UNKNOWN:
|
||||||
default:
|
default:
|
||||||
@ -109,7 +110,7 @@ public class ActivityKind {
|
|||||||
return R.drawable.ic_activity_running;
|
return R.drawable.ic_activity_running;
|
||||||
case TYPE_WALKING:
|
case TYPE_WALKING:
|
||||||
return R.drawable.ic_activity_walking;
|
return R.drawable.ic_activity_walking;
|
||||||
case TYPE_BIKING:
|
case TYPE_CYCLING:
|
||||||
return R.drawable.ic_activity_biking;
|
return R.drawable.ic_activity_biking;
|
||||||
case TYPE_SWIMMING: // fall through
|
case TYPE_SWIMMING: // fall through
|
||||||
case TYPE_NOT_WORN: // fall through
|
case TYPE_NOT_WORN: // fall through
|
||||||
|
@ -0,0 +1,38 @@
|
|||||||
|
package nodomain.freeyourgadget.gadgetbridge.service.devices.amazfitbip;
|
||||||
|
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
||||||
|
|
||||||
|
public enum BipActivityType {
|
||||||
|
Outdoor,
|
||||||
|
Treadmill,
|
||||||
|
Cycling,
|
||||||
|
Walking;
|
||||||
|
|
||||||
|
public int toActivityKind() {
|
||||||
|
switch (this) {
|
||||||
|
case Outdoor:
|
||||||
|
return ActivityKind.TYPE_RUNNING;
|
||||||
|
case Treadmill:
|
||||||
|
return ActivityKind.TYPE_TREADMILL;
|
||||||
|
case Cycling:
|
||||||
|
return ActivityKind.TYPE_CYCLING;
|
||||||
|
case Walking:
|
||||||
|
return ActivityKind.TYPE_WALKING;
|
||||||
|
}
|
||||||
|
throw new RuntimeException("Not mapped activity kind for: " + this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BipActivityType fromActivityKind(int kind) {
|
||||||
|
switch (kind) {
|
||||||
|
case ActivityKind.TYPE_RUNNING:
|
||||||
|
return Outdoor;
|
||||||
|
case ActivityKind.TYPE_TREADMILL:
|
||||||
|
return Treadmill;
|
||||||
|
case ActivityKind.TYPE_CYCLING:
|
||||||
|
return Cycling;
|
||||||
|
case ActivityKind.TYPE_WALKING:
|
||||||
|
return Walking;
|
||||||
|
}
|
||||||
|
throw new RuntimeException("No matching activity kind: " + kind);
|
||||||
|
}
|
||||||
|
}
|
@ -47,6 +47,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.WaitAction;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.WaitAction;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.amazfitbip.BipActivityType;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||||
|
|
||||||
@ -175,10 +176,13 @@ public class FetchSportsSummaryOperation extends AbstractFetchOperation {
|
|||||||
ByteBuffer buffer = ByteBuffer.wrap(stream.toByteArray()).order(ByteOrder.LITTLE_ENDIAN);
|
ByteBuffer buffer = ByteBuffer.wrap(stream.toByteArray()).order(ByteOrder.LITTLE_ENDIAN);
|
||||||
// summary.setVersion(BLETypeConversions.toUnsigned(buffer.getShort()));
|
// summary.setVersion(BLETypeConversions.toUnsigned(buffer.getShort()));
|
||||||
buffer.getShort(); // version
|
buffer.getShort(); // version
|
||||||
int rawKind = BLETypeConversions.toUnsigned(buffer.getShort());
|
int activityKind = ActivityKind.TYPE_UNKNOWN;
|
||||||
int activityKind = MiBand2Const.toActivityKind(rawKind);
|
try {
|
||||||
if (activityKind == ActivityKind.TYPE_UNKNOWN) {
|
int rawKind = BLETypeConversions.toUnsigned(buffer.getShort());
|
||||||
activityKind = rawKind; // hack for later activity kind detection
|
BipActivityType activityType = BipActivityType.values()[rawKind];
|
||||||
|
activityKind = activityType.toActivityKind();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
LOG.error("Error mapping acivity kind: " + ex.getMessage(), ex);
|
||||||
}
|
}
|
||||||
summary.setActivityKind(activityKind);
|
summary.setActivityKind(activityKind);
|
||||||
// FIXME: should save timezone etc.
|
// FIXME: should save timezone etc.
|
||||||
|
Loading…
Reference in New Issue
Block a user