2022-06-12 01:25:42 -07:00
|
|
|
//
|
|
|
|
|
// DeviceSettings.swift
|
|
|
|
|
// Meshtastic Apple
|
|
|
|
|
//
|
|
|
|
|
// Copyright (c) Garth Vander Houwen 6/7/22.
|
|
|
|
|
//
|
|
|
|
|
|
2024-06-07 22:09:20 -05:00
|
|
|
import MeshtasticProtobufs
|
2024-06-03 02:17:55 -07:00
|
|
|
import OSLog
|
2024-06-07 22:09:20 -05:00
|
|
|
import SwiftUI
|
2022-06-12 01:25:42 -07:00
|
|
|
|
|
|
|
|
struct DisplayConfig: View {
|
2023-03-06 10:33:18 -08:00
|
|
|
|
2022-06-12 01:25:42 -07:00
|
|
|
@Environment(\.managedObjectContext) var context
|
|
|
|
|
@EnvironmentObject var bleManager: BLEManager
|
2024-07-10 16:03:38 -05:00
|
|
|
@EnvironmentObject var queryCoreDataController: QueryCoreDataController
|
2022-12-09 18:19:00 -08:00
|
|
|
@Environment(\.dismiss) private var goBack
|
2023-03-06 10:33:18 -08:00
|
|
|
|
2022-07-07 00:29:52 -07:00
|
|
|
var node: NodeInfoEntity?
|
2023-03-06 10:33:18 -08:00
|
|
|
|
2022-06-21 10:02:05 -07:00
|
|
|
@State var hasChanges = false
|
2022-06-12 22:07:58 -07:00
|
|
|
@State var screenOnSeconds = 0
|
|
|
|
|
@State var screenCarouselInterval = 0
|
|
|
|
|
@State var gpsFormat = 0
|
2022-08-07 08:31:39 -07:00
|
|
|
@State var compassNorthTop = false
|
2023-03-25 00:41:57 -07:00
|
|
|
@State var wakeOnTapOrMotion = false
|
2022-10-22 08:45:53 -07:00
|
|
|
@State var flipScreen = false
|
2022-12-11 14:14:08 -08:00
|
|
|
@State var oledType = 0
|
2023-01-25 23:01:45 -08:00
|
|
|
@State var displayMode = 0
|
2023-11-26 12:54:45 -08:00
|
|
|
@State var units = 0
|
2023-03-06 10:33:18 -08:00
|
|
|
|
2022-06-12 01:25:42 -07:00
|
|
|
var body: some View {
|
2022-12-30 11:08:59 -08:00
|
|
|
Form {
|
2024-02-17 22:39:22 -07:00
|
|
|
ConfigHeader(title: "Display", config: \.displayConfig, node: node, onAppear: setDisplayValues)
|
2023-03-14 12:44:10 -07:00
|
|
|
|
2022-12-30 11:08:59 -08:00
|
|
|
Section(header: Text("Device Screen")) {
|
2024-02-21 20:41:27 -08:00
|
|
|
VStack(alignment: .leading) {
|
|
|
|
|
Picker("Display Mode", selection: $displayMode ) {
|
|
|
|
|
ForEach(DisplayModes.allCases) { dm in
|
|
|
|
|
Text(dm.description)
|
|
|
|
|
}
|
2022-06-12 01:25:42 -07:00
|
|
|
}
|
2024-05-29 16:40:07 -05:00
|
|
|
|
2024-02-21 20:41:27 -08:00
|
|
|
Text("Override automatic OLED screen detection.")
|
|
|
|
|
.foregroundColor(.gray)
|
2024-02-21 23:35:28 -08:00
|
|
|
.font(.callout)
|
2022-12-30 11:08:59 -08:00
|
|
|
}
|
2024-02-21 23:35:28 -08:00
|
|
|
.pickerStyle(DefaultPickerStyle())
|
|
|
|
|
Toggle(isOn: $compassNorthTop) {
|
|
|
|
|
Label("Always point north", systemImage: "location.north.circle")
|
2024-02-21 20:41:27 -08:00
|
|
|
Text("The compass heading on the screen outside of the circle will always point north.")
|
2022-12-30 11:08:59 -08:00
|
|
|
}
|
2024-02-21 23:35:28 -08:00
|
|
|
.toggleStyle(SwitchToggleStyle(tint: .accentColor))
|
|
|
|
|
|
|
|
|
|
Toggle(isOn: $wakeOnTapOrMotion) {
|
|
|
|
|
Label("Wake Screen on tap or motion", systemImage: "gyroscope")
|
2024-02-21 20:41:27 -08:00
|
|
|
Text("Requires that there be an accelerometer on your device.")
|
2023-03-25 00:41:57 -07:00
|
|
|
}
|
2024-02-21 23:35:28 -08:00
|
|
|
.toggleStyle(SwitchToggleStyle(tint: .accentColor))
|
2024-05-29 16:40:07 -05:00
|
|
|
|
2024-02-21 23:35:28 -08:00
|
|
|
Toggle(isOn: $flipScreen) {
|
|
|
|
|
Label("Flip Screen", systemImage: "pip.swap")
|
2024-02-21 20:41:27 -08:00
|
|
|
Text("Flip screen vertically")
|
2022-12-30 11:08:59 -08:00
|
|
|
}
|
2024-02-21 23:35:28 -08:00
|
|
|
.toggleStyle(SwitchToggleStyle(tint: .accentColor))
|
2024-05-29 16:40:07 -05:00
|
|
|
|
2024-02-21 20:41:27 -08:00
|
|
|
VStack(alignment: .leading) {
|
|
|
|
|
Picker("OLED Type", selection: $oledType ) {
|
|
|
|
|
ForEach(OledTypes.allCases) { ot in
|
|
|
|
|
Text(ot.description)
|
|
|
|
|
}
|
2022-12-11 14:14:08 -08:00
|
|
|
}
|
2024-02-21 20:41:27 -08:00
|
|
|
Text("Override automatic OLED screen detection.")
|
|
|
|
|
.foregroundColor(.gray)
|
2024-02-21 23:35:28 -08:00
|
|
|
.font(.callout)
|
2022-06-12 01:25:42 -07:00
|
|
|
}
|
2024-02-21 23:35:28 -08:00
|
|
|
.pickerStyle(DefaultPickerStyle())
|
2022-12-30 11:08:59 -08:00
|
|
|
}
|
2023-01-25 23:01:45 -08:00
|
|
|
Section(header: Text("Timing & Format")) {
|
2024-02-21 20:41:27 -08:00
|
|
|
VStack(alignment: .leading) {
|
|
|
|
|
Picker("Screen on for", selection: $screenOnSeconds ) {
|
|
|
|
|
ForEach(ScreenOnIntervals.allCases) { soi in
|
|
|
|
|
Text(soi.description)
|
|
|
|
|
}
|
2023-01-25 23:01:45 -08:00
|
|
|
}
|
2024-02-21 20:41:27 -08:00
|
|
|
Text("How long the screen remains on after the user button is pressed or messages are received.")
|
|
|
|
|
.foregroundColor(.gray)
|
2024-02-21 23:35:28 -08:00
|
|
|
.font(.callout)
|
2023-01-25 23:01:45 -08:00
|
|
|
}
|
2024-02-21 23:35:28 -08:00
|
|
|
.pickerStyle(DefaultPickerStyle())
|
2024-05-29 16:40:07 -05:00
|
|
|
|
2024-02-21 20:41:27 -08:00
|
|
|
VStack(alignment: .leading) {
|
|
|
|
|
Picker("Carousel Interval", selection: $screenCarouselInterval ) {
|
|
|
|
|
ForEach(ScreenCarouselIntervals.allCases) { sci in
|
|
|
|
|
Text(sci.description)
|
|
|
|
|
}
|
2023-01-25 23:01:45 -08:00
|
|
|
}
|
2024-05-29 16:40:07 -05:00
|
|
|
|
2024-02-21 20:41:27 -08:00
|
|
|
Text("Automatically toggles to the next page on the screen like a carousel, based the specified interval.")
|
|
|
|
|
.foregroundColor(.gray)
|
2024-02-21 23:35:28 -08:00
|
|
|
.font(.callout)
|
2023-01-25 23:01:45 -08:00
|
|
|
}
|
2024-02-21 23:35:28 -08:00
|
|
|
.pickerStyle(DefaultPickerStyle())
|
2024-05-29 16:40:07 -05:00
|
|
|
|
2024-02-21 20:41:27 -08:00
|
|
|
VStack(alignment: .leading) {
|
|
|
|
|
Picker("GPS Format", selection: $gpsFormat ) {
|
|
|
|
|
ForEach(GpsFormats.allCases) { lu in
|
|
|
|
|
Text(lu.description)
|
|
|
|
|
}
|
2022-06-12 01:25:42 -07:00
|
|
|
}
|
2024-02-21 20:41:27 -08:00
|
|
|
Text("The format used to display GPS coordinates on the device screen.")
|
|
|
|
|
.foregroundColor(.gray)
|
2024-02-21 23:35:28 -08:00
|
|
|
.font(.callout)
|
2022-06-12 01:25:42 -07:00
|
|
|
}
|
2024-02-21 23:35:28 -08:00
|
|
|
.pickerStyle(DefaultPickerStyle())
|
2024-05-29 16:40:07 -05:00
|
|
|
|
2024-02-21 20:41:27 -08:00
|
|
|
VStack(alignment: .leading) {
|
|
|
|
|
Picker("Display Units", selection: $units ) {
|
|
|
|
|
ForEach(Units.allCases) { un in
|
|
|
|
|
Text(un.description)
|
|
|
|
|
}
|
2023-11-26 12:54:45 -08:00
|
|
|
}
|
2024-02-21 20:41:27 -08:00
|
|
|
Text("Units displayed on the device screen")
|
|
|
|
|
.foregroundColor(.gray)
|
2024-02-21 23:35:28 -08:00
|
|
|
.font(.callout)
|
2023-11-26 12:54:45 -08:00
|
|
|
}
|
2024-02-21 23:35:28 -08:00
|
|
|
.pickerStyle(DefaultPickerStyle())
|
2022-06-12 01:25:42 -07:00
|
|
|
}
|
2022-12-30 11:08:59 -08:00
|
|
|
}
|
2023-01-31 22:59:43 -08:00
|
|
|
.disabled(self.bleManager.connectedPeripheral == nil || node?.displayConfig == nil)
|
2023-03-06 10:33:18 -08:00
|
|
|
|
2024-02-18 00:03:34 -07:00
|
|
|
SaveConfigButton(node: node, hasChanges: $hasChanges) {
|
2024-07-10 16:03:38 -05:00
|
|
|
let connectedNode = queryCoreDataController.getNodeInfo(id: bleManager.connectedPeripheral.num)
|
2024-02-18 00:03:34 -07:00
|
|
|
if connectedNode != nil {
|
|
|
|
|
var dc = Config.DisplayConfig()
|
|
|
|
|
dc.gpsFormat = GpsFormats(rawValue: gpsFormat)!.protoEnumValue()
|
|
|
|
|
dc.screenOnSecs = UInt32(screenOnSeconds)
|
|
|
|
|
dc.autoScreenCarouselSecs = UInt32(screenCarouselInterval)
|
|
|
|
|
dc.compassNorthTop = compassNorthTop
|
|
|
|
|
dc.wakeOnTapOrMotion = wakeOnTapOrMotion
|
|
|
|
|
dc.flipScreen = flipScreen
|
|
|
|
|
dc.oled = OledTypes(rawValue: oledType)!.protoEnumValue()
|
|
|
|
|
dc.displaymode = DisplayModes(rawValue: displayMode)!.protoEnumValue()
|
|
|
|
|
dc.units = Units(rawValue: units)!.protoEnumValue()
|
|
|
|
|
|
|
|
|
|
let adminMessageId = bleManager.saveDisplayConfig(config: dc, fromUser: connectedNode!.user!, toUser: node!.user!, adminIndex: connectedNode?.myInfo?.adminIndex ?? 0)
|
|
|
|
|
if adminMessageId > 0 {
|
|
|
|
|
|
|
|
|
|
// Should show a saved successfully alert once I know that to be true
|
|
|
|
|
// for now just disable the button after a successful save
|
|
|
|
|
hasChanges = false
|
|
|
|
|
goBack()
|
2022-06-21 10:02:05 -07:00
|
|
|
}
|
|
|
|
|
}
|
2022-06-12 01:25:42 -07:00
|
|
|
}
|
2024-02-18 00:03:34 -07:00
|
|
|
|
2022-12-13 07:49:46 -08:00
|
|
|
.navigationTitle("display.config")
|
2022-06-12 01:25:42 -07:00
|
|
|
.navigationBarItems(trailing:
|
|
|
|
|
ZStack {
|
2023-09-02 17:37:35 -07:00
|
|
|
ConnectedDevice(bluetoothOn: bleManager.isSwitchedOn, deviceConnected: bleManager.connectedPeripheral != nil, name: (bleManager.connectedPeripheral != nil) ? bleManager.connectedPeripheral.shortName : "?")
|
2022-06-12 01:25:42 -07:00
|
|
|
})
|
|
|
|
|
.onAppear {
|
2023-03-19 18:37:23 -07:00
|
|
|
setDisplayValues()
|
2023-03-06 10:33:18 -08:00
|
|
|
|
2023-01-31 22:08:03 -08:00
|
|
|
// Need to request a LoRaConfig from the remote node before allowing changes
|
|
|
|
|
if bleManager.connectedPeripheral != nil && node?.displayConfig == nil {
|
2024-06-03 02:17:55 -07:00
|
|
|
Logger.mesh.info("empty display config")
|
2024-07-10 16:03:38 -05:00
|
|
|
let connectedNode = queryCoreDataController.getNodeInfo(id: bleManager.connectedPeripheral?.num ?? 0)
|
2023-03-05 14:40:07 -08:00
|
|
|
if node != nil && connectedNode != nil {
|
2023-02-06 18:45:03 -08:00
|
|
|
_ = bleManager.requestDisplayConfig(fromUser: connectedNode!.user!, toUser: node!.user!, adminIndex: connectedNode?.myInfo?.adminIndex ?? 0)
|
2023-01-31 22:08:03 -08:00
|
|
|
}
|
|
|
|
|
}
|
2022-06-21 10:02:05 -07:00
|
|
|
}
|
|
|
|
|
.onChange(of: screenOnSeconds) { newScreenSecs in
|
2022-07-11 16:18:16 -07:00
|
|
|
if node != nil && node!.displayConfig != nil {
|
|
|
|
|
if newScreenSecs != node!.displayConfig!.screenOnSeconds { hasChanges = true }
|
2022-06-21 10:02:05 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
.onChange(of: screenCarouselInterval) { newCarouselSecs in
|
2022-07-11 16:18:16 -07:00
|
|
|
if node != nil && node!.displayConfig != nil {
|
|
|
|
|
if newCarouselSecs != node!.displayConfig!.screenCarouselInterval { hasChanges = true }
|
2022-06-21 10:02:05 -07:00
|
|
|
}
|
|
|
|
|
}
|
2022-08-07 08:31:39 -07:00
|
|
|
.onChange(of: compassNorthTop) { newCompassNorthTop in
|
|
|
|
|
if node != nil && node!.displayConfig != nil {
|
|
|
|
|
if newCompassNorthTop != node!.displayConfig!.compassNorthTop { hasChanges = true }
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-25 00:41:57 -07:00
|
|
|
.onChange(of: wakeOnTapOrMotion) { newWakeOnTapOrMotion in
|
|
|
|
|
if node != nil && node!.displayConfig != nil {
|
|
|
|
|
if newWakeOnTapOrMotion != node!.displayConfig!.wakeOnTapOrMotion { hasChanges = true }
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-06-21 10:02:05 -07:00
|
|
|
.onChange(of: gpsFormat) { newGpsFormat in
|
2022-07-11 16:18:16 -07:00
|
|
|
if node != nil && node!.displayConfig != nil {
|
|
|
|
|
if newGpsFormat != node!.displayConfig!.gpsFormat { hasChanges = true }
|
2022-06-21 10:02:05 -07:00
|
|
|
}
|
2022-06-12 01:25:42 -07:00
|
|
|
}
|
2022-10-22 08:45:53 -07:00
|
|
|
.onChange(of: flipScreen) { newFlipScreen in
|
|
|
|
|
if node != nil && node!.displayConfig != nil {
|
|
|
|
|
if newFlipScreen != node!.displayConfig!.flipScreen { hasChanges = true }
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-12-11 14:14:08 -08:00
|
|
|
.onChange(of: oledType) { newOledType in
|
|
|
|
|
if node != nil && node!.displayConfig != nil {
|
|
|
|
|
if newOledType != node!.displayConfig!.oledType { hasChanges = true }
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-01-25 23:01:45 -08:00
|
|
|
.onChange(of: displayMode) { newDisplayMode in
|
|
|
|
|
if node != nil && node!.displayConfig != nil {
|
|
|
|
|
if newDisplayMode != node!.displayConfig!.displayMode { hasChanges = true }
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-26 12:54:45 -08:00
|
|
|
.onChange(of: units) { newUnits in
|
|
|
|
|
if node != nil && node!.displayConfig != nil {
|
|
|
|
|
if newUnits != node!.displayConfig!.units { hasChanges = true }
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-06-12 01:25:42 -07:00
|
|
|
}
|
2023-03-19 18:37:23 -07:00
|
|
|
func setDisplayValues() {
|
|
|
|
|
self.gpsFormat = Int(node?.displayConfig?.gpsFormat ?? 0)
|
|
|
|
|
self.screenOnSeconds = Int(node?.displayConfig?.screenOnSeconds ?? 0)
|
|
|
|
|
self.screenCarouselInterval = Int(node?.displayConfig?.screenCarouselInterval ?? 0)
|
|
|
|
|
self.compassNorthTop = node?.displayConfig?.compassNorthTop ?? false
|
2023-03-25 00:41:57 -07:00
|
|
|
self.wakeOnTapOrMotion = node?.displayConfig?.wakeOnTapOrMotion ?? false
|
2023-03-19 18:37:23 -07:00
|
|
|
self.flipScreen = node?.displayConfig?.flipScreen ?? false
|
|
|
|
|
self.oledType = Int(node?.displayConfig?.oledType ?? 0)
|
|
|
|
|
self.displayMode = Int(node?.displayConfig?.displayMode ?? 0)
|
2023-11-26 12:54:45 -08:00
|
|
|
self.units = Int(node?.displayConfig?.units ?? 0)
|
2023-03-19 18:37:23 -07:00
|
|
|
self.hasChanges = false
|
|
|
|
|
}
|
2022-06-12 01:25:42 -07:00
|
|
|
}
|