diff --git a/Meshtastic/Helpers/BLEManager.swift b/Meshtastic/Helpers/BLEManager.swift index 828b2d4a..7267df84 100644 --- a/Meshtastic/Helpers/BLEManager.swift +++ b/Meshtastic/Helpers/BLEManager.swift @@ -1155,6 +1155,63 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph let binaryData: Data = try! toRadio.serializedData() + if connectedPeripheral!.peripheral.state == CBPeripheralState.connected { + + let newMessage = MessageEntity(context: context!) + newMessage.messageId = Int64(UInt32.random(in: UInt32(UInt8.max).. Int64 { + + var newMessageId: Int64 = 0 + + var adminPacket = AdminMessage() + adminPacket.setModuleConfig.externalNotification = config + + var meshPacket: MeshPacket = MeshPacket() + meshPacket.to = UInt32(toUser.num) + meshPacket.from = 0 //UInt32(fromUser.num) + meshPacket.id = UInt32.random(in: UInt32(UInt8.max).. Int64 { var newMessageId: Int64 = 0 diff --git a/Meshtastic/Views/Settings/Config/Module/ExternalNotificationConfig.swift b/Meshtastic/Views/Settings/Config/Module/ExternalNotificationConfig.swift index d98a8273..8a52e813 100644 --- a/Meshtastic/Views/Settings/Config/Module/ExternalNotificationConfig.swift +++ b/Meshtastic/Views/Settings/Config/Module/ExternalNotificationConfig.swift @@ -158,15 +158,17 @@ struct ExternalNotificationConfig: View { enc.output = UInt32(output) enc.outputMs = UInt32(outputMilliseconds) - //if bleManager.saveRangeTestModuleConfig(config: rtc, destNum: bleManager.connectedPeripheral.num, wantResponse: false) { + let adminMessageId = bleManager.saveExternalNotificationModuleConfig(config: enc, fromUser: node.user!, toUser: node.user!, wantResponse: true) + + 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 - //} else { + } else { - //} + } } } @@ -179,7 +181,44 @@ struct ExternalNotificationConfig: View { }) .onAppear { - self.bleManager.context = context + if self.initialLoad{ + + self.bleManager.context = context + + self.enabled = node.externalNotificationConfig?.enabled ?? false + self.alertBell = node.externalNotificationConfig?.alertBell ?? false + self.alertMessage = node.externalNotificationConfig?.alertMessage ?? false + self.active = node.externalNotificationConfig?.active ?? false + self.output = Int(node.externalNotificationConfig?.output ?? 0) + self.outputMilliseconds = Int(node.externalNotificationConfig?.outputMilliseconds ?? 0) + + self.hasChanges = false + self.initialLoad = false + } + } + .onChange(of: enabled) { newEnabled in + + if newEnabled != node.externalNotificationConfig!.enabled { hasChanges = true } + } + .onChange(of: alertBell) { newAlertBell in + + if newAlertBell != node.externalNotificationConfig!.alertBell { hasChanges = true } + } + .onChange(of: alertMessage) { newAlertMessage in + + if newAlertMessage != node.externalNotificationConfig!.alertMessage { hasChanges = true } + } + .onChange(of: active) { newActuve in + + if newActuve != node.externalNotificationConfig!.active { hasChanges = true } + } + .onChange(of: output) { newOutput in + + if newOutput != node.externalNotificationConfig!.output { hasChanges = true } + } + .onChange(of: outputMilliseconds) { newOutputMs in + + if newOutputMs != node.externalNotificationConfig!.outputMilliseconds { hasChanges = true } } .navigationViewStyle(StackNavigationViewStyle()) }