diff --git a/HDFwear/Home/Model/HealthModel.swift b/HDFwear/Home/Model/HealthModel.swift index af5d1f1..985d425 100644 --- a/HDFwear/Home/Model/HealthModel.swift +++ b/HDFwear/Home/Model/HealthModel.swift @@ -1158,9 +1158,11 @@ class BloodOxygenModel: Object { //MARK: - 睡眠 enum SleepType: Int { - case awake = 0 - case deep = 1 - case light = 2 + case awake = 7 + case eyeMove = 8 + case light = 9 + case deep = 10 + } class SleepModel: Object { @@ -1191,66 +1193,21 @@ class SleepModel: Object { class func toSleepArray(_ bytes: [UInt8]) -> [SleepModel] { var sleepArray: [SleepModel] = [] - let date = DateInRegion(year: Int(bytes[0])+2000, month: Int(bytes[1]), day: Int(bytes[2])-1, hour: 22, minute: 0, second: 0).date - let sleepBytes = Array(bytes[3.. 20 { - startDate = DateInRegion(year: Int(bytes[0])+2000, month: Int(bytes[1]), day: Int(bytes[2])-1, hour: Int(sleepBytes[i*3+1]), minute: Int(sleepBytes[i*3+2])).date - } else { - startDate = DateInRegion(year: Int(bytes[0])+2000, month: Int(bytes[1]), day: Int(bytes[2]), hour: Int(sleepBytes[i*3+1]), minute: Int(sleepBytes[i*3+2])).date - } - // if i < num { - if Int(sleepBytes[(i+1)*3+1]) > 20 { - endDate = DateInRegion(year: Int(bytes[0])+2000, month: Int(bytes[1]), day: Int(bytes[2])-1, hour: Int(sleepBytes[(i+1)*3+1]), minute: Int(sleepBytes[(i+1)*3+2])).date - } else { - endDate = DateInRegion(year: Int(bytes[0])+2000, month: Int(bytes[1]), day: Int(bytes[2]), hour: Int(sleepBytes[(i+1)*3+1]), minute: Int(sleepBytes[(i+1)*3+2])).date - } - if platform == ._828 { - if rawInt == 1 { - rawInt = 2 - } else if rawInt == 2 { - rawInt = 1 - } - endDate = endDate + 1.days - startDate = startDate + 1.days - } - - - sleepArray.append(SleepModel(type: SleepType(rawValue: rawInt) ?? .awake, startDate: startDate, endDate: endDate)) - // } - - - - /* - if i == 0 { - sleepArray.append(SleepModel(type: .awake, startDate: date, endDate: date+Int(sleepBytes[i*3+1]).hours+Int(sleepBytes[i*3+2]).minutes)) - } else { - var rawInt = Int(sleepBytes[(i-1)*3]) - if rawInt == 1 { - rawInt = 2 - } else if rawInt == 2 { - rawInt = 1 - } - sleepArray.append(SleepModel(type: SleepType(rawValue: rawInt) ?? .awake, startDate: date+Int(sleepBytes[(i-1)*3+1]).hours+Int(sleepBytes[(i-1)*3+2]).minutes, endDate: date+Int(sleepBytes[i*3+1]).hours+Int(sleepBytes[i*3+2]).minutes)) - } - */ + // 将数组分成13个一组 + let groupedArray = stride(from: 0, to: bytes.count, by: 13).map { Array(bytes[$0.. 0 else { + print("无有效的信息") + sleepClosure?([], nil) + return + } + let array = SleepModel.toSleepArray(content) + SleepModel.addArray(array)// 加入数据库 + sleepClosure?(array, nil) + } }