- fix for task #126 - battery display, it will work for Alakaline and Lithium battery, but probably not for recharchargables
This commit is contained in:
parent
5a7146d3a9
commit
67862d3385
|
@ -481,7 +481,7 @@ public class MedtronicFragment extends SubscriberFragment {
|
|||
}
|
||||
|
||||
// battery
|
||||
batteryView.setText("{fa-battery-" + (pumpStatus.batteryRemaining / 25) + "}");
|
||||
batteryView.setText("{fa-battery-" + (pumpStatus.batteryRemaining / 25) + "} " + pumpStatus.batteryRemaining + "%");
|
||||
SetWarnColor.setColorInverse(batteryView, pumpStatus.batteryRemaining, 51d, 26d);
|
||||
|
||||
// reservoir
|
||||
|
|
|
@ -135,7 +135,6 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
medtronicService = null;
|
||||
}
|
||||
|
||||
|
||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||
if (isLoggingEnabled())
|
||||
LOG.debug("RileyLinkMedtronicService is connected");
|
||||
|
@ -285,7 +284,6 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
|
||||
@Override
|
||||
public boolean isInitialized() {
|
||||
// TODO remove
|
||||
if (isLoggingEnabled() && displayConnectionMessages)
|
||||
LOG.debug("MedtronicPumpPlugin::isInitialized");
|
||||
return isServiceSet() && isInitialized;
|
||||
|
@ -532,8 +530,6 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
|
||||
readPumpHistory();
|
||||
|
||||
// TODO rewrite reading of data to be done in background or different thread perhaps ??
|
||||
|
||||
// remaining insulin (>50 = 4h; 50-20 = 1h; 15m)
|
||||
medtronicUIComm.executeCommand(MedtronicCommandType.GetRemainingInsulin);
|
||||
scheduleNextRefresh(MedtronicStatusRefreshType.RemainingInsulin, 10);
|
||||
|
|
|
@ -172,7 +172,7 @@ public class MedtronicConverter {
|
|||
// if response in 3 bytes then we add additional information
|
||||
// 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;
|
||||
|
||||
|
|
|
@ -100,10 +100,14 @@ public class MedtronicUIPostprocessor {
|
|||
case GetBatteryStatus: {
|
||||
BatteryStatusDTO batteryStatusDTO = (BatteryStatusDTO)uiTask.returnData;
|
||||
|
||||
if (batteryStatusDTO.batteryStatusType == BatteryStatusDTO.BatteryStatusType.Low)
|
||||
pumpStatus.batteryRemaining = 18;
|
||||
else
|
||||
pumpStatus.batteryRemaining = 70;
|
||||
pumpStatus.batteryRemaining = (batteryStatusDTO.getCalculatedPercent(pumpStatus.batteryType));
|
||||
|
||||
LOG.info("BatteryStatus: {}", batteryStatusDTO.toString());
|
||||
|
||||
// if (batteryStatusDTO.batteryStatusType == BatteryStatusDTO.BatteryStatusType.Low)
|
||||
// pumpStatus.batteryRemaining = 18;
|
||||
// else
|
||||
// pumpStatus.batteryRemaining = 70;
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
|
@ -12,15 +12,29 @@ public class BatteryStatusDTO {
|
|||
|
||||
@Expose
|
||||
public BatteryStatusType batteryStatusType;
|
||||
public double voltage;
|
||||
public Double voltage;
|
||||
|
||||
|
||||
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);
|
||||
|
||||
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 {
|
||||
Normal,
|
||||
Low,
|
||||
|
|
|
@ -144,8 +144,15 @@ public class TempBasalPair {
|
|||
return MedtronicUtil.createByteArray(list);
|
||||
}
|
||||
|
||||
public boolean isCancelTBR() {
|
||||
return (MedtronicUtil.isSame(insulinRate, 0.0d) && durationMinutes==0);
|
||||
}
|
||||
|
||||
|
||||
public String getDescription() {
|
||||
if (isCancelTBR()) {
|
||||
return "Cancel TBR";
|
||||
}
|
||||
|
||||
if (isPercent) {
|
||||
return String.format(Locale.ENGLISH, "Rate: %.0f%%, Duration: %d min", insulinRate, durationMinutes);
|
||||
|
|
|
@ -1,20 +1,45 @@
|
|||
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.
|
||||
*/
|
||||
|
||||
public enum BatteryType {
|
||||
|
||||
Alkaline(1.20f, 1.47f), //
|
||||
Lithium(1.32f, 1.58f);
|
||||
None(R.string.medtronic_pump_battery_no, 0, 0),
|
||||
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 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.highVoltage = highVoltage;
|
||||
}
|
||||
|
||||
public static BatteryType getByDescription(String batteryTypeStr) {
|
||||
if (mapByDescription.containsKey(batteryTypeStr)) {
|
||||
return mapByDescription.get(batteryTypeStr);
|
||||
}
|
||||
return BatteryType.None;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ public enum MedtronicStatusRefreshType {
|
|||
PumpHistory(5, null), //
|
||||
Configuration(0, null), //
|
||||
RemainingInsulin(-1, MedtronicCommandType.GetRemainingInsulin), //
|
||||
BatteryStatus(60, MedtronicCommandType.GetBatteryStatus), //
|
||||
BatteryStatus(55, MedtronicCommandType.GetBatteryStatus), //
|
||||
PumpTime(60, MedtronicCommandType.RealTimeClock) //
|
||||
;
|
||||
|
||||
|
|
|
@ -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.RileyLinkServiceState;
|
||||
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.PumpDeviceState;
|
||||
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 RileyLinkTargetFrequency targetFrequency;
|
||||
public BasalProfileStatus basalProfileStatus;
|
||||
public BatteryType batteryType = BatteryType.None;
|
||||
|
||||
|
||||
public MedtronicPumpStatus(PumpDescription pumpDescription) {
|
||||
|
@ -262,6 +264,14 @@ public class MedtronicPumpStatus extends PumpStatus {
|
|||
this.encodingChanged = true;
|
||||
}
|
||||
|
||||
String batteryTypeStr = SP.getString(MedtronicConst.Prefs.BatteryType, null);
|
||||
|
||||
BatteryType batteryType = BatteryType.getByDescription(batteryTypeStr);
|
||||
|
||||
if (this.batteryType != batteryType) {
|
||||
this.batteryType = batteryType;
|
||||
}
|
||||
|
||||
reconfigureService();
|
||||
|
||||
} catch (Exception ex) {
|
||||
|
|
|
@ -18,6 +18,7 @@ public class MedtronicConst {
|
|||
public static final String MaxBasal = PrefPrefix + "max_basal";
|
||||
public static final String BolusDelay = PrefPrefix + "bolus_delay";
|
||||
public static final String Encoding = PrefPrefix + "encoding";
|
||||
public static final String BatteryType = PrefPrefix + "battery_type";
|
||||
}
|
||||
|
||||
public class Statistics {
|
||||
|
|
|
@ -175,4 +175,10 @@
|
|||
<item>@string/medtronic_pump_encoding_4b6b_rileylink</item>
|
||||
</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>
|
||||
|
|
|
@ -1360,6 +1360,10 @@
|
|||
<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_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 -->
|
||||
<string name="rileylink_scanner_scan_scan">SCAN</string>
|
||||
|
|
|
@ -60,6 +60,14 @@
|
|||
android:selectable="true"
|
||||
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
|
||||
android:id="@+id/rileylink_mac_address_mdt"
|
||||
android:enabled="true"
|
||||
|
@ -67,22 +75,7 @@
|
|||
android:title="RileyLink Configuration"
|
||||
android:key="pref_rileylink_mac_address">
|
||||
<intent android:action="info.nightscout.androidaps.plugins.PumpCommon.dialog.RileyLinkBLEScanActivity" />
|
||||
|
||||
</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>
|
||||
</PreferenceScreen>
|
Loading…
Reference in a new issue