Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added GATT Aerobic Heart Rate Limits Characteristic Support #8

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions BluetoothExplorer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
35386B0E20EBC5920016D662 /* AlertNotificationControlPointCharacteristicViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35386B0D20EBC5920016D662 /* AlertNotificationControlPointCharacteristicViewController.swift */; };
35386B1520EBE13E0016D662 /* AgeCharacteristic.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 35386B1420EBE13E0016D662 /* AgeCharacteristic.storyboard */; };
35386B2120EBE1530016D662 /* AgeCharacteristicViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35386B2020EBE1530016D662 /* AgeCharacteristicViewController.swift */; };
35386B3820EBF0310016D662 /* AerobicHeartRateLowerLimitCharacteristicViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35386B3720EBF0310016D662 /* AerobicHeartRateLowerLimitCharacteristicViewController.swift */; };
35386B4420EBF64A0016D662 /* AerobicHeartRateLowerLimitCharacteristic.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 35386B4320EBF64A0016D662 /* AerobicHeartRateLowerLimitCharacteristic.storyboard */; };
35386B4620EBFBC50016D662 /* AerobicHeartRateUpperLimitCharacteristicViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35386B4520EBFBC50016D662 /* AerobicHeartRateUpperLimitCharacteristicViewController.swift */; };
35386B4820EBFC1B0016D662 /* AerobicHeartRateUpperLimitCharacteristic.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 35386B4720EBFC1B0016D662 /* AerobicHeartRateUpperLimitCharacteristic.storyboard */; };
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 @@ -270,6 +274,10 @@
35386B0D20EBC5920016D662 /* AlertNotificationControlPointCharacteristicViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertNotificationControlPointCharacteristicViewController.swift; sourceTree = "<group>"; };
35386B1420EBE13E0016D662 /* AgeCharacteristic.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = AgeCharacteristic.storyboard; sourceTree = "<group>"; };
35386B2020EBE1530016D662 /* AgeCharacteristicViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AgeCharacteristicViewController.swift; sourceTree = "<group>"; };
35386B3720EBF0310016D662 /* AerobicHeartRateLowerLimitCharacteristicViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AerobicHeartRateLowerLimitCharacteristicViewController.swift; sourceTree = "<group>"; };
35386B4320EBF64A0016D662 /* AerobicHeartRateLowerLimitCharacteristic.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = AerobicHeartRateLowerLimitCharacteristic.storyboard; sourceTree = "<group>"; };
35386B4520EBFBC50016D662 /* AerobicHeartRateUpperLimitCharacteristicViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AerobicHeartRateUpperLimitCharacteristicViewController.swift; sourceTree = "<group>"; };
35386B4720EBFC1B0016D662 /* AerobicHeartRateUpperLimitCharacteristic.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = AerobicHeartRateUpperLimitCharacteristic.storyboard; 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 @@ -405,6 +413,8 @@
35298F5A20EB08D10093B830 /* AlertLevelCharacteristic.storyboard */,
35386B0120EBC5000016D662 /* AlertNotificationControlPointCharacteristic.storyboard */,
35386B1420EBE13E0016D662 /* AgeCharacteristic.storyboard */,
35386B4320EBF64A0016D662 /* AerobicHeartRateLowerLimitCharacteristic.storyboard */,
35386B4720EBFC1B0016D662 /* AerobicHeartRateUpperLimitCharacteristic.storyboard */,
6E98B69C2059B51000B6F016 /* Assets.xcassets */,
6E98B6A12059B51000B6F016 /* Info.plist */,
35CA5E1720E579B100F6B589 /* Localizable.strings */,
Expand Down Expand Up @@ -508,6 +518,8 @@
35298F2520EACD700093B830 /* PnPIDCharacteristicViewController.swift */,
35386B0D20EBC5920016D662 /* AlertNotificationControlPointCharacteristicViewController.swift */,
35386B2020EBE1530016D662 /* AgeCharacteristicViewController.swift */,
35386B3720EBF0310016D662 /* AerobicHeartRateLowerLimitCharacteristicViewController.swift */,
35386B4520EBFBC50016D662 /* AerobicHeartRateUpperLimitCharacteristicViewController.swift */,
);
path = "GATT Characteristic Editors";
sourceTree = "<group>";
Expand Down Expand Up @@ -763,6 +775,7 @@
6EDE00CF20DB12B3002E951A /* BatteryLevelCharacteristic.storyboard in Resources */,
6E98B6A02059B51000B6F016 /* LaunchScreen.storyboard in Resources */,
35335A0520E1316F006ABD4D /* ModelNumberCharacteristic.storyboard in Resources */,
35386B4820EBFC1B0016D662 /* AerobicHeartRateUpperLimitCharacteristic.storyboard in Resources */,
35386B0220EBC5000016D662 /* AlertNotificationControlPointCharacteristic.storyboard in Resources */,
35317A3920E5485400D31493 /* SerialNumberStringCharacteristic.storyboard in Resources */,
35298F5B20EB08D10093B830 /* AlertLevelCharacteristic.storyboard in Resources */,
Expand All @@ -774,6 +787,7 @@
35FE560E20E435860052C0C0 /* InputTextViewCell.xib in Resources */,
35335A1A20E14830006ABD4D /* ManufacturerNameStringCharacteristic.storyboard in Resources */,
35335A1220E13FC0006ABD4D /* FirmwareRevisionStringCharacteristic.storyboard in Resources */,
35386B4420EBF64A0016D662 /* AerobicHeartRateLowerLimitCharacteristic.storyboard in Resources */,
35317A3F20E56B9800D31493 /* AlertCategoryCharacteristic.storyboard in Resources */,
35335A1620E14353006ABD4D /* SoftwareRevisionStringCharacteristic.storyboard in Resources */,
35F5BB5A20E3DAC500AC5FF1 /* InputTextView.xib in Resources */,
Expand Down Expand Up @@ -837,6 +851,7 @@
353557C720E28CB700543440 /* InstantiableViewController.swift in Sources */,
6ECCCC7320E091070054663C /* FDGapLayoutGuide.m in Sources */,
35335A1420E13FF0006ABD4D /* FirmwareRevisionStringCharacteristicViewController.swift in Sources */,
35386B4620EBFBC50016D662 /* AerobicHeartRateUpperLimitCharacteristicViewController.swift in Sources */,
6E8C68EA20DA02DA00232169 /* UIAlertAction.swift in Sources */,
35335A0720E13203006ABD4D /* ModelNumberCharacteristicViewController.swift in Sources */,
35386B0E20EBC5920016D662 /* AlertNotificationControlPointCharacteristicViewController.swift in Sources */,
Expand All @@ -861,6 +876,7 @@
35298F4920EAE1D60093B830 /* AlertLevelCharacteristicViewController.swift in Sources */,
6EFB3E9320D3EF9A00364CA0 /* ScanDataManagedObject.swift in Sources */,
6ECCCC6C20E091070054663C /* FDTransformLayer.m in Sources */,
35386B3820EBF0310016D662 /* AerobicHeartRateLowerLimitCharacteristicViewController.swift in Sources */,
6E98B6962059B51000B6F016 /* AppDelegate.swift in Sources */,
353557DF20E2D17300543440 /* BatteryPowerStateCharacteristicViewController.swift in Sources */,
35F5BB6520E3DC0000AC5FF1 /* NibDesignable.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" initialViewController="yZe-U6-RdP">
<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>
<!--Aerobic Heart Rate Lower Limit-->
<scene sceneID="p83-Hu-HXR">
<objects>
<tableViewController storyboardIdentifier="AerobicHeartRateLowerLimitCharacteristicViewController" title="Age" id="yZe-U6-RdP" userLabel="Aerobic Heart Rate Lower Limit" customClass="AerobicHeartRateLowerLimitCharacteristicViewController" 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="jgB-og-N86">
<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="yZe-U6-RdP" id="32q-bA-QPc"/>
<outlet property="delegate" destination="yZe-U6-RdP" id="gQu-7c-UP9"/>
</connections>
</tableView>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="9ur-3S-NWI" 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,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" initialViewController="bpE-ya-lBr">
<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>
<!--Aerobic Heart Rate Upper limit-->
<scene sceneID="KfI-cV-D9K">
<objects>
<tableViewController storyboardIdentifier="AerobicHeartRateUpperLimitCharacteristicViewController" title="Aerobic Heart Rate Upper limit" id="bpE-ya-lBr" userLabel="Aerobic Heart Rate Upper limit" customClass="AerobicHeartRateUpperLimitCharacteristicViewController" 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="12f-A1-qD6">
<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="bpE-ya-lBr" id="n9j-Qf-eTR"/>
<outlet property="delegate" destination="bpE-ya-lBr" id="jsJ-LR-SOj"/>
</connections>
</tableView>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="f0E-Xf-K4V" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-22" y="82"/>
</scene>
</scenes>
</document>
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
//
// AerobicHeartRateLowerLimitCharacteristicViewController.swift
// BluetoothExplorer
//
// Created by Carlos Duclos on 7/3/18.
// Copyright © 2018 PureSwift. All rights reserved.
//

import Foundation
import UIKit
import CoreData
import Bluetooth
import GATT

final class AerobicHeartRateLowerLimitCharacteristicViewController: UITableViewController, CharacteristicViewController, InstantiableViewController {

// MARK: - Properties

private let cellIdentifier = R.nib.inputTextViewCell.name

private var fields = [Field]()

var value = GATTAerobicHeartRateLowerLimit(beats: 98)

var valueDidChange: ((GATTAerobicHeartRateLowerLimit) -> ())?

// MARK: - Loading

override func viewDidLoad() {
super.viewDidLoad()

fields = [.lowerLimit("\(value.beats.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.isEnabled = valueDidChange != nil
cell.inputTextView.keyboardType = field.keyboardType
cell.inputTextView.fieldLabelText = field.title
cell.inputTextView.placeholder = field.title
cell.inputTextView.validator = { value in

guard value.trim() != ""
else { return .none }

switch field {
case .lowerLimit:

guard let _ = UInt8(value)
else { return .error("Maximum value is 0xFF") }
}

return .none
}
}
}

extension AerobicHeartRateLowerLimitCharacteristicViewController {

enum Field {

case lowerLimit(String)

var title: String {

switch self {
case .lowerLimit: return "Lower Limit"
}
}

var bluetoothValue: String {

switch self {
case .lowerLimit(let value): return value
}
}

var keyboardType: UIKeyboardType { return .numberPad }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
//
// AerobicHeartRateUpperLimitCharacteristicViewController.swift
// BluetoothExplorer
//
// Created by Carlos Duclos on 7/3/18.
// Copyright © 2018 PureSwift. All rights reserved.
//

import Foundation
import UIKit
import CoreData
import Bluetooth
import GATT

final class AerobicHeartRateUpperLimitCharacteristicViewController: UITableViewController, CharacteristicViewController, InstantiableViewController {

// MARK: - Properties

private let cellIdentifier = R.nib.inputTextViewCell.name

private var fields = [Field]()

var value = GATTAerobicHeartRateUpperLimit(beats: 98)

var valueDidChange: ((GATTAerobicHeartRateUpperLimit) -> ())?

// MARK: - Loading

override func viewDidLoad() {
super.viewDidLoad()

fields = [.upperLimit("\(value.beats.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.isEnabled = valueDidChange != nil
cell.inputTextView.keyboardType = field.keyboardType
cell.inputTextView.fieldLabelText = field.title
cell.inputTextView.placeholder = field.title
cell.inputTextView.validator = { value in

guard value.trim() != ""
else { return .none }

switch field {
case .upperLimit:

guard let _ = UInt8(value)
else { return .error("Maximum value is 0xFF") }
}

return .none
}
}
}

extension AerobicHeartRateUpperLimitCharacteristicViewController {

enum Field {

case upperLimit(String)

var title: String {

switch self {
case .upperLimit: return "Upper Limit"
}
}

var bluetoothValue: String {

switch self {
case .upperLimit(let value): return value
}
}

var keyboardType: UIKeyboardType { return .numberPad }
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ final class PeripheralCharacteristicDetailViewController: UITableViewController
case AgeCharacteristicViewController.uuid:
viewController = load(AgeCharacteristicViewController.self)

case AerobicHeartRateLowerLimitCharacteristicViewController.uuid:
viewController = load(AerobicHeartRateLowerLimitCharacteristicViewController.self)

case AerobicHeartRateUpperLimitCharacteristicViewController.uuid:
viewController = load(AerobicHeartRateUpperLimitCharacteristicViewController.self)

default:
viewController = nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,7 @@ let supportedCharacteristicViewControllers: [BluetoothUUID] = [
.alertLevel,
.batteryPowerState,
.alertNotificationControlPoint,
.age
.age,
.aerobicHeartRateLowerLimit,
.aerobicHeartRateUpperLimit
]