Skip to content

Add CGM sensor state notes customization (cgm_sensor_notes) - #84

Open
bjorkert wants to merge 3 commits into
mainfrom
cgm_sensor_notes
Open

bjorkert wants to merge 3 commits into
mainfrom
cgm_sensor_notes

Conversation

@bjorkert

@bjorkert bjorkert commented Aug 29, 2026

Copy link
Copy Markdown
Member

Adds a customization that reports Dexcom sensor states without reliable glucose to Nightscout as Note treatments, for G7 and G5/G6. It mirrors the Trio implementation in nightscout/Trio#1420 and uses the same note wording, so records from both apps read alike.

The kits decide and name everything. A reading is reported when the kit's own hasReliableGlucose is false, and the note text is the kit's own name for the state: "CGM: sensorFailed", "CGM: questionMarks", "CGM: warmup", "CGM: .unknown(23)". No state table, titles or localizations live in the patch, so nothing can drift from the kits and states added by future firmware are covered as well. Lifecycle states such as warmup, stopped and session ended are reported too, a few per sensor session.

A state is reported once and stays quiet while it persists. A reading with reliable glucose, or a new sensor session, clears the log, so a state that returns after recovery is reported again. The session comparison carries a tolerance because both kits re-derive the session start from the phone's clock on every reading.

The notes ride the CGM event pipeline Loop already has, from the CGM manager delegate through CgmEventStore and RemoteDataServicesManager to NightscoutService, which owns persistence and upload retry. The Loop app itself is untouched and no .pbxproj is edited. The patch adds no files and changes four Swift files, in CGMBLEKit, G7SensorKit, LoopKit and NightscoutService, at hook points that are identical on main, dev and next-dev. Nothing here changes dosing, glucose handling or what the app displays.

The patch applies and reverses cleanly on main and the LoopWorkspace scheme builds with it applied.

Abnormal Dexcom sensor states are uploaded to Nightscout as Note
treatments: sensor issue, sensor failure, session failure, expiry,
excess noise, calibration errors and unrecognized states, for G7 and
G5/G6.

One note per episode. A problem is reported when it starts and stays
quiet while it persists. A reading the sensor's own kit calls reliable
closes the open episodes, so a problem that clears and returns is
reported again. Warmup, a stopped or ended session and an uncalibrated
sensor leave open episodes untouched. Episodes are keyed by kind, and
are cleared when a sensor session starts.

The notes ride the CGM event pipeline Loop already has, from the CGM
manager delegate through CgmEventStore and RemoteDataServicesManager to
NightscoutService, which owns persistence and upload retry. The Loop app
and every .pbxproj are left alone. The patch adds no files and edits four
Swift files in CGMBLEKit, G7SensorKit, LoopKit and NightscoutService,
whose hook points are identical on main, dev and next-dev, so one patch
file serves all three branches.
Both Dexcom kits re-derive the sensor session start from the phone's
clock on every reading, so consecutive readings of one session differ by
the transport delay. Comparing those dates for equality treated every
reading as a new session and cleared the open episodes, so a persisting
fault produced a note every five minutes.

A session counts as new when its start differs from the tracked one by
more than fifteen minutes, far above the jitter and far below the gap
between two real sessions. The first date seen for a session is the one
kept, so the jitter cannot accumulate.

The G5/G6 event joins the array the manager already builds, so it passes
through the same future-dated event filter and arrives in the same
delegate call as a sensor start. Episodes are written back only when they
change.
A reading without reliable glucose, by the kit's own hasReliableGlucose,
is reported as "CGM: <state>" using the kit's description of the state.
The reporter keeps the last reported state; a reliable reading or a new
sensor session clears it. The patch holds no state table or note wording.
@bjorkert bjorkert changed the title Add CGM sensor error reporting customization (cgm_sensor_notes) Add CGM sensor state notes customization (cgm_sensor_notes) Sep 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant