Skip to content

Commit

Permalink
Fetch CR from loopstatus enacted in Mealview Boluscalculator
Browse files Browse the repository at this point in the history
adjust colors in boluscalc text
  • Loading branch information
dsnallfot committed Apr 26, 2024
1 parent 479d8c1 commit 63ea4d6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 20 deletions.
13 changes: 7 additions & 6 deletions LoopFollow/Application/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="22505" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="49e-Tb-3d3">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="32700.99.1234" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="49e-Tb-3d3">
<device id="retina5_9" orientation="portrait" appearance="dark"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22504"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22684"/>
<capability name="Image references" minToolsVersion="12.0"/>
<capability name="Named colors" minToolsVersion="9.0"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
Expand Down Expand Up @@ -1154,7 +1154,7 @@
<constraints>
<constraint firstAttribute="width" relation="lessThanOrEqual" constant="25" id="5W6-UB-3Ty"/>
</constraints>
<color key="textColor" name="Basal"/>
<color key="textColor" red="0.35294118520000001" green="0.35294118520000001" blue="0.35686278339999999" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
Expand All @@ -1163,7 +1163,7 @@
<accessibility key="accessibilityConfiguration">
<accessibilityTraits key="traits" notEnabled="YES"/>
</accessibility>
<color key="textColor" name="Basal"/>
<color key="textColor" red="0.80000001190000003" green="0.80000001190000003" blue="0.80000001190000003" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
Expand All @@ -1172,7 +1172,7 @@
<accessibility key="accessibilityConfiguration">
<accessibilityTraits key="traits" notEnabled="YES"/>
</accessibility>
<color key="textColor" name="Basal"/>
<color key="textColor" red="0.35294118520000001" green="0.35294118520000001" blue="0.35686278339999999" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
Expand All @@ -1184,6 +1184,7 @@
<constraints>
<constraint firstAttribute="width" constant="35" id="4ph-0r-Xa8"/>
</constraints>
<color key="textColor" red="0.80000001190000003" green="0.80000001190000003" blue="0.80000001190000003" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
Expand All @@ -1192,7 +1193,7 @@
<accessibility key="accessibilityConfiguration">
<accessibilityTraits key="traits" notEnabled="YES"/>
</accessibility>
<color key="textColor" name="Basal"/>
<color key="textColor" red="0.35294118520000001" green="0.35294118520000001" blue="0.35686278339999999" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
Expand Down
7 changes: 6 additions & 1 deletion LoopFollow/Controllers/Nightscout/DeviceStatus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import Foundation
import UIKit

var sharedCRValue: String = ""

extension MainViewController {
// NS Device Status Web Call
func webLoadNSDeviceStatus() {
Expand Down Expand Up @@ -219,7 +221,10 @@ extension MainViewController {
tableData[13].value = String(format:"%.1f", enactedData["TDD"] as! Double) + " E"
tableData[14].value = String(format:"%.1f", enactedData["ISF"] as! Double) + " mmol/L/E"
tableData[15].value = String(format:"%.1f", enactedData["CR"] as! Double) + " g/E"
// latestCR = Double(enactedData["CR"] as! Double) // Out commented preparations for fetching latestCR
// Compute tableDataCRValue here
let tableDataCRValue = String(format:"%.1f", enactedData["CR"] as! Double)
// Update sharedCRValue
sharedCRValue = tableDataCRValue

//Daniel mmol version of target
let currentTargetMgdl = enactedData["current_target"] as! Double
Expand Down
21 changes: 9 additions & 12 deletions LoopFollow/ViewControllers/MealViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import AudioToolbox
class MealViewController: UIViewController, UITextFieldDelegate, TwilioRequestable {
var appStateController: AppStateController?

//var latestCR: Double = 0.0 // Out commented preparations for fetching latestCR

@IBOutlet weak var carbsEntryField: UITextField!
@IBOutlet weak var fatEntryField: UITextField!
@IBOutlet weak var proteinEntryField: UITextField!
Expand Down Expand Up @@ -49,14 +47,13 @@ class MealViewController: UIViewController, UITextFieldDelegate, TwilioRequestab
proteinEntryField.delegate = self
self.focusCarbsEntryField()

// Retrieve the carb ratio value from UserDefaults
let carbRatio = UserDefaultsRepository.carbRatio.value
CR = Decimal(carbRatio)
// Use sharedCRValue instead of UserDefaultsRepository.carbRatio.value
if let sharedCRDouble = Double(sharedCRValue) {
CR = Decimal(sharedCRDouble)
} else {
print("CR could not be fetched")
}

// Now you can use latestCR instead of UserDefaultsRepository.carbRatio.value
//CR = Decimal(latestCR) // Out commented preparations for fetching latestCR


// Create a NumberFormatter instance
let numberFormatter = NumberFormatter()
numberFormatter.minimumFractionDigits = 0
Expand All @@ -65,8 +62,8 @@ class MealViewController: UIViewController, UITextFieldDelegate, TwilioRequestab
// Format the CR value to have one decimal place
let formattedCR = numberFormatter.string(from: NSDecimalNumber(decimal: CR) as NSNumber) ?? ""

// Set the text field with the formatted value of CR
CRValue.text = formattedCR
// Set the text field with the formatted value of CR or "N/A" if formattedCR is "0.0"
CRValue.text = formattedCR == "0" ? "N/A" : formattedCR
print("CR: \(formattedCR)")

// Check the value of hideRemoteBolus and hide the bolusRow accordingly
Expand All @@ -79,7 +76,7 @@ class MealViewController: UIViewController, UITextFieldDelegate, TwilioRequestab
hideBolusCalcRow()
}
}

// Function to calculate the suggested bolus value based on CR and check for maxCarbs
func calculateBolus() {
guard let carbsText = carbsEntryField.text,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,8 @@ class RemoteSettingsViewController: FormViewController {
self?.reloadForm()
}

//Out commented code since CR now is fetched from enacted loopstatus
/*
// Conditionally show the StepperRow based on the value of the switch row
<<< StepperRow("carbRatio") { row in
row.title = "Carb Ratio for bolus calc"
Expand All @@ -370,7 +372,7 @@ class RemoteSettingsViewController: FormViewController {
}.onChange { [weak self] row in
guard let value = row.value else { return }
UserDefaultsRepository.carbRatio.value = Double(value)
}
}*/

+++ ButtonRow() {
$0.title = "DONE"
Expand Down

0 comments on commit 63ea4d6

Please sign in to comment.