add hardware revision string to GBDevice, get and display HW Revision from Pebble

live-sensor-data
Andreas Shimokawa 2015-04-20 12:48:32 +02:00
parent fbbc808ca8
commit 16ea52e83c
3 changed files with 27 additions and 4 deletions

View File

@ -26,6 +26,7 @@ public class GBDevice implements Parcelable {
private final String mAddress; private final String mAddress;
private final Type mType; private final Type mType;
private String mFirmwareVersion = null; private String mFirmwareVersion = null;
private String mHardwareVersion = null;
private State mState = State.NOT_CONNECTED; private State mState = State.NOT_CONNECTED;
private short mBatteryLevel = 50; // unknown private short mBatteryLevel = 50; // unknown
private String mBatteryState; private String mBatteryState;
@ -41,6 +42,7 @@ public class GBDevice implements Parcelable {
mAddress = in.readString(); mAddress = in.readString();
mType = Type.values()[in.readInt()]; mType = Type.values()[in.readInt()];
mFirmwareVersion = in.readString(); mFirmwareVersion = in.readString();
mHardwareVersion = in.readString();
mState = State.values()[in.readInt()]; mState = State.values()[in.readInt()];
mBatteryLevel = (short) in.readInt(); mBatteryLevel = (short) in.readInt();
mBatteryState = in.readString(); mBatteryState = in.readString();
@ -62,6 +64,14 @@ public class GBDevice implements Parcelable {
mFirmwareVersion = firmwareVersion; mFirmwareVersion = firmwareVersion;
} }
public String getHardwareVersion() {
return mHardwareVersion;
}
public void setHardwareVersion(String hardwareVersion) {
mHardwareVersion = hardwareVersion;
}
public boolean isConnected() { public boolean isConnected() {
return mState.ordinal() >= State.CONNECTED.ordinal(); return mState.ordinal() >= State.CONNECTED.ordinal();
} }
@ -97,7 +107,11 @@ public class GBDevice implements Parcelable {
} }
public String getInfoString() { public String getInfoString() {
//FIXME: ugly
if (mFirmwareVersion != null) { if (mFirmwareVersion != null) {
if (mHardwareVersion != null) {
return getStateString() + " (HW: " + mHardwareVersion + " FW: " + mFirmwareVersion + ")";
}
return getStateString() + " (FW: " + mFirmwareVersion + ")"; return getStateString() + " (FW: " + mFirmwareVersion + ")";
} else { } else {
return getStateString(); return getStateString();
@ -140,6 +154,7 @@ public class GBDevice implements Parcelable {
dest.writeString(mAddress); dest.writeString(mAddress);
dest.writeInt(mType.ordinal()); dest.writeInt(mType.ordinal());
dest.writeString(mFirmwareVersion); dest.writeString(mFirmwareVersion);
dest.writeString(mHardwareVersion);
dest.writeInt(mState.ordinal()); dest.writeInt(mState.ordinal());
dest.writeInt(mBatteryLevel); dest.writeInt(mBatteryLevel);
dest.writeString(mBatteryState); dest.writeString(mBatteryState);

View File

@ -318,6 +318,7 @@ public class PebbleIoThread extends GBDeviceIoThread {
} }
GBDeviceCommandVersionInfo infoCmd = (GBDeviceCommandVersionInfo) deviceCmd; GBDeviceCommandVersionInfo infoCmd = (GBDeviceCommandVersionInfo) deviceCmd;
gbDevice.setFirmwareVersion(infoCmd.fwVersion); gbDevice.setFirmwareVersion(infoCmd.fwVersion);
gbDevice.setHardwareVersion(infoCmd.hwVersion);
gbDevice.sendDeviceUpdateIntent(context); gbDevice.sendDeviceUpdateIntent(context);
break; break;
case APP_INFO: case APP_INFO:

View File

@ -138,6 +138,8 @@ public class PebbleProtocol extends GBDeviceProtocol {
static final short LENGTH_UPLOADCANCEL = 5; static final short LENGTH_UPLOADCANCEL = 5;
static final short LENGTH_SYSTEMMESSAGE = 2; static final short LENGTH_SYSTEMMESSAGE = 2;
private static final String[] hwRevisions = {"unknown", "ev1", "ev2", "ev2_3", "ev2_4", "v1_5", "v2_0"};
private static byte[] encodeMessage(short endpoint, byte type, int cookie, String[] parts) { private static byte[] encodeMessage(short endpoint, byte type, int cookie, String[] parts) {
// Calculate length first // Calculate length first
int length = LENGTH_PREFIX + 1; int length = LENGTH_PREFIX + 1;
@ -452,11 +454,16 @@ public class PebbleProtocol extends GBDeviceProtocol {
case ENDPOINT_FIRMWAREVERSION: case ENDPOINT_FIRMWAREVERSION:
GBDeviceCommandVersionInfo versionCmd = new GBDeviceCommandVersionInfo(); GBDeviceCommandVersionInfo versionCmd = new GBDeviceCommandVersionInfo();
int version = buf.getInt(); buf.getInt(); // skip
byte[] versionString = new byte[32]; byte[] tmp = new byte[32];
buf.get(versionString, 0, 32); buf.get(tmp, 0, 32);
versionCmd.fwVersion = new String(versionString).trim(); versionCmd.fwVersion = new String(tmp).trim();
buf.get(tmp, 0, 9);
Byte hwRev = buf.get();
if (hwRev > 0 && hwRev < hwRevisions.length) {
versionCmd.hwVersion = hwRevisions[hwRev];
}
cmd = versionCmd; cmd = versionCmd;
break; break;
case ENDPOINT_APPMANAGER: case ENDPOINT_APPMANAGER: