use of nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandSampleProvider in project Gadgetbridge by Freeyourgadget.
the class SampleProviderTest method testActivityKind.
@Test
public void testActivityKind() {
MiBandSampleProvider sampleProvider = new MiBandSampleProvider(dummyGBDevice, daoSession);
int type = sampleProvider.normalizeType(MiBandSampleProvider.TYPE_ACTIVITY);
assertEquals(ActivityKind.TYPE_ACTIVITY, type);
type = sampleProvider.normalizeType(MiBandSampleProvider.TYPE_DEEP_SLEEP);
assertEquals(ActivityKind.TYPE_DEEP_SLEEP, type);
type = sampleProvider.normalizeType(MiBandSampleProvider.TYPE_LIGHT_SLEEP);
assertEquals(ActivityKind.TYPE_LIGHT_SLEEP, type);
type = sampleProvider.normalizeType(MiBandSampleProvider.TYPE_NONWEAR);
assertEquals(ActivityKind.TYPE_NOT_WORN, type);
}
use of nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandSampleProvider in project Gadgetbridge by Freeyourgadget.
the class FetchActivityOperation method flushActivityDataHolder.
/**
* empty the local buffer for activity data, arrange the values received in groups of three and
* store them in the DB
*/
private void flushActivityDataHolder() {
if (activityStruct == null) {
LOG.debug("nothing to flush, struct is already null");
return;
}
int bpm = getBytesPerMinuteOfActivityData();
LOG.debug("flushing activity data samples: " + activityStruct.activityDataHolderProgress / bpm);
byte category, intensity, steps, heartrate = 0;
try (DBHandler dbHandler = GBApplication.acquireDB()) {
MiBandSampleProvider provider = new MiBandSampleProvider(getDevice(), dbHandler.getDaoSession());
User user = DBHelper.getUser(dbHandler.getDaoSession());
Device device = DBHelper.getDevice(getDevice(), dbHandler.getDaoSession());
int minutes = 0;
try {
int timestampInSeconds = (int) (activityStruct.activityDataTimestampProgress.getTimeInMillis() / 1000);
if ((activityStruct.activityDataHolderProgress % bpm) != 0) {
throw new IllegalStateException("Unexpected data, progress should be multiple of " + bpm + ": " + activityStruct.activityDataHolderProgress);
}
int numSamples = activityStruct.activityDataHolderProgress / bpm;
MiBandActivitySample[] samples = new MiBandActivitySample[numSamples];
for (int i = 0; i < activityStruct.activityDataHolderProgress; i += bpm) {
category = activityStruct.activityDataHolder[i];
intensity = activityStruct.activityDataHolder[i + 1];
steps = activityStruct.activityDataHolder[i + 2];
if (hasExtendedActivityData) {
heartrate = activityStruct.activityDataHolder[i + 3];
// LOG.debug("heartrate received: " + (heartrate & 0xff));
}
MiBandActivitySample sample = getSupport().createActivitySample(device, user, timestampInSeconds, provider);
sample.setRawIntensity(intensity & 0xff);
sample.setSteps(steps & 0xff);
sample.setRawKind(category & 0xff);
sample.setHeartRate(heartrate & 0xff);
samples[minutes] = sample;
if (LOG.isDebugEnabled()) {
LOG.debug("sample: " + samples[minutes]);
}
// next minute
minutes++;
timestampInSeconds += 60;
}
provider.addGBActivitySamples(samples);
} finally {
activityStruct.bufferFlushed(minutes);
}
} catch (Exception ex) {
GB.toast(getContext(), ex.getMessage(), Toast.LENGTH_LONG, GB.ERROR, ex);
}
}
Aggregations