RandomBg source
This commit is contained in:
parent
b69af95791
commit
bb98ec94a5
4 changed files with 83 additions and 2 deletions
|
@ -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());
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
|
@ -1679,5 +1679,8 @@
|
|||
<string name="activitymonitor">Activity monitor</string>
|
||||
<string name="doyouwantresetstats">Do you want to reset activity stats?</string>
|
||||
<string name="statistics">Statistics</string>
|
||||
<string name="randombg">Random BG</string>
|
||||
<string name="description_source_randombg">Generate random BG data (Demo mode only)</string>
|
||||
<string name="randombg_short">BG</string>
|
||||
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue