Skip to content

Commit

Permalink
Support the newer libre 2 plus European sensors. (Artificial-Pancreas…
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon-b-m authored Oct 29, 2024
1 parent 30ab903 commit e754f18
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,22 @@ extension String {
}

public enum SensorType: String, CustomStringConvertible {
case libre1 = "DF"
case libre1A2 = "A2"
case libre2 = "9D"
case libre1 = "DF"
case libre1A2 = "A2"
case libre2 = "9D"
case libre2C5 = "C5"
case libreUS14day = "E5"
case libreUS14day = "E5"
case libreUS14dayE6 = "E6"
case libreProH = "70"
case libre2Plus = "C6"

public var description: String {
switch self {
case .libre1:
return "Libre 1"
case .libre1A2:
return "Libre 1 A2"
case .libre2, .libre2C5:
case .libre2, .libre2C5, .libre2Plus:
return "Libre 2"
case .libreUS14day, .libreUS14dayE6:
return "Libre US"
Expand All @@ -107,7 +108,7 @@ public extension SensorType {

let start = patchInfo[0..<2].uppercased()

let choices: [String: SensorType] = ["DF": .libre1, "A2": .libre1A2, "9D": .libre2, "C5": .libre2, "E5": .libreUS14day, "E6": .libreUS14dayE6, "70": .libreProH]
let choices: [String: SensorType] = ["DF": .libre1, "A2": .libre1A2, "9D": .libre2, "C5": .libre2C5, "C6": .libre2Plus, "E5": .libreUS14day, "E6": .libreUS14dayE6, "70": .libreProH]

if let res = choices[start] {
self = res
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public enum Libre2 {
/// - data: Encrypted FRAM data
/// - Returns: Decrypted FRAM data
static public func decryptFRAM(type: SensorType, id: [UInt8], info: [UInt8], data: [UInt8]) throws -> [UInt8] {
guard type == .libre2 || type == .libre2C5 || type == .libreUS14day || type == .libreUS14dayE6 else {
guard type == .libre2 || type == .libre2C5 || type == .libreUS14day || type == .libreUS14dayE6 || type == .libre2Plus else {
struct DecryptFRAMError: Error {
let errorDescription = "Unsupported sensor type"
}
Expand All @@ -24,8 +24,9 @@ public enum Libre2 {
return 0xcadc
}
return UInt16(info[5], info[4])
case .libre2, .libre2C5:
case .libre2, .libre2C5, .libre2Plus:
return UInt16(info[5], info[4]) ^ 0x44

default: fatalError("Unsupported sensor type")
}
}
Expand Down

0 comments on commit e754f18

Please sign in to comment.