Skip to content

Commit

Permalink
#1 added Alert notification control point view controller
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos21 committed Jul 3, 2018
1 parent aba0f03 commit 10998e0
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 6 deletions.
16 changes: 12 additions & 4 deletions BluetoothExplorer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand All @@ -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 */; };
Expand Down Expand Up @@ -237,10 +239,10 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
35298F4820EAE1D60093B830 /* AlertLevelCharacteristicViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertLevelCharacteristicViewController.swift; sourceTree = "<group>"; };
35298F5A20EB08D10093B830 /* AlertLevelCharacteristic.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = AlertLevelCharacteristic.storyboard; sourceTree = "<group>"; };
35298F1920EACCB10093B830 /* BatteryPowerStateCharacteristic.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = BatteryPowerStateCharacteristic.storyboard; sourceTree = "<group>"; };
35298F2520EACD700093B830 /* PnPIDCharacteristicViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PnPIDCharacteristicViewController.swift; sourceTree = "<group>"; };
35298F4820EAE1D60093B830 /* AlertLevelCharacteristicViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertLevelCharacteristicViewController.swift; sourceTree = "<group>"; };
35298F5A20EB08D10093B830 /* AlertLevelCharacteristic.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = AlertLevelCharacteristic.storyboard; sourceTree = "<group>"; };
35317A2D20E53BD500D31493 /* HardwareRevisionStringCharacteristic.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = HardwareRevisionStringCharacteristic.storyboard; sourceTree = "<group>"; };
35317A3620E53C2C00D31493 /* HardwareRevisionStringCharacteristicViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HardwareRevisionStringCharacteristicViewController.swift; sourceTree = "<group>"; };
35317A3820E5485400D31493 /* SerialNumberStringCharacteristic.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = SerialNumberStringCharacteristic.storyboard; sourceTree = "<group>"; };
Expand All @@ -262,6 +264,8 @@
353557CF20E28CD200543440 /* String.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = String.swift; sourceTree = "<group>"; };
353557D520E2D15000543440 /* PnPIDCharacteristic.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = PnPIDCharacteristic.storyboard; sourceTree = "<group>"; };
353557DE20E2D17300543440 /* BatteryPowerStateCharacteristicViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BatteryPowerStateCharacteristicViewController.swift; sourceTree = "<group>"; };
35386B0120EBC5000016D662 /* AlertNotificationControlPointCharacteristic.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = AlertNotificationControlPointCharacteristic.storyboard; sourceTree = "<group>"; };
35386B0D20EBC5920016D662 /* AlertNotificationControlPointCharacteristicViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertNotificationControlPointCharacteristicViewController.swift; sourceTree = "<group>"; };
35CA5E0820E5740E00F6B589 /* Integer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Integer.swift; sourceTree = "<group>"; };
35CA5E1120E5777000F6B589 /* GATTAlertCategory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GATTAlertCategory.swift; sourceTree = "<group>"; };
35CA5E1620E579B100F6B589 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -496,6 +501,7 @@
35317A4720E56CCA00D31493 /* AlertCategoryCharacteristicViewController.swift */,
35298F4820EAE1D60093B830 /* AlertLevelCharacteristicViewController.swift */,
35298F2520EACD700093B830 /* PnPIDCharacteristicViewController.swift */,
35386B0D20EBC5920016D662 /* AlertNotificationControlPointCharacteristicViewController.swift */,
);
path = "GATT Characteristic Editors";
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14113" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Alert Notification Control Point-->
<scene sceneID="ckE-l7-ti3">
<objects>
<tableViewController storyboardIdentifier="AlertNotificationControlPointCharacteristicViewController" title="Alert Notification Control Point" id="5Ij-Vs-xep" userLabel="Alert Notification Control Point" customClass="AlertNotificationControlPointCharacteristicViewController" customModule="BluetoothExplorer" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" id="A2r-Qd-mP7">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<connections>
<outlet property="dataSource" destination="5Ij-Vs-xep" id="YNI-WP-YSC"/>
<outlet property="delegate" destination="5Ij-Vs-xep" id="CCM-nt-4da"/>
</connections>
</tableView>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="D7o-68-1EX" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="182" y="78"/>
</scene>
</scenes>
</document>
Original file line number Diff line number Diff line change
@@ -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]
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//

import Foundation

import UIKit
import Bluetooth

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@ let supportedCharacteristicViewControllers: [BluetoothUUID] = [
.pnpId,
.alertCategoryId,
.alertLevel,
.batteryPowerState
.batteryPowerState,
.alertNotificationControlPoint
]
7 changes: 7 additions & 0 deletions BluetoothExplorer/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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";

0 comments on commit 10998e0

Please sign in to comment.