new settings Section for developers - G6 v2 scaling test
This commit is contained in:
parent
284ea2f3c9
commit
4eb2f2bf7d
|
@ -55,6 +55,7 @@
|
|||
F867E2612252ADAB000FD265 /* Calibration+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = F867E25D2252ADAB000FD265 /* Calibration+CoreDataProperties.swift */; };
|
||||
F897AAF92200F2D200CDDD10 /* CBPeripheralState.swift in Sources */ = {isa = PBXBuildFile; fileRef = F897AAF82200F2D200CDDD10 /* CBPeripheralState.swift */; };
|
||||
F897AAFB2201018800CDDD10 /* String.swift in Sources */ = {isa = PBXBuildFile; fileRef = F897AAFA2201018800CDDD10 /* String.swift */; };
|
||||
F8A1584D22ECA445007F5B5D /* SettingsViewDevelopmentSettingsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8A1584C22ECA445007F5B5D /* SettingsViewDevelopmentSettingsViewModel.swift */; };
|
||||
F8A54AAD22D6859200934E7A /* SlopeParameters.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8A54AAC22D6859200934E7A /* SlopeParameters.swift */; };
|
||||
F8A54AAF22D686CD00934E7A /* NightScoutBgReading.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8A54AAE22D686CD00934E7A /* NightScoutBgReading.swift */; };
|
||||
F8A54AB722D9111900934E7A /* CGMTransmitter.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8A54AB322D9111900934E7A /* CGMTransmitter.swift */; };
|
||||
|
@ -221,6 +222,7 @@
|
|||
F867E25D2252ADAB000FD265 /* Calibration+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = "Calibration+CoreDataProperties.swift"; path = "xdrip/Core Data/extensions/Calibration+CoreDataProperties.swift"; sourceTree = SOURCE_ROOT; };
|
||||
F897AAF82200F2D200CDDD10 /* CBPeripheralState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CBPeripheralState.swift; sourceTree = "<group>"; };
|
||||
F897AAFA2201018800CDDD10 /* String.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = String.swift; sourceTree = "<group>"; };
|
||||
F8A1584C22ECA445007F5B5D /* SettingsViewDevelopmentSettingsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsViewDevelopmentSettingsViewModel.swift; sourceTree = "<group>"; };
|
||||
F8A54AAC22D6859200934E7A /* SlopeParameters.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SlopeParameters.swift; sourceTree = "<group>"; };
|
||||
F8A54AAE22D686CD00934E7A /* NightScoutBgReading.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NightScoutBgReading.swift; sourceTree = "<group>"; };
|
||||
F8A54AB322D9111900934E7A /* CGMTransmitter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CGMTransmitter.swift; sourceTree = "<group>"; };
|
||||
|
@ -976,6 +978,7 @@
|
|||
F8B3A83C227F090D004BA588 /* SettingsViewHealthKitSettingsViewModel.swift */,
|
||||
F8B3A83D227F090D004BA588 /* SettingsViewSpeakSettingsViewModel.swift */,
|
||||
F8B3A83E227F090D004BA588 /* SettingsViewGeneralSettingsViewModel.swift */,
|
||||
F8A1584C22ECA445007F5B5D /* SettingsViewDevelopmentSettingsViewModel.swift */,
|
||||
);
|
||||
path = SettingsViewModels;
|
||||
sourceTree = "<group>";
|
||||
|
@ -1373,6 +1376,7 @@
|
|||
F8025C1321DA683400ECF0C0 /* Data.swift in Sources */,
|
||||
F85DC2EF21CFE2F500B9F74A /* Sensor+CoreDataProperties.swift in Sources */,
|
||||
F8A54AFA22D9156600934E7A /* CGMMiaoMiaoTransmitter.swift in Sources */,
|
||||
F8A1584D22ECA445007F5B5D /* SettingsViewDevelopmentSettingsViewModel.swift in Sources */,
|
||||
F8A54AB922D9111900934E7A /* CGMTransmitterDelegate.swift in Sources */,
|
||||
F8B3A856227F28DC004BA588 /* AlertTypeSettingsViewController.swift in Sources */,
|
||||
F8A54AE822D911BA00934E7A /* BatteryStatusRxMessage.swift in Sources */,
|
||||
|
|
|
@ -107,6 +107,14 @@ extension UserDefaults {
|
|||
// Sensor
|
||||
/// sensor Serial Number, for now only applicable to Libre
|
||||
case sensorSerialNumber = "sensorSerialNumber"
|
||||
|
||||
// development settings to test G6 scaling
|
||||
/// G6 factor1 - for testing G6 scaling
|
||||
case G6v2ScalingFactor1 = "G6v2ScalingFactor1"
|
||||
|
||||
/// G6 factor2 - for testing G6 scaling
|
||||
case G6v2ScalingFactor2 = "G6v2ScalingFactor2"
|
||||
|
||||
}
|
||||
|
||||
// MARK: - ===== User Configurable Settings ======
|
||||
|
@ -540,6 +548,29 @@ extension UserDefaults {
|
|||
set(newValue, forKey: Key.sensorSerialNumber.rawValue)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - ===== technical settings for testing ======
|
||||
|
||||
/// G6 factor 1
|
||||
@objc dynamic var G6v2ScalingFactor1:String? {
|
||||
get {
|
||||
return string(forKey: Key.G6v2ScalingFactor1.rawValue)
|
||||
}
|
||||
set {
|
||||
set(newValue, forKey: Key.G6v2ScalingFactor1.rawValue)
|
||||
}
|
||||
}
|
||||
|
||||
/// G6 factor 2
|
||||
@objc dynamic var G6v2ScalingFactor2:String? {
|
||||
get {
|
||||
return string(forKey: Key.G6v2ScalingFactor2.rawValue)
|
||||
}
|
||||
set {
|
||||
set(newValue, forKey: Key.G6v2ScalingFactor2.rawValue)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,11 @@ class CGMG6Transmitter: CGMG5Transmitter {
|
|||
/// scaling factor for G6 firmware version 1
|
||||
private let G6v1ScalingFactor = 34.0
|
||||
|
||||
/// scaling factor 1 for G6 firmware version 2
|
||||
static let G6v2DefaultScalingFactor1 = 1151500000.0
|
||||
|
||||
static let G6v2DefaultScalingFactor2 = 110000.0
|
||||
|
||||
/// - parameters:
|
||||
/// - address: if already connected before, then give here the address that was received during previous connect, if not give nil
|
||||
/// - transmitterID: expected transmitterID, 6 characters
|
||||
|
@ -24,9 +29,19 @@ class CGMG6Transmitter: CGMG5Transmitter {
|
|||
return rawValue * G6v1ScalingFactor;
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
var scalingFactor1 = CGMG6Transmitter.G6v2DefaultScalingFactor1
|
||||
if let factor = UserDefaults.standard.G6v2ScalingFactor1, let factorAsDouble = factor.toDouble() {
|
||||
scalingFactor1 = factorAsDouble
|
||||
}
|
||||
|
||||
var scalingFactor2 = CGMG6Transmitter.G6v2DefaultScalingFactor2
|
||||
if let factor = UserDefaults.standard.G6v2ScalingFactor2, let factorAsDouble = factor.toDouble() {
|
||||
scalingFactor2 = factorAsDouble
|
||||
}
|
||||
|
||||
// G6-v2
|
||||
return (rawValue - 1151395987) / 113432;
|
||||
return (rawValue - scalingFactor1) / scalingFactor2
|
||||
}
|
||||
} else {
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ final class SettingsViewController: UIViewController {
|
|||
fileprivate var healthKitSettingsViewModel = SettingsViewHealthKitSettingsViewModel()
|
||||
fileprivate var alarmsSettingsViewModel = SettingsViewAlertSettingsViewModel()
|
||||
fileprivate var speakSettingsViewModel = SettingsViewSpeakSettingsViewModel()
|
||||
fileprivate var developmentSettingsViewModel = SettingsViewDevelopmentSettingsViewModel()
|
||||
|
||||
private lazy var pickerViewController: PickerViewController = {
|
||||
// Instantiate View Controller
|
||||
|
@ -132,6 +133,8 @@ extension SettingsViewController:UITableViewDataSource, UITableViewDelegate {
|
|||
case healthkit
|
||||
/// store bg values in healthkit
|
||||
case speak
|
||||
/// developper settings
|
||||
case developer
|
||||
}
|
||||
|
||||
// MARK: - UITableViewDataSource protocol Methods
|
||||
|
@ -153,6 +156,8 @@ extension SettingsViewController:UITableViewDataSource, UITableViewDelegate {
|
|||
return alarmsSettingsViewModel.sectionTitle()
|
||||
case .speak:
|
||||
return speakSettingsViewModel.sectionTitle()
|
||||
case .developer:
|
||||
return developmentSettingsViewModel.sectionTitle()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -177,6 +182,8 @@ extension SettingsViewController:UITableViewDataSource, UITableViewDelegate {
|
|||
return alarmsSettingsViewModel.numberOfRows()
|
||||
case .speak:
|
||||
return speakSettingsViewModel.numberOfRows()
|
||||
case .developer:
|
||||
return developmentSettingsViewModel.numberOfRows()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -201,6 +208,8 @@ extension SettingsViewController:UITableViewDataSource, UITableViewDelegate {
|
|||
viewModel = alarmsSettingsViewModel
|
||||
case .speak:
|
||||
viewModel = speakSettingsViewModel
|
||||
case .developer:
|
||||
viewModel = developmentSettingsViewModel
|
||||
}
|
||||
|
||||
|
||||
|
@ -289,6 +298,8 @@ extension SettingsViewController:UITableViewDataSource, UITableViewDelegate {
|
|||
viewModel = alarmsSettingsViewModel
|
||||
case .speak:
|
||||
viewModel = speakSettingsViewModel
|
||||
case .developer:
|
||||
viewModel = developmentSettingsViewModel
|
||||
}
|
||||
|
||||
if let viewModel = viewModel {
|
||||
|
|
|
@ -0,0 +1,121 @@
|
|||
import UIKit
|
||||
|
||||
fileprivate enum Setting:Int, CaseIterable {
|
||||
|
||||
// for G6 testing, factor 1
|
||||
case G6v2ScalingFactor1 = 0
|
||||
|
||||
// for G6 testing, factor 2
|
||||
case G6v2ScalingFactor2 = 1
|
||||
|
||||
}
|
||||
|
||||
struct SettingsViewDevelopmentSettingsViewModel:SettingsViewModelProtocol {
|
||||
|
||||
func sectionTitle() -> String? {
|
||||
return "Developer Settings"
|
||||
}
|
||||
|
||||
func settingsRowText(index: Int) -> String {
|
||||
|
||||
guard let setting = Setting(rawValue: index) else { fatalError("Unexpected Section") }
|
||||
|
||||
switch setting {
|
||||
|
||||
case .G6v2ScalingFactor1:
|
||||
return "G6 v2 scaling factor 1"
|
||||
case .G6v2ScalingFactor2:
|
||||
return "G6 v2 scaling factor 2"
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func accessoryType(index: Int) -> UITableViewCell.AccessoryType {
|
||||
|
||||
guard let setting = Setting(rawValue: index) else { fatalError("Unexpected Section") }
|
||||
|
||||
switch setting {
|
||||
|
||||
case .G6v2ScalingFactor1:
|
||||
return UITableViewCell.AccessoryType.disclosureIndicator
|
||||
|
||||
case .G6v2ScalingFactor2:
|
||||
return UITableViewCell.AccessoryType.disclosureIndicator
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func detailedText(index: Int) -> String? {
|
||||
|
||||
guard let setting = Setting(rawValue: index) else { fatalError("Unexpected Section") }
|
||||
|
||||
switch setting {
|
||||
|
||||
case .G6v2ScalingFactor1:
|
||||
if let factor = UserDefaults.standard.G6v2ScalingFactor1 {
|
||||
return factor
|
||||
} else {
|
||||
return CGMG6Transmitter.G6v2DefaultScalingFactor1.description
|
||||
}
|
||||
case .G6v2ScalingFactor2:
|
||||
if let factor = UserDefaults.standard.G6v2ScalingFactor2 {
|
||||
return factor
|
||||
} else {
|
||||
return CGMG6Transmitter.G6v2DefaultScalingFactor2.description
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func uiView(index: Int) -> UIView? {
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func numberOfRows() -> Int {
|
||||
return Setting.allCases.count
|
||||
}
|
||||
|
||||
func onRowSelect(index: Int) -> SettingsSelectedRowAction {
|
||||
|
||||
guard let setting = Setting(rawValue: index) else { fatalError("Unexpected Section") }
|
||||
|
||||
switch setting {
|
||||
|
||||
case .G6v2ScalingFactor1:
|
||||
|
||||
return SettingsSelectedRowAction.askText(title: "G6 scaling", message: "Give G6 v2 scaling factor 1", keyboardType: UIKeyboardType.decimalPad, text: UserDefaults.standard.G6v2ScalingFactor1, placeHolder: CGMG6Transmitter.G6v2DefaultScalingFactor1.description, actionTitle: nil, cancelTitle: nil, actionHandler: {(factor:String) in
|
||||
|
||||
// convert to uppercase
|
||||
if let factorAsDouble = factor.toDouble() {
|
||||
UserDefaults.standard.G6v2ScalingFactor1 = factorAsDouble.description
|
||||
}
|
||||
|
||||
}, cancelHandler: nil)
|
||||
|
||||
case .G6v2ScalingFactor2:
|
||||
|
||||
return SettingsSelectedRowAction.askText(title: "G6 scaling", message: "Give G6 v2 scaling factor 2", keyboardType: UIKeyboardType.decimalPad, text: UserDefaults.standard.G6v2ScalingFactor2, placeHolder: CGMG6Transmitter.G6v2DefaultScalingFactor2.description, actionTitle: nil, cancelTitle: nil, actionHandler: {(factor:String) in
|
||||
|
||||
// convert to uppercase
|
||||
if let factorAsDouble = factor.toDouble() {
|
||||
UserDefaults.standard.G6v2ScalingFactor2 = factorAsDouble.description
|
||||
}
|
||||
|
||||
|
||||
}, cancelHandler: nil)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func isEnabled(index: Int) -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func completeSettingsViewRefreshNeeded(index: Int) -> Bool {
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue