Config cleanup

This commit is contained in:
Garth Vander Houwen 2023-11-26 12:54:45 -08:00
parent 93d3cb33c8
commit f12eed755d
5 changed files with 58 additions and 0 deletions

View file

@ -168,3 +168,29 @@ enum DisplayModes: Int, CaseIterable, Identifiable {
}
}
}
// Default of 0 is metric
enum Units: Int, CaseIterable, Identifiable {
case metric = 0
case imperial = 1
var id: Int { self.rawValue }
var description: String {
switch self {
case .metric:
return "Metric"
case .imperial:
return "Imperial"
}
}
func protoEnumValue() -> Config.DisplayConfig.DisplayUnits {
switch self {
case .metric:
return Config.DisplayConfig.DisplayUnits.metric
case .imperial:
return Config.DisplayConfig.DisplayUnits.imperial
}
}
}

View file

@ -92,6 +92,7 @@
<attribute name="oledType" 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"/>
<attribute name="units" optional="YES" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="wakeOnTapOrMotion" optional="YES" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
<relationship name="displayConfigNode" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="NodeInfoEntity" inverseName="displayConfig" inverseEntity="NodeInfoEntity"/>
</entity>

View file

@ -413,6 +413,7 @@ func upsertDisplayConfigPacket(config: Meshtastic.Config.DisplayConfig, nodeNum:
newDisplayConfig.flipScreen = config.flipScreen
newDisplayConfig.oledType = Int32(config.oled.rawValue)
newDisplayConfig.displayMode = Int32(config.displaymode.rawValue)
newDisplayConfig.units = Int32(config.units.rawValue)
newDisplayConfig.headingBold = config.headingBold
fetchedNode[0].displayConfig = newDisplayConfig
@ -425,6 +426,7 @@ func upsertDisplayConfigPacket(config: Meshtastic.Config.DisplayConfig, nodeNum:
fetchedNode[0].displayConfig?.flipScreen = config.flipScreen
fetchedNode[0].displayConfig?.oledType = Int32(config.oled.rawValue)
fetchedNode[0].displayConfig?.displayMode = Int32(config.displaymode.rawValue)
fetchedNode[0].displayConfig?.units = Int32(config.units.rawValue)
fetchedNode[0].displayConfig?.headingBold = config.headingBold
}

View file

@ -26,6 +26,7 @@ struct DisplayConfig: View {
@State var flipScreen = false
@State var oledType = 0
@State var displayMode = 0
@State var units = 0
var body: some View {
@ -125,6 +126,15 @@ struct DisplayConfig: View {
Text("The format used to display GPS coordinates on the device screen.")
.font(.caption)
.listRowSeparator(.visible)
Picker("Display Units", selection: $units ) {
ForEach(Units.allCases) { un in
Text(un.description)
}
}
.pickerStyle(DefaultPickerStyle())
Text("Units displayed on the device screen")
.font(.caption)
}
}
.disabled(self.bleManager.connectedPeripheral == nil || node?.displayConfig == nil)
@ -160,6 +170,7 @@ struct DisplayConfig: View {
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 {
@ -233,6 +244,11 @@ struct DisplayConfig: View {
if newDisplayMode != node!.displayConfig!.displayMode { hasChanges = true }
}
}
.onChange(of: units) { newUnits in
if node != nil && node!.displayConfig != nil {
if newUnits != node!.displayConfig!.units { hasChanges = true }
}
}
}
func setDisplayValues() {
self.gpsFormat = Int(node?.displayConfig?.gpsFormat ?? 0)
@ -243,6 +259,7 @@ struct DisplayConfig: View {
self.flipScreen = node?.displayConfig?.flipScreen ?? false
self.oledType = Int(node?.displayConfig?.oledType ?? 0)
self.displayMode = Int(node?.displayConfig?.displayMode ?? 0)
self.units = Int(node?.displayConfig?.units ?? 0)
self.hasChanges = false
}
}

View file

@ -184,6 +184,12 @@ struct LoRaConfig: View {
.scrollDismissesKeyboard(.immediately)
.focused($focusedField, equals: .frequencyOverride)
}
HStack {
Image(systemName: "antenna.radiowaves.left.and.right")
.foregroundColor(.accentColor)
Stepper("\(txPower)db Transmit Power", value: $txPower, in: 1...30, step: 1)
.padding(5)
}
}
}
.disabled(self.bleManager.connectedPeripheral == nil || node?.loRaConfig == nil)
@ -214,6 +220,7 @@ struct LoRaConfig: View {
lc.modemPreset = ModemPresets(rawValue: modemPreset)!.protoEnumValue()
lc.usePreset = usePreset
lc.txEnabled = txEnabled
lc.txPower = Int32(txPower)
lc.channelNum = UInt32(channelNum)
lc.bandwidth = UInt32(bandwidth)
lc.codingRate = UInt32(codingRate)
@ -302,6 +309,11 @@ struct LoRaConfig: View {
if newOverrideFrequency != node!.loRaConfig!.overrideFrequency { hasChanges = true }
}
}
.onChange(of: txPower) { newTxPower in
if node != nil && node!.loRaConfig != nil {
if newTxPower != node!.loRaConfig!.txPower { hasChanges = true }
}
}
}
func setLoRaValues() {
self.hopLimit = Int(node?.loRaConfig?.hopLimit ?? 3)