Skip to content

Feat/dexcom g7 direct - #1

Merged
mk89pwnz merged 27 commits into
mk89pwnz:dev_combo_test-3-PRfrom
t1dude:feat/dexcom-g7-direct
Oct 28, 2026
Merged

mk89pwnz merged 27 commits into
mk89pwnz:dev_combo_test-3-PRfrom
t1dude:feat/dexcom-g7-direct

Conversation

@mk89pwnz

Copy link
Copy Markdown
Owner

No description provided.

A new BG source that reads a Dexcom G7 or ONE+ sensor over Bluetooth,
with no other app on the phone. It covers pairing (barcode or code),
readings, backfill, sensor status, lifecycle alerts and calibration.
Protocol and pairing flow are ported from Trio's G7SensorKit.

Backfill is asked for only when the AAPS database has a gap, and sensor
time is turned into phone time through one stored clock anchor, so the
same reading is never stored twice. A reconnect right after a reading
is dropped without a handshake.

Not yet tested on a sensor. Personal use only, not for upstream.
Glucose and sensor alarms like in the Dexcom G7 app, built into the G7
Direct plugin and set up in its settings: urgent low, sensor failed,
urgent low soon, low, fall rate, high, rise rate, sensor ended, signal
loss and brief sensor issue. Each alarm has its own level, rate or delay
where it has one, repeat time, sound, "first alarm vibrate only", and a
test button.

An alarm that is not acknowledged goes off again every 5 minutes, with
sound. Only the most important alarm of a group goes off at a time. The
sound plays on the alarm stream, like the AAPS alarm, so it is heard on
silent and vibrate. The alarm volume can be raised to a minimum while an
alarm plays. Reminders and signal loss are woken by AlarmManager, so they
work in Doze.

The alarms also go to the AAPS watch app. It shows them with an
Acknowledge button and vibrates for the time set for each alarm, with a
separate time at night. An acknowledge on the watch, or the watch's
snooze, acknowledges on the phone too.

The Dexcom sound files are not in git. Run
cgm/dexcomg7/copy-dexcom-sounds.sh with the Dexcom sounds folder before
building.

Not yet tested on a phone or watch.
Sensor end (was "Sensor ended") now goes off 24, 6 and 2 hours before the
session ends, when the 12-hour grace period starts, 6 and 2 hours before
the grace period ends, and when readings stop. Each moment is a new alert,
so acknowledging one does not quiet the next. The same messages go to the
AAPS notification list.

Alarm events (goes off, reminder, sent to the watch, acknowledged and
where, stopped) are written to the G7 log. The log now keeps 24 hours in
the app's own storage, so it survives a restart, and Save to file writes
it to the exports folder of the AAPS directory.

"Sound until acknowledged" is removed: the 5-minute reminder already
repeats the sound. The alarm settings are in a new order, starting with
"Alarms: General". The watch vibrates at full strength where it allows
the strength to be set.

A link that comes right after a reading is now left idle instead of being
hung up. Hanging up re-armed the connection at once, and phone and sensor
went round that loop about a hundred times a second.

The plugin has its own icon: a G7 sensor seen from above.

Not yet tested on a phone or watch.
…g, night sensor end

Reconnect: pairing and the scan fallback open a direct connection. Re-arming
such a client repeats the direct connect, which gives up after about 10 s
(status 147) unless the sensor is advertising just then. After a sensor
change this lost 8 live readings in 1 h 45 min and once 20 minutes of
silence, until the watchdog opened a new client. reconnect() now replaces a
direct client with a background (autoConnect) one.

Alarms: the 5-minute reminder came at the same moment as the next reading,
and once sounded with the old value one second before a reading that ended
the alarm. A due reminder now waits for a newer reading, at most 30 s.

Sensor end: an alert that goes off during the night hours goes off once,
with no reminders. The watch night hours setting is now called "Night
hours" and covers this too.

Dates: alert texts and the status screen use a fixed short date and time
("30/09 10:22"). The locale-based date changed between "9/30/26" and
"30.09.2026" depending on whether an AAPS screen had set the app language.
A saved log uses "yyyy-MM-dd HH:mm:ss".

The key exchange log line about the sensor's proofs now says this is
normal: the key challenge after it is the real check (same as in Trio).
After almost every reading the sensor opens 1 to 7 short links within a few
seconds. Each one wrote "Connected" and "Disconnected" to the G7 log, about
2,200 of 4,500 lines a day. In the minute after a reading these normal
connects and disconnects are now left out, and the session writes one line
when that minute is over (or at the next connection), for example:
"The sensor came back 4 times right after its reading; the links were left
idle". Disconnects with an unusual status are still logged.
A reconnect answered with auth=1 bond=2 was handled as a refusal, which
paused reconnects for 15 minutes and missed three readings. The key was
accepted and the next connection was normal, so retry at the next reading.
A second phone can pair as display type WATCH while the main phone keeps
the phone slot. This tests direct-to-watch before any watch code exists.
The slot is saved with the pairing, because the sensor ties the key to it.

Tested 2026-10-16: both slots connect at each reading, each has its own
key, and the phone slot is not affected.
The Bluetooth link, pairing, the session and the saved sensor state now
live in a module without screens, so the watch app can run the same
connection in the sensor's watch slot.

- The backfill gap check asks a small G7ReadingHistory interface instead
  of the AAPS database. On the phone, G7DatabaseHistory answers it.
- Call connectGatt directly; connectGattCompat was a plain wrapper, and
  this keeps :core:utils out of the watch app.
- The Bluetooth permissions move with the connection code.
The phone can now hand the sensor to the AAPS watch app as well. The watch
connects to the Dexcom G7 itself, in the sensor's watch slot, with its own
key, next to the phone.

- Phone: "Direct to watch" on the G7 status page sends the pairing code
  and the sensor's address to the watch (never the phone's key). A Watch
  row shows what the watch reports. The setting is sent again when the
  watch asks for data or reports something that does not match.
- Watch: runs the G7 session from :cgm:dexcomg7:core in the app process.
  Asks for Bluetooth and keeps the screen on for the pairing requests.
  Needs Android 12; older watches report that they cannot do it.
- The face shows the newest reading. The phone's copy of the same reading
  wins; the watch's own shows when the phone has nothing newer. Watch
  readings also fill gaps in the graph and carry a fromSensor flag.
- The phone keeps the alarms. The watch only alarms on a low or urgent
  low from the sensor when the phone has sent nothing for 15 minutes.
Dev made SourceSensor one entry per sensor (DEXCOM_G7_NATIVE is now
DEXCOM_G7) and removed plugin short names. Drop the unused short name
string too.
Seen on a Galaxy Watch Ultra 2: the watch froze the AAPS app every time
the screen dimmed, foreground service or not, so after the first reading
the watch missed every visit of the sensor. Unrestricted battery use for
AAPS on the watch stopped it.

- The watch asks for unrestricted battery use: a notification, and a
  button on its G7 screen that opens the system prompt or the settings.
- The watch reports when it is restricted. The phone shows a warning row
  on the G7 status page and notes it in the G7 log.
- A foreground service of type connectedDevice runs while direct to watch
  is on, as Android expects for a device link in the background.
- The watch's G7 log lines go to the phone's G7 log, marked "Watch:", in
  time order and without doubles. They are sent again for the last two
  hours when the phone comes back.
- libs.versions.toml: dev added the same CameraX libraries. Keep dev's
  entries (version key cameraX) and drop our copies.
- G7OverviewViewModel: dev replaced PumpAction and ActionCategory with
  ScreenAction. The list a button is in now decides where it is shown.
Remove section banner lines, and comments that only repeat the code or
tell how a problem was found. Fix the G7DisplayType comment: the watch
now takes the watch slot.
…gency slider

Replace the Dexcom alarm sounds with the open source sounds from Trio
(nightscout/Trio#1645, merge commit cd6ad0706d).
Brought into Trio by Deniz Cengiz (dnzxy), designed by an anonymous sound
designer who is a diabetes dad and Trio user. Trio is MIT licensed; the
licence text and the details are in cgm/dexcomg7/SOUNDS.md.

- Acoustic and Electronic sets at mild, medium and harsh for urgent low,
  low, low soon, high, device critical and device time-sensitive, plus
  the eight new tones from the same PR. Converted from CAF to AAC m4a.
- Alarms without a set of their own share one: fall rate uses low soon,
  rise rate uses high, signal loss, sensor issue and sensor end use device
  time-sensitive, sensor failed uses device critical.
- Every alarm defaults to Electronic, mild. A stored Dexcom sound falls
  back to the default.
- The sound is chosen on its own screen, like in Trio: one row per style,
  an urgency slider under the chosen one, and the other tones folded
  below. A preview never cuts off an alarm that is going off.
- The sounds are now in git, so the module builds without the Dexcom
  files. The copy script and its .gitignore are removed.
…onnect, and stop the handshake when the client closes
@mk89pwnz
mk89pwnz merged commit 8f4788e into mk89pwnz:dev_combo_test-3-PR Oct 28, 2026
1 of 2 checks passed
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.

2 participants