From e286b9e3c26c0f4b4c589990bd7d038c74980f40 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Thu, 7 Dec 2017 23:36:34 +0100 Subject: [PATCH] RuffyScripter: read/infer pump time from menu. --- .../src/main/java/de/jotomo/ruffy/spi/PumpState.java | 5 ++++- .../java/de/jotomo/ruffyscripter/RuffyScripter.java | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/PumpState.java b/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/PumpState.java index 77fa0c6ef1..d646de7f63 100644 --- a/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/PumpState.java +++ b/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/PumpState.java @@ -2,8 +2,11 @@ package de.jotomo.ruffy.spi; /** State displayed on the main screen of the pump. */ public class PumpState { - /** Time the state was captured. This is NOT the pump's time! */ + /** Time the state was captured. */ public long timestamp; + /** Pump time. Note that this is derived from the time displayed on the main menu and assumes + * the date is set correctly */ + public long pumpTime; public String menu = null; public boolean suspended; diff --git a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java index c8d7d20bf9..7e78a4816b 100644 --- a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java +++ b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java @@ -22,6 +22,7 @@ import org.monkey.d.ruffy.ruffy.driver.display.menu.MenuTime; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.Date; import java.util.List; import java.util.Objects; @@ -509,12 +510,22 @@ public class RuffyScripter implements RuffyCommands { } state.batteryState = ((int) menu.getAttribute(MenuAttribute.BATTERY_STATE)); state.insulinState = ((int) menu.getAttribute(MenuAttribute.INSULIN_STATE)); + MenuTime time = (MenuTime) menu.getAttribute(MenuAttribute.TIME); + Date date = new Date(); + date.setHours(time.getHour()); + date.setMinutes(time.getMinute()); + state.pumpTime = date.getTime(); } else if (menuType == MenuType.WARNING_OR_ERROR) { state.activeAlert = readWarningOrErrorCode(); } else if (menuType == MenuType.STOP) { state.suspended = true; state.batteryState = ((int) menu.getAttribute(MenuAttribute.BATTERY_STATE)); state.insulinState = ((int) menu.getAttribute(MenuAttribute.INSULIN_STATE)); + MenuTime time = (MenuTime) menu.getAttribute(MenuAttribute.TIME); + Date date = new Date(); + date.setHours(time.getHour()); + date.setMinutes(time.getMinute()); + state.pumpTime = date.getTime(); } return state;