Update RileyLink battery level in sendAndListen()

This commit is contained in:
Bart Sopers 2020-12-19 01:16:03 +01:00
parent ecaeebb2f9
commit 85baae326d
3 changed files with 10 additions and 7 deletions

View file

@ -81,6 +81,8 @@ public abstract class RileyLinkCommunicationManager<T extends RLMessage> {
RadioResponse radioResponse = rfSpyResponse.getRadioResponse(injector); RadioResponse radioResponse = rfSpyResponse.getRadioResponse(injector);
T response = createResponseMessage(radioResponse.getPayload()); T response = createResponseMessage(radioResponse.getPayload());
updateBatteryLevel();
if (response.isValid()) { if (response.isValid()) {
// Mark this as the last time we heard from the pump. // Mark this as the last time we heard from the pump.
rememberLastGoodDeviceCommunicationTime(); rememberLastGoodDeviceCommunicationTime();
@ -116,6 +118,10 @@ public abstract class RileyLinkCommunicationManager<T extends RLMessage> {
return response; return response;
} }
private void updateBatteryLevel() {
rileyLinkServiceData.batteryLevel = rfspy.getBatteryLevel();
}
public abstract T createResponseMessage(byte[] payload); public abstract T createResponseMessage(byte[] payload);

View file

@ -116,12 +116,12 @@ public class RFSpy {
public Integer getBatteryLevel() { public Integer getBatteryLevel() {
BLECommOperationResult result = rileyLinkBle.readCharacteristic_blocking(batteryServiceUUID, batteryLevelUUID); BLECommOperationResult result = rileyLinkBle.readCharacteristic_blocking(batteryServiceUUID, batteryLevelUUID);
if (result.resultCode == BLECommOperationResult.RESULT_SUCCESS) { if (result.resultCode == BLECommOperationResult.RESULT_SUCCESS) {
Integer value = (int) result.value[0]; int value = result.value[0];
aapsLogger.debug(LTag.PUMPBTCOMM, "BLE battery level: " + value.toString()); aapsLogger.debug(LTag.PUMPBTCOMM, "BLE battery level: {}", value);
return value; return value;
} else { } else {
aapsLogger.error(LTag.PUMPBTCOMM, "getBatteryLevel failed with code: " + result.resultCode); aapsLogger.error(LTag.PUMPBTCOMM, "getBatteryLevel failed with code: " + result.resultCode);
return -1; return null;
} }
} }
@ -439,8 +439,6 @@ public class RFSpy {
* Reset RileyLink Configuration (set all updateRegisters) * Reset RileyLink Configuration (set all updateRegisters)
*/ */
public void resetRileyLinkConfiguration() { public void resetRileyLinkConfiguration() {
//TODO: Please move me to an appropriate place!
rileyLinkServiceData.batteryLevel = this.getBatteryLevel();
if (this.currentFrequencyMHz != null) if (this.currentFrequencyMHz != null)
this.setBaseFrequency(this.currentFrequencyMHz); this.setBaseFrequency(this.currentFrequencyMHz);
} }

View file

@ -17,7 +17,6 @@ import info.nightscout.androidaps.interfaces.ActivePluginProvider;
import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.plugins.pump.common.R; import info.nightscout.androidaps.plugins.pump.common.R;
import info.nightscout.androidaps.plugins.pump.common.dialog.RefreshableInterface; import info.nightscout.androidaps.plugins.pump.common.dialog.RefreshableInterface;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkFirmwareVersion;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkPumpDevice; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkPumpDevice;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkPumpInfo; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkPumpInfo;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice;
@ -118,7 +117,7 @@ public class RileyLinkStatusGeneralFragment extends DaggerFragment implements Re
"\nCC110: " + rileyLinkServiceData.versionCC110); "\nCC110: " + rileyLinkServiceData.versionCC110);
} }
Integer batteryLevel = rileyLinkServiceData.batteryLevel; Integer batteryLevel = rileyLinkServiceData.batteryLevel;
if (batteryLevel == null || batteryLevel <= 0) { if (batteryLevel == null) {
this.batteryLevel.setText("???"); this.batteryLevel.setText("???");
} else { } else {
this.batteryLevel.setText(batteryLevel + "%"); this.batteryLevel.setText(batteryLevel + "%");