diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBActivitySample.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBActivitySample.java index 2bc341ef..18b8b9d4 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBActivitySample.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBActivitySample.java @@ -3,6 +3,7 @@ package nodomain.freeyourgadget.gadgetbridge; public class GBActivitySample { public static final byte PROVIDER_MIBAND = 0; public static final byte PROVIDER_PEBBLE_MORPHEUZ = 1; + public static final byte PROVIDER_PEBBLE_GADGETBRIDGE = 2; // public static final byte TYPE_CHARGING = 6; // public static final byte TYPE_NONWEAR = 3; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AbstractChartFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AbstractChartFragment.java index f2fd7c09..6ded621d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AbstractChartFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AbstractChartFragment.java @@ -74,6 +74,7 @@ public abstract class AbstractChartFragment extends Fragment { break; case PEBBLE: provider = GBActivitySample.PROVIDER_PEBBLE_MORPHEUZ; // FIXME + //provider = GBActivitySample.PROVIDER_PEBBLE_GADGETBRIDGE; break; } return provider; @@ -167,6 +168,10 @@ public abstract class AbstractChartFragment extends Fragment { movement_divisor = 180.0f; //256.0f; use_steps_as_movement = true; break; + case GBActivitySample.PROVIDER_PEBBLE_GADGETBRIDGE: + movement_divisor = 63.0f; + use_steps_as_movement = false; + break; default: // Morpheuz movement_divisor = 5000.0f; use_steps_as_movement = false; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/pebble/GadgetbridgePblSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/pebble/GadgetbridgePblSupport.java index ea44ff2e..01bb537e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/pebble/GadgetbridgePblSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/pebble/GadgetbridgePblSupport.java @@ -6,9 +6,14 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.nio.ByteBuffer; +import java.nio.ByteOrder; import java.util.ArrayList; +import java.util.SimpleTimeZone; +import java.util.TimeZone; import java.util.UUID; +import nodomain.freeyourgadget.gadgetbridge.GBActivitySample; +import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes; @@ -31,14 +36,25 @@ public class GadgetbridgePblSupport { for (Pair pair : pairs) { switch (pair.first) { case KEY_TIMESTAMP: - timestamp = (int) pair.second; + TimeZone tz = SimpleTimeZone.getDefault(); + timestamp = (int) pair.second - (tz.getOffset(System.currentTimeMillis())) / 1000; LOG.info("got timestamp " + timestamp); break; case KEY_SAMPLES: byte[] samples = (byte[]) pair.second; - LOG.info("got " + samples.length / 2 + " samples"); ByteBuffer samplesBuffer = ByteBuffer.wrap(samples); - // TODO: read samples and put into database + samplesBuffer.order(ByteOrder.LITTLE_ENDIAN); + int samples_remaining = samples.length / 2; + LOG.info("got " + samples_remaining + " samples"); + int offset_seconds = 0; + while (samples_remaining-- > 0) { + short sample = samplesBuffer.getShort(); + byte type = (byte) ((sample & 0xe000) >>> 13); + byte intensity = (byte) ((sample & 0x1f80) >>> 7); + byte steps = (byte) (sample & 0x007f); + GBApplication.getActivityDatabaseHandler().addGBActivitySample(timestamp + offset_seconds, GBActivitySample.PROVIDER_PEBBLE_GADGETBRIDGE, intensity, steps, type); + offset_seconds += 60; + } break; default: LOG.info("unhandled key: " + pair.first);