mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-01 06:22:55 +01:00
Fix current realtime steps calculations #450
timestamp is already in seconds instead of milliseconds Also: port to REALTIME_SAMPLES
This commit is contained in:
parent
999d3e3252
commit
305bd7600c
@ -136,7 +136,7 @@ public class LiveActivityFragment extends AbstractChartFragment {
|
|||||||
throw new IllegalArgumentException("delta in seconds is <= 0 -- time change?");
|
throw new IllegalArgumentException("delta in seconds is <= 0 -- time change?");
|
||||||
}
|
}
|
||||||
|
|
||||||
int oneMinute = 60 * 1000;
|
int oneMinute = 60;
|
||||||
float factor = oneMinute / seconds;
|
float factor = oneMinute / seconds;
|
||||||
int result = (int) (stepsDelta * factor);
|
int result = (int) (stepsDelta * factor);
|
||||||
if (result > MAX_STEPS_PER_MINUTE) {
|
if (result > MAX_STEPS_PER_MINUTE) {
|
||||||
@ -152,24 +152,25 @@ public class LiveActivityFragment extends AbstractChartFragment {
|
|||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
String action = intent.getAction();
|
String action = intent.getAction();
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case DeviceService.ACTION_REALTIME_STEPS: {
|
case DeviceService.ACTION_REALTIME_SAMPLES: {
|
||||||
int steps = intent.getIntExtra(DeviceService.EXTRA_REALTIME_STEPS, 0);
|
ActivitySample sample = (ActivitySample) intent.getSerializableExtra(DeviceService.EXTRA_REALTIME_SAMPLE);
|
||||||
int timestamp = translateTimestampFrom(intent);
|
addSample(sample);
|
||||||
addEntries(steps, timestamp);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case DeviceService.ACTION_HEARTRATE_MEASUREMENT: {
|
|
||||||
int heartRate = intent.getIntExtra(DeviceService.EXTRA_HEART_RATE_VALUE, 0);
|
|
||||||
int timestamp = translateTimestampFrom(intent);
|
|
||||||
if (isValidHeartRateValue(heartRate)) {
|
|
||||||
setCurrentHeartRate(heartRate, timestamp);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private void addSample(ActivitySample sample) {
|
||||||
|
int heartRate = sample.getHeartRate();
|
||||||
|
int timestamp = tsTranslation.shorten(sample.getTimestamp());
|
||||||
|
if (isValidHeartRateValue(heartRate)) {
|
||||||
|
setCurrentHeartRate(heartRate, timestamp);
|
||||||
|
}
|
||||||
|
int steps = sample.getSteps();
|
||||||
|
addEntries(steps, timestamp);
|
||||||
|
}
|
||||||
|
|
||||||
private int translateTimestampFrom(Intent intent) {
|
private int translateTimestampFrom(Intent intent) {
|
||||||
return translateTimestamp(intent.getLongExtra(DeviceService.EXTRA_TIMESTAMP, System.currentTimeMillis()));
|
return translateTimestamp(intent.getLongExtra(DeviceService.EXTRA_TIMESTAMP, System.currentTimeMillis()));
|
||||||
}
|
}
|
||||||
@ -251,8 +252,7 @@ public class LiveActivityFragment extends AbstractChartFragment {
|
|||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
IntentFilter filterLocal = new IntentFilter();
|
IntentFilter filterLocal = new IntentFilter();
|
||||||
filterLocal.addAction(DeviceService.ACTION_REALTIME_STEPS);
|
filterLocal.addAction(DeviceService.ACTION_REALTIME_SAMPLES);
|
||||||
filterLocal.addAction(DeviceService.ACTION_HEARTRATE_MEASUREMENT);
|
|
||||||
heartRateValues = new ArrayList<>();
|
heartRateValues = new ArrayList<>();
|
||||||
tsTranslation = new TimestampTranslation();
|
tsTranslation = new TimestampTranslation();
|
||||||
|
|
||||||
|
@ -38,11 +38,6 @@ public interface DeviceService extends EventHandler {
|
|||||||
String ACTION_SET_ALARMS = PREFIX + ".action.set_alarms";
|
String ACTION_SET_ALARMS = PREFIX + ".action.set_alarms";
|
||||||
String ACTION_ENABLE_REALTIME_STEPS = PREFIX + ".action.enable_realtime_steps";
|
String ACTION_ENABLE_REALTIME_STEPS = PREFIX + ".action.enable_realtime_steps";
|
||||||
String ACTION_REALTIME_SAMPLES = PREFIX + ".action.realtime_samples";
|
String ACTION_REALTIME_SAMPLES = PREFIX + ".action.realtime_samples";
|
||||||
/**
|
|
||||||
* Use EXTRA_REALTIME_SAMPLE instead
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
String ACTION_REALTIME_STEPS = PREFIX + ".action.realtime_steps";
|
|
||||||
String ACTION_ENABLE_REALTIME_HEARTRATE_MEASUREMENT = PREFIX + ".action.realtime_hr_measurement";
|
String ACTION_ENABLE_REALTIME_HEARTRATE_MEASUREMENT = PREFIX + ".action.realtime_hr_measurement";
|
||||||
String ACTION_ENABLE_HEARTRATE_SLEEP_SUPPORT = PREFIX + ".action.enable_heartrate_sleep_support";
|
String ACTION_ENABLE_HEARTRATE_SLEEP_SUPPORT = PREFIX + ".action.enable_heartrate_sleep_support";
|
||||||
String ACTION_HEARTRATE_MEASUREMENT = PREFIX + ".action.hr_measurement";
|
String ACTION_HEARTRATE_MEASUREMENT = PREFIX + ".action.hr_measurement";
|
||||||
|
@ -954,23 +954,9 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
|||||||
sample.setRawIntensity(ActivitySample.NOT_MEASURED);
|
sample.setRawIntensity(ActivitySample.NOT_MEASURED);
|
||||||
sample.setRawKind(MiBandSampleProvider.TYPE_ACTIVITY); // to make it visible in the charts TODO: add a MANUAL kind for that?
|
sample.setRawKind(MiBandSampleProvider.TYPE_ACTIVITY); // to make it visible in the charts TODO: add a MANUAL kind for that?
|
||||||
|
|
||||||
// TODO: remove this once fully ported to REALTIME_SAMPLES
|
Intent intent = new Intent(DeviceService.ACTION_REALTIME_SAMPLES)
|
||||||
if (sample.getSteps() != ActivitySample.NOT_MEASURED) {
|
.putExtra(DeviceService.EXTRA_REALTIME_SAMPLE, sample);
|
||||||
Intent intent = new Intent(DeviceService.ACTION_REALTIME_STEPS)
|
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent);
|
||||||
.putExtra(DeviceService.EXTRA_REALTIME_STEPS, sample.getSteps())
|
|
||||||
.putExtra(DeviceService.EXTRA_TIMESTAMP, System.currentTimeMillis());
|
|
||||||
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent);
|
|
||||||
}
|
|
||||||
if (sample.getHeartRate() != ActivitySample.NOT_MEASURED) {
|
|
||||||
Intent intent = new Intent(DeviceService.ACTION_HEARTRATE_MEASUREMENT)
|
|
||||||
.putExtra(DeviceService.EXTRA_HEART_RATE_VALUE, sample.getHeartRate())
|
|
||||||
.putExtra(DeviceService.EXTRA_TIMESTAMP, System.currentTimeMillis());
|
|
||||||
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Intent intent = new Intent(DeviceService.ACTION_REALTIME_SAMPLES)
|
|
||||||
// .putExtra(DeviceService.EXTRA_REALTIME_SAMPLE, sample);
|
|
||||||
// LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent);
|
|
||||||
|
|
||||||
LOG.debug("Storing realtime sample: " + sample);
|
LOG.debug("Storing realtime sample: " + sample);
|
||||||
provider.addGBActivitySample(sample);
|
provider.addGBActivitySample(sample);
|
||||||
|
@ -70,7 +70,6 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.deviceinfo.Dev
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.heartrate.HeartRateProfile;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.heartrate.HeartRateProfile;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.CheckAuthenticationNeededAction;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.CheckAuthenticationNeededAction;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.DeviceInfo;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.DeviceInfo;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.MiBandSupport;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.NotificationStrategy;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.NotificationStrategy;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.RealtimeSamplesSupport;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.RealtimeSamplesSupport;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.operations.FetchActivityOperation;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.operations.FetchActivityOperation;
|
||||||
@ -983,23 +982,9 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
|||||||
sample.setRawIntensity(ActivitySample.NOT_MEASURED);
|
sample.setRawIntensity(ActivitySample.NOT_MEASURED);
|
||||||
sample.setRawKind(MiBand2SampleProvider.TYPE_ACTIVITY); // to make it visible in the charts TODO: add a MANUAL kind for that?
|
sample.setRawKind(MiBand2SampleProvider.TYPE_ACTIVITY); // to make it visible in the charts TODO: add a MANUAL kind for that?
|
||||||
|
|
||||||
// TODO: remove this once fully ported to REALTIME_SAMPLES
|
Intent intent = new Intent(DeviceService.ACTION_REALTIME_SAMPLES)
|
||||||
if (sample.getSteps() != ActivitySample.NOT_MEASURED) {
|
.putExtra(DeviceService.EXTRA_REALTIME_SAMPLE, sample);
|
||||||
Intent intent = new Intent(DeviceService.ACTION_REALTIME_STEPS)
|
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent);
|
||||||
.putExtra(DeviceService.EXTRA_REALTIME_STEPS, sample.getSteps())
|
|
||||||
.putExtra(DeviceService.EXTRA_TIMESTAMP, System.currentTimeMillis());
|
|
||||||
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent);
|
|
||||||
}
|
|
||||||
if (sample.getHeartRate() != ActivitySample.NOT_MEASURED) {
|
|
||||||
Intent intent = new Intent(DeviceService.ACTION_HEARTRATE_MEASUREMENT)
|
|
||||||
.putExtra(DeviceService.EXTRA_HEART_RATE_VALUE, sample.getHeartRate())
|
|
||||||
.putExtra(DeviceService.EXTRA_TIMESTAMP, System.currentTimeMillis());
|
|
||||||
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Intent intent = new Intent(DeviceService.ACTION_REALTIME_SAMPLES)
|
|
||||||
// .putExtra(DeviceService.EXTRA_REALTIME_SAMPLE, sample);
|
|
||||||
// LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent);
|
|
||||||
|
|
||||||
LOG.debug("Storing realtime sample: " + sample);
|
LOG.debug("Storing realtime sample: " + sample);
|
||||||
provider.addGBActivitySample(sample);
|
provider.addGBActivitySample(sample);
|
||||||
|
Loading…
Reference in New Issue
Block a user