Pebble 2: add Workout system app to app manager on P2 and hexdump incoming HRM datalog

This commit is contained in:
Andreas Shimokawa 2016-11-15 11:56:14 +01:00
parent 1a22752b98
commit 4b7f47ba6c
9 changed files with 71 additions and 18 deletions

View File

@ -182,12 +182,20 @@ public abstract class AbstractAppManagerFragment extends Fragment {
cachedAppList.add(new GBDeviceApp(UUID.fromString("cf1e816a-9db0-4511-bbb8-f60c48ca8fac"), "Golf (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM)); cachedAppList.add(new GBDeviceApp(UUID.fromString("cf1e816a-9db0-4511-bbb8-f60c48ca8fac"), "Golf (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM));
} }
*/ */
if (mGBDevice != null && !"aplite".equals(PebbleUtils.getPlatformName(mGBDevice.getModel()))) { if (mGBDevice != null) {
if (PebbleUtils.hasHealth(mGBDevice.getModel())) {
if (baseName.equals(PebbleProtocol.UUID_PEBBLE_HEALTH.toString())) { if (baseName.equals(PebbleProtocol.UUID_PEBBLE_HEALTH.toString())) {
cachedAppList.add(new GBDeviceApp(PebbleProtocol.UUID_PEBBLE_HEALTH, "Health (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM)); cachedAppList.add(new GBDeviceApp(PebbleProtocol.UUID_PEBBLE_HEALTH, "Health (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM));
continue; continue;
} }
} }
if (PebbleUtils.hasHRM(mGBDevice.getModel())) {
if (baseName.equals(PebbleProtocol.UUID_WORKOUT.toString())) {
cachedAppList.add(new GBDeviceApp(PebbleProtocol.UUID_WORKOUT, "Workout (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM));
continue;
}
}
}
if (uuids == null) { if (uuids == null) {
cachedAppList.add(new GBDeviceApp(UUID.fromString(baseName), baseName, "N/A", "", GBDeviceApp.Type.UNKNOWN)); cachedAppList.add(new GBDeviceApp(UUID.fromString(baseName), baseName, "N/A", "", GBDeviceApp.Type.UNKNOWN));
} }

View File

@ -20,10 +20,15 @@ public class AppManagerFragmentInstalledApps extends AbstractAppManagerFragment
systemApps.add(new GBDeviceApp(UUID.fromString("67a32d95-ef69-46d4-a0b9-854cc62f97f9"), "Alarms (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM)); systemApps.add(new GBDeviceApp(UUID.fromString("67a32d95-ef69-46d4-a0b9-854cc62f97f9"), "Alarms (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM));
systemApps.add(new GBDeviceApp(UUID.fromString("18e443ce-38fd-47c8-84d5-6d0c775fbe55"), "Watchfaces (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM)); systemApps.add(new GBDeviceApp(UUID.fromString("18e443ce-38fd-47c8-84d5-6d0c775fbe55"), "Watchfaces (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM));
if (mGBDevice != null && !"aplite".equals(PebbleUtils.getPlatformName(mGBDevice.getModel()))) { if (mGBDevice != null) {
if (PebbleUtils.hasHealth(mGBDevice.getModel())) {
systemApps.add(new GBDeviceApp(UUID.fromString("0863fc6a-66c5-4f62-ab8a-82ed00a98b5d"), "Send Text (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM)); systemApps.add(new GBDeviceApp(UUID.fromString("0863fc6a-66c5-4f62-ab8a-82ed00a98b5d"), "Send Text (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM));
systemApps.add(new GBDeviceApp(PebbleProtocol.UUID_PEBBLE_HEALTH, "Health (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM)); systemApps.add(new GBDeviceApp(PebbleProtocol.UUID_PEBBLE_HEALTH, "Health (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM));
} }
if (PebbleUtils.hasHRM(mGBDevice.getModel())) {
systemApps.add(new GBDeviceApp(PebbleProtocol.UUID_WORKOUT, "Workout (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM));
}
}
return systemApps; return systemApps;
} }

View File

@ -0,0 +1,27 @@
package nodomain.freeyourgadget.gadgetbridge.service.devices.pebble;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.nio.ByteBuffer;
import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
class DatalogSessionHealthHR extends DatalogSessionPebbleHealth {
private static final Logger LOG = LoggerFactory.getLogger(DatalogSessionHealthHR.class);
DatalogSessionHealthHR(byte id, UUID uuid, int tag, byte item_type, short item_size, GBDevice device) {
super(id, uuid, tag, item_type, item_size, device);
taginfo = "(Health - HR " + tag + " )";
}
@Override
public boolean handleMessage(ByteBuffer datalogMessage, int length) {
LOG.info("DATALOG " + taginfo + GB.hexdump(datalogMessage.array(), datalogMessage.position(), length));
return isPebbleHealthEnabled();
}
}

View File

@ -24,7 +24,7 @@ class DatalogSessionHealthOverlayData extends DatalogSessionPebbleHealth {
public DatalogSessionHealthOverlayData(byte id, UUID uuid, int tag, byte item_type, short item_size, GBDevice device) { public DatalogSessionHealthOverlayData(byte id, UUID uuid, int tag, byte item_type, short item_size, GBDevice device) {
super(id, uuid, tag, item_type, item_size, device); super(id, uuid, tag, item_type, item_size, device);
taginfo = "(health - overlay data " + tag + " )"; taginfo = "(Health - overlay data " + tag + " )";
} }
@Override @Override
@ -85,7 +85,7 @@ class DatalogSessionHealthOverlayData extends DatalogSessionPebbleHealth {
int durationSeconds; int durationSeconds;
byte[] rawData; byte[] rawData;
public OverlayRecord(byte[] rawData) { OverlayRecord(byte[] rawData) {
this.rawData = rawData; this.rawData = rawData;
ByteBuffer record = ByteBuffer.wrap(rawData); ByteBuffer record = ByteBuffer.wrap(rawData);
record.order(ByteOrder.LITTLE_ENDIAN); record.order(ByteOrder.LITTLE_ENDIAN);
@ -99,7 +99,7 @@ class DatalogSessionHealthOverlayData extends DatalogSessionPebbleHealth {
this.durationSeconds = record.getInt(); this.durationSeconds = record.getInt();
} }
public byte[] getRawData() { byte[] getRawData() {
if (storePebbleHealthRawRecord()) { if (storePebbleHealthRawRecord()) {
return rawData; return rawData;
} }

View File

@ -24,7 +24,7 @@ class DatalogSessionHealthSleep extends DatalogSessionPebbleHealth {
public DatalogSessionHealthSleep(byte id, UUID uuid, int tag, byte item_type, short item_size, GBDevice device) { public DatalogSessionHealthSleep(byte id, UUID uuid, int tag, byte item_type, short item_size, GBDevice device) {
super(id, uuid, tag, item_type, item_size, device); super(id, uuid, tag, item_type, item_size, device);
taginfo = "(health - sleep " + tag + " )"; taginfo = "(Health - sleep " + tag + " )";
} }
@Override @Override
@ -87,7 +87,7 @@ class DatalogSessionHealthSleep extends DatalogSessionPebbleHealth {
int deepSleepSeconds; int deepSleepSeconds;
byte[] rawData; byte[] rawData;
public SleepRecord(byte[] rawData) { SleepRecord(byte[] rawData) {
this.rawData = rawData; this.rawData = rawData;
ByteBuffer record = ByteBuffer.wrap(rawData); ByteBuffer record = ByteBuffer.wrap(rawData);
record.order(ByteOrder.LITTLE_ENDIAN); record.order(ByteOrder.LITTLE_ENDIAN);
@ -101,7 +101,7 @@ class DatalogSessionHealthSleep extends DatalogSessionPebbleHealth {
this.deepSleepSeconds = record.getInt(); this.deepSleepSeconds = record.getInt();
} }
public byte[] getRawData() { byte[] getRawData() {
if (storePebbleHealthRawRecord()) { if (storePebbleHealthRawRecord()) {
return rawData; return rawData;
} }

View File

@ -22,7 +22,7 @@ public class DatalogSessionHealthSteps extends DatalogSessionPebbleHealth {
public DatalogSessionHealthSteps(byte id, UUID uuid, int tag, byte item_type, short item_size, GBDevice device) { public DatalogSessionHealthSteps(byte id, UUID uuid, int tag, byte item_type, short item_size, GBDevice device) {
super(id, uuid, tag, item_type, item_size, device); super(id, uuid, tag, item_type, item_size, device);
taginfo = "(health - steps)"; taginfo = "(Health - steps)";
} }
@Override @Override
@ -110,7 +110,7 @@ public class DatalogSessionHealthSteps extends DatalogSessionPebbleHealth {
int light_intensity; int light_intensity;
byte[] rawData; byte[] rawData;
public StepsRecord(int timestamp, short version, byte[] rawData) { StepsRecord(int timestamp, short version, byte[] rawData) {
this.timestamp = timestamp; this.timestamp = timestamp;
this.rawData = rawData; this.rawData = rawData;
ByteBuffer record = ByteBuffer.wrap(rawData); ByteBuffer record = ByteBuffer.wrap(rawData);
@ -125,7 +125,7 @@ public class DatalogSessionHealthSteps extends DatalogSessionPebbleHealth {
this.light_intensity = record.get() & 0xff; this.light_intensity = record.get() & 0xff;
} }
public byte[] getRawData() { byte[] getRawData() {
if (storePebbleHealthRawRecord()) { if (storePebbleHealthRawRecord()) {
return rawData; return rawData;
} }

View File

@ -19,12 +19,12 @@ abstract class DatalogSessionPebbleHealth extends DatalogSession {
return mDevice; return mDevice;
} }
protected boolean isPebbleHealthEnabled() { boolean isPebbleHealthEnabled() {
Prefs prefs = GBApplication.getPrefs(); Prefs prefs = GBApplication.getPrefs();
return prefs.getBoolean("pebble_sync_health", true); return prefs.getBoolean("pebble_sync_health", true);
} }
protected boolean storePebbleHealthRawRecord() { boolean storePebbleHealthRawRecord() {
Prefs prefs = GBApplication.getPrefs(); Prefs prefs = GBApplication.getPrefs();
return prefs.getBoolean("pebble_health_store_raw", true); return prefs.getBoolean("pebble_health_store_raw", true);
} }

View File

@ -366,6 +366,7 @@ public class PebbleProtocol extends GBDeviceProtocol {
private final ArrayList<UUID> tmpUUIDS = new ArrayList<>(); private final ArrayList<UUID> tmpUUIDS = new ArrayList<>();
public static final UUID UUID_PEBBLE_HEALTH = UUID.fromString("36d8c6ed-4c83-4fa1-a9e2-8f12dc941f8c"); // FIXME: store somewhere else, this is also accessed by other code public static final UUID UUID_PEBBLE_HEALTH = UUID.fromString("36d8c6ed-4c83-4fa1-a9e2-8f12dc941f8c"); // FIXME: store somewhere else, this is also accessed by other code
public static final UUID UUID_WORKOUT = UUID.fromString("fef82c82-7176-4e22-88de-35a3fc18d43f"); // FIXME: store somewhere else, this is also accessed by other code
private static final UUID UUID_GBPEBBLE = UUID.fromString("61476764-7465-7262-6469-656775527a6c"); private static final UUID UUID_GBPEBBLE = UUID.fromString("61476764-7465-7262-6469-656775527a6c");
private static final UUID UUID_MORPHEUZ = UUID.fromString("5be44f1d-d262-4ea6-aa30-ddbec1e3cab2"); private static final UUID UUID_MORPHEUZ = UUID.fromString("5be44f1d-d262-4ea6-aa30-ddbec1e3cab2");
private static final UUID UUID_WHETHERNEAT = UUID.fromString("3684003b-a685-45f9-a713-abc6364ba051"); private static final UUID UUID_WHETHERNEAT = UUID.fromString("3684003b-a685-45f9-a713-abc6364ba051");
@ -2020,6 +2021,8 @@ public class PebbleProtocol extends GBDeviceProtocol {
mDatalogSessions.put(id, new DatalogSessionHealthSleep(id, uuid, log_tag, item_type, item_size, getDevice())); mDatalogSessions.put(id, new DatalogSessionHealthSleep(id, uuid, log_tag, item_type, item_size, getDevice()));
} else if (uuid.equals(UUID_ZERO) && log_tag == 84) { } else if (uuid.equals(UUID_ZERO) && log_tag == 84) {
mDatalogSessions.put(id, new DatalogSessionHealthOverlayData(id, uuid, log_tag, item_type, item_size, getDevice())); mDatalogSessions.put(id, new DatalogSessionHealthOverlayData(id, uuid, log_tag, item_type, item_size, getDevice()));
} else if (uuid.equals(UUID_ZERO) && log_tag == 85) {
mDatalogSessions.put(id, new DatalogSessionHealthHR(id, uuid, log_tag, item_type, item_size, getDevice()));
} else { } else {
mDatalogSessions.put(id, new DatalogSession(id, uuid, log_tag, item_type, item_size)); mDatalogSessions.put(id, new DatalogSession(id, uuid, log_tag, item_type, item_size));
} }

View File

@ -37,4 +37,14 @@ public class PebbleUtils {
public static int getFwMajor(String fwString) { public static int getFwMajor(String fwString) {
return fwString.charAt(1) - 48; return fwString.charAt(1) - 48;
} }
public static boolean hasHRM(String hwRev) {
String platformName = getPlatformName(hwRev);
return "diorite".equals(platformName) || "emery".equals(platformName);
}
public static boolean hasHealth(String hwRev) {
String platformName = getPlatformName(hwRev);
return !"aplite".equals(platformName);
}
} }