Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
3ad969c
support start, stop, calibrate
thebookins Feb 27, 2018
fbc6270
use let not var
thebookins Feb 27, 2018
8f69c04
remove print statetment
thebookins Feb 27, 2018
2c09c15
add Command enum, and logic for start, stop and calibrate
thebookins Mar 11, 2018
0778ab0
use closures to call transmitter delegate methods
thebookins Mar 11, 2018
832b74f
merge with LoopKit/dev
thebookins Mar 13, 2018
549df79
remove extra whitespace and HealthKit dependency
thebookins Mar 13, 2018
71442e2
add opcode for calibrateGlucoseRx
thebookins Mar 13, 2018
ea60bc4
add CRC to SessionStopTxMessage
thebookins Mar 13, 2018
167f5d6
add seconds since epoch, add CRC to SessionStartTxMessage
thebookins Mar 13, 2018
5b3ee24
build CalibrateGlucoseTxMessage
thebookins Mar 13, 2018
383b5b2
add stubs for TransmitterDelgate methods
thebookins Mar 13, 2018
d8f7b4e
split control into several functions, to avoid excessive use of closures
thebookins Mar 13, 2018
76f8506
remove actions from example app temporarily
thebookins Mar 13, 2018
97deddf
revert change to start restoration, add rawValue to log
thebookins Mar 13, 2018
b507741
restore line return at eof
thebookins Mar 13, 2018
d2b7200
add calibration button
thebookins Mar 14, 2018
fd4bf0d
set glucose units in one place
thebookins Mar 16, 2018
a76ea2b
add else clause
thebookins Mar 16, 2018
15b8b6c
revert previous commit
thebookins Mar 16, 2018
ac841ce
rename synchronize readTimeMessage
thebookins Mar 16, 2018
623bfc3
add method to read calibration data
thebookins Mar 16, 2018
82d82cc
fix glucose units in calibrate function
thebookins Mar 22, 2018
80cc54b
add documentation comments for disambiguation
thebookins Mar 22, 2018
237b1b9
move Command enum to new file
thebookins Mar 22, 2018
4d57dc4
add private Action enum
thebookins Mar 22, 2018
1acb6a8
add changes to project
thebookins Mar 22, 2018
55195a6
round before cast
thebookins Mar 22, 2018
80abe97
serialize action as raw value
thebookins Mar 23, 2018
faad37d
just use Int, not UInt8
thebookins Mar 23, 2018
99a8e95
remove glucoseUnits user preference
thebookins Mar 25, 2018
6c051c3
use toInt()
thebookins Mar 25, 2018
fbd0721
use startTime, stopTime rather than time
thebookins Mar 25, 2018
b27b41e
add lastCalibration as optional property of Glucose
thebookins Mar 29, 2018
0d3b20a
add default value of nil
thebookins Mar 29, 2018
93afb9c
add thread-safe CommandQueue
thebookins Mar 29, 2018
0920e65
create protocol TransmitterCommandSource
thebookins Mar 29, 2018
6eb4e6b
merge with latest dev
thebookins Mar 29, 2018
4558322
remove HealthKit dependency
thebookins Mar 29, 2018
ce56a02
remove dev team
thebookins Mar 29, 2018
bd14665
add custom string for CalibrationState
thebookins Mar 30, 2018
39b1700
add start and stop actions to example app
thebookins Mar 30, 2018
1af862a
fix button names
thebookins Mar 30, 2018
b02be6e
use let not var
thebookins Mar 30, 2018
1df3cf3
remove isEmpty, always access list inside lock
thebookins Mar 30, 2018
6203380
don't use default case; use String(describing:)
thebookins Mar 30, 2018
f1cb6c3
don't dispatch TransmitterCommandSource methods
thebookins Mar 30, 2018
7934547
mask glucose value to exclude 4 most-significant bits
Apr 8, 2018
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
23 changes: 21 additions & 2 deletions CGMBLEKit Example/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import xDripG5
import CoreBluetooth

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, TransmitterDelegate {
class AppDelegate: UIResponder, UIApplicationDelegate, TransmitterDelegate, TransmitterCommandSource {

var window: UIWindow?

static var sharedDelegate: AppDelegate {
Expand All @@ -28,14 +28,20 @@ class AppDelegate: UIResponder, UIApplicationDelegate, TransmitterDelegate {
)
transmitter?.stayConnected = UserDefaults.standard.stayConnected
transmitter?.delegate = self
transmitter?.commandSource = self

UserDefaults.standard.transmitterID = id
}
glucose = nil
}
}

var transmitter: Transmitter?

let commandQueue = CommandQueue()

var glucose: Glucose?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

transmitterID = UserDefaults.standard.transmitterID
Expand Down Expand Up @@ -82,6 +88,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate, TransmitterDelegate {
return dateFormatter
}()

func dequeuePendingCommand(for transmitter: Transmitter) -> Command? {
return commandQueue.dequeue()
}

func transmitter(_ transmitter: Transmitter, didFail command: Command, with error: Error) {
// TODO: implement
}

func transmitter(_ transmitter: Transmitter, didComplete command: Command) {
// TODO: implement
}

func transmitter(_ transmitter: Transmitter, didError error: Error) {
DispatchQueue.main.async {
if let vc = self.window?.rootViewController as? TransmitterDelegate {
Expand All @@ -91,6 +109,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, TransmitterDelegate {
}

func transmitter(_ transmitter: Transmitter, didRead glucose: Glucose) {
self.glucose = glucose
DispatchQueue.main.async {
if let vc = self.window?.rootViewController as? TransmitterDelegate {
vc.transmitter(transmitter, didRead: glucose)
Expand Down
56 changes: 50 additions & 6 deletions CGMBLEKit Example/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,40 +1,48 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11201" systemVersion="15G1004" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina5_5" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="xDripG5_Example" customModuleProvider="target" sceneMemberID="viewController">
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="CGMBLEKit_Example" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<rect key="frame" x="0.0" y="0.0" width="414" height="736"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" distribution="equalSpacing" alignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="mqJ-p6-sSU">
<rect key="frame" x="20" y="40" width="374" height="676"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="K5I-e5-MvQ">
<rect key="frame" x="15.666666666666657" y="0.0" width="343" height="52"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Transmitter ID" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="5y6-vU-qC3">
<rect key="frame" x="8" y="14.333333333333334" width="249" height="20.333333333333329"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="oUg-jb-mCK">
<rect key="frame" x="265" y="42" width="70" height="1"/>
<color key="backgroundColor" red="0.33333333333333331" green="0.33333333333333331" blue="0.33333333333333331" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="1" id="Rjq-qn-DaB"/>
</constraints>
</view>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" text="500000" textAlignment="center" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="e0T-ru-tWD">
<rect key="frame" x="265" y="8" width="70" height="34"/>
<constraints>
<constraint firstAttribute="width" constant="70" id="1v1-n5-aT4"/>
<constraint firstAttribute="height" constant="34" id="CVt-L0-Ts1"/>
Expand All @@ -59,40 +67,76 @@
</constraints>
</view>
<stackView opaque="NO" contentMode="scaleToFill" spacing="8" baselineRelativeArrangement="YES" translatesAutoresizingMaskIntoConstraints="NO" id="4lp-eb-b4C">
<rect key="frame" x="74.333333333333329" y="129" width="225.33333333333337" height="31"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Stay connected" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="NSs-9e-3Sl">
<rect key="frame" x="0.0" y="0.0" width="168.33333333333334" height="31"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="DR7-3h-biq">
<rect key="frame" x="176.33333333333337" y="0.0" width="51" height="31"/>
<connections>
<action selector="toggleStayConnected:" destination="BYZ-38-t0r" eventType="valueChanged" id="Wci-5s-BJm"/>
</connections>
</switch>
</subviews>
</stackView>
<stackView opaque="NO" contentMode="scaleToFill" spacing="8" baselineRelativeArrangement="YES" translatesAutoresizingMaskIntoConstraints="NO" id="lPZ-HJ-Wji">
<rect key="frame" x="74.333333333333329" y="237.33333333333331" width="225.33333333333337" height="31"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Run alongside G5 app" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="3i8-2m-QFG">
<rect key="frame" x="0.0" y="0.0" width="168.33333333333334" height="31"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="mjL-My-zyc">
<rect key="frame" x="176.33333333333337" y="0.0" width="51" height="31"/>
<connections>
<action selector="togglePassiveMode:" destination="BYZ-38-t0r" eventType="valueChanged" id="vGB-RZ-H3T"/>
</connections>
</switch>
</subviews>
</stackView>
<activityIndicatorView opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" hidesWhenStopped="YES" animating="YES" style="gray" translatesAutoresizingMaskIntoConstraints="NO" id="v7k-HB-Hm0"/>
<activityIndicatorView opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" hidesWhenStopped="YES" animating="YES" style="gray" translatesAutoresizingMaskIntoConstraints="NO" id="v7k-HB-Hm0">
<rect key="frame" x="177" y="345.33333333333331" width="20" height="20"/>
</activityIndicatorView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="––" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="zAF-A7-1Oc">
<rect key="frame" x="173.66666666666666" y="442.33333333333331" width="27" height="31.333333333333314"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleTitle1"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" alignment="center" spacing="20" baselineRelativeArrangement="YES" translatesAutoresizingMaskIntoConstraints="NO" id="VKn-a6-Gbj">
<rect key="frame" x="74" y="551" width="226" height="30"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="HEQ-Bp-kx7" userLabel="Start">
<rect key="frame" x="0.0" y="0.0" width="62" height="30"/>
<state key="normal" title="Start"/>
<connections>
<action selector="start:" destination="BYZ-38-t0r" eventType="touchUpInside" id="CoA-cH-SFe"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="HYW-Ex-7LC">
<rect key="frame" x="82" y="0.0" width="62" height="30"/>
<state key="normal" title="Calibrate"/>
<connections>
<action selector="calibrate:" destination="BYZ-38-t0r" eventType="touchUpInside" id="5Ft-BY-tyB"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="JAM-9K-KeE" userLabel="Stop">
<rect key="frame" x="164" y="0.0" width="62" height="30"/>
<state key="normal" title="Stop"/>
<connections>
<action selector="stop:" destination="BYZ-38-t0r" eventType="touchUpInside" id="hWH-qi-m3s"/>
</connections>
</button>
</subviews>
</stackView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Waiting for first reading" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="9p7-LX-EMK">
<rect key="frame" x="-20" y="658" width="0.0" height="18"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleSubhead"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
Expand Down
34 changes: 34 additions & 0 deletions CGMBLEKit Example/CommandQueue.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// CommandQueue.swift
// CGMBLEKit Example
//
// Created by Paul Dickens on 25/03/2018.
// Copyright © 2018 LoopKit Authors. All rights reserved.
//

import Foundation
import xDripG5


class CommandQueue {
private var list = Array<Command>()
private var lock = os_unfair_lock()

func enqueue(_ element: Command) {
os_unfair_lock_lock(&lock)
list.append(element)
os_unfair_lock_unlock(&lock)
}

func dequeue() -> Command? {
os_unfair_lock_lock(&lock)
defer {
os_unfair_lock_unlock(&lock)
}
if !list.isEmpty {
return list.removeFirst()
} else {
return nil
}
}
}
Loading