Skip to content

Commit

Permalink
Add support for recovery mode, minor updates to Infineat watchface, a…
Browse files Browse the repository at this point in the history
…dd brightness level to watch settings
  • Loading branch information
liamcharger committed Mar 19, 2024
1 parent 073ed20 commit 7ff39d9
Show file tree
Hide file tree
Showing 13 changed files with 259 additions and 174 deletions.
2 changes: 1 addition & 1 deletion InfiniLink/BLE/BLEManagerVariables.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class BLEManagerVal: NSObject, ObservableObject {

@Published var watchFace: Int = -1
@Published var pineTimeStyleData: PineTimeStyleData?
@Published var infineatWatchFace: WatchFaceInfineat?
@Published var timeFormat: ClockType?
@Published var infineatColorIndex: UInt8 = 0

@Published var weatherInformation = WeatherInformation()
@Published var loadingWeather = true
Expand Down
24 changes: 14 additions & 10 deletions InfiniLink/BLE/BLE_FS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,6 @@ class BLEFSHandler : ObservableObject {
readFileFS.group.wait()
}

// print(readFileFS.data.hexString)

return readFileFS
}

Expand Down Expand Up @@ -602,6 +600,12 @@ enum WakeUpMode: UInt8 {
case LowerWrist = 4
}

enum BrightLevel: UInt8 {
case Low = 0
case Mid = 1
case High = 2
}

enum Colors: UInt8 {
case White = 0
case Silver = 1
Expand Down Expand Up @@ -635,16 +639,16 @@ enum PTSWeather: UInt8 {
}

struct PineTimeStyleData {
let ColorTime : Colors = .Teal
let ColorBar : Colors = .Teal
let ColorBG : Colors = .Black
let gaugeStyle : PTSGaugeStyle = .Full
let weatherEnable : PTSWeather = .Off
let ColorTime: Colors = .Teal
let ColorBar: Colors = .Teal
let ColorBG: Colors = .Black
let gaugeStyle: PTSGaugeStyle = .Full
let weatherEnable: PTSWeather = .Off
}

struct WatchFaceInfineat {
let showSideCover : Bool = true
let colorIndex : UInt8 = 0
let showSideCover: Bool = true
let colorIndex: UInt8 = 0
}

struct Settings {
Expand All @@ -660,5 +664,5 @@ struct Settings {
let watchFaceInfineat: WatchFaceInfineat
let wakeUpMode: WakeUpMode
let shakeWakeThreshold: UInt16
let brightLevel: UInt8
let brightLevel: BrightLevel
}
54 changes: 28 additions & 26 deletions InfiniLink/Core/Home/DFU/DFUDownloadView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,33 +85,35 @@ struct DownloadView: View {
DebugLogManager.shared.debug(error: error.localizedDescription, log: .dfu, date: Date())
}
}
Button {
externalResources = true
showResourcePicker = true
} label: {
Text(NSLocalizedString("update_external_resources", comment: ""))
.frame(maxWidth: .infinity)
.padding()
.background(Color.blue)
.foregroundColor(.white)
.clipShape(Capsule())
}
.fileImporter(isPresented: $showResourcePicker, allowedContentTypes: [.zip]) { (res) in
do {
let fileUrl = try res.get()

guard fileUrl.startAccessingSecurityScopedResource() else { return }

dfuUpdater.firmwareSelected = true
dfuUpdater.resourceFilename = fileUrl.lastPathComponent
dfuUpdater.firmwareURL = fileUrl.absoluteURL

if BLEManager.shared.blefsTransfer != nil {
Button {
externalResources = true

fileUrl.stopAccessingSecurityScopedResource()
presentation.wrappedValue.dismiss()
} catch{
DebugLogManager.shared.debug(error: error.localizedDescription, log: .dfu, date: Date())
showResourcePicker = true
} label: {
Text(NSLocalizedString("update_external_resources", comment: ""))
.frame(maxWidth: .infinity)
.padding()
.background(Color.blue)
.foregroundColor(.white)
.clipShape(Capsule())
}
.fileImporter(isPresented: $showResourcePicker, allowedContentTypes: [.zip]) { (res) in
do {
let fileUrl = try res.get()

guard fileUrl.startAccessingSecurityScopedResource() else { return }

dfuUpdater.firmwareSelected = true
dfuUpdater.resourceFilename = fileUrl.lastPathComponent
dfuUpdater.firmwareURL = fileUrl.absoluteURL

externalResources = true

fileUrl.stopAccessingSecurityScopedResource()
presentation.wrappedValue.dismiss()
} catch {
DebugLogManager.shared.debug(error: error.localizedDescription, log: .dfu, date: Date())
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions InfiniLink/Core/Home/DFU/DFUWithBLE.swift
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,9 @@ struct NewUpdate: View {
}
}
DFUStartTransferButton(updateStarted: $updateStarted, firmwareSelected: $dfuUpdater.firmwareSelected, externalResources: .constant(false))
.disabled(bleManager.batteryLevel <= 30)
.opacity(bleManager.batteryLevel <= 30 ? 0.5 : 1.0)
if bleManager.batteryLevel <= 30 {
.disabled((bleManager.batteryLevel <= 30 && bleManager.blefsTransfer != nil))
.opacity((bleManager.batteryLevel <= 30 && bleManager.blefsTransfer != nil) ? 0.5 : 1.0)
if bleManager.batteryLevel <= 30 && bleManager.blefsTransfer != nil {
Text(NSLocalizedString("update_requirement_1", comment: "") + deviceInfo.deviceName + NSLocalizedString("update_requirement_2", comment: ""))
.foregroundColor(.gray)
.font(.system(size: 15))
Expand Down
28 changes: 15 additions & 13 deletions InfiniLink/Core/Home/DeviceView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -421,19 +421,21 @@ struct CustomScrollView<Content: View>: View {
.onChange(of: deviceInfo.firmware) { firmware in
if firmware != "" {
DispatchQueue.main.async {
BLEFSHandler.shared.readSettings { settings in
self.settings = settings
print(settings)
self.stepCountGoal = Int(settings.stepsGoal)
self.bleManagerVal.watchFace = Int(settings.watchFace)
self.bleManagerVal.pineTimeStyleData = settings.pineTimeStyle
self.bleManagerVal.timeFormat = settings.clockType
self.bleManagerVal.infineatColorIndex = settings.watchFaceInfineat.colorIndex
switch settings.weatherFormat {
case .Metric:
self.deviceDataForSettings.chosenWeatherMode = "Metric"
case .Imperial:
self.deviceDataForSettings.chosenWeatherMode = "Imperial"
if bleManager.blefsTransfer != nil {
BLEFSHandler.shared.readSettings { settings in
self.settings = settings
print(settings)
self.stepCountGoal = Int(settings.stepsGoal)
self.bleManagerVal.watchFace = Int(settings.watchFace)
self.bleManagerVal.pineTimeStyleData = settings.pineTimeStyle
self.bleManagerVal.timeFormat = settings.clockType
self.bleManagerVal.infineatWatchFace = settings.watchFaceInfineat
switch settings.weatherFormat {
case .Metric:
self.deviceDataForSettings.chosenWeatherMode = "Metric"
case .Imperial:
self.deviceDataForSettings.chosenWeatherMode = "Imperial"
}
}
}
}
Expand Down
125 changes: 61 additions & 64 deletions InfiniLink/Core/Home/WatchFace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ struct InfineatWF: View {
func infineatColor(for item: InfineatItem) -> Color {
switch item {
case .base:
switch bleManagerVal.infineatColorIndex {
switch bleManagerVal.infineatWatchFace?.colorIndex {
case 0:
return orangeColors[2]
case 1:
Expand All @@ -413,10 +413,10 @@ struct InfineatWF: View {
case 6:
return nordGreenColors[2]
default:
break
return orangeColors[2]
}
case .bottom:
switch bleManagerVal.infineatColorIndex {
switch bleManagerVal.infineatWatchFace?.colorIndex {
case 0:
return orangeColors[1]
case 1:
Expand All @@ -432,10 +432,10 @@ struct InfineatWF: View {
case 6:
return nordGreenColors[1]
default:
break
return orangeColors[1]
}
case .topTop:
switch bleManagerVal.infineatColorIndex {
switch bleManagerVal.infineatWatchFace?.colorIndex {
case 0:
return orangeColors[4]
case 1:
Expand All @@ -451,10 +451,10 @@ struct InfineatWF: View {
case 6:
return nordGreenColors[4]
default:
break
return orangeColors[4]
}
case .topBottom:
switch bleManagerVal.infineatColorIndex {
switch bleManagerVal.infineatWatchFace?.colorIndex {
case 0:
return orangeColors[5]
case 1:
Expand All @@ -470,10 +470,10 @@ struct InfineatWF: View {
case 6:
return nordGreenColors[5]
default:
break
return orangeColors[5]
}
case .midBottom:
switch bleManagerVal.infineatColorIndex {
switch bleManagerVal.infineatWatchFace?.colorIndex {
case 0:
return orangeColors[3]
case 1:
Expand All @@ -489,10 +489,10 @@ struct InfineatWF: View {
case 6:
return nordGreenColors[3]
default:
break
return orangeColors[3]
}
case .midTop:
switch bleManagerVal.infineatColorIndex {
switch bleManagerVal.infineatWatchFace?.colorIndex {
case 0:
return orangeColors[0]
case 1:
Expand All @@ -508,15 +508,15 @@ struct InfineatWF: View {
case 6:
return nordGreenColors[0]
default:
break
return orangeColors[0]
}
}
return .clear
}

var body: some View {
ZStack {
if hour24 {
if !hour24 {
CustomTextView(text: Calendar.current.component(.hour, from: Date()) >= 12 ? "PM" : "AM", font: .custom("Teko-Light", size: geometry.size.width * 0.125), lineSpacing: 0)
.foregroundColor(.white)
.frame(width: geometry.size.width, height: geometry.size.height / 1.35, alignment: .topTrailing)
Expand Down Expand Up @@ -565,59 +565,59 @@ struct InfineatWF: View {
.foregroundColor(.gray)
.frame(width: geometry.size.width, height: geometry.size.height, alignment: .bottom)
.padding(.bottom, -16)
ZStack {
Rectangle()
.frame(width: 19)
.frame(height: geometry.size.height / 1.5, alignment: .topLeading)
.frame(maxHeight: .infinity, alignment: .topLeading)
.foregroundColor(infineatColor(for: .midTop))
.rotationEffect(Angle(degrees: 49))
.offset(x: -36, y: -48)
Rectangle()
.frame(width: 19)
.frame(height: geometry.size.height / 1.5, alignment: .bottomLeading)
.frame(maxHeight: .infinity, alignment: .bottomLeading)
.foregroundColor(infineatColor(for: .bottom))
.opacity(0.8)
.rotationEffect(Angle(degrees: -22))
.offset(x: -16, y: 14)
Rectangle()
.frame(width: 26, alignment: .leading)
.offset(x: -9)
.foregroundColor(infineatColor(for: .base))
Rectangle()
.frame(width: 26)
.frame(height: geometry.size.height / 1.5, alignment: .topLeading)
.frame(maxHeight: .infinity, alignment: .bottomLeading)
.foregroundColor(infineatColor(for: .midBottom))
.rotationEffect(Angle(degrees: -42))
.offset(x: -31, y: 38)
ZStack {
DiamondShape()
.fill(Color.white)
.frame(width: 50, height: 75)
.offset(x: -5)
if bleManagerVal.infineatWatchFace?.showSideCover ?? true {
Rectangle()
.frame(width: 19)
.frame(height: geometry.size.height / 1.5, alignment: .topLeading)
.frame(maxHeight: .infinity, alignment: .topLeading)
.foregroundColor(infineatColor(for: .midTop))
.rotationEffect(Angle(degrees: 49))
.offset(x: -36, y: -48)
Rectangle()
.frame(width: 19)
.frame(height: geometry.size.height / 1.5, alignment: .bottomLeading)
.frame(maxHeight: .infinity, alignment: .bottomLeading)
.foregroundColor(infineatColor(for: .bottom))
.opacity(0.8)
.rotationEffect(Angle(degrees: -22))
.offset(x: -16, y: 14)
Rectangle()
.frame(width: 26, alignment: .leading)
.offset(x: -9)
.foregroundColor(infineatColor(for: .base))
Rectangle()
.frame(width: 26)
.frame(height: geometry.size.height / 1.5, alignment: .topLeading)
.frame(maxHeight: .infinity, alignment: .bottomLeading)
.foregroundColor(infineatColor(for: .midBottom))
.rotationEffect(Angle(degrees: -42))
.offset(x: -31, y: 38)
DiamondShape()
.fill(Color.white)
.frame(width: 50, height: 75)
.offset(x: -5)
Rectangle()
.frame(width: 38)
.frame(height: geometry.size.height / 1.3, alignment: .topLeading)
.frame(maxHeight: .infinity, alignment: .topLeading)
.foregroundColor(infineatColor(for: .topTop))
.rotationEffect(Angle(degrees: 18))
.offset(x: -32, y: -16)
Rectangle()
.frame(width: 38)
.frame(height: geometry.size.height / 1.3, alignment: .topLeading)
.frame(maxHeight: .infinity, alignment: .bottomLeading)
.foregroundColor(infineatColor(for: .topBottom))
.rotationEffect(Angle(degrees: -18))
.offset(x: -32, y: 16)
}
Image("pine_logo")
.resizable()
.frame(width: 20, height: 25)
.frame(width: 19, height: 25)
.offset(x: -1)
}
Rectangle()
.frame(width: 38)
.frame(height: geometry.size.height / 1.3, alignment: .topLeading)
.frame(maxHeight: .infinity, alignment: .topLeading)
.foregroundColor(infineatColor(for: .topTop))
.rotationEffect(Angle(degrees: 18))
.offset(x: -32, y: -16)
Rectangle()
.frame(width: 38)
.frame(height: geometry.size.height / 1.3, alignment: .topLeading)
.frame(maxHeight: .infinity, alignment: .bottomLeading)
.foregroundColor(infineatColor(for: .topBottom))
.rotationEffect(Angle(degrees: -18))
.offset(x: -32, y: 16)
}
.frame(width: geometry.size.width, height: geometry.size.height, alignment: .leading)
.frame(width: geometry.size.width, height: geometry.size.height, alignment: .leading)
}
.frame(width: geometry.size.width, height: geometry.size.height, alignment: .center)
.clipped()
Expand Down Expand Up @@ -865,9 +865,6 @@ enum InfineatItem {
.padding(22)
.frame(width: geometry.size.width / 1.65, height: geometry.size.width / 1.65, alignment: .center)
.clipped(antialiased: true)
.onAppear {
BLEManagerVal.shared.infineatColorIndex = 1
}
}
}
}
Loading

0 comments on commit 7ff39d9

Please sign in to comment.