Detection sensor trigger types

This commit is contained in:
Garth Vander Houwen 2024-10-11 18:18:45 -07:00
parent b2f6ebd6b3
commit 65a5b3adc8
6 changed files with 75 additions and 13 deletions

View file

@ -21872,6 +21872,9 @@
},
"Treat double tap on supported accelerometers as a user button press." : {
},
"TriggerType" : {
},
"Triple Click Ad Hoc Ping" : {

View file

@ -54,6 +54,7 @@
D9C983A22B79D1A600BDBE6A /* RequestPositionButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9C983A12B79D1A600BDBE6A /* RequestPositionButton.swift */; };
DD007BAE2AA4E91200F5FA12 /* MyInfoEntityExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD007BAD2AA4E91200F5FA12 /* MyInfoEntityExtension.swift */; };
DD007BB02AA5981000F5FA12 /* NodeInfoEntityExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD007BAF2AA5981000F5FA12 /* NodeInfoEntityExtension.swift */; };
DD0BE3102CB9FDC4000BA445 /* DetectionSensorEnums.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD0BE30F2CB9FDC4000BA445 /* DetectionSensorEnums.swift */; };
DD0D3D222A55CEB10066DB71 /* CocoaMQTT in Frameworks */ = {isa = PBXBuildFile; productRef = DD0D3D212A55CEB10066DB71 /* CocoaMQTT */; };
DD0E21012B8A6F1300F2D100 /* DeviceHardware.json in Resources */ = {isa = PBXBuildFile; fileRef = DD0E21002B8A6BC500F2D100 /* DeviceHardware.json */; };
DD13AA492AB73BF400BA0C98 /* PositionPopover.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD13AA482AB73BF400BA0C98 /* PositionPopover.swift */; };
@ -300,6 +301,7 @@
DD007BAF2AA5981000F5FA12 /* NodeInfoEntityExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NodeInfoEntityExtension.swift; sourceTree = "<group>"; };
DD05296F2B77F454008E44CD /* MeshtasticDataModelV 26.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "MeshtasticDataModelV 26.xcdatamodel"; sourceTree = "<group>"; };
DD0BE30C2CB785D8000BA445 /* MeshtasticDataModelV 46.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "MeshtasticDataModelV 46.xcdatamodel"; sourceTree = "<group>"; };
DD0BE30F2CB9FDC4000BA445 /* DetectionSensorEnums.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetectionSensorEnums.swift; sourceTree = "<group>"; };
DD0E20FF2B892E1300F2D100 /* MeshtasticDataModelV 28.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "MeshtasticDataModelV 28.xcdatamodel"; sourceTree = "<group>"; };
DD0E21002B8A6BC500F2D100 /* DeviceHardware.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = DeviceHardware.json; sourceTree = "<group>"; };
DD0E9C222A30CE3A00580CBB /* MeshtasticDataModelV14.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = MeshtasticDataModelV14.xcdatamodel; sourceTree = "<group>"; };
@ -797,6 +799,7 @@
DDB6ABD828B0A4BA00384BA1 /* BluetoothModes.swift */,
DD1925B628CDA5A400720036 /* CannedMessagesConfigEnums.swift */,
DDA1C48D28DB49D3009933EC /* ChannelRoles.swift */,
DD0BE30F2CB9FDC4000BA445 /* DetectionSensorEnums.swift */,
DDB6ABDF28B13AC700384BA1 /* DeviceEnums.swift */,
DDB6ABE328B13FFF00384BA1 /* DisplayEnums.swift */,
DD5D0A9B2931B9F200F7EA61 /* EthernetModes.swift */,
@ -1395,6 +1398,7 @@
DD2553572855B02500E55709 /* LoRaConfig.swift in Sources */,
DDB6ABD928B0A4BA00384BA1 /* BluetoothModes.swift in Sources */,
DD1BD0EE2C603C91008C0C70 /* CustomFormatters.swift in Sources */,
DD0BE3102CB9FDC4000BA445 /* DetectionSensorEnums.swift in Sources */,
DDD9E4E4284B208E003777C5 /* UserEntityExtension.swift in Sources */,
DD2553592855B52700E55709 /* PositionConfig.swift in Sources */,
DD97E96828EFE9A00056DDA4 /* About.swift in Sources */,

View file

@ -0,0 +1,53 @@
//
// DetectionSensorEnums.swift
// Meshtastic
//
// Copyright(c) Garth Vander Houwen 10/11/24.
//
import MeshtasticProtobufs
enum TriggerTypes: Int, CaseIterable, Identifiable {
case logicLow = 0
case logicHigh = 1
case fallingEdge = 2
case risingEdge = 3
case eitherEdgeActiveLow = 4
case eitherEdgeActiveHigh = 5
var id: Int { self.rawValue }
var name: String {
switch self {
case .logicLow:
return "Low"
case .logicHigh:
return "High"
case .fallingEdge:
return "Falling Edge"
case .risingEdge:
return "Rising Edge"
case .eitherEdgeActiveLow:
return "Either Edge Low"
case .eitherEdgeActiveHigh:
return "Either Edge Hight"
}
}
func protoEnumValue() -> ModuleConfig.DetectionSensorConfig.TriggerType {
switch self {
case .logicLow:
return ModuleConfig.DetectionSensorConfig.TriggerType.logicLow
case .logicHigh:
return ModuleConfig.DetectionSensorConfig.TriggerType.logicHigh
case .fallingEdge:
return ModuleConfig.DetectionSensorConfig.TriggerType.fallingEdge
case .risingEdge:
return ModuleConfig.DetectionSensorConfig.TriggerType.risingEdge
case .eitherEdgeActiveLow:
return ModuleConfig.DetectionSensorConfig.TriggerType.eitherEdgeActiveLow
case .eitherEdgeActiveHigh:
return ModuleConfig.DetectionSensorConfig.TriggerType.eitherEdgeActiveHigh
}
}
}

View file

@ -47,13 +47,13 @@
</uniquenessConstraints>
</entity>
<entity name="DetectionSensorConfigEntity" representedClassName="DetectionSensorConfigEntity" syncable="YES" codeGenerationType="class">
<attribute name="detectionTriggeredHigh" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="enabled" optional="YES" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
<attribute name="minimumBroadcastSecs" optional="YES" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="monitorPin" optional="YES" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="name" optional="YES" attributeType="String"/>
<attribute name="sendBell" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="stateBroadcastSecs" optional="YES" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="triggerType" optional="YES" attributeType="Integer 32" usesScalarValueType="YES"/>
<attribute name="usePullup" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
<relationship name="detectionSensorConfigNode" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="NodeInfoEntity" inverseName="detectionSensorConfig" inverseEntity="NodeInfoEntity"/>
</entity>

View file

@ -989,7 +989,7 @@ func upsertDetectionSensorModuleConfigPacket(config: ModuleConfig.DetectionSenso
newConfig.sendBell = config.sendBell
newConfig.name = config.name
newConfig.monitorPin = Int32(config.monitorPin)
newConfig.detectionTriggeredHigh = config.detectionTriggerType == .logicHigh ? true : false
newConfig.triggerType = Int32(config.detectionTriggerType.rawValue)
newConfig.usePullup = config.usePullup
newConfig.minimumBroadcastSecs = Int32(truncatingIfNeeded: config.minimumBroadcastSecs)
newConfig.stateBroadcastSecs = Int32(truncatingIfNeeded: config.stateBroadcastSecs)
@ -1000,7 +1000,7 @@ func upsertDetectionSensorModuleConfigPacket(config: ModuleConfig.DetectionSenso
fetchedNode[0].detectionSensorConfig?.name = config.name
fetchedNode[0].detectionSensorConfig?.monitorPin = Int32(config.monitorPin)
fetchedNode[0].detectionSensorConfig?.usePullup = config.usePullup
fetchedNode[0].detectionSensorConfig?.detectionTriggeredHigh = config.detectionTriggerType == .logicHigh ? true : false
fetchedNode[0].detectionSensorConfig?.triggerType = Int32(config.detectionTriggerType.rawValue)
fetchedNode[0].detectionSensorConfig?.minimumBroadcastSecs = Int32(truncatingIfNeeded: config.minimumBroadcastSecs)
fetchedNode[0].detectionSensorConfig?.stateBroadcastSecs = Int32(truncatingIfNeeded: config.stateBroadcastSecs)
}

View file

@ -36,7 +36,7 @@ struct DetectionSensorConfig: View {
@State var enabled = false
@State var sendBell: Bool = false
@State var name: String = ""
@State var detectionTriggeredHigh: Bool = true
@State var triggerType = 0
@State var usePullup: Bool = false
@State var minimumBroadcastSecs = 0
@State var stateBroadcastSecs = 0
@ -116,11 +116,13 @@ struct DetectionSensorConfig: View {
}
.pickerStyle(DefaultPickerStyle())
// Toggle(isOn: $detectionTriggeredHigh) {
// Label("Detection trigger High", systemImage: "dial.high")
// Text("Whether or not the GPIO pin state detection is triggered on HIGH (1) or LOW (0)")
// }
// .toggleStyle(SwitchToggleStyle(tint: .accentColor))
Picker("TriggerType", selection: $triggerType) {
ForEach(TriggerTypes.allCases) { tt in
Text(tt.name).tag(tt.rawValue)
}
}
.pickerStyle(DefaultPickerStyle())
.listRowSeparator(.hidden)
Toggle(isOn: $usePullup) {
Label("Uses pullup resistor", systemImage: "arrow.up.to.line")
@ -166,7 +168,7 @@ struct DetectionSensorConfig: View {
dsc.sendBell = self.sendBell
dsc.name = self.name
dsc.monitorPin = UInt32(self.monitorPin)
// dsc.detectionTriggeredHigh = self.detectionTriggeredHigh
dsc.detectionTriggerType = TriggerTypes(rawValue: triggerType)!.protoEnumValue()
dsc.usePullup = self.usePullup
dsc.minimumBroadcastSecs = UInt32(self.minimumBroadcastSecs)
dsc.stateBroadcastSecs = UInt32(self.stateBroadcastSecs)
@ -216,8 +218,8 @@ struct DetectionSensorConfig: View {
.onChange(of: sendBell) { _, newSendBell in
if newSendBell != node?.detectionSensorConfig?.sendBell { hasChanges = true }
}
.onChange(of: detectionTriggeredHigh) { _, newDetectionTriggeredHigh in
// if newDetectionTriggeredHigh != node?.detectionSensorConfig?.detectionTriggeredHigh { hasChanges = true }
.onChange(of: triggerType) { _, newTriggerType in
if newTriggerType != node?.detectionSensorConfig?.triggerType ?? 0 { hasChanges = true }
}
.onChange(of: usePullup) { _, newUsePullup in
if newUsePullup != node?.detectionSensorConfig?.usePullup { hasChanges = true }
@ -244,7 +246,7 @@ struct DetectionSensorConfig: View {
self.name = (node?.detectionSensorConfig?.name ?? "")
self.monitorPin = Int(node?.detectionSensorConfig?.monitorPin ?? 0)
self.usePullup = (node?.detectionSensorConfig?.usePullup ?? false)
// self.detectionTriggeredHigh = (node?.detectionSensorConfig?.detectionTriggeredHigh ?? true)
self.triggerType = Int(node?.detectionSensorConfig?.triggerType ?? 0)
self.minimumBroadcastSecs = Int(node?.detectionSensorConfig?.minimumBroadcastSecs ?? 45)
self.stateBroadcastSecs = Int(node?.detectionSensorConfig?.stateBroadcastSecs ?? 0)