Skip to content

Commit d8aa6b7

Browse files
authored
Merge pull request #74 from loudnate/minimed-glucose
Adding support for Minimed CGM data
2 parents 1c5dc45 + a523ac2 commit d8aa6b7

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

Loop/Managers/DeviceDataManager.swift

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ class DeviceDataManager: CarbStoreDelegate, TransmitterDelegate {
147147
*/
148148
private func updatePumpStatus(status: MySentryPumpStatusMessageBody, fromDevice device: RileyLinkDevice) {
149149
status.pumpDateComponents.timeZone = pumpState?.timeZone
150+
status.glucoseDateComponents?.timeZone = pumpState?.timeZone
150151

151152
// The pump sends the same message 3x, so ignore it if we've already seen it.
152153
guard status != latestPumpStatus, let pumpDate = status.pumpDateComponents.date else {
@@ -157,6 +158,27 @@ class DeviceDataManager: CarbStoreDelegate, TransmitterDelegate {
157158

158159
backfillGlucoseFromShareIfNeeded()
159160

161+
// Minimed sensor glucose
162+
switch status.glucose {
163+
case .Active(glucose: let glucose):
164+
if let date = status.glucoseDateComponents?.date {
165+
glucoseStore?.addGlucose(
166+
HKQuantity(unit: HKUnit.milligramsPerDeciliterUnit(), doubleValue: Double(glucose)),
167+
date: date,
168+
displayOnly: false,
169+
device: nil
170+
) { (success, sample, error) in
171+
if let error = error {
172+
self.logger.addError(error, fromSource: "GlucoseStore")
173+
}
174+
175+
NSNotificationCenter.defaultCenter().postNotificationName(self.dynamicType.GlucoseUpdatedNotification, object: self)
176+
}
177+
}
178+
default:
179+
break
180+
}
181+
160182
// Sentry packets are sent in groups of 3, 5s apart. Wait 11s before allowing the loop data to continue to avoid conflicting comms.
161183
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(11 * NSEC_PER_SEC)), dispatch_get_global_queue(QOS_CLASS_UTILITY, 0)) {
162184
self.updateReservoirVolume(status.reservoirRemainingUnits, atDate: pumpDate, withTimeLeft: NSTimeInterval(minutes: Double(status.reservoirRemainingMinutes)))
@@ -301,7 +323,6 @@ class DeviceDataManager: CarbStoreDelegate, TransmitterDelegate {
301323
NSNotificationCenter.defaultCenter().postNotificationName(self.dynamicType.PumpStatusUpdatedNotification, object: self)
302324
self.remoteDataManager.nightscoutUploader?.processPumpEvents(events, source: device.deviceURI, pumpModel: pumpModel)
303325

304-
305326
var lastFinalDate: NSDate?
306327
var firstMutableDate: NSDate?
307328

@@ -317,11 +338,11 @@ class DeviceDataManager: CarbStoreDelegate, TransmitterDelegate {
317338
} else if let finalDate = lastFinalDate {
318339
self.observingPumpEventsSince = finalDate
319340
}
320-
321-
322341
case .Failure(let error):
323342
self.logger.addError("Failed to fetch history: \(error)", fromSource: "RileyLink")
324-
self.troubleshootPumpCommsWithDevice(device)
343+
344+
// Continue with the loop anyway
345+
NSNotificationCenter.defaultCenter().postNotificationName(self.dynamicType.PumpStatusUpdatedNotification, object: self)
325346
}
326347
}
327348
}

Loop/Models/TransmitterGlucose.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ struct TransmitterGlucose: GlucoseValue {
3232
var startDate: NSDate {
3333
return NSDate(timeIntervalSince1970: startTime).dateByAddingTimeInterval(NSTimeInterval(glucoseMessage.timestamp))
3434
}
35-
}
35+
}

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Please understand that this project:
3939
</thead>
4040
<tbody>
4141
<tr>
42-
<th rowspan="2">CGM</th>
42+
<th rowspan="3">CGM</th>
4343
<th>Dexcom G4 + Share</th>
4444
<td>✅<sup><a href="#hw1">1</a> <a href="#hw2">2</a></sup></td>
4545
<td>✅<sup><a href="#hw1">1</a></sup></td>
@@ -49,11 +49,17 @@ Please understand that this project:
4949
<td>✅<sup><a href="#hw2">2</a></sup></td>
5050
<td>✅</td>
5151
</tr>
52+
<tr>
53+
<th>MM CGM</th>
54+
<td>❌<sup><a href="#hw3">3</a></sup></td>
55+
<td>✅</td>
56+
</tr>
5257
</tbody>
5358
</table>
5459

5560
<br/><a name="hw1">1</a>. Internet connection required to retrieve glucose
5661
<br/><a name="hw2">2</a>. Pump must have a remote ID added in the [Remote Options](https://www.medtronicdiabetes.com/sites/default/files/library/download-library/workbooks/x22_menu_map.pdf) menu
62+
<br/><a name="hw3">3</a>. It's not impossible, but comms-heavy and there's some work to be done. File an issue if you're someone who's up for the challenge and can test this hardware configuration.
5763

5864
### RileyLink
5965

0 commit comments

Comments
 (0)