Skip to content

[WIP] Apex TruCare III insulin pump driver #3896

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 31 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d3574f0
Initial Apex TruCare III plugin
tdrkDev Feb 19, 2025
57ea58e
apex: fix TBR and add pump icon to the fragmentFix TBR and add pump i…
tdrkDev Feb 19, 2025
77bc791
Apex: bug fixes
tdrkDev Feb 21, 2025
562b4fa
apex: remove extended bolus capability
tdrkDev Feb 22, 2025
680def9
constraints: Respect pump bolus and basal dynamic constraints
tdrkDev Feb 22, 2025
d84524e
apex: fix reservoir value text
tdrkDev Feb 22, 2025
372a762
apex: add reservoir value to short status
tdrkDev Feb 22, 2025
9c7c80c
apex: do not report pump as busy
tdrkDev Feb 22, 2025
ad196bd
apex: report max bolus size
tdrkDev Feb 22, 2025
069826c
apex: service: fix race condition in getValue
tdrkDev Feb 22, 2025
07442af
apex: rework isThisProfileSet implementation
tdrkDev Feb 22, 2025
a68369a
apex: fix threading issues
tdrkDev Feb 22, 2025
3d73276
apex: rework bolus state sync
tdrkDev Feb 25, 2025
22f66d1
apex: increase timeouts
tdrkDev Feb 25, 2025
b2cd66a
apex: increase battery change percentage trigger
tdrkDev Feb 25, 2025
f637ce8
apex: status/settings V1 scheme update
tdrkDev Feb 25, 2025
29767b3
apex: new strings
tdrkDev Feb 25, 2025
6166a31
apex: bluetooth: change delays and rework logging
tdrkDev Feb 25, 2025
5f9039c
apex: round basal using DoseStepSize precision
tdrkDev Feb 25, 2025
a0d56c4
apex: plugin: implement new bolus sync as in service
tdrkDev Feb 25, 2025
83baaaf
apex: improve alarms handling
tdrkDev Feb 25, 2025
dfba9e4
apex: make critical sections synchronized
tdrkDev Feb 25, 2025
6a8e801
Merge remote-tracking branch 'origin/dev' into dev-apex
tdrkDev Mar 4, 2025
a815895
apex: initial 4.11 protocol support
tdrkDev Mar 18, 2025
809623b
apex: fragment: fix voltage visibility logic
tdrkDev Mar 18, 2025
71a571c
Merge remote-tracking branch 'origin/dev' into dev-apex
tdrkDev Mar 18, 2025
ce4126b
apex: do not handle fake bolus entry
tdrkDev Mar 20, 2025
51264bb
apex: more aggressive reconnects
tdrkDev Mar 20, 2025
333b911
apex: rework reconnect
tdrkDev Mar 20, 2025
30a08e8
apex: add pretty icon to the fragment
sexytrigger Mar 20, 2025
4cd5055
apex: fix exact battery percentage getString
tdrkDev Mar 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ dependencies {
implementation(project(":implementation"))
implementation(project(":database:impl"))
implementation(project(":database:persistence"))
implementation(project(":pump:apex"))
implementation(project(":pump:combov2"))
implementation(project(":pump:dana"))
implementation(project(":pump:danars"))
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/kotlin/app/aaps/di/AppComponent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import app.aaps.plugins.main.di.PluginsModule
import app.aaps.plugins.source.di.SourceModule
import app.aaps.plugins.sync.di.OpenHumansModule
import app.aaps.plugins.sync.di.SyncModule
import app.aaps.pump.apex.di.ApexModule
import app.aaps.pump.common.di.PumpCommonModule
import app.aaps.pump.dana.di.DanaHistoryModule
import app.aaps.pump.dana.di.DanaModule
Expand Down Expand Up @@ -88,6 +89,7 @@ import javax.inject.Singleton
RileyLinkModule::class,
MedtrumModule::class,
EquilModule::class,
ApexModule::class,
VirtualPumpModule::class
]
)
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/kotlin/app/aaps/di/PluginsListModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import app.aaps.pump.medtrum.MedtrumPlugin
import app.aaps.pump.omnipod.dash.OmnipodDashPumpPlugin
import app.aaps.pump.omnipod.eros.OmnipodErosPumpPlugin
import app.aaps.pump.virtual.VirtualPumpPlugin
import app.aaps.pump.apex.ApexPumpPlugin
import dagger.Binds
import dagger.Module
import dagger.multibindings.IntKey
Expand Down Expand Up @@ -222,6 +223,12 @@ abstract class PluginsListModule {
@IntKey(170)
abstract fun bindEquilPumpPlugin(plugin: EquilPumpPlugin): PluginBase

@Binds
@PumpDriver
@IntoMap
@IntKey(171)
abstract fun bindApexPumpPlugin(plugin: ApexPumpPlugin): PluginBase

@Binds
@AllConfigs
@IntoMap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ enum class DoseStepSize(private val entries: Array<DoseStepSizeEntry>) {
DoseStepSizeEntry(2.0, 15.0, 0.1),
DoseStepSizeEntry(15.0, 40.0, 0.5)
)
),
Apex(
arrayOf(
DoseStepSizeEntry(0.0, 1.0, 0.025),
DoseStepSizeEntry(1.0, 2.0, 0.05),
DoseStepSizeEntry(2.0, Double.MAX_VALUE, 0.1)
)
);

fun getStepSizeForAmount(amount: Double): Double {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ enum class ManufacturerType(val description: String) {
Ypsomed("Ypsomed"),
G2e("G2e"),
Eoflow("Eoflow"),
Equil("Equil");

Equil("Equil"),
Apex("APEX");
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ enum class PumpCapability {
DiaconnCapabilities(arrayOf(Capability.Bolus, Capability.ExtendedBolus, Capability.TempBasal, Capability.BasalProfileSet, Capability.Refill, Capability.ReplaceBattery, Capability.TDD, Capability.ManualTDDLoad)), //
EopatchCapabilities(arrayOf(Capability.Bolus, Capability.ExtendedBolus, Capability.TempBasal, Capability.BasalProfileSet, Capability.BasalRate30min)),
MedtrumCapabilities(arrayOf(Capability.Bolus, Capability.TempBasal, Capability.BasalProfileSet, Capability.BasalRate30min, Capability.TDD)), // Technically the pump supports ExtendedBolus, but not implemented (yet)
ApexCapabilities(arrayOf(Capability.Bolus, Capability.TempBasal, Capability.BasalProfileSet, Capability.BasalRate30min, Capability.TDD, Capability.ManualTDDLoad, Capability.ReplaceBattery, Capability.Refill))
;

var children: ArrayList<Capability> = ArrayList()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package app.aaps.core.data.pump.defs

class PumpDescription {
open class PumpDescription {

var pumpType = PumpType.GENERIC_AAPS
var isBolusCapable = false
Expand All @@ -25,6 +25,7 @@ class PumpDescription {
var basalMaximumRate = 0.0
var isRefillingCapable = false
var isBatteryReplaceable = false
var maxBolusSize = 0.0

//var storesCarbInfo = false
var is30minBasalRatesCapable = false
Expand Down Expand Up @@ -64,6 +65,7 @@ class PumpDescription {
needsManualTDDLoad = true
hasCustomUnreachableAlertCheck = false
useHardwareLink = false
maxBolusSize = 0.0
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,22 @@ enum class PumpType(
pumpCapability = PumpCapability.DiaconnCapabilities,
source = Source.EQuil,
useHardwareLink = true,
),
APEX_TRUCARE_III(
description = "APEX TruCare III",
manufacturer = ManufacturerType.Apex,
model = "TruCare III",
extendedBolusSettings = DoseSettings(0.025, 15, 24 * 60, 0.025),
tbrSettings = DoseSettings(0.025, 15, 24 * 60, 0.0),
pumpTempBasalType = PumpTempBasalType.Absolute,
bolusSize = 0.025,
baseBasalMinValue = 0.025,
baseBasalStep = 0.025,
baseBasalSpecialSteps = DoseStepSize.Apex,
specialBolusSize = DoseStepSize.Apex,
pumpCapability = PumpCapability.ApexCapabilities,
source = Source.ApexTruCareIII,
useHardwareLink = true,
);

fun manufacturer() = parent?.manufacturer ?: manufacturer ?: throw IllegalStateException()
Expand Down Expand Up @@ -511,7 +527,8 @@ enum class PumpType(
MDI,
VirtualPump,
Unknown,
EQuil
EQuil,
ApexTruCareIII
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ data class InterfaceIDs @Ignore constructor(
MEDTRUM_UNTESTED,
USER,
CACHE,
EQUIL;
EQUIL,
APEX_TRUCARE_III;

companion object {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ fun InterfaceIDs.PumpType.fromDb(): PumpType =
InterfaceIDs.PumpType.MEDTRUM_UNTESTED -> PumpType.MEDTRUM_UNTESTED
InterfaceIDs.PumpType.CACHE -> PumpType.CACHE
InterfaceIDs.PumpType.EQUIL -> PumpType.EQUIL
InterfaceIDs.PumpType.APEX_TRUCARE_III -> PumpType.APEX_TRUCARE_III
}

fun PumpType.toDb(): InterfaceIDs.PumpType =
Expand Down Expand Up @@ -83,5 +84,6 @@ fun PumpType.toDb(): InterfaceIDs.PumpType =
PumpType.MEDTRUM_UNTESTED -> InterfaceIDs.PumpType.MEDTRUM_UNTESTED
PumpType.CACHE -> InterfaceIDs.PumpType.CACHE
PumpType.EQUIL -> InterfaceIDs.PumpType.EQUIL
PumpType.APEX_TRUCARE_III -> InterfaceIDs.PumpType.APEX_TRUCARE_III

}
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ class SafetyPlugin @Inject constructor(
if (pump.pumpDescription.tempBasalStyle == PumpDescription.ABSOLUTE) {
val pumpLimit = pump.pumpDescription.pumpType.tbrSettings()?.maxDose ?: 0.0
absoluteRate.setIfSmaller(pumpLimit, rh.gs(app.aaps.core.ui.R.string.limitingbasalratio, pumpLimit, rh.gs(app.aaps.core.ui.R.string.pumplimit)), this)

// Not all pumps have dynamic TBR constraint
val dynamicPumpLimit = pump.pumpDescription.maxTempAbsolute
if (dynamicPumpLimit > 0.0) absoluteRate.setIfSmaller(dynamicPumpLimit, rh.gs(app.aaps.core.ui.R.string.limitingbasalratio, dynamicPumpLimit, rh.gs(app.aaps.core.ui.R.string.pumplimit)), this)
}

// do rounding
Expand Down Expand Up @@ -149,6 +153,12 @@ class SafetyPlugin @Inject constructor(
insulin.setIfSmaller(maxBolus, rh.gs(app.aaps.core.ui.R.string.limitingbolus, maxBolus, rh.gs(R.string.maxvalueinpreferences)), this)
insulin.setIfSmaller(hardLimits.maxBolus(), rh.gs(app.aaps.core.ui.R.string.limitingbolus, hardLimits.maxBolus(), rh.gs(R.string.hardlimit)), this)
val pump = activePlugin.activePump
val dynamicPumpLimit = pump.pumpDescription.maxBolusSize
if (dynamicPumpLimit > 0.0) {
// Not all pumps have dynamic bolus size constraint
insulin.setIfSmaller(dynamicPumpLimit, rh.gs(app.aaps.core.ui.R.string.limitingbolus, dynamicPumpLimit, rh.gs(app.aaps.core.ui.R.string.pumplimit)), this)
}

val rounded = pump.pumpDescription.pumpType.determineCorrectBolusSize(insulin.value())
insulin.setIfDifferent(rounded, rh.gs(app.aaps.core.ui.R.string.pumplimit), this)
return insulin
Expand Down
1 change: 1 addition & 0 deletions pump/apex/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
31 changes: 31 additions & 0 deletions pump/apex/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
plugins {
alias(libs.plugins.android.library)
id("kotlin-android")
id("kotlin-kapt")
id("android-module-dependencies")
id("test-module-dependencies")
id("jacoco-module-dependencies")
}

android {
namespace = "app.aaps.pump.apex"
buildFeatures {
dataBinding = true
}
}

dependencies {
implementation(project(":core:data"))
implementation(project(":core:interfaces"))
implementation(project(":core:keys"))
implementation(project(":core:libraries"))
implementation(project(":core:objects"))
implementation(project(":core:ui"))
implementation(project(":core:utils"))
implementation(project(":core:validators"))
implementation(project(":pump:pump-common"))
testImplementation(project(":shared:tests"))

kapt(libs.com.google.dagger.compiler)
kapt(libs.com.google.dagger.android.processor)
}
21 changes: 21 additions & 0 deletions pump/apex/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
17 changes: 17 additions & 0 deletions pump/apex/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

<application>
<service
android:name=".ApexService"
android:enabled="true"
android:exported="false" />
</application>

</manifest>
Loading