- fix for task #126 - battery display, it will work for Alakaline and Lithium battery, but probably not for recharchargables

This commit is contained in:
Andy Rozman 2019-05-26 14:44:33 +01:00
parent 5a7146d3a9
commit 67862d3385
13 changed files with 90 additions and 30 deletions

View file

@ -481,7 +481,7 @@ public class MedtronicFragment extends SubscriberFragment {
} }
// battery // battery
batteryView.setText("{fa-battery-" + (pumpStatus.batteryRemaining / 25) + "}"); batteryView.setText("{fa-battery-" + (pumpStatus.batteryRemaining / 25) + "} " + pumpStatus.batteryRemaining + "%");
SetWarnColor.setColorInverse(batteryView, pumpStatus.batteryRemaining, 51d, 26d); SetWarnColor.setColorInverse(batteryView, pumpStatus.batteryRemaining, 51d, 26d);
// reservoir // reservoir

View file

@ -135,7 +135,6 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
medtronicService = null; medtronicService = null;
} }
public void onServiceConnected(ComponentName name, IBinder service) { public void onServiceConnected(ComponentName name, IBinder service) {
if (isLoggingEnabled()) if (isLoggingEnabled())
LOG.debug("RileyLinkMedtronicService is connected"); LOG.debug("RileyLinkMedtronicService is connected");
@ -285,7 +284,6 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
@Override @Override
public boolean isInitialized() { public boolean isInitialized() {
// TODO remove
if (isLoggingEnabled() && displayConnectionMessages) if (isLoggingEnabled() && displayConnectionMessages)
LOG.debug("MedtronicPumpPlugin::isInitialized"); LOG.debug("MedtronicPumpPlugin::isInitialized");
return isServiceSet() && isInitialized; return isServiceSet() && isInitialized;
@ -532,8 +530,6 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
readPumpHistory(); readPumpHistory();
// TODO rewrite reading of data to be done in background or different thread perhaps ??
// remaining insulin (>50 = 4h; 50-20 = 1h; 15m) // remaining insulin (>50 = 4h; 50-20 = 1h; 15m)
medtronicUIComm.executeCommand(MedtronicCommandType.GetRemainingInsulin); medtronicUIComm.executeCommand(MedtronicCommandType.GetRemainingInsulin);
scheduleNextRefresh(MedtronicStatusRefreshType.RemainingInsulin, 10); scheduleNextRefresh(MedtronicStatusRefreshType.RemainingInsulin, 10);

View file

@ -172,7 +172,7 @@ public class MedtronicConverter {
// if response in 3 bytes then we add additional information // if response in 3 bytes then we add additional information
// double d = MedtronicUtil.makeUnsignedShort(rawData[2], rawData[1]) / 100.0d; // double d = MedtronicUtil.makeUnsignedShort(rawData[2], rawData[1]) / 100.0d;
double d = ByteUtil.toInt(rawData[1], rawData[2]) / 100.0d; double d = (ByteUtil.toInt(rawData[1], rawData[2])*1.0d) / 100.0d;
batteryStatus.voltage = d; batteryStatus.voltage = d;

View file

@ -100,10 +100,14 @@ public class MedtronicUIPostprocessor {
case GetBatteryStatus: { case GetBatteryStatus: {
BatteryStatusDTO batteryStatusDTO = (BatteryStatusDTO)uiTask.returnData; BatteryStatusDTO batteryStatusDTO = (BatteryStatusDTO)uiTask.returnData;
if (batteryStatusDTO.batteryStatusType == BatteryStatusDTO.BatteryStatusType.Low) pumpStatus.batteryRemaining = (batteryStatusDTO.getCalculatedPercent(pumpStatus.batteryType));
pumpStatus.batteryRemaining = 18;
else LOG.info("BatteryStatus: {}", batteryStatusDTO.toString());
pumpStatus.batteryRemaining = 70;
// if (batteryStatusDTO.batteryStatusType == BatteryStatusDTO.BatteryStatusType.Low)
// pumpStatus.batteryRemaining = 18;
// else
// pumpStatus.batteryRemaining = 70;
} }
break; break;

View file

@ -12,15 +12,29 @@ public class BatteryStatusDTO {
@Expose @Expose
public BatteryStatusType batteryStatusType; public BatteryStatusType batteryStatusType;
public double voltage; public Double voltage;
public int getCalculatedPercent(BatteryType batteryType) { public int getCalculatedPercent(BatteryType batteryType) {
if (voltage==null || batteryType==BatteryType.None) {
return (batteryStatusType==BatteryStatusType.Low || batteryStatusType==BatteryStatusType.Unknown) ? 18 : 70;
}
double percent = (voltage - batteryType.lowVoltage) / (batteryType.highVoltage - batteryType.lowVoltage); double percent = (voltage - batteryType.lowVoltage) / (batteryType.highVoltage - batteryType.lowVoltage);
return (int)(percent * 100.0d); return (int)(percent * 100.0d);
} }
public String toString() {
return String.format("BatteryStatusDTO [voltage=%.2f, alkaline=%d, lithium=%d]",
voltage==null? 0.0f : voltage,
getCalculatedPercent(BatteryType.Alkaline),
getCalculatedPercent(BatteryType.Lithium));
}
public enum BatteryStatusType { public enum BatteryStatusType {
Normal, Normal,
Low, Low,

View file

@ -144,8 +144,15 @@ public class TempBasalPair {
return MedtronicUtil.createByteArray(list); return MedtronicUtil.createByteArray(list);
} }
public boolean isCancelTBR() {
return (MedtronicUtil.isSame(insulinRate, 0.0d) && durationMinutes==0);
}
public String getDescription() { public String getDescription() {
if (isCancelTBR()) {
return "Cancel TBR";
}
if (isPercent) { if (isPercent) {
return String.format(Locale.ENGLISH, "Rate: %.0f%%, Duration: %d min", insulinRate, durationMinutes); return String.format(Locale.ENGLISH, "Rate: %.0f%%, Duration: %d min", insulinRate, durationMinutes);

View file

@ -1,20 +1,45 @@
package info.nightscout.androidaps.plugins.pump.medtronic.defs; package info.nightscout.androidaps.plugins.pump.medtronic.defs;
import java.util.HashMap;
import java.util.Map;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
/** /**
* Created by andy on 6/4/18. * Created by andy on 6/4/18.
*/ */
public enum BatteryType { public enum BatteryType {
Alkaline(1.20f, 1.47f), // None(R.string.medtronic_pump_battery_no, 0, 0),
Lithium(1.32f, 1.58f); Alkaline(R.string.medtronic_pump_battery_alkaline,1.20f, 1.47f), //
Lithium(R.string.medtronic_pump_battery_lithium,1.32f, 1.58f);
private final String description;
public float lowVoltage; public float lowVoltage;
public float highVoltage; public float highVoltage;
static Map<String,BatteryType> mapByDescription;
BatteryType(float lowVoltage, float highVoltage) { static {
mapByDescription = new HashMap<>();
for (BatteryType value : values()) {
mapByDescription.put(value.description, value);
}
}
BatteryType(int resId, float lowVoltage, float highVoltage) {
this.description = MainApp.gs(resId);
this.lowVoltage = lowVoltage; this.lowVoltage = lowVoltage;
this.highVoltage = highVoltage; this.highVoltage = highVoltage;
} }
public static BatteryType getByDescription(String batteryTypeStr) {
if (mapByDescription.containsKey(batteryTypeStr)) {
return mapByDescription.get(batteryTypeStr);
}
return BatteryType.None;
}
} }

View file

@ -11,7 +11,7 @@ public enum MedtronicStatusRefreshType {
PumpHistory(5, null), // PumpHistory(5, null), //
Configuration(0, null), // Configuration(0, null), //
RemainingInsulin(-1, MedtronicCommandType.GetRemainingInsulin), // RemainingInsulin(-1, MedtronicCommandType.GetRemainingInsulin), //
BatteryStatus(60, MedtronicCommandType.GetBatteryStatus), // BatteryStatus(55, MedtronicCommandType.GetBatteryStatus), //
PumpTime(60, MedtronicCommandType.RealTimeClock) // PumpTime(60, MedtronicCommandType.RealTimeClock) //
; ;

View file

@ -23,6 +23,7 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.Rile
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.BasalProfileStatus; import info.nightscout.androidaps.plugins.pump.medtronic.defs.BasalProfileStatus;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.BatteryType;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicDeviceType; import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicDeviceType;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState; import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicConst; import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicConst;
@ -75,6 +76,7 @@ public class MedtronicPumpStatus extends PumpStatus {
private Map<String, MedtronicDeviceType> medtronicDeviceTypeMap = null; private Map<String, MedtronicDeviceType> medtronicDeviceTypeMap = null;
private RileyLinkTargetFrequency targetFrequency; private RileyLinkTargetFrequency targetFrequency;
public BasalProfileStatus basalProfileStatus; public BasalProfileStatus basalProfileStatus;
public BatteryType batteryType = BatteryType.None;
public MedtronicPumpStatus(PumpDescription pumpDescription) { public MedtronicPumpStatus(PumpDescription pumpDescription) {
@ -262,6 +264,14 @@ public class MedtronicPumpStatus extends PumpStatus {
this.encodingChanged = true; this.encodingChanged = true;
} }
String batteryTypeStr = SP.getString(MedtronicConst.Prefs.BatteryType, null);
BatteryType batteryType = BatteryType.getByDescription(batteryTypeStr);
if (this.batteryType != batteryType) {
this.batteryType = batteryType;
}
reconfigureService(); reconfigureService();
} catch (Exception ex) { } catch (Exception ex) {

View file

@ -18,6 +18,7 @@ public class MedtronicConst {
public static final String MaxBasal = PrefPrefix + "max_basal"; public static final String MaxBasal = PrefPrefix + "max_basal";
public static final String BolusDelay = PrefPrefix + "bolus_delay"; public static final String BolusDelay = PrefPrefix + "bolus_delay";
public static final String Encoding = PrefPrefix + "encoding"; public static final String Encoding = PrefPrefix + "encoding";
public static final String BatteryType = PrefPrefix + "battery_type";
} }
public class Statistics { public class Statistics {

View file

@ -175,4 +175,10 @@
<item>@string/medtronic_pump_encoding_4b6b_rileylink</item> <item>@string/medtronic_pump_encoding_4b6b_rileylink</item>
</string-array> </string-array>
<string-array name="medtronicBatteryType">
<item>@string/medtronic_pump_battery_no</item>
<item>@string/medtronic_pump_battery_alkaline</item>
<item>@string/medtronic_pump_battery_lithium</item>
</string-array>
</resources> </resources>

View file

@ -1360,6 +1360,10 @@
<string name="medtronic_custom_action_wake_and_tune">Wake and Tune Up</string> <string name="medtronic_custom_action_wake_and_tune">Wake and Tune Up</string>
<string name="medtronic_custom_action_clear_bolus_block">Clear Bolus Block</string> <string name="medtronic_custom_action_clear_bolus_block">Clear Bolus Block</string>
<string name="medtronic_custom_action_reset_rileylink">Reset RileyLink</string> <string name="medtronic_custom_action_reset_rileylink">Reset RileyLink</string>
<string name="medtronic_pump_battery_select">Battery Type (Power View)</string>
<string name="medtronic_pump_battery_no">Not selected (Simple view)</string>
<string name="medtronic_pump_battery_alkaline">Alkaline (Extended view)</string>
<string name="medtronic_pump_battery_lithium">Lithium (Extended view)</string>
<!-- RL BLE Scanning --> <!-- RL BLE Scanning -->
<string name="rileylink_scanner_scan_scan">SCAN</string> <string name="rileylink_scanner_scan_scan">SCAN</string>

View file

@ -60,6 +60,14 @@
android:selectable="true" android:selectable="true"
android:title="@string/medtronic_pump_encoding" /> android:title="@string/medtronic_pump_encoding" />
<ListPreference
android:defaultValue="@string/medtronic_pump_battery_no"
android:entries="@array/medtronicBatteryType"
android:entryValues="@array/medtronicBatteryType"
android:key="pref_medtronic_battery_type"
android:selectable="true"
android:title="@string/medtronic_pump_battery_select" />
<info.nightscout.androidaps.plugins.pump.common.ui.RileyLinkSelectPreference <info.nightscout.androidaps.plugins.pump.common.ui.RileyLinkSelectPreference
android:id="@+id/rileylink_mac_address_mdt" android:id="@+id/rileylink_mac_address_mdt"
android:enabled="true" android:enabled="true"
@ -67,22 +75,7 @@
android:title="RileyLink Configuration" android:title="RileyLink Configuration"
android:key="pref_rileylink_mac_address"> android:key="pref_rileylink_mac_address">
<intent android:action="info.nightscout.androidaps.plugins.PumpCommon.dialog.RileyLinkBLEScanActivity" /> <intent android:action="info.nightscout.androidaps.plugins.PumpCommon.dialog.RileyLinkBLEScanActivity" />
</info.nightscout.androidaps.plugins.pump.common.ui.RileyLinkSelectPreference> </info.nightscout.androidaps.plugins.pump.common.ui.RileyLinkSelectPreference>
<!-- android:key="rileylink_scanner" -->
<!--
<EditTextPreference
android:id="@+id/rileylink_mac_address_mdt"
android:defaultValue="xx:xx:xx:xx:xx:xx"
android:editable="false"
android:inputType="textFilter"
android:key="pref_rileylink_mac_address"
android:selectAllOnFocus="true"
android:singleLine="true"
android:title="@string/rileylink_mac_address" />
-->
</PreferenceCategory> </PreferenceCategory>
</PreferenceScreen> </PreferenceScreen>