diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index 64d260c99d..6b0ac728e3 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -51,6 +51,7 @@ import info.nightscout.androidaps.plugins.general.nsclient.receivers.DBAccessRec import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin; import info.nightscout.androidaps.plugins.general.persistentNotification.PersistentNotificationPlugin; import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin; +import info.nightscout.androidaps.plugins.source.RandomBgPlugin; import info.nightscout.androidaps.utils.ActivityMonitor; import info.nightscout.androidaps.plugins.general.wear.WearPlugin; import info.nightscout.androidaps.plugins.general.xdripStatusline.StatuslinePlugin; @@ -212,6 +213,7 @@ public class MainApp extends Application { pluginsList.add(SourcePoctechPlugin.getPlugin()); pluginsList.add(SourceTomatoPlugin.getPlugin()); pluginsList.add(SourceEversensePlugin.getPlugin()); + if (engineeringMode) pluginsList.add(RandomBgPlugin.INSTANCE); if (!Config.NSCLIENT) pluginsList.add(SmsCommunicatorPlugin.INSTANCE); pluginsList.add(FoodPlugin.getPlugin()); diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/PluginDescription.java b/app/src/main/java/info/nightscout/androidaps/interfaces/PluginDescription.java index 5882c5870c..2929d3f21b 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/PluginDescription.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/PluginDescription.java @@ -29,8 +29,8 @@ public class PluginDescription { return this; } - public PluginDescription alwaysVisible(boolean alwayVisible) { - this.alwaysVisible = alwayVisible; + public PluginDescription alwaysVisible(boolean alwaysVisible) { + this.alwaysVisible = alwaysVisible; return this; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/source/RandomBgPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/source/RandomBgPlugin.kt new file mode 100644 index 0000000000..d4463e39bd --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/RandomBgPlugin.kt @@ -0,0 +1,76 @@ +package info.nightscout.androidaps.plugins.source + +import android.content.Intent +import android.os.Handler +import info.nightscout.androidaps.MainApp +import info.nightscout.androidaps.R +import info.nightscout.androidaps.db.BgReading +import info.nightscout.androidaps.interfaces.BgSourceInterface +import info.nightscout.androidaps.interfaces.PluginBase +import info.nightscout.androidaps.interfaces.PluginDescription +import info.nightscout.androidaps.interfaces.PluginType +import info.nightscout.androidaps.logging.L +import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin +import info.nightscout.androidaps.utils.DateUtil +import info.nightscout.androidaps.utils.T +import org.slf4j.LoggerFactory +import java.util.* +import kotlin.math.PI +import kotlin.math.sin + +object RandomBgPlugin : PluginBase(PluginDescription() + .mainType(PluginType.BGSOURCE) + .fragmentClass(BGSourceFragment::class.java.name) + .pluginName(R.string.randombg) + .shortName(R.string.randombg_short) + .description(R.string.description_source_randombg)), BgSourceInterface { + + private val log = LoggerFactory.getLogger(L.BGSOURCE) + + private val loopHandler = Handler() + private lateinit var refreshLoop: Runnable + + const val interval = 5L // minutes + + init { + refreshLoop = Runnable { + handleNewData(Intent()) + loopHandler.postDelayed(refreshLoop, T.mins(interval).msecs()) + } + } + + override fun advancedFilteringSupported(): Boolean { + return false + } + + override fun onStart() { + super.onStart() + loopHandler.postDelayed(refreshLoop, T.mins(interval).msecs()) + } + + override fun onStop() { + super.onStop() + loopHandler.removeCallbacks(refreshLoop) + } + + override fun specialEnableCondition(): Boolean { + return VirtualPumpPlugin.getPlugin().isEnabled(PluginType.PUMP) + } + + override fun handleNewData(intent: Intent) { + if (!isEnabled(PluginType.BGSOURCE)) return + val min = 70 + val max = 190 + + val cal = GregorianCalendar() + val currentMinute = cal.get(Calendar.MINUTE) + (cal.get(Calendar.HOUR_OF_DAY) % 2) * 60 + val bgMgdl = min + (max - min) * sin(currentMinute / 120.0 * 2 * PI) + + val bgReading = BgReading() + bgReading.value = bgMgdl + bgReading.date = DateUtil.now() + bgReading.raw = bgMgdl + MainApp.getDbHelper().createIfNotExists(bgReading, "RandomBG") + log.debug("Generated BG: $bgReading") + } +} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0ae7ebf708..60d2ecbdad 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1679,5 +1679,8 @@ Activity monitor Do you want to reset activity stats? Statistics + Random BG + Generate random BG data (Demo mode only) + BG