use of com.eveningoutpost.dexdrip.insulin.inpen.messages.BatteryRx in project xDrip-plus by jamorham.
the class InPenService method getBattery.
private void getBattery() {
if (JoH.pratelimit("inpen-battery-poll-" + I.address, 40000)) {
I.connection.readCharacteristic(BATTERY).subscribe(batteryValue -> {
final BatteryRx battery = new BatteryRx().fromBytes(batteryValue);
if (battery != null) {
lastBattery = battery.getBatteryPercent();
PersistentStore.setLong(STORE_INPEN_BATTERY + I.address, lastBattery);
UserError.Log.d(TAG, "GetBattery result: " + battery.getBatteryPercent());
changeNextState();
} else {
UserError.Log.e(TAG, "Invalid GetBattery result: " + dumpHexString(batteryValue));
changeNextState();
}
}, throwable -> {
UserError.Log.e(TAG, "Could not read after Battery status: " + throwable);
changeNextState();
});
} else {
UserError.Log.d(TAG, "Skipping battery read");
if (lastBattery == -1) {
lastBattery = (int) PersistentStore.getLong(STORE_INPEN_BATTERY + I.address);
if (lastBattery == 0) {
lastBattery = -1;
} else {
UserError.Log.d(TAG, "Loaded battery from store: " + lastBattery);
}
}
changeNextState();
}
}
use of com.eveningoutpost.dexdrip.insulin.inpen.messages.BatteryRx in project xDrip by NightscoutFoundation.
the class InPenService method getBattery.
private void getBattery() {
if (JoH.pratelimit("inpen-battery-poll-" + I.address, 40000)) {
I.connection.readCharacteristic(BATTERY).subscribe(batteryValue -> {
final BatteryRx battery = new BatteryRx().fromBytes(batteryValue);
if (battery != null) {
lastBattery = battery.getBatteryPercent();
PersistentStore.setLong(STORE_INPEN_BATTERY + I.address, lastBattery);
UserError.Log.d(TAG, "GetBattery result: " + battery.getBatteryPercent());
changeNextState();
} else {
UserError.Log.e(TAG, "Invalid GetBattery result: " + dumpHexString(batteryValue));
changeNextState();
}
}, throwable -> {
UserError.Log.e(TAG, "Could not read after Battery status: " + throwable);
changeNextState();
});
} else {
UserError.Log.d(TAG, "Skipping battery read");
if (lastBattery == -1) {
lastBattery = (int) PersistentStore.getLong(STORE_INPEN_BATTERY + I.address);
if (lastBattery == 0) {
lastBattery = -1;
} else {
UserError.Log.d(TAG, "Loaded battery from store: " + lastBattery);
}
}
changeNextState();
}
}
Aggregations