Skip to content

Commit 7ff39d9

Browse files
committed
Add support for recovery mode, minor updates to Infineat watchface, add brightness level to watch settings
1 parent 073ed20 commit 7ff39d9

13 files changed

Lines changed: 259 additions & 174 deletions

InfiniLink/BLE/BLEManagerVariables.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ class BLEManagerVal: NSObject, ObservableObject {
3636

3737
@Published var watchFace: Int = -1
3838
@Published var pineTimeStyleData: PineTimeStyleData?
39+
@Published var infineatWatchFace: WatchFaceInfineat?
3940
@Published var timeFormat: ClockType?
40-
@Published var infineatColorIndex: UInt8 = 0
4141

4242
@Published var weatherInformation = WeatherInformation()
4343
@Published var loadingWeather = true

InfiniLink/BLE/BLE_FS.swift

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,6 @@ class BLEFSHandler : ObservableObject {
197197
readFileFS.group.wait()
198198
}
199199

200-
// print(readFileFS.data.hexString)
201-
202200
return readFileFS
203201
}
204202

@@ -602,6 +600,12 @@ enum WakeUpMode: UInt8 {
602600
case LowerWrist = 4
603601
}
604602

603+
enum BrightLevel: UInt8 {
604+
case Low = 0
605+
case Mid = 1
606+
case High = 2
607+
}
608+
605609
enum Colors: UInt8 {
606610
case White = 0
607611
case Silver = 1
@@ -635,16 +639,16 @@ enum PTSWeather: UInt8 {
635639
}
636640

637641
struct PineTimeStyleData {
638-
let ColorTime : Colors = .Teal
639-
let ColorBar : Colors = .Teal
640-
let ColorBG : Colors = .Black
641-
let gaugeStyle : PTSGaugeStyle = .Full
642-
let weatherEnable : PTSWeather = .Off
642+
let ColorTime: Colors = .Teal
643+
let ColorBar: Colors = .Teal
644+
let ColorBG: Colors = .Black
645+
let gaugeStyle: PTSGaugeStyle = .Full
646+
let weatherEnable: PTSWeather = .Off
643647
}
644648

645649
struct WatchFaceInfineat {
646-
let showSideCover : Bool = true
647-
let colorIndex : UInt8 = 0
650+
let showSideCover: Bool = true
651+
let colorIndex: UInt8 = 0
648652
}
649653

650654
struct Settings {
@@ -660,5 +664,5 @@ struct Settings {
660664
let watchFaceInfineat: WatchFaceInfineat
661665
let wakeUpMode: WakeUpMode
662666
let shakeWakeThreshold: UInt16
663-
let brightLevel: UInt8
667+
let brightLevel: BrightLevel
664668
}

InfiniLink/Core/Home/DFU/DFUDownloadView.swift

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -85,33 +85,35 @@ struct DownloadView: View {
8585
DebugLogManager.shared.debug(error: error.localizedDescription, log: .dfu, date: Date())
8686
}
8787
}
88-
Button {
89-
externalResources = true
90-
showResourcePicker = true
91-
} label: {
92-
Text(NSLocalizedString("update_external_resources", comment: ""))
93-
.frame(maxWidth: .infinity)
94-
.padding()
95-
.background(Color.blue)
96-
.foregroundColor(.white)
97-
.clipShape(Capsule())
98-
}
99-
.fileImporter(isPresented: $showResourcePicker, allowedContentTypes: [.zip]) { (res) in
100-
do {
101-
let fileUrl = try res.get()
102-
103-
guard fileUrl.startAccessingSecurityScopedResource() else { return }
104-
105-
dfuUpdater.firmwareSelected = true
106-
dfuUpdater.resourceFilename = fileUrl.lastPathComponent
107-
dfuUpdater.firmwareURL = fileUrl.absoluteURL
108-
88+
if BLEManager.shared.blefsTransfer != nil {
89+
Button {
10990
externalResources = true
110-
111-
fileUrl.stopAccessingSecurityScopedResource()
112-
presentation.wrappedValue.dismiss()
113-
} catch{
114-
DebugLogManager.shared.debug(error: error.localizedDescription, log: .dfu, date: Date())
91+
showResourcePicker = true
92+
} label: {
93+
Text(NSLocalizedString("update_external_resources", comment: ""))
94+
.frame(maxWidth: .infinity)
95+
.padding()
96+
.background(Color.blue)
97+
.foregroundColor(.white)
98+
.clipShape(Capsule())
99+
}
100+
.fileImporter(isPresented: $showResourcePicker, allowedContentTypes: [.zip]) { (res) in
101+
do {
102+
let fileUrl = try res.get()
103+
104+
guard fileUrl.startAccessingSecurityScopedResource() else { return }
105+
106+
dfuUpdater.firmwareSelected = true
107+
dfuUpdater.resourceFilename = fileUrl.lastPathComponent
108+
dfuUpdater.firmwareURL = fileUrl.absoluteURL
109+
110+
externalResources = true
111+
112+
fileUrl.stopAccessingSecurityScopedResource()
113+
presentation.wrappedValue.dismiss()
114+
} catch {
115+
DebugLogManager.shared.debug(error: error.localizedDescription, log: .dfu, date: Date())
116+
}
115117
}
116118
}
117119
}

InfiniLink/Core/Home/DFU/DFUWithBLE.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,9 @@ struct NewUpdate: View {
224224
}
225225
}
226226
DFUStartTransferButton(updateStarted: $updateStarted, firmwareSelected: $dfuUpdater.firmwareSelected, externalResources: .constant(false))
227-
.disabled(bleManager.batteryLevel <= 30)
228-
.opacity(bleManager.batteryLevel <= 30 ? 0.5 : 1.0)
229-
if bleManager.batteryLevel <= 30 {
227+
.disabled((bleManager.batteryLevel <= 30 && bleManager.blefsTransfer != nil))
228+
.opacity((bleManager.batteryLevel <= 30 && bleManager.blefsTransfer != nil) ? 0.5 : 1.0)
229+
if bleManager.batteryLevel <= 30 && bleManager.blefsTransfer != nil {
230230
Text(NSLocalizedString("update_requirement_1", comment: "") + deviceInfo.deviceName + NSLocalizedString("update_requirement_2", comment: ""))
231231
.foregroundColor(.gray)
232232
.font(.system(size: 15))

InfiniLink/Core/Home/DeviceView.swift

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -421,19 +421,21 @@ struct CustomScrollView<Content: View>: View {
421421
.onChange(of: deviceInfo.firmware) { firmware in
422422
if firmware != "" {
423423
DispatchQueue.main.async {
424-
BLEFSHandler.shared.readSettings { settings in
425-
self.settings = settings
426-
print(settings)
427-
self.stepCountGoal = Int(settings.stepsGoal)
428-
self.bleManagerVal.watchFace = Int(settings.watchFace)
429-
self.bleManagerVal.pineTimeStyleData = settings.pineTimeStyle
430-
self.bleManagerVal.timeFormat = settings.clockType
431-
self.bleManagerVal.infineatColorIndex = settings.watchFaceInfineat.colorIndex
432-
switch settings.weatherFormat {
433-
case .Metric:
434-
self.deviceDataForSettings.chosenWeatherMode = "Metric"
435-
case .Imperial:
436-
self.deviceDataForSettings.chosenWeatherMode = "Imperial"
424+
if bleManager.blefsTransfer != nil {
425+
BLEFSHandler.shared.readSettings { settings in
426+
self.settings = settings
427+
print(settings)
428+
self.stepCountGoal = Int(settings.stepsGoal)
429+
self.bleManagerVal.watchFace = Int(settings.watchFace)
430+
self.bleManagerVal.pineTimeStyleData = settings.pineTimeStyle
431+
self.bleManagerVal.timeFormat = settings.clockType
432+
self.bleManagerVal.infineatWatchFace = settings.watchFaceInfineat
433+
switch settings.weatherFormat {
434+
case .Metric:
435+
self.deviceDataForSettings.chosenWeatherMode = "Metric"
436+
case .Imperial:
437+
self.deviceDataForSettings.chosenWeatherMode = "Imperial"
438+
}
437439
}
438440
}
439441
}

InfiniLink/Core/Home/WatchFace.swift

Lines changed: 61 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ struct InfineatWF: View {
397397
func infineatColor(for item: InfineatItem) -> Color {
398398
switch item {
399399
case .base:
400-
switch bleManagerVal.infineatColorIndex {
400+
switch bleManagerVal.infineatWatchFace?.colorIndex {
401401
case 0:
402402
return orangeColors[2]
403403
case 1:
@@ -413,10 +413,10 @@ struct InfineatWF: View {
413413
case 6:
414414
return nordGreenColors[2]
415415
default:
416-
break
416+
return orangeColors[2]
417417
}
418418
case .bottom:
419-
switch bleManagerVal.infineatColorIndex {
419+
switch bleManagerVal.infineatWatchFace?.colorIndex {
420420
case 0:
421421
return orangeColors[1]
422422
case 1:
@@ -432,10 +432,10 @@ struct InfineatWF: View {
432432
case 6:
433433
return nordGreenColors[1]
434434
default:
435-
break
435+
return orangeColors[1]
436436
}
437437
case .topTop:
438-
switch bleManagerVal.infineatColorIndex {
438+
switch bleManagerVal.infineatWatchFace?.colorIndex {
439439
case 0:
440440
return orangeColors[4]
441441
case 1:
@@ -451,10 +451,10 @@ struct InfineatWF: View {
451451
case 6:
452452
return nordGreenColors[4]
453453
default:
454-
break
454+
return orangeColors[4]
455455
}
456456
case .topBottom:
457-
switch bleManagerVal.infineatColorIndex {
457+
switch bleManagerVal.infineatWatchFace?.colorIndex {
458458
case 0:
459459
return orangeColors[5]
460460
case 1:
@@ -470,10 +470,10 @@ struct InfineatWF: View {
470470
case 6:
471471
return nordGreenColors[5]
472472
default:
473-
break
473+
return orangeColors[5]
474474
}
475475
case .midBottom:
476-
switch bleManagerVal.infineatColorIndex {
476+
switch bleManagerVal.infineatWatchFace?.colorIndex {
477477
case 0:
478478
return orangeColors[3]
479479
case 1:
@@ -489,10 +489,10 @@ struct InfineatWF: View {
489489
case 6:
490490
return nordGreenColors[3]
491491
default:
492-
break
492+
return orangeColors[3]
493493
}
494494
case .midTop:
495-
switch bleManagerVal.infineatColorIndex {
495+
switch bleManagerVal.infineatWatchFace?.colorIndex {
496496
case 0:
497497
return orangeColors[0]
498498
case 1:
@@ -508,15 +508,15 @@ struct InfineatWF: View {
508508
case 6:
509509
return nordGreenColors[0]
510510
default:
511-
break
511+
return orangeColors[0]
512512
}
513513
}
514514
return .clear
515515
}
516516

517517
var body: some View {
518518
ZStack {
519-
if hour24 {
519+
if !hour24 {
520520
CustomTextView(text: Calendar.current.component(.hour, from: Date()) >= 12 ? "PM" : "AM", font: .custom("Teko-Light", size: geometry.size.width * 0.125), lineSpacing: 0)
521521
.foregroundColor(.white)
522522
.frame(width: geometry.size.width, height: geometry.size.height / 1.35, alignment: .topTrailing)
@@ -565,59 +565,59 @@ struct InfineatWF: View {
565565
.foregroundColor(.gray)
566566
.frame(width: geometry.size.width, height: geometry.size.height, alignment: .bottom)
567567
.padding(.bottom, -16)
568-
ZStack {
569-
Rectangle()
570-
.frame(width: 19)
571-
.frame(height: geometry.size.height / 1.5, alignment: .topLeading)
572-
.frame(maxHeight: .infinity, alignment: .topLeading)
573-
.foregroundColor(infineatColor(for: .midTop))
574-
.rotationEffect(Angle(degrees: 49))
575-
.offset(x: -36, y: -48)
576-
Rectangle()
577-
.frame(width: 19)
578-
.frame(height: geometry.size.height / 1.5, alignment: .bottomLeading)
579-
.frame(maxHeight: .infinity, alignment: .bottomLeading)
580-
.foregroundColor(infineatColor(for: .bottom))
581-
.opacity(0.8)
582-
.rotationEffect(Angle(degrees: -22))
583-
.offset(x: -16, y: 14)
584-
Rectangle()
585-
.frame(width: 26, alignment: .leading)
586-
.offset(x: -9)
587-
.foregroundColor(infineatColor(for: .base))
588-
Rectangle()
589-
.frame(width: 26)
590-
.frame(height: geometry.size.height / 1.5, alignment: .topLeading)
591-
.frame(maxHeight: .infinity, alignment: .bottomLeading)
592-
.foregroundColor(infineatColor(for: .midBottom))
593-
.rotationEffect(Angle(degrees: -42))
594-
.offset(x: -31, y: 38)
595568
ZStack {
596-
DiamondShape()
597-
.fill(Color.white)
598-
.frame(width: 50, height: 75)
599-
.offset(x: -5)
569+
if bleManagerVal.infineatWatchFace?.showSideCover ?? true {
570+
Rectangle()
571+
.frame(width: 19)
572+
.frame(height: geometry.size.height / 1.5, alignment: .topLeading)
573+
.frame(maxHeight: .infinity, alignment: .topLeading)
574+
.foregroundColor(infineatColor(for: .midTop))
575+
.rotationEffect(Angle(degrees: 49))
576+
.offset(x: -36, y: -48)
577+
Rectangle()
578+
.frame(width: 19)
579+
.frame(height: geometry.size.height / 1.5, alignment: .bottomLeading)
580+
.frame(maxHeight: .infinity, alignment: .bottomLeading)
581+
.foregroundColor(infineatColor(for: .bottom))
582+
.opacity(0.8)
583+
.rotationEffect(Angle(degrees: -22))
584+
.offset(x: -16, y: 14)
585+
Rectangle()
586+
.frame(width: 26, alignment: .leading)
587+
.offset(x: -9)
588+
.foregroundColor(infineatColor(for: .base))
589+
Rectangle()
590+
.frame(width: 26)
591+
.frame(height: geometry.size.height / 1.5, alignment: .topLeading)
592+
.frame(maxHeight: .infinity, alignment: .bottomLeading)
593+
.foregroundColor(infineatColor(for: .midBottom))
594+
.rotationEffect(Angle(degrees: -42))
595+
.offset(x: -31, y: 38)
596+
DiamondShape()
597+
.fill(Color.white)
598+
.frame(width: 50, height: 75)
599+
.offset(x: -5)
600+
Rectangle()
601+
.frame(width: 38)
602+
.frame(height: geometry.size.height / 1.3, alignment: .topLeading)
603+
.frame(maxHeight: .infinity, alignment: .topLeading)
604+
.foregroundColor(infineatColor(for: .topTop))
605+
.rotationEffect(Angle(degrees: 18))
606+
.offset(x: -32, y: -16)
607+
Rectangle()
608+
.frame(width: 38)
609+
.frame(height: geometry.size.height / 1.3, alignment: .topLeading)
610+
.frame(maxHeight: .infinity, alignment: .bottomLeading)
611+
.foregroundColor(infineatColor(for: .topBottom))
612+
.rotationEffect(Angle(degrees: -18))
613+
.offset(x: -32, y: 16)
614+
}
600615
Image("pine_logo")
601616
.resizable()
602-
.frame(width: 20, height: 25)
617+
.frame(width: 19, height: 25)
603618
.offset(x: -1)
604619
}
605-
Rectangle()
606-
.frame(width: 38)
607-
.frame(height: geometry.size.height / 1.3, alignment: .topLeading)
608-
.frame(maxHeight: .infinity, alignment: .topLeading)
609-
.foregroundColor(infineatColor(for: .topTop))
610-
.rotationEffect(Angle(degrees: 18))
611-
.offset(x: -32, y: -16)
612-
Rectangle()
613-
.frame(width: 38)
614-
.frame(height: geometry.size.height / 1.3, alignment: .topLeading)
615-
.frame(maxHeight: .infinity, alignment: .bottomLeading)
616-
.foregroundColor(infineatColor(for: .topBottom))
617-
.rotationEffect(Angle(degrees: -18))
618-
.offset(x: -32, y: 16)
619-
}
620-
.frame(width: geometry.size.width, height: geometry.size.height, alignment: .leading)
620+
.frame(width: geometry.size.width, height: geometry.size.height, alignment: .leading)
621621
}
622622
.frame(width: geometry.size.width, height: geometry.size.height, alignment: .center)
623623
.clipped()
@@ -865,9 +865,6 @@ enum InfineatItem {
865865
.padding(22)
866866
.frame(width: geometry.size.width / 1.65, height: geometry.size.width / 1.65, alignment: .center)
867867
.clipped(antialiased: true)
868-
.onAppear {
869-
BLEManagerVal.shared.infineatColorIndex = 1
870-
}
871868
}
872869
}
873870
}

0 commit comments

Comments
 (0)