diff --git a/BluetoothExplorer.xcodeproj/project.pbxproj b/BluetoothExplorer.xcodeproj/project.pbxproj index 0721c00..b14b555 100644 --- a/BluetoothExplorer.xcodeproj/project.pbxproj +++ b/BluetoothExplorer.xcodeproj/project.pbxproj @@ -7,10 +7,10 @@ objects = { /* Begin PBXBuildFile section */ - 35298F4920EAE1D60093B830 /* AlertLevelCharacteristicViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35298F4820EAE1D60093B830 /* AlertLevelCharacteristicViewController.swift */; }; - 35298F5B20EB08D10093B830 /* AlertLevelCharacteristic.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 35298F5A20EB08D10093B830 /* AlertLevelCharacteristic.storyboard */; }; 35298F1A20EACCB10093B830 /* BatteryPowerStateCharacteristic.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 35298F1920EACCB10093B830 /* BatteryPowerStateCharacteristic.storyboard */; }; 35298F2620EACD700093B830 /* PnPIDCharacteristicViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35298F2520EACD700093B830 /* PnPIDCharacteristicViewController.swift */; }; + 35298F4920EAE1D60093B830 /* AlertLevelCharacteristicViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35298F4820EAE1D60093B830 /* AlertLevelCharacteristicViewController.swift */; }; + 35298F5B20EB08D10093B830 /* AlertLevelCharacteristic.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 35298F5A20EB08D10093B830 /* AlertLevelCharacteristic.storyboard */; }; 35317A2E20E53BD500D31493 /* HardwareRevisionStringCharacteristic.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 35317A2D20E53BD500D31493 /* HardwareRevisionStringCharacteristic.storyboard */; }; 35317A3720E53C2C00D31493 /* HardwareRevisionStringCharacteristicViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35317A3620E53C2C00D31493 /* HardwareRevisionStringCharacteristicViewController.swift */; }; 35317A3920E5485400D31493 /* SerialNumberStringCharacteristic.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 35317A3820E5485400D31493 /* SerialNumberStringCharacteristic.storyboard */; }; @@ -32,6 +32,8 @@ 353557D020E28CD200543440 /* String.swift in Sources */ = {isa = PBXBuildFile; fileRef = 353557CF20E28CD200543440 /* String.swift */; }; 353557D620E2D15000543440 /* PnPIDCharacteristic.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 353557D520E2D15000543440 /* PnPIDCharacteristic.storyboard */; }; 353557DF20E2D17300543440 /* BatteryPowerStateCharacteristicViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 353557DE20E2D17300543440 /* BatteryPowerStateCharacteristicViewController.swift */; }; + 35386B0220EBC5000016D662 /* AlertNotificationControlPointCharacteristic.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 35386B0120EBC5000016D662 /* AlertNotificationControlPointCharacteristic.storyboard */; }; + 35386B0E20EBC5920016D662 /* AlertNotificationControlPointCharacteristicViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35386B0D20EBC5920016D662 /* AlertNotificationControlPointCharacteristicViewController.swift */; }; 35CA5E0920E5740E00F6B589 /* Integer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35CA5E0820E5740E00F6B589 /* Integer.swift */; }; 35CA5E1220E5777000F6B589 /* GATTAlertCategory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35CA5E1120E5777000F6B589 /* GATTAlertCategory.swift */; }; 35CA5E1520E579B100F6B589 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 35CA5E1720E579B100F6B589 /* Localizable.strings */; }; @@ -237,10 +239,10 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 35298F4820EAE1D60093B830 /* AlertLevelCharacteristicViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertLevelCharacteristicViewController.swift; sourceTree = ""; }; - 35298F5A20EB08D10093B830 /* AlertLevelCharacteristic.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = AlertLevelCharacteristic.storyboard; sourceTree = ""; }; 35298F1920EACCB10093B830 /* BatteryPowerStateCharacteristic.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = BatteryPowerStateCharacteristic.storyboard; sourceTree = ""; }; 35298F2520EACD700093B830 /* PnPIDCharacteristicViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PnPIDCharacteristicViewController.swift; sourceTree = ""; }; + 35298F4820EAE1D60093B830 /* AlertLevelCharacteristicViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertLevelCharacteristicViewController.swift; sourceTree = ""; }; + 35298F5A20EB08D10093B830 /* AlertLevelCharacteristic.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = AlertLevelCharacteristic.storyboard; sourceTree = ""; }; 35317A2D20E53BD500D31493 /* HardwareRevisionStringCharacteristic.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = HardwareRevisionStringCharacteristic.storyboard; sourceTree = ""; }; 35317A3620E53C2C00D31493 /* HardwareRevisionStringCharacteristicViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HardwareRevisionStringCharacteristicViewController.swift; sourceTree = ""; }; 35317A3820E5485400D31493 /* SerialNumberStringCharacteristic.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = SerialNumberStringCharacteristic.storyboard; sourceTree = ""; }; @@ -262,6 +264,8 @@ 353557CF20E28CD200543440 /* String.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = String.swift; sourceTree = ""; }; 353557D520E2D15000543440 /* PnPIDCharacteristic.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = PnPIDCharacteristic.storyboard; sourceTree = ""; }; 353557DE20E2D17300543440 /* BatteryPowerStateCharacteristicViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BatteryPowerStateCharacteristicViewController.swift; sourceTree = ""; }; + 35386B0120EBC5000016D662 /* AlertNotificationControlPointCharacteristic.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = AlertNotificationControlPointCharacteristic.storyboard; sourceTree = ""; }; + 35386B0D20EBC5920016D662 /* AlertNotificationControlPointCharacteristicViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertNotificationControlPointCharacteristicViewController.swift; sourceTree = ""; }; 35CA5E0820E5740E00F6B589 /* Integer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Integer.swift; sourceTree = ""; }; 35CA5E1120E5777000F6B589 /* GATTAlertCategory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GATTAlertCategory.swift; sourceTree = ""; }; 35CA5E1620E579B100F6B589 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = ""; }; @@ -395,6 +399,7 @@ 35317A3820E5485400D31493 /* SerialNumberStringCharacteristic.storyboard */, 35317A3E20E56B9800D31493 /* AlertCategoryCharacteristic.storyboard */, 35298F5A20EB08D10093B830 /* AlertLevelCharacteristic.storyboard */, + 35386B0120EBC5000016D662 /* AlertNotificationControlPointCharacteristic.storyboard */, 6E98B69C2059B51000B6F016 /* Assets.xcassets */, 6E98B6A12059B51000B6F016 /* Info.plist */, 35CA5E1720E579B100F6B589 /* Localizable.strings */, @@ -496,6 +501,7 @@ 35317A4720E56CCA00D31493 /* AlertCategoryCharacteristicViewController.swift */, 35298F4820EAE1D60093B830 /* AlertLevelCharacteristicViewController.swift */, 35298F2520EACD700093B830 /* PnPIDCharacteristicViewController.swift */, + 35386B0D20EBC5920016D662 /* AlertNotificationControlPointCharacteristicViewController.swift */, ); path = "GATT Characteristic Editors"; sourceTree = ""; @@ -751,6 +757,7 @@ 6EDE00CF20DB12B3002E951A /* BatteryLevelCharacteristic.storyboard in Resources */, 6E98B6A02059B51000B6F016 /* LaunchScreen.storyboard in Resources */, 35335A0520E1316F006ABD4D /* ModelNumberCharacteristic.storyboard in Resources */, + 35386B0220EBC5000016D662 /* AlertNotificationControlPointCharacteristic.storyboard in Resources */, 35317A3920E5485400D31493 /* SerialNumberStringCharacteristic.storyboard in Resources */, 35298F5B20EB08D10093B830 /* AlertLevelCharacteristic.storyboard in Resources */, 35317A2E20E53BD500D31493 /* HardwareRevisionStringCharacteristic.storyboard in Resources */, @@ -825,6 +832,7 @@ 35335A1420E13FF0006ABD4D /* FirmwareRevisionStringCharacteristicViewController.swift in Sources */, 6E8C68EA20DA02DA00232169 /* UIAlertAction.swift in Sources */, 35335A0720E13203006ABD4D /* ModelNumberCharacteristicViewController.swift in Sources */, + 35386B0E20EBC5920016D662 /* AlertNotificationControlPointCharacteristicViewController.swift in Sources */, 35298F2620EACD700093B830 /* PnPIDCharacteristicViewController.swift in Sources */, 6EC0D9C720DE076A005FB128 /* Appearance.swift in Sources */, 6EFB3E9720D3F0D700364CA0 /* CentralManagedObject.swift in Sources */, diff --git a/BluetoothExplorer/AlertNotificationControlPointCharacteristic.storyboard b/BluetoothExplorer/AlertNotificationControlPointCharacteristic.storyboard new file mode 100644 index 0000000..458e129 --- /dev/null +++ b/BluetoothExplorer/AlertNotificationControlPointCharacteristic.storyboard @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/BluetoothExplorer/Controller/GATT Characteristic Editors/AlertNotificationControlPointCharacteristicViewController.swift b/BluetoothExplorer/Controller/GATT Characteristic Editors/AlertNotificationControlPointCharacteristicViewController.swift new file mode 100644 index 0000000..dda1398 --- /dev/null +++ b/BluetoothExplorer/Controller/GATT Characteristic Editors/AlertNotificationControlPointCharacteristicViewController.swift @@ -0,0 +1,126 @@ +// +// AlertNotificationControlPointCharacteristicViewController.swift +// BluetoothExplorer +// +// Created by Carlos Duclos on 7/3/18. +// Copyright © 2018 PureSwift. All rights reserved. +// + +import Foundation +import UIKit +import Bluetooth + +final class AlertNotificationControlPointCharacteristicViewController: UITableViewController, CharacteristicViewController, InstantiableViewController { + + typealias Command = GATTAlertNotificationControlPoint.Command + + // MARK: - Properties + + private let cellIdentifier = R.nib.inputTextViewCell.name + + private var fields = [Field]() + + var value = GATTAlertNotificationControlPoint(command: .enableNewIncomingAlertNotification, category: .simpleAlert) + + var valueDidChange: ((GATTAlertNotificationControlPoint) -> ())? + + // MARK: - Loading + + override func viewDidLoad() { + super.viewDidLoad() + + fields = [.command("\(value.command.rawValue)"), + .alertCategory("\(value.category.rawValue)")] + + tableView.register(R.nib.inputTextViewCell(), forCellReuseIdentifier: cellIdentifier) + tableView.separatorStyle = .none + } + + // MARK: - UITableViewController + + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return fields.count + } + + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + + let field = fields[indexPath.row] + let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! InputTextViewCell + cell.selectionStyle = .none + + configure(cell, field: field) + + return cell + } + + override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + + let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! InputTextViewCell + cell.inputTextView.textField.becomeFirstResponder() + } + + // MARK: - Methods + + func configure(_ cell: InputTextViewCell, field: Field) { + + cell.inputTextView.value = field.bluetoothValue + cell.inputTextView.posibleInputValues = field.posibleValues + cell.inputTextView.isEnabled = valueDidChange != nil + cell.inputTextView.fieldLabelText = field.title + cell.inputTextView.placeholder = field.title + } +} + +extension AlertNotificationControlPointCharacteristicViewController { + + enum Field { + + case command(String) + case alertCategory(String) + + var title: String { + + switch self { + case .command: + return "Command" + + case .alertCategory: + return "Alert Category" + } + } + + var bluetoothValue: String { + switch self { + case .command(let value): + return value + + case .alertCategory(let value): + return value + } + } + + var posibleValues: [String] { + switch self { + case .command: + return [Command.enableNewIncomingAlertNotification.rawValue.description, + Command.enableUnreadCategoryStatusNotification.rawValue.description, + Command.disableNewIncomingAlertNotification.rawValue.description, + Command.disableUnreadCategoryStatusNotification.rawValue.description, + Command.notifyNewIncomingAlertImmediately.rawValue.description, + Command.notifyUnreadCategoryStatusImmediately.rawValue.description] + + case .alertCategory: + return [GATTAlertCategory.simpleAlert.rawValue.description, + GATTAlertCategory.email.rawValue.description, + GATTAlertCategory.news.rawValue.description, + GATTAlertCategory.call.rawValue.description, + GATTAlertCategory.missedCall.rawValue.description, + GATTAlertCategory.sms.rawValue.description, + GATTAlertCategory.voiceMail.rawValue.description, + GATTAlertCategory.schedule.rawValue.description, + GATTAlertCategory.highPrioritizedAlert.rawValue.description, + GATTAlertCategory.instantMessage.rawValue.description] + } + } + } +} diff --git a/BluetoothExplorer/Controller/GATT Characteristic Editors/PnPIDCharacteristicViewController.swift b/BluetoothExplorer/Controller/GATT Characteristic Editors/PnPIDCharacteristicViewController.swift index 7ebd616..a652da3 100644 --- a/BluetoothExplorer/Controller/GATT Characteristic Editors/PnPIDCharacteristicViewController.swift +++ b/BluetoothExplorer/Controller/GATT Characteristic Editors/PnPIDCharacteristicViewController.swift @@ -7,7 +7,6 @@ // import Foundation - import UIKit import Bluetooth diff --git a/BluetoothExplorer/Controller/PeripheralCharacteristicDetailViewController.swift b/BluetoothExplorer/Controller/PeripheralCharacteristicDetailViewController.swift index 68af098..b1cebd1 100644 --- a/BluetoothExplorer/Controller/PeripheralCharacteristicDetailViewController.swift +++ b/BluetoothExplorer/Controller/PeripheralCharacteristicDetailViewController.swift @@ -201,6 +201,9 @@ final class PeripheralCharacteristicDetailViewController: UITableViewController case BatteryPowerStateCharacteristicViewController.uuid: viewController = load(BatteryPowerStateCharacteristicViewController.self) + case AlertNotificationControlPointCharacteristicViewController.uuid: + viewController = load(AlertNotificationControlPointCharacteristicViewController.self) + default: viewController = nil } diff --git a/BluetoothExplorer/Controller/Protocols/CharacteristicViewController.swift b/BluetoothExplorer/Controller/Protocols/CharacteristicViewController.swift index 7d462fd..fd220ca 100644 --- a/BluetoothExplorer/Controller/Protocols/CharacteristicViewController.swift +++ b/BluetoothExplorer/Controller/Protocols/CharacteristicViewController.swift @@ -46,5 +46,6 @@ let supportedCharacteristicViewControllers: [BluetoothUUID] = [ .pnpId, .alertCategoryId, .alertLevel, - .batteryPowerState + .batteryPowerState, + .alertNotificationControlPoint ] diff --git a/BluetoothExplorer/en.lproj/Localizable.strings b/BluetoothExplorer/en.lproj/Localizable.strings index a3e23b6..daa639c 100644 --- a/BluetoothExplorer/en.lproj/Localizable.strings +++ b/BluetoothExplorer/en.lproj/Localizable.strings @@ -17,3 +17,10 @@ "gattAlertCategoryHighPrioritized" = "High Prioritized Alert"; "gattAlertCategoryInstantMessage" = "Instant Message"; +"gattAlertNotificationControlPointDisableNewIncoming" = "Disable new incoming alert notification"; +"gattAlertNotificationControlPointDisableUnreadCategoryStatus" = "Disable unread category status"; +"gattAlertNotificationControlPointEnableNewIncomingAlert" = "Enable new incoming alert notification"; +"gattAlertNotificationControlPointEnableUnreadCategoryStatus" = "Enable unread category status"; +"gattAlertNotificationControlPointNotifyNewIncomingAlert" = "Notify new incoming alert immediately"; +"gattAlertNotificationControlPointNotifyUnreadCategoryStatus" = "Notify unread category status immediately"; +