Skip to content

Commit 0300d58

Browse files
authored
Merge pull request #116 from NordicSemiconductor/feature/fix_nus_filter
Service UUID Filter
2 parents 253c56a + 26e0cb4 commit 0300d58

File tree

7 files changed

+150
-12
lines changed

7 files changed

+150
-12
lines changed

nRF Toolbox.xcodeproj/project.pbxproj

+19-3
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,8 @@
271271
C3CD27D826B0977F0026FE67 /* McuManager in Frameworks */ = {isa = PBXBuildFile; productRef = C3CD27D726B0977F0026FE67 /* McuManager */; };
272272
C3CD27DB26B097AB0026FE67 /* NordicDFU in Frameworks */ = {isa = PBXBuildFile; productRef = C3CD27DA26B097AB0026FE67 /* NordicDFU */; };
273273
C3CD27DE26B098070026FE67 /* Charts in Frameworks */ = {isa = PBXBuildFile; productRef = C3CD27DD26B098070026FE67 /* Charts */; };
274+
C3E8C1AC26F21FD0000A3737 /* FilterSwitchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3E8C1AB26F21FD0000A3737 /* FilterSwitchView.swift */; };
275+
C3E8C1AE26F21FE4000A3737 /* FilterSwitchView.xib in Resources */ = {isa = PBXBuildFile; fileRef = C3E8C1AD26F21FE3000A3737 /* FilterSwitchView.xib */; };
274276
CC7B90D148FC21C73B54BFAB /* NumberFormatter+Ext.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC7B93FA695799F95D065492 /* NumberFormatter+Ext.swift */; };
275277
CC7B91DDFD7EF39F27FEC85A /* CommandImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC7B95845343A3D826B220D5 /* CommandImage.swift */; };
276278
/* End PBXBuildFile section */
@@ -567,6 +569,8 @@
567569
52D9BC9D1DD0CB760030E824 /* Data+Ext.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Data+Ext.swift"; sourceTree = "<group>"; };
568570
7E1B422818A8DF4D006BA1BC /* high.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = high.mp3; sourceTree = "<group>"; };
569571
89CF4D2BA242FBAD9F6C46E9 /* Pods.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods.framework; sourceTree = BUILT_PRODUCTS_DIR; };
572+
C3E8C1AB26F21FD0000A3737 /* FilterSwitchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilterSwitchView.swift; sourceTree = "<group>"; };
573+
C3E8C1AD26F21FE3000A3737 /* FilterSwitchView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = FilterSwitchView.xib; sourceTree = "<group>"; };
570574
CC7B93FA695799F95D065492 /* NumberFormatter+Ext.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NumberFormatter+Ext.swift"; sourceTree = "<group>"; };
571575
CC7B95845343A3D826B220D5 /* CommandImage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CommandImage.swift; sourceTree = "<group>"; };
572576
/* End PBXFileReference section */
@@ -818,6 +822,7 @@
818822
children = (
819823
01B56C1523A11FB600140A1C /* PeripheralScanner.swift */,
820824
01AD26E62395084000F56210 /* ConnectionViewController.swift */,
825+
C3E8C1AA26F21F80000A3737 /* FilterSwitch */,
821826
);
822827
path = Connection;
823828
sourceTree = "<group>";
@@ -1725,6 +1730,15 @@
17251730
name = StoryBoard;
17261731
sourceTree = "<group>";
17271732
};
1733+
C3E8C1AA26F21F80000A3737 /* FilterSwitch */ = {
1734+
isa = PBXGroup;
1735+
children = (
1736+
C3E8C1AB26F21FD0000A3737 /* FilterSwitchView.swift */,
1737+
C3E8C1AD26F21FE3000A3737 /* FilterSwitchView.xib */,
1738+
);
1739+
path = FilterSwitch;
1740+
sourceTree = "<group>";
1741+
};
17281742
/* End PBXGroup section */
17291743

17301744
/* Begin PBXNativeTarget section */
@@ -1885,6 +1899,7 @@
18851899
20E07B652306975700FCB205 /* GT-Eesti-Display-ULight.ttf in Resources */,
18861900
016EF389241632AF005FFA30 /* LoggerTableViewController.xib in Resources */,
18871901
20E07B612306975700FCB205 /* GT-Eesti-Display-Medium.ttf in Resources */,
1902+
C3E8C1AE26F21FE4000A3737 /* FilterSwitchView.xib in Resources */,
18881903
20F15C3C2313D2C7000C5503 /* InfoActionView.xib in Resources */,
18891904
4353A50F243175C300159CDF /* HMAccessoryListTableViewController.xib in Resources */,
18901905
4381AD1C23BA057000FB1A1F /* UARTViewController.xib in Resources */,
@@ -2070,6 +2085,7 @@
20702085
204485E1233A148700A8A3A3 /* RunningTableViewController.swift in Sources */,
20712086
01BEADD6241AE65300FC7183 /* NordicBottomDetailsTableViewCell.swift in Sources */,
20722087
203D0F09232F782200C0340D /* CyclingTableViewController.swift in Sources */,
2088+
C3E8C1AC26F21FD0000A3737 /* FilterSwitchView.swift in Sources */,
20732089
203D0F0C232FB7D100C0340D /* DetailsTableViewSection.swift in Sources */,
20742090
01D98C8F242E2B3C000A3B35 /* DocumentFileManager.swift in Sources */,
20752091
01B6D3DA234CB6B3000942C4 /* HeartRateSection.swift in Sources */,
@@ -2302,7 +2318,7 @@
23022318
CLANG_ENABLE_MODULES = YES;
23032319
CODE_SIGN_ENTITLEMENTS = "nRF Toolbox/nRF Toolbox.entitlements";
23042320
CODE_SIGN_IDENTITY = "iPhone Developer";
2305-
CURRENT_PROJECT_VERSION = 1;
2321+
CURRENT_PROJECT_VERSION = 2;
23062322
DEFINES_MODULE = NO;
23072323
ENABLE_BITCODE = YES;
23082324
FRAMEWORK_SEARCH_PATHS = (
@@ -2469,7 +2485,7 @@
24692485
CLANG_ENABLE_MODULES = YES;
24702486
CODE_SIGN_ENTITLEMENTS = "nRF Toolbox/nRF Toolbox.entitlements";
24712487
CODE_SIGN_IDENTITY = "iPhone Developer";
2472-
CURRENT_PROJECT_VERSION = 1;
2488+
CURRENT_PROJECT_VERSION = 2;
24732489
DEFINES_MODULE = NO;
24742490
ENABLE_BITCODE = YES;
24752491
FRAMEWORK_SEARCH_PATHS = (
@@ -2520,7 +2536,7 @@
25202536
CLANG_ENABLE_MODULES = YES;
25212537
CODE_SIGN_ENTITLEMENTS = "nRF Toolbox/nRF Toolbox.entitlements";
25222538
CODE_SIGN_IDENTITY = "iPhone Developer";
2523-
CURRENT_PROJECT_VERSION = 1;
2539+
CURRENT_PROJECT_VERSION = 2;
25242540
DEFINES_MODULE = NO;
25252541
ENABLE_BITCODE = YES;
25262542
FRAMEWORK_SEARCH_PATHS = (

nRF Toolbox/CommonViews/LoggerTableView/LoggerTableView.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ extension LoggerTableView: LogPresenter, Logger {
129129

130130
extension LoggerTableView: UITableViewDataSource {
131131
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
132-
print("count: \(filteredData.count)")
132+
// print("count: \(filteredData.count)")
133133
return filteredData.count
134134
}
135135

nRF Toolbox/Connection/ConnectionViewController.swift

+15-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,21 @@ class ConnectionViewController: UITableViewController {
5555
super.viewDidLoad()
5656
scanner.scannerDelegate = self
5757
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "Cell")
58+
59+
tableView.tableHeaderView = nil
60+
tableView.tableHeaderView = scanner.scanServices.flatMap { _ in
61+
let headerView = FilterSwitchView.instance()
62+
headerView.toggleAction = { [weak self] isOn in
63+
self?.scanner.serviceFilterEnabled = isOn
64+
self?.tableView.reloadData()
65+
}
66+
return headerView
67+
}
68+
}
69+
70+
override func viewDidLayoutSubviews() {
71+
super.viewDidLayoutSubviews()
72+
tableView.tableHeaderView?.frame.size.height = 44
5873
}
5974

6075
@objc func close() {
@@ -87,7 +102,6 @@ class ConnectionViewController: UITableViewController {
87102
navigationItem.leftBarButtonItem = leftButton
88103
}
89104

90-
override func numberOfSections(in tableView: UITableView) -> Int { 1 }
91105
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
92106
return scanner.peripherals.count
93107
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2021, Nordic Semiconductor
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without modification,
6+
* are permitted provided that the following conditions are met:
7+
*
8+
* 1. Redistributions of source code must retain the above copyright notice, this
9+
* list of conditions and the following disclaimer.
10+
*
11+
* 2. Redistributions in binary form must reproduce the above copyright notice, this
12+
* list of conditions and the following disclaimer in the documentation and/or
13+
* other materials provided with the distribution.
14+
*
15+
* 3. Neither the name of the copyright holder nor the names of its contributors may
16+
* be used to endorse or promote products derived from this software without
17+
* specific prior written permission.
18+
*
19+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22+
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24+
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
* POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
import UIKit
31+
32+
class FilterSwitchView: UIView, XibInstantiable {
33+
var toggleAction: ((Bool) -> ())?
34+
35+
@IBAction
36+
func toggle(_ sender: UISwitch) {
37+
toggleAction?(sender.isOn)
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="18122" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
3+
<device id="retina6_1" orientation="portrait" appearance="light"/>
4+
<dependencies>
5+
<deployment identifier="iOS"/>
6+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="18093"/>
7+
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
8+
<capability name="System colors in document resources" minToolsVersion="11.0"/>
9+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
10+
</dependencies>
11+
<objects>
12+
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
13+
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
14+
<view contentMode="scaleToFill" id="iN0-l3-epB" customClass="FilterSwitchView" customModule="nRF_Toolbox" customModuleProvider="target">
15+
<rect key="frame" x="0.0" y="0.0" width="432" height="44"/>
16+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
17+
<subviews>
18+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Filter by Service UUID" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="yZ0-NV-9E3">
19+
<rect key="frame" x="20" y="11.5" width="167" height="21"/>
20+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
21+
<nil key="textColor"/>
22+
<nil key="highlightedColor"/>
23+
</label>
24+
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="3zi-4v-r38">
25+
<rect key="frame" x="363" y="6.5" width="51" height="31"/>
26+
<connections>
27+
<action selector="toggle:" destination="-1" eventType="valueChanged" id="Mag-52-rPN"/>
28+
<action selector="toggle:" destination="iN0-l3-epB" eventType="valueChanged" id="XaC-cm-7v1"/>
29+
</connections>
30+
</switch>
31+
</subviews>
32+
<viewLayoutGuide key="safeArea" id="vUN-kp-3ea"/>
33+
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
34+
<constraints>
35+
<constraint firstItem="3zi-4v-r38" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="centerY" id="BQ2-ys-GQL"/>
36+
<constraint firstItem="vUN-kp-3ea" firstAttribute="trailing" secondItem="3zi-4v-r38" secondAttribute="trailing" constant="20" id="E4T-qS-GNI"/>
37+
<constraint firstItem="yZ0-NV-9E3" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="centerY" id="Kf3-Vd-At3"/>
38+
<constraint firstItem="yZ0-NV-9E3" firstAttribute="leading" secondItem="vUN-kp-3ea" secondAttribute="leading" constant="20" id="vfZ-q3-wHX"/>
39+
</constraints>
40+
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
41+
<point key="canvasLocation" x="182.60869565217394" y="-598.66071428571422"/>
42+
</view>
43+
</objects>
44+
<resources>
45+
<systemColor name="systemBackgroundColor">
46+
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
47+
</systemColor>
48+
</resources>
49+
</document>

nRF Toolbox/Connection/PeripheralScanner.swift

+16-2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ open class PeripheralScanner: NSObject {
6969
}
7070

7171
let scanServices: [CBUUID]?
72+
var serviceFilterEnabled = true {
73+
didSet {
74+
refresh()
75+
}
76+
}
7277

7378
private (set) var status: Status = .uninitialized {
7479
didSet {
@@ -118,15 +123,17 @@ open class PeripheralScanner: NSObject {
118123
}
119124

120125
open func startScanning() {
121-
centralManager.scanForPeripherals(withServices: scanServices, options:
122-
[CBCentralManagerScanOptionAllowDuplicatesKey:true])
126+
rescan()
123127
dispatchSource.schedule(deadline: .now() + .seconds(1), repeating: 1)
124128
dispatchSource.activate()
125129
status = .scanning
126130
}
127131

128132
open func refresh() {
133+
stopScanning()
129134
peripherals.removeAll()
135+
tmpPeripherals.removeAll()
136+
rescan()
130137
}
131138

132139
open func stopScanning() {
@@ -138,6 +145,13 @@ open class PeripheralScanner: NSObject {
138145
stopScanning()
139146
status = .connecting(peripheral)
140147
}
148+
149+
private func rescan() {
150+
let services = serviceFilterEnabled ? scanServices : nil
151+
centralManager.scanForPeripherals(withServices: services, options:
152+
[CBCentralManagerScanOptionAllowDuplicatesKey:true])
153+
status = .scanning
154+
}
141155
}
142156

143157
extension PeripheralScanner: CBCentralManagerDelegate {

nRF Toolbox/Profiles/UART/PeripheralView/PeripheralView.xib

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="15705" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="18122" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
33
<device id="retina6_1" orientation="portrait" appearance="light"/>
44
<dependencies>
55
<deployment identifier="iOS"/>
6-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15706"/>
6+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="18093"/>
77
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
8+
<capability name="System colors in document resources" minToolsVersion="11.0"/>
89
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
910
</dependencies>
1011
<customFonts key="customFonts">
@@ -34,7 +35,7 @@
3435
<nil key="textColor"/>
3536
<nil key="highlightedColor"/>
3637
</label>
37-
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="qUF-3f-iiU" customClass="NordicButton" customModule="nRF_Toolbox" customModuleProvider="target">
38+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="qUF-3f-iiU" customClass="NordicButton" customModule="nRF_Toolbox" customModuleProvider="target">
3839
<rect key="frame" x="282" y="0.0" width="100" height="30"/>
3940
<constraints>
4041
<constraint firstAttribute="width" constant="100" id="ioW-iM-rLn"/>
@@ -47,15 +48,20 @@
4748
</subviews>
4849
</stackView>
4950
</subviews>
50-
<color key="backgroundColor" systemColor="secondarySystemBackgroundColor" red="0.94901960780000005" green="0.94901960780000005" blue="0.96862745100000003" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
51+
<viewLayoutGuide key="safeArea" id="vUN-kp-3ea"/>
52+
<color key="backgroundColor" systemColor="secondarySystemBackgroundColor"/>
5153
<constraints>
5254
<constraint firstItem="IQ6-Gq-bqQ" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="centerY" id="VYs-uZ-htY"/>
5355
<constraint firstItem="IQ6-Gq-bqQ" firstAttribute="leading" secondItem="vUN-kp-3ea" secondAttribute="leading" constant="16" id="gUu-rX-qIZ"/>
5456
<constraint firstItem="IQ6-Gq-bqQ" firstAttribute="centerX" secondItem="iN0-l3-epB" secondAttribute="centerX" id="yGT-YI-W95"/>
5557
</constraints>
5658
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
57-
<viewLayoutGuide key="safeArea" id="vUN-kp-3ea"/>
5859
<point key="canvasLocation" x="-277" y="31"/>
5960
</view>
6061
</objects>
62+
<resources>
63+
<systemColor name="secondarySystemBackgroundColor">
64+
<color red="0.94901960784313721" green="0.94901960784313721" blue="0.96862745098039216" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
65+
</systemColor>
66+
</resources>
6167
</document>

0 commit comments

Comments
 (0)