Skip to content

Commit

Permalink
Merge pull request #10 from jgslade/EN-MASTER
Browse files Browse the repository at this point in the history
Dexcom G7 enablement patches and Dash Connection Improvements
  • Loading branch information
dicko72 authored Jun 28, 2023
2 parents b5cb379 + 313f0d6 commit 4004619
Show file tree
Hide file tree
Showing 55 changed files with 4,004 additions and 83 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
<action android:name="it.ct.glicemia.ACTION_GLUCOSE_MEASURED" />
<!-- Receiver from Dexcom -->
<action android:name="com.dexcom.cgm.EXTERNAL_BROADCAST" />
<action android:name="com.dexcom.g7.EXTERNAL_BROADCAST" />
<!-- Receiver from Poctech -->
<action android:name="com.china.poctech.data" />
<!-- Receiver from Tomato -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
val graphData = GraphData(injector, binding.bgGraph, historyBrowserData.overviewData)
val menuChartSettings = overviewMenus.setting
graphData.addInRangeArea(historyBrowserData.overviewData.fromTime, historyBrowserData.overviewData.endTime, defaultValueHelper.determineLowLine(), defaultValueHelper.determineHighLine())
graphData.addBgReadings(menuChartSettings[0][OverviewMenus.CharType.PRE.ordinal], context)
graphData.addBgReadings(menuChartSettings[0][OverviewMenus.CharType.PRE.ordinal], menuChartSettings[0][OverviewMenus.CharType.RAW.ordinal], context)
if (buildHelper.isDev()) graphData.addBucketedData()
graphData.addTreatments(context)
graphData.addEps(context, 0.95)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import info.nightscout.androidaps.database.entities.ValueWithUnit
import info.nightscout.androidaps.database.transactions.InsertAndCancelCurrentTemporaryTargetTransaction
import info.nightscout.androidaps.databinding.DialogCarbsBinding
import info.nightscout.androidaps.extensions.formatColor
import info.nightscout.androidaps.extensions.rawOrSmoothed
import info.nightscout.androidaps.interfaces.*
import info.nightscout.shared.logging.LTag
import info.nightscout.androidaps.logging.UserEntryLogger
Expand Down Expand Up @@ -184,7 +185,7 @@ class CarbsDialog : DialogFragmentWithDate() {
}

iobCobCalculator.ads.actualBg()?.let { bgReading ->
if (bgReading.value < 72)
if (bgReading.rawOrSmoothed(sp) < 72)
binding.hypoTt.isChecked = true
}
binding.hypoTt.setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ class WizardDialog : DaggerDialogFragment() {
binding.bgInput.step = if (units == GlucoseUnit.MGDL) 1.0 else 0.1

// Set BG if not old
binding.bgInput.value = iobCobCalculator.ads.actualBg()?.valueToUnits(units) ?: 0.0
binding.bgInput.value = iobCobCalculator.ads.actualBg()?.valueToUnits(units, sp) ?: 0.0

binding.ttCheckbox.isEnabled = tempTarget is ValueWrapper.Existing
binding.ttCheckboxIcon.visibility = binding.ttCheckbox.isEnabled.toVisibility()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class BGDatum {
constructor(json: JSONObject, dateUtil: DateUtil) {
this.dateUtil = dateUtil
try {
//if (json.has("_id")) id = json.getLong("_id")
if (json.has("_id")) id = json.getLong("_id")
if (json.has("date")) date = json.getLong("date")
if (json.has("sgv")) value = json.getDouble("sgv")
if (json.has("direction")) direction = TrendArrow.fromString(json.getString("direction"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ class OverviewData @Inject constructor(

val isLow: Boolean
get() = lastBg?.let { lastBg ->
lastBg.valueToUnits(profileFunction.getUnits()) < defaultValueHelper.determineLowLine()
lastBg.valueToUnits(profileFunction.getUnits(), sp) < defaultValueHelper.determineLowLine()
} ?: false

val isHigh: Boolean
get() = lastBg?.let { lastBg ->
lastBg.valueToUnits(profileFunction.getUnits()) > defaultValueHelper.determineHighLine()
lastBg.valueToUnits(profileFunction.getUnits(), sp) > defaultValueHelper.determineHighLine()
} ?: false

@ColorInt
Expand Down Expand Up @@ -249,6 +249,7 @@ class OverviewData @Inject constructor(
var maxBgValue = Double.MIN_VALUE
var bucketedGraphSeries: PointsWithLabelGraphSeries<DataPointWithLabelInterface> = PointsWithLabelGraphSeries()
var bgReadingGraphSeries: PointsWithLabelGraphSeries<DataPointWithLabelInterface> = PointsWithLabelGraphSeries()
var bgReadingRawGraphSeries: PointsWithLabelGraphSeries<DataPointWithLabelInterface> = PointsWithLabelGraphSeries()
var predictionsGraphSeries: PointsWithLabelGraphSeries<DataPointWithLabelInterface> = PointsWithLabelGraphSeries()

val basalScale = Scale()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
val lastBgDescription = overviewData.lastBgDescription
runOnUiThread {
_binding ?: return@runOnUiThread
binding.infoLayout.bg.text = lastBg?.valueToUnitsString(units)
binding.infoLayout.bg.text = lastBg?.valueToUnitsString(units, sp)
?: rh.gs(R.string.notavailable)
binding.infoLayout.bg.setTextColor(lastBgColor)
binding.infoLayout.arrow.setImageResource(trendArrow.directionToIcon())
Expand Down Expand Up @@ -1010,7 +1010,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
val menuChartSettings = overviewMenus.setting
if (menuChartSettings.isEmpty()) return
graphData.addInRangeArea(overviewData.fromTime, overviewData.endTime, defaultValueHelper.determineLowLine(), defaultValueHelper.determineHighLine())
graphData.addBgReadings(menuChartSettings[0][OverviewMenus.CharType.PRE.ordinal], context)
graphData.addBgReadings(menuChartSettings[0][OverviewMenus.CharType.PRE.ordinal], menuChartSettings[0][OverviewMenus.CharType.RAW.ordinal], context)
if (buildHelper.isDev()) graphData.addBucketedData()
graphData.addTreatments(context)
graphData.addEps(context, 0.95)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class OverviewMenus @Inject constructor(
) {

enum class CharType(@StringRes val nameId: Int, @AttrRes val attrId: Int, @AttrRes val attrTextId: Int, val primary: Boolean, val secondary: Boolean, @StringRes val shortnameId: Int) {
RAW(R.string.overview_show_raw_bg, R.attr.defaultTextColor, R.attr.menuTextColorInverse, primary = true, secondary = false, shortnameId = R.string.activity_shortname),
PRE(R.string.overview_show_predictions, R.attr.predictionColor, R.attr.menuTextColor, primary = true, secondary = false, shortnameId = R.string.prediction_shortname),
TREAT(R.string.overview_show_treatments, R.attr.cobColor, R.attr.menuTextColor, primary = true, secondary = false, shortnameId = R.string.treatments_shortname),
BAS(R.string.overview_show_basals, R.attr.basal, R.attr.menuTextColor, primary = true, secondary = false, shortnameId = R.string.basal_shortname),
Expand Down Expand Up @@ -126,6 +127,7 @@ class OverviewMenus @Inject constructor(
if (g == 0 && !m.primary) return@forEach
if (g > 0 && !m.secondary) return@forEach
var insert = true
if (m == CharType.RAW) insert = sp.getBoolean(info.nightscout.androidaps.core.R.string.key_use_data_smoothing, false)
if (m == CharType.PRE) insert = predictionsAvailable
if (m == CharType.DEVSLOPE) insert = buildHelper.isDev()
if (used.contains(m.ordinal)) insert = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ class GraphData(
addSeries(overviewData.bucketedGraphSeries)
}

fun addBgReadings(addPredictions: Boolean, context: Context?) {
fun addBgReadings(addPredictions: Boolean, addRawBg: Boolean, context: Context?) {
maxY = if (overviewData.bgReadingsArray.isEmpty()) {
if (units == GlucoseUnit.MGDL) 180.0 else 10.0
} else overviewData.maxBgValue
minY = 0.0
if (addRawBg && !overviewData.bgReadingRawGraphSeries.isEmpty) addSeries(overviewData.bgReadingRawGraphSeries)
addSeries(overviewData.bgReadingGraphSeries)
if (addPredictions) addSeries(overviewData.predictionsGraphSeries)
overviewData.bgReadingGraphSeries.setOnDataPointTapListener { _, dataPoint ->
Expand Down Expand Up @@ -93,7 +94,7 @@ class GraphData(
maxY = maxOf(maxY, overviewData.maxTreatmentsValue)
addSeries(overviewData.treatmentsSeries)
overviewData.treatmentsSeries.setOnDataPointTapListener { _, dataPoint ->
if (dataPoint is BolusDataPoint) ToastUtils.showToastInUiThread(context, dataPoint.label)
if (dataPoint is BolusDataPoint) ToastUtils.infoToast(context, dataPoint.label)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import android.content.Context
import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.core.R
import info.nightscout.androidaps.database.entities.GlucoseValue
import info.nightscout.androidaps.extensions.rawOrSmoothed
import info.nightscout.androidaps.extensions.useDataSmoothing
import info.nightscout.androidaps.interfaces.GlucoseUnit
import info.nightscout.androidaps.interfaces.Profile
import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.interfaces.ResourceHelper
import info.nightscout.androidaps.utils.DefaultValueHelper
import info.nightscout.shared.sharedPreferences.SP

class GlucoseValueDataPoint(
val data: GlucoseValue,
Expand All @@ -17,22 +20,51 @@ class GlucoseValueDataPoint(
private val rh: ResourceHelper
) : DataPointWithLabelInterface {

private var useSmoothed : Boolean = false
private var isAdditional : Boolean = false

constructor(data: GlucoseValue,
defaultValueHelper: DefaultValueHelper,
profileFunction: ProfileFunction,
rh: ResourceHelper,
useSmoothed: Boolean,
isAdditional: Boolean = false) : this(
data,
defaultValueHelper,
profileFunction,
rh) {
this.useSmoothed = useSmoothed
this.isAdditional = isAdditional
}

constructor(data: GlucoseValue,
defaultValueHelper: DefaultValueHelper,
profileFunction: ProfileFunction,
rh: ResourceHelper,
sp: SP) : this(
data,
defaultValueHelper,
profileFunction,
rh) {
useSmoothed = useDataSmoothing(sp)
}
fun valueToUnits(units: GlucoseUnit): Double =
if (units == GlucoseUnit.MGDL) data.value else data.value * Constants.MGDL_TO_MMOLL
if (units == GlucoseUnit.MGDL) data.rawOrSmoothed(useSmoothed) else data.rawOrSmoothed(useSmoothed) * Constants.MGDL_TO_MMOLL

override fun getX(): Double = data.timestamp.toDouble()
override fun getY(): Double = valueToUnits(profileFunction.getUnits())

override fun setY(y: Double) {}
override val label: String = Profile.toCurrentUnitsString(profileFunction, data.value)
override val label: String = Profile.toCurrentUnitsString(profileFunction, data.rawOrSmoothed(useSmoothed))
override val duration = 0L
override val shape get() = if (isPrediction) PointsWithLabelGraphSeries.Shape.PREDICTION else PointsWithLabelGraphSeries.Shape.BG
override val size = 1f
override val size get() = if (isAdditional) 0.5f else 1f
override fun color(context: Context?): Int {
val units = profileFunction.getUnits()
val lowLine = defaultValueHelper.determineLowLine()
val highLine = defaultValueHelper.determineHighLine()
return when {
isAdditional -> rh.gac(context, R.attr.defaultTextColor)
isPrediction -> predictionColor(context)
valueToUnits(units) < lowLine -> rh.gac(context, R.attr.bgLow)
valueToUnits(units) > highLine -> rh.gac(context, R.attr.highColor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ import info.nightscout.androidaps.data.InMemoryGlucoseValue
import info.nightscout.androidaps.interfaces.GlucoseUnit
import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.interfaces.ResourceHelper
import info.nightscout.shared.sharedPreferences.SP

class InMemoryGlucoseValueDataPoint(
val data: InMemoryGlucoseValue,
private val profileFunction: ProfileFunction,
private val rh: ResourceHelper
private val rh: ResourceHelper,
private val sp: SP
) : DataPointWithLabelInterface {

fun valueToUnits(units: GlucoseUnit): Double =
if (units == GlucoseUnit.MGDL) data.value else data.value * Constants.MGDL_TO_MMOLL
if (units == GlucoseUnit.MGDL) data.rawOrSmoothed(sp)
else data.rawOrSmoothed(sp) * Constants.MGDL_TO_MMOLL

override fun getX(): Double = data.timestamp.toDouble()
override fun getY(): Double = valueToUnits(profileFunction.getUnits())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.interfaces.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.shared.sharedPreferences.SP
import io.reactivex.rxjava3.disposables.CompositeDisposable
import io.reactivex.rxjava3.kotlin.plusAssign
import javax.inject.Inject
Expand All @@ -34,6 +35,7 @@ class PersistentNotificationPlugin @Inject constructor(
injector: HasAndroidInjector,
aapsLogger: AAPSLogger,
rh: ResourceHelper,
private val sp: SP,
private val aapsSchedulers: AapsSchedulers,
private val profileFunction: ProfileFunction,
private val fabricPrivacy: FabricPrivacy,
Expand Down Expand Up @@ -112,7 +114,7 @@ class PersistentNotificationPlugin @Inject constructor(
val lastBG = iobCobCalculator.ads.lastBg()
val glucoseStatus = glucoseStatusProvider.glucoseStatusData
if (lastBG != null) {
line1aa = lastBG.valueToUnitsString(units)
line1aa = lastBG.valueToUnitsString(units, sp)
line1 = line1aa
if (glucoseStatus != null) {
line1 += (" Δ" + Profile.toSignedUnitsString(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, units)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,11 @@ class SmsCommunicatorPlugin @Inject constructor(
var reply = ""
val units = profileFunction.getUnits()
if (actualBG != null) {
reply = rh.gs(R.string.sms_actualbg) + " " + actualBG.valueToUnitsString(units) + ", "
reply = rh.gs(R.string.sms_actualbg) + " " + actualBG.valueToUnitsString(units, sp) + ", "
} else if (lastBG != null) {
val agoMilliseconds = dateUtil.now() - lastBG.timestamp
val agoMin = (agoMilliseconds / 60.0 / 1000.0).toInt()
reply = rh.gs(R.string.sms_lastbg) + " " + lastBG.valueToUnitsString(units) + " " + rh.gs(R.string.sms_minago, agoMin) + ", "
reply = rh.gs(R.string.sms_lastbg) + " " + lastBG.valueToUnitsString(units, sp) + " " + rh.gs(R.string.sms_minago, agoMin) + ", "
}
val glucoseStatus = glucoseStatusProvider.glucoseStatusData
if (glucoseStatus != null) reply += rh.gs(R.string.sms_delta) + " " + Profile.toUnitsString(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, units) + " " + units + ", "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ class DataHandlerMobile @Inject constructor(
tempTarget = tempTarget,
carbs = carbsAfterConstraints,
cob = cobInfo.displayCob!!,
bg = bgReading.valueToUnits(profileFunction.getUnits()),
bg = bgReading.valueToUnits(profileFunction.getUnits(), sp),
correction = 0.0,
percentageCorrection = percentage,
useBg = sp.getBoolean(R.string.key_wearwizard_bg, true),
Expand Down Expand Up @@ -830,7 +830,7 @@ class DataHandlerMobile @Inject constructor(
val finalLastRun = loop.lastRun
if (sp.getBoolean("wear_predictions", true) && finalLastRun?.request?.hasPredictions == true && finalLastRun.constraintsProcessed != null) {
val predArray = finalLastRun.constraintsProcessed!!.predictions
.stream().map { bg: GlucoseValue -> GlucoseValueDataPoint(bg, defaultValueHelper, profileFunction, rh) }
.stream().map { bg: GlucoseValue -> GlucoseValueDataPoint(bg, defaultValueHelper, profileFunction, rh, sp) }
.collect(Collectors.toList())
if (predArray.isNotEmpty())
for (bg in predArray) if (bg.data.value > 39)
Expand Down Expand Up @@ -917,7 +917,7 @@ class DataHandlerMobile @Inject constructor(

return EventData.SingleBg(
timeStamp = glucoseValue.timestamp,
sgvString = glucoseValue.valueToUnitsString(units),
sgvString = glucoseValue.valueToUnitsString(units, sp),
glucoseUnits = units.asText,
slopeArrow = trendCalculator.getTrendArrow(glucoseValue).symbol,
delta = glucoseStatus?.let { deltaString(it.delta, it.delta * Constants.MGDL_TO_MMOLL, units) } ?: "--",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class IobCobCalculatorPlugin @Inject constructor(
private var iobTable = LongSparseArray<IobTotal>() // oldest at index 0
private var basalDataTable = LongSparseArray<BasalData>() // oldest at index 0

override var ads: AutosensDataStore = AutosensDataStore()
override var ads: AutosensDataStore = AutosensDataStore(sp)

private val dataLock = Any()
private var thread: Thread? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@ class IobCobOref1Worker(
//console.error(bgTime , bucketed_data[i].glucose);
var avgDelta: Double
var delta: Double
val bg: Double = bucketedData[i].value
if (bg < 39 || bucketedData[i + 3].value < 39) {
val bg: Double = bucketedData[i].rawOrSmoothed(sp)
if (bg < 39 || bucketedData[i + 3].rawOrSmoothed(sp) < 39) {
aapsLogger.error("! value < 39")
continue
}
autosensData.bg = bg
delta = bg - bucketedData[i + 1].value
avgDelta = (bg - bucketedData[i + 3].value) / 3
delta = bg - bucketedData[i + 1].rawOrSmoothed(sp)
avgDelta = (bg - bucketedData[i + 3].rawOrSmoothed(sp)) / 3
val iob = data.iobCobCalculator.calculateFromTreatmentsAndTemps(bgTime, profile)
val bgi = -iob.activity * sens * 5
val deviation = delta - bgi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,14 @@ class IobCobOrefWorker @Inject internal constructor(
//console.error(bgTime , bucketed_data[i].glucose);
var avgDelta: Double
var delta: Double
val bg: Double = bucketedData[i].value
if (bg < 39 || bucketedData[i + 3].value < 39) {
val bg: Double = bucketedData[i].rawOrSmoothed(sp)
if (bg < 39 || bucketedData[i + 3].rawOrSmoothed(sp) < 39) {
aapsLogger.error("! value < 39")
continue
}
autosensData.bg = bg
delta = bg - bucketedData[i + 1].value
avgDelta = (bg - bucketedData[i + 3].value) / 3
delta = bg - bucketedData[i + 1].rawOrSmoothed(sp)
avgDelta = (bg - bucketedData[i + 3].rawOrSmoothed(sp)) / 3
val iob = data.iobCobCalculatorPlugin.calculateFromTreatmentsAndTemps(bgTime, profile)
val bgi = -iob.activity * sens * 5
val deviation = delta - bgi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class AidexPlugin @Inject constructor(
glucoseValues += CgmSourceTransaction.TransactionGlucoseValue(
timestamp = timestamp,
value = bgValueTarget,
smoothed = null,
raw = null,
noise = null,
trendArrow = GlucoseValue.TrendArrow.fromString(bundle.getString(Intents.AIDEX_BG_SLOPE_NAME)),
Expand Down
Loading

0 comments on commit 4004619

Please sign in to comment.