Pebble: reenable battery level reporting, with percentage drom datalog

master
Andreas Shimokawa 2017-04-09 17:05:09 +02:00
parent 5bf6251dc5
commit 810ba5419b
1 changed files with 5 additions and 29 deletions

View File

@ -50,11 +50,13 @@ class DatalogSessionAnalytics extends DatalogSession {
datalogMessage.position(datalogMessage.position() + 12);
short reportedMilliVolts = datalogMessage.getShort();
LOG.info("Battery reading for TS " + messageTS + " is: " + reportedMilliVolts + " milliVolts, mapped to percentage: " + milliVoltstoPercentage(reportedMilliVolts));
datalogMessage.position(datalogMessage.position() + 2);
byte reportedPercentage = datalogMessage.get();
if (false && (messageTS > 0 && reportedMilliVolts < 5000)) { //some safety checks, always disabled for now
LOG.info("Battery reading for TS " + messageTS + " is: " + reportedMilliVolts + " milliVolts, percentage: " + reportedPercentage);
if (messageTS > 0 && reportedMilliVolts < 5000) { //some safety checks
mGBDeviceEventBatteryInfo.state = BatteryState.BATTERY_NORMAL;
mGBDeviceEventBatteryInfo.level = milliVoltstoPercentage(reportedMilliVolts);
mGBDeviceEventBatteryInfo.level = reportedPercentage;
return new GBDeviceEvent[]{mGBDeviceEventBatteryInfo, null};
} else { //invalid data, but we ack nevertheless
@ -62,30 +64,4 @@ class DatalogSessionAnalytics extends DatalogSession {
}
}
private short milliVoltstoPercentage(short batteryMilliVolts) {
if (batteryMilliVolts > 4145) { //(4146 is still 100, next reported value is already 90)
return 100;
} else if (batteryMilliVolts > 4053) { //(4054 is still 90, next reported value is already 80)
return 90;
} else if (batteryMilliVolts > 4000) { //guessed
return 80;
} else if (batteryMilliVolts > 3890) { //3890 was already 60
return 70;
} else if (batteryMilliVolts > 3855) { //probably
return 60;
} else if (batteryMilliVolts > 3780) { //3781 is still 50, next reading is 3776 but percentage on pebble unknown
return 50;
} else if (batteryMilliVolts >= 3750) { //3750 is still 40, next reported value is 3746 and already 30
return 40;
} else if (batteryMilliVolts > 3720) { //3723 is still 30, next reported value is 3719 and already 20
return 30;
} else if (batteryMilliVolts > 3680) { //3683 is still 20, next reported value is 3675 and already 10
return 20;
} else if (batteryMilliVolts > 3650) { //3657 is still 10
return 10;
} else {
return 0; //or -1 for invalid?
}
}
}