Add flip screen display config option

This commit is contained in:
Garth Vander Houwen 2022-10-22 08:45:53 -07:00
parent 1f8cb77533
commit 091874a9f2
4 changed files with 19 additions and 5 deletions

View file

@ -1091,13 +1091,10 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
toRadio.packet = meshPacket
let binaryData: Data = try! toRadio.serializedData()
if connectedPeripheral!.peripheral.state == CBPeripheralState.connected {
//let timer1 = Timer.scheduledTimer(withTimeInterval: 0.1, repeats: false) { timer in
self.connectedPeripheral.peripheral.writeValue(binaryData, for: self.TORADIO_characteristic, type: .withResponse)
MeshLogger.log("💾 Saved a Channel for: \(String(self.connectedPeripheral.num))")
//}
}
print(chan)
}
@ -1124,7 +1121,6 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
toRadio.packet = meshPacket
let binaryData: Data = try! toRadio.serializedData()
if connectedPeripheral!.peripheral.state == CBPeripheralState.connected {
// let timer1 = Timer.scheduledTimer(withTimeInterval: 2, repeats: false) { timer in
self.connectedPeripheral.peripheral.writeValue(binaryData, for: self.TORADIO_characteristic, type: .withResponse)
MeshLogger.log("💾 Saved a LoRaConfig for: \(String(self.connectedPeripheral.num))")

View file

@ -122,6 +122,7 @@ func localConfig (config: Config, context:NSManagedObjectContext, nodeNum: Int64
newDisplayConfig.screenOnSeconds = Int32(config.display.screenOnSecs)
newDisplayConfig.screenCarouselInterval = Int32(config.display.autoScreenCarouselSecs)
newDisplayConfig.compassNorthTop = config.display.compassNorthTop
newDisplayConfig.flipScreen = config.display.flipScreen
fetchedNode[0].displayConfig = newDisplayConfig
} else {
@ -130,6 +131,7 @@ func localConfig (config: Config, context:NSManagedObjectContext, nodeNum: Int64
fetchedNode[0].displayConfig?.screenOnSeconds = Int32(config.display.screenOnSecs)
fetchedNode[0].displayConfig?.screenCarouselInterval = Int32(config.display.autoScreenCarouselSecs)
fetchedNode[0].displayConfig?.compassNorthTop = config.display.compassNorthTop
fetchedNode[0].displayConfig?.flipScreen = config.display.flipScreen
}
do {

View file

@ -42,6 +42,7 @@
</entity>
<entity name="DisplayConfigEntity" representedClassName="DisplayConfigEntity" syncable="YES" codeGenerationType="class">
<attribute name="compassNorthTop" optional="YES" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
<attribute name="flipScreen" optional="YES" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
<attribute name="gpsFormat" optional="YES" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="screenCarouselInterval" optional="YES" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="screenOnSeconds" optional="YES" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/>

View file

@ -21,6 +21,7 @@ struct DisplayConfig: View {
@State var screenCarouselInterval = 0
@State var gpsFormat = 0
@State var compassNorthTop = false
@State var flipScreen = false
var body: some View {
@ -45,7 +46,6 @@ struct DisplayConfig: View {
}
}
.pickerStyle(DefaultPickerStyle())
Text("Automatically toggles to the next page on the screen like a carousel, based the specified interval.")
.font(.caption)
@ -57,6 +57,14 @@ struct DisplayConfig: View {
Text("The compass heading on the screen outside of the circle will always point north.")
.font(.caption)
Toggle(isOn: $flipScreen) {
Label("Flip Screen", systemImage: "pip.swap")
}
.toggleStyle(SwitchToggleStyle(tint: .accentColor))
Text("Flip screen vertically")
.font(.caption)
}
Section(header: Text("Format")) {
Picker("GPS Format", selection: $gpsFormat ) {
@ -98,6 +106,7 @@ struct DisplayConfig: View {
dc.screenOnSecs = UInt32(screenOnSeconds)
dc.autoScreenCarouselSecs = UInt32(screenCarouselInterval)
dc.compassNorthTop = compassNorthTop
dc.flipScreen = flipScreen
let adminMessageId = bleManager.saveDisplayConfig(config: dc, fromUser: node!.user!, toUser: node!.user!)
@ -124,6 +133,7 @@ struct DisplayConfig: View {
self.screenOnSeconds = Int(node?.displayConfig?.screenOnSeconds ?? 0)
self.screenCarouselInterval = Int(node?.displayConfig?.screenCarouselInterval ?? 0)
self.compassNorthTop = node?.displayConfig?.compassNorthTop ?? false
self.flipScreen = node?.displayConfig?.flipScreen ?? false
self.hasChanges = false
}
.onChange(of: screenOnSeconds) { newScreenSecs in
@ -146,6 +156,11 @@ struct DisplayConfig: View {
if newGpsFormat != node!.displayConfig!.gpsFormat { hasChanges = true }
}
}
.onChange(of: flipScreen) { newFlipScreen in
if node != nil && node!.displayConfig != nil {
if newFlipScreen != node!.displayConfig!.flipScreen { hasChanges = true }
}
}
.navigationViewStyle(StackNavigationViewStyle())
}
}