Pebble: improvemnts for upcoming Gadgetbridge Pebble watchapp

This commit is contained in:
Andreas Shimokawa 2015-07-27 23:21:06 +02:00
parent dbbcf20bbc
commit 91b8d7789d
3 changed files with 25 additions and 3 deletions

View File

@ -3,6 +3,7 @@ package nodomain.freeyourgadget.gadgetbridge;
public class GBActivitySample { 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 PROVIDER_PEBBLE_GADGETBRIDGE = 2;
// public static final byte TYPE_CHARGING = 6; // public static final byte TYPE_CHARGING = 6;
// public static final byte TYPE_NONWEAR = 3; // public static final byte TYPE_NONWEAR = 3;

View File

@ -74,6 +74,7 @@ public abstract class AbstractChartFragment extends Fragment {
break; break;
case PEBBLE: case PEBBLE:
provider = GBActivitySample.PROVIDER_PEBBLE_MORPHEUZ; // FIXME provider = GBActivitySample.PROVIDER_PEBBLE_MORPHEUZ; // FIXME
//provider = GBActivitySample.PROVIDER_PEBBLE_GADGETBRIDGE;
break; break;
} }
return provider; return provider;
@ -167,6 +168,10 @@ public abstract class AbstractChartFragment extends Fragment {
movement_divisor = 180.0f; //256.0f; movement_divisor = 180.0f; //256.0f;
use_steps_as_movement = true; use_steps_as_movement = true;
break; break;
case GBActivitySample.PROVIDER_PEBBLE_GADGETBRIDGE:
movement_divisor = 63.0f;
use_steps_as_movement = false;
break;
default: // Morpheuz default: // Morpheuz
movement_divisor = 5000.0f; movement_divisor = 5000.0f;
use_steps_as_movement = false; use_steps_as_movement = false;

View File

@ -6,9 +6,14 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.SimpleTimeZone;
import java.util.TimeZone;
import java.util.UUID; 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.GBDeviceEvent;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes;
@ -31,14 +36,25 @@ public class GadgetbridgePblSupport {
for (Pair<Integer, Object> pair : pairs) { for (Pair<Integer, Object> pair : pairs) {
switch (pair.first) { switch (pair.first) {
case KEY_TIMESTAMP: 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); LOG.info("got timestamp " + timestamp);
break; break;
case KEY_SAMPLES: case KEY_SAMPLES:
byte[] samples = (byte[]) pair.second; byte[] samples = (byte[]) pair.second;
LOG.info("got " + samples.length / 2 + " samples");
ByteBuffer samplesBuffer = ByteBuffer.wrap(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; break;
default: default:
LOG.info("unhandled key: " + pair.first); LOG.info("unhandled key: " + pair.first);