reset function for G5
This commit is contained in:
parent
aa88bf1afe
commit
733f5d05ef
|
@ -523,7 +523,7 @@ class CGMG5Transmitter:BluetoothTransmitter, CGMTransmitter {
|
|||
|
||||
/// sends G5 reset to transmitter
|
||||
private func sendG5Reset() {
|
||||
trace("sending G5Reset", log: log, category: ConstantsLog.categoryCGMG5, type: .info)
|
||||
trace("in sendG5Reset", log: log, category: ConstantsLog.categoryCGMG5, type: .info)
|
||||
if let writeControlCharacteristic = writeControlCharacteristic {
|
||||
_ = writeDataToPeripheral(data: ResetTxMessage().data, characteristicToWriteTo: writeControlCharacteristic, type: .withResponse)
|
||||
G5ResetRequested = false
|
||||
|
@ -544,13 +544,11 @@ class CGMG5Transmitter:BluetoothTransmitter, CGMTransmitter {
|
|||
|
||||
private func processResetRxMessage(value:Data) {
|
||||
if let resetRxMessage = ResetRxMessage(data: value) {
|
||||
if resetRxMessage.status == 0 {
|
||||
trace("resetRxMessage status is 0, considering reset successful", log: log, category: ConstantsLog.categoryCGMG5, type: .info)
|
||||
bluetoothTransmitterDelegate?.reset(for: self, successful: true)
|
||||
} else {
|
||||
trace("resetRxMessage status is %{public}d, considering reset failed", log: log, category: ConstantsLog.categoryCGMG5, type: .info, resetRxMessage.status)
|
||||
bluetoothTransmitterDelegate?.reset(for: self, successful: false)
|
||||
}
|
||||
|
||||
trace("in processResetRxMessage, considering reset successful = %{public}@", log: log, category: ConstantsLog.categoryCGMG5, type: .info, (resetRxMessage.status == 0).description)
|
||||
|
||||
cGMG5TransmitterDelegate?.reset(for: self, successful: resetRxMessage.status == 0 )
|
||||
|
||||
} else {
|
||||
trace("resetRxMessage is nil", log: log, category: ConstantsLog.categoryCGMG5, type: .error)
|
||||
}
|
||||
|
|
|
@ -6,5 +6,9 @@ protocol CGMG5TransmitterDelegate: AnyObject {
|
|||
func received(firmware: String, cGMG5Transmitter: CGMG5Transmitter)
|
||||
|
||||
func received(transmitterBatteryInfo: TransmitterBatteryInfo, cGMG5Transmitter: CGMG5Transmitter)
|
||||
|
||||
/// transmitter reset result
|
||||
func reset(for cGMG5Transmitter: CGMG5Transmitter, successful: Bool)
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -26,9 +26,6 @@ protocol BluetoothTransmitterDelegate: AnyObject {
|
|||
/// transmitter pairing failed
|
||||
func pairingFailed()
|
||||
|
||||
/// transmitter reset result
|
||||
func reset(for bluetoothTransmitter: BluetoothTransmitter, successful: Bool)
|
||||
|
||||
/// to pass some text error message, delegate can decide to show to user, log, ...
|
||||
func error(message: String)
|
||||
|
||||
|
|
|
@ -166,6 +166,7 @@ final class M5StackBluetoothTransmitter: BluetoothTransmitter {
|
|||
func writeRotation(rotation: Int) -> Bool {
|
||||
|
||||
trace("in writeRotation, attempting to send", log: log, category: ConstantsLog.categoryM5StackBluetoothTransmitter, type: .info)
|
||||
|
||||
return writeDataToPeripheral(data: rotationValues[rotation].data, opCode: .writeRotationTx)
|
||||
|
||||
}
|
||||
|
|
|
@ -10,10 +10,6 @@ extension WatlaaBluetoothTransmitterMaster: CGMTransmitter {
|
|||
// no web oop for watlaa as sensorid detection not supported
|
||||
}
|
||||
|
||||
func reset(for bluetoothTransmitter: BluetoothTransmitter, successful: Bool) {
|
||||
// no reset need for watlaa
|
||||
}
|
||||
|
||||
func setWebOOPEnabled(enabled: Bool) {
|
||||
// no web oop for watlaa as sensorid detection not supported
|
||||
}
|
||||
|
|
|
@ -69,4 +69,5 @@ enum ConstantsNotifications {
|
|||
/// transmitter reset result
|
||||
static let transmitterResetResult = "transmitterResetResult"
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ public class BLEPeripheral: NSManagedObject {
|
|||
self.shouldconnect = true
|
||||
self.alias = alias
|
||||
self.parameterUpdateNeededAtNextConnect = false
|
||||
self.resetrequired = false
|
||||
|
||||
webOOPEnabled = false
|
||||
|
||||
|
|
|
@ -16,9 +16,6 @@ extension BLEPeripheral {
|
|||
/// should app try to connect to the device yes or no
|
||||
@NSManaged public var shouldconnect: Bool
|
||||
|
||||
/// is a reset require or not (only applicable to transmitters for which reset is supported, like DexcomG5)
|
||||
@NSManaged public var resetrequired: Bool
|
||||
|
||||
/// alias chosen by user, to recognize the device or to distinguish two devices that have the same name
|
||||
@NSManaged public var alias: String?
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ import CoreData
|
|||
|
||||
public class DexcomG5: NSManagedObject {
|
||||
|
||||
/// should reset be done ? Not stored in coreData, means will be reset to false each time app is resarted
|
||||
public var resetRequired: Bool = false
|
||||
|
||||
/// create DexcomG5
|
||||
/// - parameters:
|
||||
init(address: String, name: String, alias: String?, nsManagedObjectContext:NSManagedObjectContext) {
|
||||
|
|
|
@ -24,4 +24,6 @@ extension DexcomG5 {
|
|||
|
||||
@NSManaged public var voltageB: Int32
|
||||
|
||||
@NSManaged public var lastResetTimeStamp: Date?
|
||||
|
||||
}
|
||||
|
|
|
@ -45,7 +45,6 @@
|
|||
<attribute name="oopWebSite" optional="YES" attributeType="String"/>
|
||||
<attribute name="oopWebToken" optional="YES" attributeType="String"/>
|
||||
<attribute name="parameterUpdateNeededAtNextConnect" attributeType="Boolean" usesScalarValueType="YES"/>
|
||||
<attribute name="resetrequired" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
|
||||
<attribute name="sensorSerialNumber" optional="YES" attributeType="String"/>
|
||||
<attribute name="shouldconnect" attributeType="Boolean" usesScalarValueType="YES"/>
|
||||
<attribute name="transmitterId" optional="YES" attributeType="String"/>
|
||||
|
@ -86,6 +85,7 @@
|
|||
<attribute name="batteryStatus" optional="YES" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/>
|
||||
<attribute name="batteryTemperature" optional="YES" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/>
|
||||
<attribute name="firmwareVersion" optional="YES" attributeType="String"/>
|
||||
<attribute name="lastResetTimeStamp" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
|
||||
<attribute name="voltageA" optional="YES" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/>
|
||||
<attribute name="voltageB" optional="YES" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/>
|
||||
<relationship name="blePeripheral" maxCount="1" deletionRule="Cascade" destinationEntity="BLEPeripheral" inverseName="dexcomG5" inverseEntity="BLEPeripheral"/>
|
||||
|
@ -121,13 +121,13 @@
|
|||
<element name="AlertEntry" positionX="-648" positionY="189" width="128" height="105"/>
|
||||
<element name="AlertType" positionX="-657" positionY="180" width="128" height="165"/>
|
||||
<element name="BgReading" positionX="-285.87109375" positionY="31.9921875" width="128" height="330"/>
|
||||
<element name="BLEPeripheral" positionX="-630" positionY="216" width="128" height="298"/>
|
||||
<element name="BLEPeripheral" positionX="-630" positionY="216" width="128" height="283"/>
|
||||
<element name="Bubble" positionX="-657" positionY="189" width="128" height="103"/>
|
||||
<element name="Calibration" positionX="-859.21484375" positionY="46.21484375" width="128" height="285"/>
|
||||
<element name="DexcomG5" positionX="-648" positionY="198" width="128" height="163"/>
|
||||
<element name="DexcomG5" positionX="-648" positionY="198" width="128" height="178"/>
|
||||
<element name="M5Stack" positionX="-657" positionY="180" width="128" height="163"/>
|
||||
<element name="MiaoMiao" positionX="-657" positionY="189" width="128" height="103"/>
|
||||
<element name="Sensor" positionX="-603.0859375" positionY="482.2890625" width="128" height="133"/>
|
||||
<element name="Watlaa" positionX="-639" positionY="207" width="128" height="58"/>
|
||||
<element name="MiaoMiao" positionX="-657" positionY="189" width="128" height="103"/>
|
||||
</elements>
|
||||
</model>
|
|
@ -124,33 +124,6 @@ extension BluetoothPeripheralManager: BluetoothTransmitterDelegate {
|
|||
}
|
||||
}
|
||||
|
||||
func reset(for bluetoothTransmitter: BluetoothTransmitter, successful: Bool) {
|
||||
|
||||
// set resetrequired to false in coredata, there's no need to reset as it's just been done
|
||||
if let bluetoothPeripheral = getBluetoothPeripheral(for: bluetoothTransmitter) {
|
||||
bluetoothPeripheral.blePeripheral.resetrequired = false
|
||||
}
|
||||
|
||||
// Create Notification Content to give info about reset result of reset attempt
|
||||
let notificationContent = UNMutableNotificationContent()
|
||||
|
||||
// Configure NnotificationContent title
|
||||
notificationContent.title = successful ? Texts_HomeView.info : Texts_Common.warning
|
||||
|
||||
notificationContent.body = Texts_HomeView.transmitterResetResult + " : " + (successful ? Texts_HomeView.success : Texts_HomeView.failed)
|
||||
|
||||
// Create Notification Request
|
||||
let notificationRequest = UNNotificationRequest(identifier: ConstantsNotifications.NotificationIdentifierForResetResult.transmitterResetResult, content: notificationContent, trigger: nil)
|
||||
|
||||
// Add Request to User Notification Center
|
||||
UNUserNotificationCenter.current().add(notificationRequest) { (error) in
|
||||
if let error = error {
|
||||
trace("Unable add notification request : transmitter reset result, error: %{public}@", log: self.log, category: ConstantsLog.categoryRootView, type: .error, error.localizedDescription)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func didConnectTo(bluetoothTransmitter: BluetoothTransmitter) {
|
||||
|
||||
// before exiting save the changes
|
||||
|
|
|
@ -2,9 +2,24 @@ import Foundation
|
|||
|
||||
extension BluetoothPeripheralManager: CGMG5TransmitterDelegate {
|
||||
|
||||
func reset(for cGMG5Transmitter: CGMG5Transmitter, successful: Bool) {
|
||||
|
||||
guard let dexcomG5 = getDexcomG5(cGMG5Transmitter: cGMG5Transmitter) else {return}
|
||||
|
||||
// as reset was done, set back to false
|
||||
dexcomG5.resetRequired = false
|
||||
|
||||
// only if successful, set the lastResetTimeStamp to now
|
||||
if successful {
|
||||
dexcomG5.lastResetTimeStamp = Date()
|
||||
coreDataManager.saveChanges()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func received(transmitterBatteryInfo: TransmitterBatteryInfo, cGMG5Transmitter: CGMG5Transmitter) {
|
||||
|
||||
guard let index = bluetoothTransmitters.firstIndex(of: cGMG5Transmitter), let dexcomG5 = bluetoothPeripherals[index] as? DexcomG5 else {return}
|
||||
guard let dexcomG5 = getDexcomG5(cGMG5Transmitter: cGMG5Transmitter) else {return}
|
||||
|
||||
guard case .DexcomG5(let voltA, let voltB, let res, let runt, let temp) = transmitterBatteryInfo else {return}
|
||||
|
||||
|
@ -25,7 +40,7 @@ extension BluetoothPeripheralManager: CGMG5TransmitterDelegate {
|
|||
|
||||
func received(firmware: String, cGMG5Transmitter: CGMG5Transmitter) {
|
||||
|
||||
guard let index = bluetoothTransmitters.firstIndex(of: cGMG5Transmitter), let dexcomG5 = bluetoothPeripherals[index] as? DexcomG5 else {return}
|
||||
guard let dexcomG5 = getDexcomG5(cGMG5Transmitter: cGMG5Transmitter) else {return}
|
||||
|
||||
dexcomG5.firmwareVersion = firmware
|
||||
|
||||
|
@ -33,4 +48,12 @@ extension BluetoothPeripheralManager: CGMG5TransmitterDelegate {
|
|||
|
||||
}
|
||||
|
||||
private func getDexcomG5(cGMG5Transmitter: CGMG5Transmitter) -> DexcomG5? {
|
||||
|
||||
guard let index = bluetoothTransmitters.firstIndex(of: cGMG5Transmitter), let dexcomG5 = bluetoothPeripherals[index] as? DexcomG5 else {return nil}
|
||||
|
||||
return dexcomG5
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,3 +19,7 @@
|
|||
"disConnectedAt" = "Disconnected At";
|
||||
"connectedAt" = "Connected At";
|
||||
"startScanningInfo" = "Scannnig Started.\n\nKeep xDrip open on the foreground until a connection is made. (there's no need to turn off Auto-Lock. Just don't press the home button and don't lock the iOS device.)";
|
||||
"resetRequired" = "Reset Required";
|
||||
"lastReset" = "Last reset";
|
||||
"lastResetNotKnown" = "Last reset timestamp not known";
|
||||
"transmitterResultResult" = "Transmitter reset result";
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
"transmitternotpaired" = "Transmitter is not paired with this iOS device. Open the application.";
|
||||
"transmitterpairingtoolate" = "Too late, the transmitter has disconnected now. You should get a new pairing request in a few minutes.";
|
||||
"transmitterpairingattempttimeout" = "Transmitter did not reply to pairing request.";
|
||||
"transmitterResultResult" = "Transmitter reset result";
|
||||
"success" = "success";
|
||||
"failed" = "failed";
|
||||
"calibrationNotNecessary" = "With Web OOP enabled, calibration is not necessary for the selected type of transmitter";
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
"transmitternotpaired" = "Transmitter is not paired with this iOS device. Open the application.";
|
||||
"transmitterpairingtoolate" = "Too late, the transmitter has disconnected now. You should get a new pairing request in a few minutes.";
|
||||
"transmitterpairingattempttimeout" = "Transmitter did not reply to pairing request.";
|
||||
"transmitterResultResult" = "Transmitter reset result";
|
||||
"success" = "success";
|
||||
"failed" = "failed";
|
||||
"calibrationNotNecessary" = "With Web OOP enabled, calibration is not necessary for the selected type of transmitter";
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
<key>CFBundleShortVersionString</key>
|
||||
<string>$(MARKETING_VERSION)</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>3662</string>
|
||||
<string>3691</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>NSAppTransportSecurity</key>
|
||||
|
|
|
@ -88,4 +88,20 @@ class Texts_BluetoothPeripheralView {
|
|||
return NSLocalizedString("disConnectedAt", tableName: filename, bundle: Bundle.main, value: "Disconnected At", comment: "cell text, where the disconnection timestamp is shown")
|
||||
}()
|
||||
|
||||
static let resetRequired: String = {
|
||||
return NSLocalizedString("resetRequired", tableName: filename, bundle: Bundle.main, value: "Reset Required", comment: "cell text, where user can select to reset a transmitter at next connect. Only for Dexcom")
|
||||
}()
|
||||
|
||||
static let lastResetTimeStamp: String = {
|
||||
return NSLocalizedString("lastReset", tableName: filename, bundle: Bundle.main, value: "Last reset", comment: "cell text, shows when last reset was done, if known. Only for Dexcom")
|
||||
}()
|
||||
|
||||
static let lastResetTimeStampNotKnown: String = {
|
||||
return NSLocalizedString("lastResetNotKnown", tableName: filename, bundle: Bundle.main, value: "Last reset timestamp not known", comment: "cell text, shows when last reset was done, if known. Only for Dexcom")
|
||||
}()
|
||||
|
||||
static let transmitterResetResult:String = {
|
||||
return NSLocalizedString("transmitterResultResult", tableName: filename, bundle: Bundle.main, value: "Transmitter reset result", comment: "To give result about transitter result in notification body")
|
||||
}()
|
||||
|
||||
}
|
||||
|
|
|
@ -132,10 +132,6 @@ enum Texts_HomeView {
|
|||
return NSLocalizedString("transmitterpairingattempttimeout", tableName: filename, bundle: Bundle.main, value: "Transmitter did not reply to pairing request.", comment: "To give info to user that the transmitter pairing requeset timed out")
|
||||
}()
|
||||
|
||||
static let transmitterResetResult:String = {
|
||||
return NSLocalizedString("transmitterResultResult", tableName: filename, bundle: Bundle.main, value: "Transmitter reset result", comment: "To give result about transitter result in notification body")
|
||||
}()
|
||||
|
||||
static let success:String = {
|
||||
return NSLocalizedString("success", tableName: filename, bundle: Bundle.main, value: "success", comment: "To give result about transitter result in notification body, successful")
|
||||
}()
|
||||
|
@ -147,5 +143,5 @@ enum Texts_HomeView {
|
|||
static let calibrationNotNecessary:String = {
|
||||
return NSLocalizedString("calibrationNotNecessary", tableName: filename, bundle: Bundle.main, value: "With Web OOP enabled, calibration is not necessary for the selected type of transmitter", comment: "if web oop enabled, and also if transmitter supports this, user clicks calibrate button, but calibration is not possible")
|
||||
}()
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -272,21 +272,27 @@ class BluetoothPeripheralViewController: UIViewController {
|
|||
|
||||
}
|
||||
|
||||
override func viewWillDisappear(_ animated: Bool) {
|
||||
|
||||
super.viewWillDisappear(animated)
|
||||
override func willMove(toParent parent: UIViewController?) {
|
||||
|
||||
super.willMove(toParent: parent)
|
||||
|
||||
// willMove is called when BluetoothPeripheralViewController is added and when BluetoothPeripheralViewController is removed.
|
||||
// It has no added value in the adding phase
|
||||
// It doe shave an added value when being removed. bluetoothPeripheralViewModel must be assigned to nil. bluetoothPeripheralViewModel deinit will be called which should reassign the delegate to BluetoothPeripheralManager. Also here the bluetoothtransmitter delegate will be reassigned to BluetoothPeripheralManager
|
||||
// and finally stopScanningForNewDevice will be called, for the case where scanning would still be ongoing
|
||||
|
||||
// save any changes that are made
|
||||
coreDataManager?.saveChanges()
|
||||
|
||||
// set bluetoothPeripheralViewModel to nil. The bluetoothPeripheralViewModel's deinit will be called, which will set the delegate in the model to BluetoothPeripheralManager
|
||||
|
||||
bluetoothPeripheralViewModel = nil
|
||||
|
||||
// reassign delegate in BluetoothTransmitter to bluetoothPeripheralManager
|
||||
reassignBluetoothTransmitterDelegateToBluetoothPeripheralManager()
|
||||
|
||||
// just in case scanning for a new device is still ongoing, call stopscanning
|
||||
bluetoothPeripheralManager?.stopScanningForNewDevice()
|
||||
|
||||
// set bluetoothPeripheralViewModel to nil, so it can change the delegates
|
||||
bluetoothPeripheralViewModel = nil
|
||||
|
||||
}
|
||||
|
||||
|
@ -1096,13 +1102,6 @@ extension BluetoothPeripheralViewController: BluetoothTransmitterDelegate {
|
|||
|
||||
}
|
||||
|
||||
func reset(for bluetoothTransmitter: BluetoothTransmitter, successful: Bool) {
|
||||
|
||||
// handled in BluetoothPeripheralManager
|
||||
bluetoothPeripheralManager?.reset(for: bluetoothTransmitter, successful: successful)
|
||||
|
||||
}
|
||||
|
||||
func didConnectTo(bluetoothTransmitter: BluetoothTransmitter) {
|
||||
|
||||
// handled in BluetoothPeripheralManager
|
||||
|
|
|
@ -15,6 +15,16 @@ class DexcomG5BluetoothPeripheralViewModel {
|
|||
|
||||
}
|
||||
|
||||
private enum ResetSettings:Int, CaseIterable {
|
||||
|
||||
/// should reset be done yes or no
|
||||
case resetRequired = 0
|
||||
|
||||
/// last time reset was done
|
||||
case lastResetTimeStamp = 1
|
||||
|
||||
}
|
||||
|
||||
private enum TransmitterBatteryInfoSettings: Int, CaseIterable {
|
||||
|
||||
case voltageA = 0
|
||||
|
@ -31,13 +41,16 @@ class DexcomG5BluetoothPeripheralViewModel {
|
|||
|
||||
/// - list of sections available in Dexcom
|
||||
/// - counting starts at 0
|
||||
private enum DexcomSections: Int, CaseIterable {
|
||||
private enum DexcomSection: Int, CaseIterable {
|
||||
|
||||
/// helptest, blepassword, rotation, color, ... settings applicable to both M5Stack and M5StickC
|
||||
case commonDexcomSettings = 0
|
||||
|
||||
/// reset settings
|
||||
case resetSetings = 1
|
||||
|
||||
/// batterySettings
|
||||
case batterySettings = 1
|
||||
case batterySettings = 2
|
||||
|
||||
}
|
||||
|
||||
|
@ -60,30 +73,53 @@ class DexcomG5BluetoothPeripheralViewModel {
|
|||
}
|
||||
}
|
||||
|
||||
// MARK: - deinit
|
||||
// MARK: - deinit
|
||||
|
||||
deinit {
|
||||
|
||||
// when closing the viewModel, and if there's still a bluetoothTransmitter existing, then reset the specific delegate to BluetoothPeripheralManager
|
||||
|
||||
guard let bluetoothPeripheralManager = bluetoothPeripheralManager else {return}
|
||||
|
||||
guard let dexcomG5 = dexcomG5 else {return}
|
||||
|
||||
guard let blueToothTransmitter = bluetoothPeripheralManager.getBluetoothTransmitter(for: dexcomG5, createANewOneIfNecesssary: false) else {return}
|
||||
|
||||
guard let cGMG5Transmitter = blueToothTransmitter as? CGMG5Transmitter else {return}
|
||||
guard let cGMG5Transmitter = getTransmitter(for: dexcomG5) else {return}
|
||||
|
||||
cGMG5Transmitter.cGMG5TransmitterDelegate = bluetoothPeripheralManager as! BluetoothPeripheralManager
|
||||
|
||||
}
|
||||
|
||||
// MARK: - private functions
|
||||
|
||||
private func getDexcomSection(forSectionInTable section: Int) -> DexcomSection {
|
||||
|
||||
guard let bluetoothPeripheralViewController = bluetoothPeripheralViewController else {
|
||||
fatalError("in DexcomG5BluetoothPeripheralViewModel, getDexcomSection(forSectionInTable section: Int), bluetoothPeripheralViewController is nil")
|
||||
}
|
||||
|
||||
guard let dexcomSection = DexcomSection(rawValue: section - bluetoothPeripheralViewController.numberOfGeneralSections()) else {
|
||||
fatalError("in DexcomG5BluetoothPeripheralViewModel, getDexcomSection(forSectionInTable section: Int), could not create dexcomSection is nil")
|
||||
}
|
||||
|
||||
return dexcomSection
|
||||
|
||||
}
|
||||
|
||||
private func getTransmitter(for dexcomG5: DexcomG5) -> CGMG5Transmitter? {
|
||||
|
||||
if let bluetoothPeripheralManager = bluetoothPeripheralManager, let blueToothTransmitter = bluetoothPeripheralManager.getBluetoothTransmitter(for: dexcomG5, createANewOneIfNecesssary: false), let cGMG5Transmitter = blueToothTransmitter as? CGMG5Transmitter {
|
||||
|
||||
return cGMG5Transmitter
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - conform to BluetoothPeripheralViewModel
|
||||
|
||||
extension DexcomG5BluetoothPeripheralViewModel: BluetoothPeripheralViewModel {
|
||||
|
||||
|
||||
func canWebOOP() -> Bool {
|
||||
// web oop only applicable to cgm transmitters and DexcomG5 is not a cgm transmitter
|
||||
return false
|
||||
|
@ -103,11 +139,11 @@ extension DexcomG5BluetoothPeripheralViewModel: BluetoothPeripheralViewModel {
|
|||
|
||||
if let dexcomG5 = bluetoothPeripheral as? DexcomG5 {
|
||||
|
||||
if let blueToothTransmitter = bluetoothPeripheralManager.getBluetoothTransmitter(for: dexcomG5, createANewOneIfNecesssary: false), let cGMG5Transmitter = blueToothTransmitter as? CGMG5Transmitter {
|
||||
if let cGMG5Transmitter = getTransmitter(for: dexcomG5) {
|
||||
|
||||
// set cGMG5Transmitter delegate to self.
|
||||
cGMG5Transmitter.cGMG5TransmitterDelegate = self
|
||||
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
@ -124,15 +160,19 @@ extension DexcomG5BluetoothPeripheralViewModel: BluetoothPeripheralViewModel {
|
|||
|
||||
func sectionTitle(forSection section: Int) -> String {
|
||||
|
||||
// unwrap
|
||||
guard let bluetoothPeripheralViewController = bluetoothPeripheralViewController else {return ""}
|
||||
|
||||
if section == DexcomSections.commonDexcomSettings.rawValue + bluetoothPeripheralViewController.numberOfGeneralSections() {
|
||||
return "Dexcom"
|
||||
} else {
|
||||
switch getDexcomSection(forSectionInTable: section) {
|
||||
|
||||
case .resetSetings:
|
||||
return Texts_SettingsView.labelResetTransmitter
|
||||
|
||||
case .batterySettings:
|
||||
return Texts_BluetoothPeripheralView.battery
|
||||
|
||||
case .commonDexcomSettings:
|
||||
return "Dexcom"
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
func update(cell: UITableViewCell, forRow rawValue: Int, forSection section: Int, for bluetoothPeripheral: BluetoothPeripheral) {
|
||||
|
@ -142,14 +182,13 @@ extension DexcomG5BluetoothPeripheralViewModel: BluetoothPeripheralViewModel {
|
|||
fatalError("DexcomG5BluetoothPeripheralViewModel update, bluetoothPeripheral is not DexcomG5")
|
||||
}
|
||||
|
||||
//unwrap
|
||||
guard let bluetoothPeripheralViewController = bluetoothPeripheralViewController else {return}
|
||||
|
||||
// default value for accessoryView is nil
|
||||
cell.accessoryView = nil
|
||||
|
||||
if section == DexcomSections.commonDexcomSettings.rawValue + bluetoothPeripheralViewController.numberOfGeneralSections() {
|
||||
|
||||
switch getDexcomSection(forSectionInTable: section) {
|
||||
|
||||
case .commonDexcomSettings:
|
||||
|
||||
// section that has for the moment only the firmware
|
||||
guard let setting = Settings(rawValue: rawValue) else { fatalError("DexcomG5BluetoothPeripheralViewModel update, unexpected setting") }
|
||||
|
||||
|
@ -163,8 +202,51 @@ extension DexcomG5BluetoothPeripheralViewModel: BluetoothPeripheralViewModel {
|
|||
|
||||
}
|
||||
|
||||
} else if section == DexcomSections.batterySettings.rawValue + bluetoothPeripheralViewController.numberOfGeneralSections() {
|
||||
case .resetSetings:
|
||||
|
||||
// reset section
|
||||
guard let setting = ResetSettings(rawValue: rawValue) else { fatalError("DexcomG5BluetoothPeripheralViewModel update, unexpected setting") }
|
||||
|
||||
switch setting {
|
||||
|
||||
case .resetRequired:
|
||||
|
||||
cell.textLabel?.text = Texts_BluetoothPeripheralView.resetRequired
|
||||
cell.detailTextLabel?.text = nil //it's a UISwitch, no detailed text
|
||||
cell.accessoryType = .none
|
||||
cell.accessoryView = UISwitch(isOn: dexcomG5.resetRequired, action: { (isOn:Bool) in
|
||||
|
||||
dexcomG5.resetRequired = isOn
|
||||
|
||||
if let cGMG5Transmitter = self.getTransmitter(for: dexcomG5) {
|
||||
|
||||
// set isOn value to cGMG5Transmitter
|
||||
cGMG5Transmitter.reset(requested: isOn)
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
case .lastResetTimeStamp:
|
||||
|
||||
if let lastResetTimeStamp = dexcomG5.lastResetTimeStamp {
|
||||
|
||||
cell.textLabel?.text = Texts_BluetoothPeripheralView.lastResetTimeStamp
|
||||
cell.detailTextLabel?.text = lastResetTimeStamp.toShortString()
|
||||
cell.accessoryType = .none
|
||||
|
||||
} else {
|
||||
|
||||
cell.textLabel?.text = Texts_BluetoothPeripheralView.lastResetTimeStampNotKnown
|
||||
cell.detailTextLabel?.text = nil
|
||||
cell.accessoryType = .none
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
case .batterySettings:
|
||||
|
||||
// battery info section
|
||||
guard let setting = TransmitterBatteryInfoSettings(rawValue: rawValue) else { fatalError("DexcomG5BluetoothPeripheralViewModel update, unexpected setting") }
|
||||
|
||||
|
@ -198,7 +280,7 @@ extension DexcomG5BluetoothPeripheralViewModel: BluetoothPeripheralViewModel {
|
|||
cell.detailTextLabel?.text = dexcomG5.batteryTemperature != 0 ? dexcomG5.batteryTemperature.description : ""
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -207,43 +289,65 @@ extension DexcomG5BluetoothPeripheralViewModel: BluetoothPeripheralViewModel {
|
|||
|
||||
return .nothing
|
||||
|
||||
// verify that bluetoothPeripheral is a DexcomG5
|
||||
/*guard let dexcomG5 = bluetoothPeripheral as? DexcomG5 else {
|
||||
fatalError("DexcomG5BluetoothPeripheralViewModel userDidSelectRow, bluetoothPeripheral is not DexcomG5")
|
||||
}
|
||||
|
||||
guard let setting = Settings(rawValue: rawValue) else { fatalError("DexcomG5BluetoothPeripheralViewModel userDidSelectRow, unexpected setting") }
|
||||
|
||||
switch setting {
|
||||
|
||||
case .firmWareVersion:
|
||||
return .nothing
|
||||
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
func numberOfSettings(inSection section: Int) -> Int {
|
||||
|
||||
//unwrap
|
||||
guard let bluetoothPeripheralViewController = bluetoothPeripheralViewController else {return 0}
|
||||
|
||||
if section == DexcomSections.commonDexcomSettings.rawValue + bluetoothPeripheralViewController.numberOfGeneralSections() {
|
||||
switch getDexcomSection(forSectionInTable: section) {
|
||||
|
||||
case .commonDexcomSettings:
|
||||
return Settings.allCases.count
|
||||
} else {
|
||||
|
||||
case .resetSetings:
|
||||
return ResetSettings.allCases.count
|
||||
|
||||
case .batterySettings:
|
||||
return TransmitterBatteryInfoSettings.allCases.count
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
func numberOfSections() -> Int {
|
||||
return DexcomSections.allCases.count
|
||||
|
||||
return DexcomSection.allCases.count
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension DexcomG5BluetoothPeripheralViewModel: CGMG5TransmitterDelegate {
|
||||
|
||||
func reset(for cGMG5Transmitter: CGMG5Transmitter, successful: Bool) {
|
||||
|
||||
// storage in dexcomG5 object is handled in bluetoothPeripheralManager
|
||||
(bluetoothPeripheralManager as? CGMG5TransmitterDelegate)?.reset(for: cGMG5Transmitter, successful: successful)
|
||||
|
||||
// update two rows
|
||||
if let bluetoothPeripheralViewController = bluetoothPeripheralViewController {
|
||||
|
||||
tableView?.reloadSections(IndexSet(integer: DexcomSection.resetSetings.rawValue +
|
||||
bluetoothPeripheralViewController.numberOfGeneralSections()), with: .none)
|
||||
|
||||
}
|
||||
|
||||
// Create Notification Content to give info about reset result of reset attempt
|
||||
let notificationContent = UNMutableNotificationContent()
|
||||
|
||||
// Configure notificationContent title
|
||||
notificationContent.title = successful ? Texts_HomeView.info : Texts_Common.warning
|
||||
|
||||
// Configure notificationContent body
|
||||
notificationContent.body = Texts_BluetoothPeripheralView.transmitterResetResult + " : " + (successful ? Texts_HomeView.success : Texts_HomeView.failed)
|
||||
|
||||
// Create Notification Request
|
||||
let notificationRequest = UNNotificationRequest(identifier: ConstantsNotifications.NotificationIdentifierForResetResult.transmitterResetResult, content: notificationContent, trigger: nil)
|
||||
|
||||
// Add Request to User Notification Center
|
||||
UNUserNotificationCenter.current().add(notificationRequest)
|
||||
|
||||
}
|
||||
|
||||
func received(transmitterBatteryInfo: TransmitterBatteryInfo, cGMG5Transmitter: CGMG5Transmitter) {
|
||||
|
||||
// storage in dexcomG5 object is handled in bluetoothPeripheralManager
|
||||
|
@ -251,7 +355,7 @@ extension DexcomG5BluetoothPeripheralViewModel: CGMG5TransmitterDelegate {
|
|||
|
||||
// update rows
|
||||
if let bluetoothPeripheralViewController = bluetoothPeripheralViewController {
|
||||
tableView?.reloadSections(IndexSet(integer: DexcomSections.batterySettings.rawValue + bluetoothPeripheralViewController.numberOfGeneralSections()), with: .none)
|
||||
tableView?.reloadSections(IndexSet(integer: DexcomSection.batterySettings.rawValue + bluetoothPeripheralViewController.numberOfGeneralSections()), with: .none)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -262,7 +366,7 @@ extension DexcomG5BluetoothPeripheralViewModel: CGMG5TransmitterDelegate {
|
|||
|
||||
// firmware should get updated in DexcomG5 object by bluetoothPeripheralManager, here's the trigger to update the table
|
||||
if let bluetoothPeripheralViewController = bluetoothPeripheralViewController {
|
||||
reloadRow(row: Settings.firmWareVersion.rawValue, section: DexcomSections.commonDexcomSettings.rawValue + bluetoothPeripheralViewController.numberOfGeneralSections())
|
||||
reloadRow(row: Settings.firmWareVersion.rawValue, section: DexcomSection.commonDexcomSettings.rawValue + bluetoothPeripheralViewController.numberOfGeneralSections())
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -258,8 +258,8 @@ class M5StackBluetoothPeripheralViewModel {
|
|||
|
||||
if index != selectedRow {
|
||||
|
||||
// set rotationTempValue to new rotation
|
||||
m5Stack.rotation = Int32(index * 10)
|
||||
// set brightness to new brightness
|
||||
m5Stack.brightness = Int16(index * 10)
|
||||
|
||||
// send value to M5Stack, if that would fail then set updateNeeded for that m5Stack
|
||||
if let blueToothTransmitter = bluetoothPeripheralManager.getBluetoothTransmitter(for: m5Stack, createANewOneIfNecesssary: false), let m5StackBluetoothTransmitter = blueToothTransmitter as? M5StackBluetoothTransmitter, m5StackBluetoothTransmitter.writeBrightness(brightness: index * 10) {
|
||||
|
@ -437,7 +437,6 @@ class M5StackBluetoothPeripheralViewModel {
|
|||
deinit {
|
||||
|
||||
// when closing the viewModel, and if there's still a bluetoothTransmitter existing, then reset the specific delegate to BluetoothPeripheralManager
|
||||
|
||||
guard let bluetoothPeripheralManager = bluetoothPeripheralManager else {return}
|
||||
|
||||
guard let m5Stack = m5Stack else {return}
|
||||
|
@ -445,7 +444,7 @@ class M5StackBluetoothPeripheralViewModel {
|
|||
guard let blueToothTransmitter = bluetoothPeripheralManager.getBluetoothTransmitter(for: m5Stack, createANewOneIfNecesssary: false) else {return}
|
||||
|
||||
guard let m5StackBluetoothTransmitter = blueToothTransmitter as? M5StackBluetoothTransmitter else {return}
|
||||
|
||||
|
||||
m5StackBluetoothTransmitter.m5StackBluetoothTransmitterDelegate = bluetoothPeripheralManager as! BluetoothPeripheralManager
|
||||
|
||||
}
|
||||
|
|
|
@ -230,7 +230,7 @@ final class BluetoothPeripheralsViewController: UIViewController {
|
|||
/// - sets the delegates of each transmitter to self
|
||||
/// - bluetoothPeripheralManager will also still receive delegate calls
|
||||
private func initializeBluetoothTransmitterDelegates() {
|
||||
|
||||
|
||||
if let bluetoothPeripheralManager = bluetoothPeripheralManager {
|
||||
|
||||
for bluetoothTransmitter in bluetoothPeripheralManager.getBluetoothTransmitters() {
|
||||
|
@ -356,13 +356,6 @@ extension BluetoothPeripheralsViewController: BluetoothTransmitterDelegate {
|
|||
|
||||
}
|
||||
|
||||
func reset(for bluetoothTransmitter: BluetoothTransmitter, successful: Bool) {
|
||||
|
||||
// forward this call to bluetoothPeripheralManager who will handle it
|
||||
bluetoothPeripheralManager?.reset(for: bluetoothTransmitter, successful: successful)
|
||||
|
||||
}
|
||||
|
||||
func error(message: String) {
|
||||
|
||||
// forward this call to bluetoothPeripheralManager who will handle it
|
||||
|
|
|
@ -1270,10 +1270,6 @@ extension RootViewController: UNUserNotificationCenterDelegate {
|
|||
// call completionhandler to show the notification even though the app is in the foreground, without sound
|
||||
completionHandler([.alert])
|
||||
|
||||
} else if notification.request.identifier == ConstantsNotifications.NotificationIdentifierForResetResult.transmitterResetResult {
|
||||
|
||||
completionHandler([.alert])
|
||||
|
||||
} else if notification.request.identifier == ConstantsNotifications.NotificationIdentifierForTransmitterNeedsPairing.transmitterNeedsPairing {
|
||||
|
||||
// so actually the app was in the foreground, at the moment the Transmitter Class called the cgmTransmitterNeedsPairing function, there's no need to show the notification, we can immediately call back the cgmTransmitter initiatePairing function
|
||||
|
@ -1319,10 +1315,6 @@ extension RootViewController: UNUserNotificationCenterDelegate {
|
|||
|
||||
// nothing required, the pairing function will be called as it's been added to ApplicationManager in function cgmTransmitterNeedsPairing
|
||||
|
||||
} else if response.notification.request.identifier == ConstantsNotifications.NotificationIdentifierForResetResult.transmitterResetResult {
|
||||
|
||||
// nothing required
|
||||
|
||||
} else {
|
||||
|
||||
// it's not an initial calibration request notification that the user clicked, by calling alertManager?.userNotificationCenter, we check if it was an alert notification that was clicked and if yes pickerViewData will have the list of alert snooze values
|
||||
|
|
Loading…
Reference in New Issue