Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
48 changes: 26 additions & 22 deletions Loop.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
437CCAE01D285C7B0075D2C3 /* ServiceAuthentication.swift in Sources */ = {isa = PBXBuildFile; fileRef = 437CCADF1D285C7B0075D2C3 /* ServiceAuthentication.swift */; };
437CEEE41CDE5C0A003C8C80 /* UIImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 437CEEE31CDE5C0A003C8C80 /* UIImage.swift */; };
437D9BA31D7BC977007245E8 /* PredictionTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 437D9BA21D7BC977007245E8 /* PredictionTableViewController.swift */; };
438172D91F4E9E37003C3328 /* NewPumpEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 438172D81F4E9E37003C3328 /* NewPumpEvent.swift */; };
4381D2261F3C0FDD004ACCF9 /* RileyLinkDevice.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4381D2251F3C0FDD004ACCF9 /* RileyLinkDevice.swift */; };
43846AD51D8FA67800799272 /* Base.lproj in Resources */ = {isa = PBXBuildFile; fileRef = 43846AD41D8FA67800799272 /* Base.lproj */; };
43846ADB1D91057000799272 /* ContextUpdatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43846ADA1D91057000799272 /* ContextUpdatable.swift */; };
Expand Down Expand Up @@ -447,6 +448,7 @@
437CEEE31CDE5C0A003C8C80 /* UIImage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIImage.swift; sourceTree = "<group>"; };
437D9BA11D7B5203007245E8 /* Loop.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Loop.xcconfig; sourceTree = "<group>"; };
437D9BA21D7BC977007245E8 /* PredictionTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PredictionTableViewController.swift; sourceTree = "<group>"; };
438172D81F4E9E37003C3328 /* NewPumpEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewPumpEvent.swift; sourceTree = "<group>"; };
4381D2251F3C0FDD004ACCF9 /* RileyLinkDevice.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RileyLinkDevice.swift; sourceTree = "<group>"; };
43846AD41D8FA67800799272 /* Base.lproj */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Base.lproj; sourceTree = "<group>"; };
43846ADA1D91057000799272 /* ContextUpdatable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContextUpdatable.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -888,6 +890,7 @@
4302F4E41D4EA75100F0FCAF /* DoseStore.swift */,
43C513181E864C4E001547C7 /* GlucoseRangeSchedule.swift */,
C15713811DAC6983005BC4D2 /* MealBolusNightscoutTreatment.swift */,
438172D81F4E9E37003C3328 /* NewPumpEvent.swift */,
43CEE6E51E56AFD400CB9116 /* NightscoutUploader.swift */,
4398973A1CD2FC2000223065 /* NSDateFormatter.swift */,
43E344A31B9E1B1C00C85C07 /* NSUserDefaults.swift */,
Expand Down Expand Up @@ -1278,7 +1281,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 0820;
LastUpgradeCheck = 0820;
ORGANIZATIONNAME = "LoopKit Authors";
TargetAttributes = {
43776F8B1B8022E90074EA36 = {
Expand Down Expand Up @@ -1499,7 +1502,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "# /usr/local/bin/carthage build --platform \"$PLATFORM_NAME\" \"$SRCROOT\"\n# Only run this script if we're not using a workspace or installing\nif [ ! -d $PROJECT_DIR/Loop.xcworkspace ] || [ \"$ACTION\" = \"install\" ]; then\n /usr/local/bin/carthage copy-frameworks\nfi";
shellScript = "# /usr/local/bin/carthage build --platform \"$PLATFORM_NAME\" \"$SRCROOT\"\n# Only run this script if we're not using a workspace or installing\nif [ ! -d $PROJECT_DIR/Loop.xcworkspace ] || [ \"$ACTION\" = \"install\" ]; then\n /usr/local/bin/carthage copy-frameworks\nfi";
};
/* End PBXShellScriptBuildPhase section */

Expand Down Expand Up @@ -1560,6 +1563,7 @@
439BED2A1E76093C00B0AED5 /* CGMManager.swift in Sources */,
C18C8C511D5A351900E043FB /* NightscoutDataManager.swift in Sources */,
438849EA1D297CB6003B3F23 /* NightscoutService.swift in Sources */,
438172D91F4E9E37003C3328 /* NewPumpEvent.swift in Sources */,
437CCADC1D284B830075D2C3 /* ButtonTableViewCell.swift in Sources */,
4389916B1E91B689000EEF90 /* ChartSettings+Loop.swift in Sources */,
4315D2871CA5CC3B00589052 /* CarbEntryEditTableViewController.swift in Sources */,
Expand Down Expand Up @@ -1838,7 +1842,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "iPhone Developer: [email protected] (XZN842LDLT)";
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 39;
CURRENT_PROJECT_VERSION = 39;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
Expand Down Expand Up @@ -1866,7 +1870,7 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0.1;
SWIFT_VERSION = 3.0.1;
TARGETED_DEVICE_FAMILY = "1,2";
WARNING_CFLAGS = "-Wall";
};
Expand Down Expand Up @@ -1896,7 +1900,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "iPhone Developer: [email protected] (XZN842LDLT)";
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 39;
CURRENT_PROJECT_VERSION = 39;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand All @@ -1917,7 +1921,7 @@
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0.1;
SWIFT_VERSION = 3.0.1;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
WARNING_CFLAGS = "-Wall";
Expand All @@ -1931,7 +1935,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = Loop/Loop.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = Loop/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
"OTHER_SWIFT_FLAGS[sdk=iphonesimulator*]" = "-D IOS_SIMULATOR";
Expand All @@ -1948,7 +1952,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = Loop/Loop.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = Loop/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "$(MAIN_APP_BUNDLE_IDENTIFIER)";
Expand All @@ -1963,7 +1967,7 @@
ASSETCATALOG_COMPILER_COMPLICATION_NAME = Complication;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=watchos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = "WatchApp Extension/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "$(MAIN_APP_BUNDLE_IDENTIFIER).watchkitapp.watchkitextension";
Expand All @@ -1981,7 +1985,7 @@
ASSETCATALOG_COMPILER_COMPLICATION_NAME = Complication;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=watchos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = "WatchApp Extension/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "$(MAIN_APP_BUNDLE_IDENTIFIER).watchkitapp.watchkitextension";
Expand All @@ -2000,7 +2004,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=watchos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = "";
IBSC_MODULE = WatchApp_Extension;
INFOPLIST_FILE = WatchApp/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand All @@ -2020,7 +2024,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=watchos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = "";
IBSC_MODULE = WatchApp_Extension;
INFOPLIST_FILE = WatchApp/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand All @@ -2038,7 +2042,7 @@
buildSettings = {
CLANG_ANALYZER_NONNULL = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = DoseMathTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.loudnate.DoseMathTests;
Expand All @@ -2051,7 +2055,7 @@
buildSettings = {
CLANG_ANALYZER_NONNULL = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = DoseMathTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.loudnate.DoseMathTests;
Expand All @@ -2065,7 +2069,7 @@
BUNDLE_LOADER = "$(TEST_HOST)";
CLANG_ANALYZER_NONNULL = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = LoopTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.loudnate.LoopTests;
Expand All @@ -2080,7 +2084,7 @@
BUNDLE_LOADER = "$(TEST_HOST)";
CLANG_ANALYZER_NONNULL = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = LoopTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.loudnate.LoopTests;
Expand All @@ -2098,7 +2102,7 @@
CODE_SIGN_ENTITLEMENTS = "Loop Status Extension/Loop Status Extension.entitlements";
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = "Loop Status Extension/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "$(MAIN_APP_BUNDLE_IDENTIFIER).statuswidget";
Expand All @@ -2117,7 +2121,7 @@
CODE_SIGN_ENTITLEMENTS = "Loop Status Extension/Loop Status Extension.entitlements";
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = "Loop Status Extension/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "$(MAIN_APP_BUNDLE_IDENTIFIER).statuswidget";
Expand All @@ -2135,11 +2139,11 @@
CLANG_WARN_SUSPICIOUS_MOVES = YES;
CODE_SIGN_IDENTITY = "";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
CURRENT_PROJECT_VERSION = 39;
CURRENT_PROJECT_VERSION = 39;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 39;
DYLIB_CURRENT_VERSION = 39;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = LoopUI/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
Expand All @@ -2162,11 +2166,11 @@
CLANG_WARN_SUSPICIOUS_MOVES = YES;
CODE_SIGN_IDENTITY = "";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
CURRENT_PROJECT_VERSION = 39;
CURRENT_PROJECT_VERSION = 39;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 39;
DYLIB_CURRENT_VERSION = 39;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = LoopUI/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
Expand Down
5 changes: 4 additions & 1 deletion Loop/Extensions/DoseStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ extension LoopDataManager {

switch event.pumpEvent {
case let bolus as BolusNormalPumpEvent:
dose = DoseEntry(type: .bolus, startDate: event.date, endDate: event.date.addingTimeInterval(bolus.duration), value: bolus.amount, unit: .units)
// For entries in-progress, use the programmed amount
let units = event.isMutable() ? bolus.programmed : bolus.amount

dose = DoseEntry(type: .bolus, startDate: event.date, endDate: event.date.addingTimeInterval(bolus.duration), value: units, unit: .units)
case is SuspendPumpEvent:
dose = DoseEntry(suspendDate: event.date)
case is ResumePumpEvent:
Expand Down
29 changes: 29 additions & 0 deletions Loop/Extensions/NewPumpEvent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// NewPumpEvent.swift
// Loop
//
// Copyright © 2017 LoopKit Authors. All rights reserved.
//

import InsulinKit


extension NewPumpEvent {

/// Constructs a pump event placeholder representing a bolus just enacted.
///
/// - Parameters:
/// - units: The units of insulin requested
/// - date: The date the bolus was enacted
static func enactedBolus(units: Double, at date: Date) -> NewPumpEvent {
let dose = DoseEntry(type: .bolus, startDate: date, endDate: date, value: units, unit: .units)

return self.init(
date: date,
dose: dose,
isMutable: true,
raw: Data(), // This can be empty, as mutable events aren't persisted
title: ""
)
}
}
40 changes: 24 additions & 16 deletions Loop/Managers/DeviceDataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -427,13 +427,16 @@ final class DeviceDataManager {
}

let setBolus = {
ops.setNormalBolus(units: units) { (error) in
if let error = error {
self.logger.addError(error, fromSource: "Bolus")
notify(error)
} else {
self.loopManager.addExpectedBolus(units, at: Date())
notify(nil)
self.loopManager.addRequestedBolus(units: units, at: Date()) {
ops.setNormalBolus(units: units) { (error) in
if let error = error {
self.logger.addError(error, fromSource: "Bolus")
notify(error)
} else {
self.loopManager.addConfirmedBolus(units: units, at: Date()) {
notify(nil)
}
}
}
}
}
Expand Down Expand Up @@ -735,28 +738,33 @@ extension DeviceDataManager: LoopDataManagerDelegate {
return
}

let notify = { (result: Result<DoseEntry>) -> Void in
// If we haven't fetched history in a while (preferredInsulinDataSource == .reservoir),
// let's try to do so while the pump radio is on.
if self.loopManager.doseStore.lastAddedPumpEvents.timeIntervalSinceNow < .minutes(-4) {
self.fetchPumpHistory { (_) in
completion(result)
}
} else {
completion(result)
}
}

ops.setTempBasal(rate: basal.rate, duration: basal.duration) { (result) -> Void in
switch result {
case .success(let body):
let now = Date()
let endDate = now.addingTimeInterval(body.timeRemaining)
let startDate = endDate.addingTimeInterval(-basal.duration)

completion(.success(DoseEntry(
notify(.success(DoseEntry(
type: .tempBasal,
startDate: startDate,
endDate: endDate,
value: body.rate,
unit: .unitsPerHour
)))

// If we haven't fetched history in a while (preferredInsulinDataSource == .reservoir),
// let's try to do so while the pump radio is on.
if self.loopManager.doseStore.lastAddedPumpEvents.timeIntervalSinceNow < .minutes(-4) {
self.fetchPumpHistory { (_) in }
}
case .failure(let error):
completion(.failure(error))
notify(.failure(error))
}
}
}
Expand Down
Loading