mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-01-25 00:57:33 +01:00
HPlus: Improve intensity calculation based on Tanaka et al, 2001
This commit is contained in:
parent
166695f00a
commit
69d215cb99
@ -198,7 +198,6 @@ public class HPlusCoordinator extends AbstractDeviceCoordinator {
|
||||
}else{
|
||||
return HPlusConstants.ARG_TIMEMODE_12H;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static byte getUnit(String address) {
|
||||
@ -211,25 +210,25 @@ public class HPlusCoordinator extends AbstractDeviceCoordinator {
|
||||
}
|
||||
}
|
||||
|
||||
public static byte getUserWeight(String address) {
|
||||
public static byte getUserWeight() {
|
||||
ActivityUser activityUser = new ActivityUser();
|
||||
|
||||
return (byte) (activityUser.getWeightKg() & 0xFF);
|
||||
}
|
||||
|
||||
public static byte getUserHeight(String address) {
|
||||
public static byte getUserHeight() {
|
||||
ActivityUser activityUser = new ActivityUser();
|
||||
|
||||
return (byte) (activityUser.getHeightCm() & 0xFF);
|
||||
}
|
||||
|
||||
public static byte getUserAge(String address) {
|
||||
public static byte getUserAge() {
|
||||
ActivityUser activityUser = new ActivityUser();
|
||||
|
||||
return (byte) (activityUser.getAge() & 0xFF);
|
||||
}
|
||||
|
||||
public static byte getUserGender(String address) {
|
||||
public static byte getUserGender() {
|
||||
ActivityUser activityUser = new ActivityUser();
|
||||
|
||||
if (activityUser.getGender() == ActivityUser.GENDER_MALE)
|
||||
@ -238,7 +237,7 @@ public class HPlusCoordinator extends AbstractDeviceCoordinator {
|
||||
return HPlusConstants.ARG_GENDER_FEMALE;
|
||||
}
|
||||
|
||||
public static int getGoal(String address) {
|
||||
public static int getGoal() {
|
||||
ActivityUser activityUser = new ActivityUser();
|
||||
|
||||
return activityUser.getStepsGoal();
|
||||
|
@ -51,7 +51,13 @@ public class HPlusDataRecordDaySlot extends HPlusDataRecord {
|
||||
*/
|
||||
public int heartRate;
|
||||
|
||||
public HPlusDataRecordDaySlot(byte[] data) {
|
||||
private int age = 0;
|
||||
/**
|
||||
* Raw intensity calculated from calories
|
||||
*/
|
||||
public int intensity;
|
||||
|
||||
public HPlusDataRecordDaySlot(byte[] data, int age) {
|
||||
super(data, TYPE_DAY_SLOT);
|
||||
|
||||
int a = (data[4] & 0xFF) * 256 + (data[5] & 0xFF);
|
||||
@ -77,6 +83,8 @@ public class HPlusDataRecordDaySlot extends HPlusDataRecord {
|
||||
slotTime.set(Calendar.SECOND, 0);
|
||||
|
||||
timestamp = (int) (slotTime.getTimeInMillis() / 1000L);
|
||||
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
@ -101,6 +109,9 @@ public class HPlusDataRecordDaySlot extends HPlusDataRecord {
|
||||
}
|
||||
|
||||
secondsInactive += other.secondsInactive;
|
||||
|
||||
intensity = (int) ((100*heartRate)/(208-0.7*age));
|
||||
|
||||
}
|
||||
|
||||
public boolean isValid(){
|
||||
|
@ -66,7 +66,7 @@ class HPlusDataRecordRealtime extends HPlusDataRecord {
|
||||
*/
|
||||
public int intensity;
|
||||
|
||||
public HPlusDataRecordRealtime(byte[] data) {
|
||||
public HPlusDataRecordRealtime(byte[] data, int age) {
|
||||
super(data, TYPE_REALTIME);
|
||||
|
||||
if (data.length < 15) {
|
||||
@ -91,7 +91,7 @@ class HPlusDataRecordRealtime extends HPlusDataRecord {
|
||||
heartRate = ActivitySample.NOT_MEASURED;
|
||||
}
|
||||
else {
|
||||
intensity = (int) (100 * Math.max(0, Math.min((heartRate - 60) / 120.0, 1))); // TODO: Calculate a proper value
|
||||
intensity = (int) ((100*heartRate)/(208-0.7*age));
|
||||
activityKind = ActivityKind.TYPE_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
@ -220,12 +220,12 @@ class HPlusHandlerThread extends GBDeviceIoThread {
|
||||
* @param data the message from the device
|
||||
* @return boolean indicating success or fail
|
||||
*/
|
||||
public boolean processIncomingDaySlotData(byte[] data) {
|
||||
public boolean processIncomingDaySlotData(byte[] data, int age) {
|
||||
|
||||
HPlusDataRecordDaySlot record;
|
||||
|
||||
try{
|
||||
record = new HPlusDataRecordDaySlot(data);
|
||||
record = new HPlusDataRecordDaySlot(data, age);
|
||||
} catch(IllegalArgumentException e){
|
||||
LOG.info((e.getMessage()));
|
||||
return false;
|
||||
@ -302,7 +302,7 @@ class HPlusHandlerThread extends GBDeviceIoThread {
|
||||
sample.setSteps(storedRecord.steps);
|
||||
sample.setHeartRate(storedRecord.heartRate);
|
||||
sample.setRawKind(storedRecord.type);
|
||||
|
||||
sample.setRawIntensity(record.intensity);
|
||||
sample.setProvider(provider);
|
||||
samples.add(sample);
|
||||
}
|
||||
@ -383,11 +383,11 @@ class HPlusHandlerThread extends GBDeviceIoThread {
|
||||
* @param data the message from the device
|
||||
* @return boolean indicating success or fail
|
||||
*/
|
||||
public boolean processRealtimeStats(byte[] data) {
|
||||
public boolean processRealtimeStats(byte[] data, int age) {
|
||||
HPlusDataRecordRealtime record;
|
||||
|
||||
try{
|
||||
record = new HPlusDataRecordRealtime(data);
|
||||
record = new HPlusDataRecordRealtime(data, age);
|
||||
} catch(IllegalArgumentException e){
|
||||
LOG.info((e.getMessage()));
|
||||
return false;
|
||||
|
@ -292,7 +292,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
|
||||
private HPlusSupport setWeight(TransactionBuilder transaction) {
|
||||
byte value = HPlusCoordinator.getUserWeight(getDevice().getAddress());
|
||||
byte value = HPlusCoordinator.getUserWeight();
|
||||
transaction.write(ctrlCharacteristic, new byte[]{
|
||||
HPlusConstants.CMD_SET_WEIGHT,
|
||||
value
|
||||
@ -302,7 +302,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
|
||||
private HPlusSupport setHeight(TransactionBuilder transaction) {
|
||||
byte value = HPlusCoordinator.getUserHeight(getDevice().getAddress());
|
||||
byte value = HPlusCoordinator.getUserHeight();
|
||||
transaction.write(ctrlCharacteristic, new byte[]{
|
||||
HPlusConstants.CMD_HEIGHT,
|
||||
value
|
||||
@ -313,7 +313,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
|
||||
|
||||
|
||||
private HPlusSupport setAge(TransactionBuilder transaction) {
|
||||
byte value = HPlusCoordinator.getUserAge(getDevice().getAddress());
|
||||
byte value = HPlusCoordinator.getUserAge();
|
||||
transaction.write(ctrlCharacteristic, new byte[]{
|
||||
HPlusConstants.CMD_SET_AGE,
|
||||
value
|
||||
@ -323,7 +323,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
|
||||
private HPlusSupport setGender(TransactionBuilder transaction) {
|
||||
byte value = HPlusCoordinator.getUserGender(getDevice().getAddress());
|
||||
byte value = HPlusCoordinator.getUserGender();
|
||||
transaction.write(ctrlCharacteristic, new byte[]{
|
||||
HPlusConstants.CMD_SET_GENDER,
|
||||
value
|
||||
@ -334,7 +334,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
|
||||
|
||||
|
||||
private HPlusSupport setGoal(TransactionBuilder transaction) {
|
||||
int value = HPlusCoordinator.getGoal(getDevice().getAddress());
|
||||
int value = HPlusCoordinator.getGoal();
|
||||
transaction.write(ctrlCharacteristic, new byte[]{
|
||||
HPlusConstants.CMD_SET_GOAL,
|
||||
(byte) ((value / 256) & 0xff),
|
||||
@ -842,7 +842,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
|
||||
return syncHelper.processVersion(data);
|
||||
|
||||
case HPlusConstants.DATA_STATS:
|
||||
boolean result = syncHelper.processRealtimeStats(data);
|
||||
boolean result = syncHelper.processRealtimeStats(data, HPlusCoordinator.getUserAge());
|
||||
if (result) {
|
||||
processExtraInfo (data);
|
||||
}
|
||||
@ -856,7 +856,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
|
||||
|
||||
case HPlusConstants.DATA_DAY_SUMMARY:
|
||||
case HPlusConstants.DATA_DAY_SUMMARY_ALT:
|
||||
return syncHelper.processIncomingDaySlotData(data);
|
||||
return syncHelper.processIncomingDaySlotData(data, HPlusCoordinator.getUserAge());
|
||||
case HPlusConstants.DATA_UNKNOWN:
|
||||
return true;
|
||||
default:
|
||||
@ -868,7 +868,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
|
||||
|
||||
private void processExtraInfo (byte[] data) {
|
||||
try {
|
||||
HPlusDataRecordRealtime record = new HPlusDataRecordRealtime(data);
|
||||
HPlusDataRecordRealtime record = new HPlusDataRecordRealtime(data, HPlusCoordinator.getUserAge());
|
||||
|
||||
handleBatteryInfo(record.battery);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user