mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-02-10 00:46:47 +01:00
Bip: fix activity track kind constants
This commit is contained in:
parent
7b3556756a
commit
923d7ae09d
@ -3,10 +3,16 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.amazfitbip;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
||||||
|
|
||||||
public enum BipActivityType {
|
public enum BipActivityType {
|
||||||
Outdoor,
|
Outdoor(1),
|
||||||
Treadmill,
|
Treadmill(2),
|
||||||
Cycling,
|
Cycling(3),
|
||||||
Walking;
|
Walking(4);
|
||||||
|
|
||||||
|
private final int code;
|
||||||
|
|
||||||
|
BipActivityType(final int code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
public int toActivityKind() {
|
public int toActivityKind() {
|
||||||
switch (this) {
|
switch (this) {
|
||||||
@ -22,8 +28,17 @@ public enum BipActivityType {
|
|||||||
throw new RuntimeException("Not mapped activity kind for: " + this);
|
throw new RuntimeException("Not mapped activity kind for: " + this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BipActivityType fromActivityKind(int kind) {
|
public static BipActivityType fromCode(int bipCode) {
|
||||||
switch (kind) {
|
for (BipActivityType type : values()) {
|
||||||
|
if (type.code == bipCode) {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new RuntimeException("No matching BipActivityType for code: " + bipCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BipActivityType fromActivityKind(int activityKind) {
|
||||||
|
switch (activityKind) {
|
||||||
case ActivityKind.TYPE_RUNNING:
|
case ActivityKind.TYPE_RUNNING:
|
||||||
return Outdoor;
|
return Outdoor;
|
||||||
case ActivityKind.TYPE_TREADMILL:
|
case ActivityKind.TYPE_TREADMILL:
|
||||||
@ -33,6 +48,6 @@ public enum BipActivityType {
|
|||||||
case ActivityKind.TYPE_WALKING:
|
case ActivityKind.TYPE_WALKING:
|
||||||
return Walking;
|
return Walking;
|
||||||
}
|
}
|
||||||
throw new RuntimeException("No matching activity kind: " + kind);
|
throw new RuntimeException("No matching activity activityKind: " + activityKind);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -179,7 +179,7 @@ public class FetchSportsSummaryOperation extends AbstractFetchOperation {
|
|||||||
int activityKind = ActivityKind.TYPE_UNKNOWN;
|
int activityKind = ActivityKind.TYPE_UNKNOWN;
|
||||||
try {
|
try {
|
||||||
int rawKind = BLETypeConversions.toUnsigned(buffer.getShort());
|
int rawKind = BLETypeConversions.toUnsigned(buffer.getShort());
|
||||||
BipActivityType activityType = BipActivityType.values()[rawKind];
|
BipActivityType activityType = BipActivityType.fromCode(rawKind);
|
||||||
activityKind = activityType.toActivityKind();
|
activityKind = activityType.toActivityKind();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
LOG.error("Error mapping acivity kind: " + ex.getMessage(), ex);
|
LOG.error("Error mapping acivity kind: " + ex.getMessage(), ex);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user