mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-01-13 11:17:33 +01:00
Unify SleepMonitor with code from PR #59. Thanks Daniele!
This commit is contained in:
parent
2f1908e480
commit
813a02d5c7
@ -4,7 +4,9 @@ public class GBActivitySample {
|
|||||||
public static final byte PROVIDER_MIBAND = 0;
|
public static final byte PROVIDER_MIBAND = 0;
|
||||||
public static final byte PROVIDER_PEBBLE_MORPHEUZ = 1;
|
public static final byte PROVIDER_PEBBLE_MORPHEUZ = 1;
|
||||||
|
|
||||||
public static final byte TYPE_SLEEP = 0; //FIXME: we could just adapt to Mi Band (Dont know the correct values)
|
public static final byte TYPE_DEEP_SLEEP = 5;
|
||||||
|
public static final byte TYPE_LIGHT_SLEEP = 4;
|
||||||
|
public static final byte TYPE_UNKNOWN = -1;
|
||||||
// add more here
|
// add more here
|
||||||
|
|
||||||
private final int timestamp;
|
private final int timestamp;
|
||||||
|
@ -96,9 +96,27 @@ public class SleepMonitorActivity extends Activity implements SurfaceHolder.Call
|
|||||||
int height = canvas.getHeight();
|
int height = canvas.getHeight();
|
||||||
|
|
||||||
RectF r = new RectF(0.0f, 0.0f, 0.0f, height);
|
RectF r = new RectF(0.0f, 0.0f, 0.0f, height);
|
||||||
short last_movement = 5000;
|
float movement_divisor;
|
||||||
|
boolean annotate;
|
||||||
|
boolean use_steps_as_movement;
|
||||||
|
switch (provider) {
|
||||||
|
case GBActivitySample.PROVIDER_MIBAND:
|
||||||
|
movement_divisor = 256.0f;
|
||||||
|
annotate = false; // sample density to high?
|
||||||
|
use_steps_as_movement = true;
|
||||||
|
break;
|
||||||
|
default: // Morpheuz
|
||||||
|
movement_divisor = 5000.0f;
|
||||||
|
annotate = true;
|
||||||
|
use_steps_as_movement = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
byte last_type = GBActivitySample.TYPE_UNKNOWN;
|
||||||
|
|
||||||
for (int i = 0; i < samples.size(); i++) {
|
for (int i = 0; i < samples.size(); i++) {
|
||||||
GBActivitySample sample = samples.get(i);
|
GBActivitySample sample = samples.get(i);
|
||||||
|
byte type = sample.getType();
|
||||||
|
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
cal.setTimeInMillis((long) sample.getTimestamp() * 1000L);
|
cal.setTimeInMillis((long) sample.getTimestamp() * 1000L);
|
||||||
@ -109,30 +127,42 @@ public class SleepMonitorActivity extends Activity implements SurfaceHolder.Call
|
|||||||
date = cal.getTime();
|
date = cal.getTime();
|
||||||
dateStringTo = new SimpleDateFormat("dd.MM.yyyy HH:mm").format(date);
|
dateStringTo = new SimpleDateFormat("dd.MM.yyyy HH:mm").format(date);
|
||||||
}
|
}
|
||||||
boolean annotate = false;
|
|
||||||
short movement = sample.getIntensity();
|
short movement = sample.getIntensity();
|
||||||
r.left = r.right;
|
r.left = r.right;
|
||||||
r.right = (float) (i + 1) / (samples.size()) * width;
|
r.right = (float) (i + 1) / (samples.size()) * width;
|
||||||
r.top = (1.0f - (float) movement / 5000.0f) * height;
|
if (type == GBActivitySample.TYPE_DEEP_SLEEP) {
|
||||||
if (movement > 1000) {
|
paint.setColor(Color.BLUE);
|
||||||
paint.setColor(Color.RED);
|
r.top = 0.98f * height;
|
||||||
if (last_movement <= 1000) {
|
|
||||||
annotate = true;
|
|
||||||
}
|
|
||||||
} else if (movement > 120) {
|
|
||||||
paint.setColor(Color.YELLOW);
|
|
||||||
} else {
|
} else {
|
||||||
paint.setColor(Color.GREEN);
|
if (type == GBActivitySample.TYPE_LIGHT_SLEEP) {
|
||||||
|
paint.setColor(Color.CYAN);
|
||||||
|
} else {
|
||||||
|
if (use_steps_as_movement) {
|
||||||
|
movement = sample.getSteps();
|
||||||
|
}
|
||||||
|
paint.setColor(Color.YELLOW);
|
||||||
|
}
|
||||||
|
r.top = (1.0f - (float) movement / movement_divisor) * height;
|
||||||
}
|
}
|
||||||
|
|
||||||
canvas.drawRect(r, paint);
|
canvas.drawRect(r, paint);
|
||||||
|
boolean annotate_this = false;
|
||||||
if (annotate) {
|
if (annotate) {
|
||||||
cal.setTimeInMillis((long) (sample.getTimestamp()) * 1000L);
|
if (type != GBActivitySample.TYPE_DEEP_SLEEP && type != GBActivitySample.TYPE_LIGHT_SLEEP &&
|
||||||
date = cal.getTime();
|
(last_type == GBActivitySample.TYPE_DEEP_SLEEP || last_type == GBActivitySample.TYPE_LIGHT_SLEEP)) {
|
||||||
String dateString = new SimpleDateFormat("HH:mm").format(date);
|
// seems that we woke up
|
||||||
paint.setColor(Color.WHITE);
|
annotate_this = true;
|
||||||
canvas.drawText(dateString, r.left - 20, r.top - 20, paint);
|
}
|
||||||
|
if (annotate_this) {
|
||||||
|
cal.setTimeInMillis((long) (sample.getTimestamp()) * 1000L);
|
||||||
|
date = cal.getTime();
|
||||||
|
String dateString = new SimpleDateFormat("HH:mm").format(date);
|
||||||
|
paint.setColor(Color.WHITE);
|
||||||
|
canvas.drawText(dateString, r.left - 20, r.top - 20, paint);
|
||||||
|
}
|
||||||
|
last_type = type;
|
||||||
}
|
}
|
||||||
last_movement = movement;
|
|
||||||
}
|
}
|
||||||
textView.setText(dateStringFrom + " to " + dateStringTo);
|
textView.setText(dateStringFrom + " to " + dateStringTo);
|
||||||
|
|
||||||
|
@ -98,10 +98,16 @@ public class MorpheuzSupport {
|
|||||||
ctrl_message = MorpheuzSupport.CTRL_VERSION_DONE | MorpheuzSupport.CTRL_GONEOFF_DONE | MorpheuzSupport.CTRL_TRANSMIT_DONE | MorpheuzSupport.CTRL_SET_LAST_SENT;
|
ctrl_message = MorpheuzSupport.CTRL_VERSION_DONE | MorpheuzSupport.CTRL_GONEOFF_DONE | MorpheuzSupport.CTRL_TRANSMIT_DONE | MorpheuzSupport.CTRL_SET_LAST_SENT;
|
||||||
} else {
|
} else {
|
||||||
short index = (short) ((int) pair.second >> 16);
|
short index = (short) ((int) pair.second >> 16);
|
||||||
short data = (short) ((int) pair.second & 0xffff);
|
short intensity = (short) ((int) pair.second & 0xffff);
|
||||||
LOG.info("got point:" + index + " " + data);
|
LOG.info("got point:" + index + " " + intensity);
|
||||||
|
byte type = GBActivitySample.TYPE_UNKNOWN;
|
||||||
|
if (intensity <= 120) {
|
||||||
|
type = GBActivitySample.TYPE_DEEP_SLEEP;
|
||||||
|
} else if (intensity <= 1000) {
|
||||||
|
type = GBActivitySample.TYPE_LIGHT_SLEEP;
|
||||||
|
}
|
||||||
if (index >= 0 && index < 54) {
|
if (index >= 0 && index < 54) {
|
||||||
GBApplication.getActivityDatabaseHandler().addGBActivitySample(recording_base_timestamp + index * 600, GBActivitySample.PROVIDER_PEBBLE_MORPHEUZ, data, (byte) 0, GBActivitySample.TYPE_SLEEP);
|
GBApplication.getActivityDatabaseHandler().addGBActivitySample(recording_base_timestamp + index * 600, GBActivitySample.PROVIDER_PEBBLE_MORPHEUZ, intensity, (byte) 0, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
ctrl_message = MorpheuzSupport.CTRL_VERSION_DONE | MorpheuzSupport.CTRL_SET_LAST_SENT | MorpheuzSupport.CTRL_DO_NEXT;
|
ctrl_message = MorpheuzSupport.CTRL_VERSION_DONE | MorpheuzSupport.CTRL_SET_LAST_SENT | MorpheuzSupport.CTRL_DO_NEXT;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user