Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.