mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-24 02:46:50 +01:00
add hardware revision string to GBDevice, get and display HW Revision from Pebble
This commit is contained in:
parent
fbbc808ca8
commit
16ea52e83c
@ -26,6 +26,7 @@ public class GBDevice implements Parcelable {
|
||||
private final String mAddress;
|
||||
private final Type mType;
|
||||
private String mFirmwareVersion = null;
|
||||
private String mHardwareVersion = null;
|
||||
private State mState = State.NOT_CONNECTED;
|
||||
private short mBatteryLevel = 50; // unknown
|
||||
private String mBatteryState;
|
||||
@ -41,6 +42,7 @@ public class GBDevice implements Parcelable {
|
||||
mAddress = in.readString();
|
||||
mType = Type.values()[in.readInt()];
|
||||
mFirmwareVersion = in.readString();
|
||||
mHardwareVersion = in.readString();
|
||||
mState = State.values()[in.readInt()];
|
||||
mBatteryLevel = (short) in.readInt();
|
||||
mBatteryState = in.readString();
|
||||
@ -62,6 +64,14 @@ public class GBDevice implements Parcelable {
|
||||
mFirmwareVersion = firmwareVersion;
|
||||
}
|
||||
|
||||
public String getHardwareVersion() {
|
||||
return mHardwareVersion;
|
||||
}
|
||||
|
||||
public void setHardwareVersion(String hardwareVersion) {
|
||||
mHardwareVersion = hardwareVersion;
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
return mState.ordinal() >= State.CONNECTED.ordinal();
|
||||
}
|
||||
@ -97,7 +107,11 @@ public class GBDevice implements Parcelable {
|
||||
}
|
||||
|
||||
public String getInfoString() {
|
||||
//FIXME: ugly
|
||||
if (mFirmwareVersion != null) {
|
||||
if (mHardwareVersion != null) {
|
||||
return getStateString() + " (HW: " + mHardwareVersion + " FW: " + mFirmwareVersion + ")";
|
||||
}
|
||||
return getStateString() + " (FW: " + mFirmwareVersion + ")";
|
||||
} else {
|
||||
return getStateString();
|
||||
@ -140,6 +154,7 @@ public class GBDevice implements Parcelable {
|
||||
dest.writeString(mAddress);
|
||||
dest.writeInt(mType.ordinal());
|
||||
dest.writeString(mFirmwareVersion);
|
||||
dest.writeString(mHardwareVersion);
|
||||
dest.writeInt(mState.ordinal());
|
||||
dest.writeInt(mBatteryLevel);
|
||||
dest.writeString(mBatteryState);
|
||||
|
@ -318,6 +318,7 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
||||
}
|
||||
GBDeviceCommandVersionInfo infoCmd = (GBDeviceCommandVersionInfo) deviceCmd;
|
||||
gbDevice.setFirmwareVersion(infoCmd.fwVersion);
|
||||
gbDevice.setHardwareVersion(infoCmd.hwVersion);
|
||||
gbDevice.sendDeviceUpdateIntent(context);
|
||||
break;
|
||||
case APP_INFO:
|
||||
|
@ -138,6 +138,8 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
||||
static final short LENGTH_UPLOADCANCEL = 5;
|
||||
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) {
|
||||
// Calculate length first
|
||||
int length = LENGTH_PREFIX + 1;
|
||||
@ -452,11 +454,16 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
||||
case ENDPOINT_FIRMWAREVERSION:
|
||||
GBDeviceCommandVersionInfo versionCmd = new GBDeviceCommandVersionInfo();
|
||||
|
||||
int version = buf.getInt();
|
||||
byte[] versionString = new byte[32];
|
||||
buf.get(versionString, 0, 32);
|
||||
buf.getInt(); // skip
|
||||
byte[] tmp = new byte[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;
|
||||
break;
|
||||
case ENDPOINT_APPMANAGER:
|
||||
|
Loading…
Reference in New Issue
Block a user