From b8d5b0dea77b098a1c9d88e410f485b7b17b8fd7 Mon Sep 17 00:00:00 2001 From: Johan Degraeve Date: Tue, 21 Jul 2020 17:30:24 +0200 Subject: [PATCH] fix #131 - with 4.2 a check was added on slope parameters. This was taken over from bubbledevteam pull request. Apparently this causes Libre 1 A2 failure. --- .../Utilities/Libre1DerivedAlgorithmParameters.swift | 8 +------- .../CGM/Libre/Utilities/LibreDataParser.swift | 5 +++-- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/xdrip/BluetoothTransmitter/CGM/Libre/Utilities/Libre1DerivedAlgorithmParameters.swift b/xdrip/BluetoothTransmitter/CGM/Libre/Utilities/Libre1DerivedAlgorithmParameters.swift index c90233cc4..750fea804 100644 --- a/xdrip/BluetoothTransmitter/CGM/Libre/Utilities/Libre1DerivedAlgorithmParameters.swift +++ b/xdrip/BluetoothTransmitter/CGM/Libre/Utilities/Libre1DerivedAlgorithmParameters.swift @@ -24,13 +24,7 @@ public struct Libre1DerivedAlgorithmParameters: Codable, CustomStringConvertible return "LibreDerivedAlgorithmParameters:: slopeslope: \(slope_slope), slopeoffset: \(slope_offset), offsetoffset: \(offset_offset), offsetSlope: \(offset_slope), extraSlope: \(extraSlope), extraOffset: \(extraOffset), isValidForFooterWithReverseCRCs: \(isValidForFooterWithReverseCRCs)" } - /// init will fail if slope_slope == 0 && slope_offset == 0 && offset_slope == 0 && offset_offset == 0 - public init?(slope_slope: Double, slope_offset:Double, offset_slope: Double, offset_offset: Double, isValidForFooterWithReverseCRCs: Int, extraSlope: Double, extraOffset: Double, sensorSerialNumber:String) { - - guard slope_slope != 0 && - slope_offset != 0 && - offset_slope != 0 && - offset_offset != 0 else {return nil} + public init(slope_slope: Double, slope_offset:Double, offset_slope: Double, offset_offset: Double, isValidForFooterWithReverseCRCs: Int, extraSlope: Double, extraOffset: Double, sensorSerialNumber:String) { self.slope_slope = slope_slope self.slope_offset = slope_offset diff --git a/xdrip/BluetoothTransmitter/CGM/Libre/Utilities/LibreDataParser.swift b/xdrip/BluetoothTransmitter/CGM/Libre/Utilities/LibreDataParser.swift index 20bf5697e..e44bbc550 100644 --- a/xdrip/BluetoothTransmitter/CGM/Libre/Utilities/LibreDataParser.swift +++ b/xdrip/BluetoothTransmitter/CGM/Libre/Utilities/LibreDataParser.swift @@ -144,8 +144,9 @@ class LibreDataParser { LibreOOPClient.getOopWebCalibrationStatus(bytes: libreData, libreSensorSerialNumber: libreSensorSerialNumber, oopWebSite: oopWebSite, oopWebToken: oopWebToken) { (oopWebCalibrationStatus, xDripError) in if let oopWebCalibrationStatus = oopWebCalibrationStatus as? OopWebCalibrationStatus, - let slope = oopWebCalibrationStatus.slope, - let libre1DerivedAlgorithmParameters = Libre1DerivedAlgorithmParameters(slope_slope: slope.slopeSlope ?? 0, slope_offset: slope.slopeOffset ?? 0, offset_slope: slope.offsetSlope ?? 0, offset_offset: slope.offsetOffset ?? 0, isValidForFooterWithReverseCRCs: Int(slope.isValidForFooterWithReverseCRCs ?? 1), extraSlope: 1.0, extraOffset: 0.0, sensorSerialNumber: libreSensorSerialNumber.serialNumber) { + let slope = oopWebCalibrationStatus.slope { + + let libre1DerivedAlgorithmParameters = Libre1DerivedAlgorithmParameters(slope_slope: slope.slopeSlope ?? 0, slope_offset: slope.slopeOffset ?? 0, offset_slope: slope.offsetSlope ?? 0, offset_offset: slope.offsetOffset ?? 0, isValidForFooterWithReverseCRCs: Int(slope.isValidForFooterWithReverseCRCs ?? 1), extraSlope: 1.0, extraOffset: 0.0, sensorSerialNumber: libreSensorSerialNumber.serialNumber) // store result in UserDefaults, next time, server will not be used anymore, we will use the stored value UserDefaults.standard.libre1DerivedAlgorithmParameters = libre1DerivedAlgorithmParameters