Skip to content

Commit

Permalink
Merge pull request #116 from NordicSemiconductor/feature/fix_nus_filter
Browse files Browse the repository at this point in the history
Service UUID Filter
  • Loading branch information
NickKibish authored Sep 15, 2021
2 parents 253c56a + 26e0cb4 commit 0300d58
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 12 deletions.
22 changes: 19 additions & 3 deletions nRF Toolbox.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@
C3CD27D826B0977F0026FE67 /* McuManager in Frameworks */ = {isa = PBXBuildFile; productRef = C3CD27D726B0977F0026FE67 /* McuManager */; };
C3CD27DB26B097AB0026FE67 /* NordicDFU in Frameworks */ = {isa = PBXBuildFile; productRef = C3CD27DA26B097AB0026FE67 /* NordicDFU */; };
C3CD27DE26B098070026FE67 /* Charts in Frameworks */ = {isa = PBXBuildFile; productRef = C3CD27DD26B098070026FE67 /* Charts */; };
C3E8C1AC26F21FD0000A3737 /* FilterSwitchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3E8C1AB26F21FD0000A3737 /* FilterSwitchView.swift */; };
C3E8C1AE26F21FE4000A3737 /* FilterSwitchView.xib in Resources */ = {isa = PBXBuildFile; fileRef = C3E8C1AD26F21FE3000A3737 /* FilterSwitchView.xib */; };
CC7B90D148FC21C73B54BFAB /* NumberFormatter+Ext.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC7B93FA695799F95D065492 /* NumberFormatter+Ext.swift */; };
CC7B91DDFD7EF39F27FEC85A /* CommandImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC7B95845343A3D826B220D5 /* CommandImage.swift */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -567,6 +569,8 @@
52D9BC9D1DD0CB760030E824 /* Data+Ext.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Data+Ext.swift"; sourceTree = "<group>"; };
7E1B422818A8DF4D006BA1BC /* high.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = high.mp3; sourceTree = "<group>"; };
89CF4D2BA242FBAD9F6C46E9 /* Pods.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods.framework; sourceTree = BUILT_PRODUCTS_DIR; };
C3E8C1AB26F21FD0000A3737 /* FilterSwitchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilterSwitchView.swift; sourceTree = "<group>"; };
C3E8C1AD26F21FE3000A3737 /* FilterSwitchView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = FilterSwitchView.xib; sourceTree = "<group>"; };
CC7B93FA695799F95D065492 /* NumberFormatter+Ext.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NumberFormatter+Ext.swift"; sourceTree = "<group>"; };
CC7B95845343A3D826B220D5 /* CommandImage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CommandImage.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -818,6 +822,7 @@
children = (
01B56C1523A11FB600140A1C /* PeripheralScanner.swift */,
01AD26E62395084000F56210 /* ConnectionViewController.swift */,
C3E8C1AA26F21F80000A3737 /* FilterSwitch */,
);
path = Connection;
sourceTree = "<group>";
Expand Down Expand Up @@ -1725,6 +1730,15 @@
name = StoryBoard;
sourceTree = "<group>";
};
C3E8C1AA26F21F80000A3737 /* FilterSwitch */ = {
isa = PBXGroup;
children = (
C3E8C1AB26F21FD0000A3737 /* FilterSwitchView.swift */,
C3E8C1AD26F21FE3000A3737 /* FilterSwitchView.xib */,
);
path = FilterSwitch;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -1885,6 +1899,7 @@
20E07B652306975700FCB205 /* GT-Eesti-Display-ULight.ttf in Resources */,
016EF389241632AF005FFA30 /* LoggerTableViewController.xib in Resources */,
20E07B612306975700FCB205 /* GT-Eesti-Display-Medium.ttf in Resources */,
C3E8C1AE26F21FE4000A3737 /* FilterSwitchView.xib in Resources */,
20F15C3C2313D2C7000C5503 /* InfoActionView.xib in Resources */,
4353A50F243175C300159CDF /* HMAccessoryListTableViewController.xib in Resources */,
4381AD1C23BA057000FB1A1F /* UARTViewController.xib in Resources */,
Expand Down Expand Up @@ -2070,6 +2085,7 @@
204485E1233A148700A8A3A3 /* RunningTableViewController.swift in Sources */,
01BEADD6241AE65300FC7183 /* NordicBottomDetailsTableViewCell.swift in Sources */,
203D0F09232F782200C0340D /* CyclingTableViewController.swift in Sources */,
C3E8C1AC26F21FD0000A3737 /* FilterSwitchView.swift in Sources */,
203D0F0C232FB7D100C0340D /* DetailsTableViewSection.swift in Sources */,
01D98C8F242E2B3C000A3B35 /* DocumentFileManager.swift in Sources */,
01B6D3DA234CB6B3000942C4 /* HeartRateSection.swift in Sources */,
Expand Down Expand Up @@ -2302,7 +2318,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = "nRF Toolbox/nRF Toolbox.entitlements";
CODE_SIGN_IDENTITY = "iPhone Developer";
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 2;
DEFINES_MODULE = NO;
ENABLE_BITCODE = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -2469,7 +2485,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = "nRF Toolbox/nRF Toolbox.entitlements";
CODE_SIGN_IDENTITY = "iPhone Developer";
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 2;
DEFINES_MODULE = NO;
ENABLE_BITCODE = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -2520,7 +2536,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = "nRF Toolbox/nRF Toolbox.entitlements";
CODE_SIGN_IDENTITY = "iPhone Developer";
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 2;
DEFINES_MODULE = NO;
ENABLE_BITCODE = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ extension LoggerTableView: LogPresenter, Logger {

extension LoggerTableView: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
print("count: \(filteredData.count)")
// print("count: \(filteredData.count)")
return filteredData.count
}

Expand Down
16 changes: 15 additions & 1 deletion nRF Toolbox/Connection/ConnectionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,21 @@ class ConnectionViewController: UITableViewController {
super.viewDidLoad()
scanner.scannerDelegate = self
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "Cell")

tableView.tableHeaderView = nil
tableView.tableHeaderView = scanner.scanServices.flatMap { _ in
let headerView = FilterSwitchView.instance()
headerView.toggleAction = { [weak self] isOn in
self?.scanner.serviceFilterEnabled = isOn
self?.tableView.reloadData()
}
return headerView
}
}

override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
tableView.tableHeaderView?.frame.size.height = 44
}

@objc func close() {
Expand Down Expand Up @@ -87,7 +102,6 @@ class ConnectionViewController: UITableViewController {
navigationItem.leftBarButtonItem = leftButton
}

override func numberOfSections(in tableView: UITableView) -> Int { 1 }
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return scanner.peripherals.count
}
Expand Down
39 changes: 39 additions & 0 deletions nRF Toolbox/Connection/FilterSwitch/FilterSwitchView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2021, Nordic Semiconductor
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
import UIKit

class FilterSwitchView: UIView, XibInstantiable {
var toggleAction: ((Bool) -> ())?

@IBAction
func toggle(_ sender: UISwitch) {
toggleAction?(sender.isOn)
}
}
49 changes: 49 additions & 0 deletions nRF Toolbox/Connection/FilterSwitch/FilterSwitchView.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="18093"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="iN0-l3-epB" customClass="FilterSwitchView" customModule="nRF_Toolbox" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="432" height="44"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<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">
<rect key="frame" x="20" y="11.5" width="167" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="3zi-4v-r38">
<rect key="frame" x="363" y="6.5" width="51" height="31"/>
<connections>
<action selector="toggle:" destination="-1" eventType="valueChanged" id="Mag-52-rPN"/>
<action selector="toggle:" destination="iN0-l3-epB" eventType="valueChanged" id="XaC-cm-7v1"/>
</connections>
</switch>
</subviews>
<viewLayoutGuide key="safeArea" id="vUN-kp-3ea"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<constraints>
<constraint firstItem="3zi-4v-r38" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="centerY" id="BQ2-ys-GQL"/>
<constraint firstItem="vUN-kp-3ea" firstAttribute="trailing" secondItem="3zi-4v-r38" secondAttribute="trailing" constant="20" id="E4T-qS-GNI"/>
<constraint firstItem="yZ0-NV-9E3" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="centerY" id="Kf3-Vd-At3"/>
<constraint firstItem="yZ0-NV-9E3" firstAttribute="leading" secondItem="vUN-kp-3ea" secondAttribute="leading" constant="20" id="vfZ-q3-wHX"/>
</constraints>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<point key="canvasLocation" x="182.60869565217394" y="-598.66071428571422"/>
</view>
</objects>
<resources>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
</resources>
</document>
18 changes: 16 additions & 2 deletions nRF Toolbox/Connection/PeripheralScanner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ open class PeripheralScanner: NSObject {
}

let scanServices: [CBUUID]?
var serviceFilterEnabled = true {
didSet {
refresh()
}
}

private (set) var status: Status = .uninitialized {
didSet {
Expand Down Expand Up @@ -118,15 +123,17 @@ open class PeripheralScanner: NSObject {
}

open func startScanning() {
centralManager.scanForPeripherals(withServices: scanServices, options:
[CBCentralManagerScanOptionAllowDuplicatesKey:true])
rescan()
dispatchSource.schedule(deadline: .now() + .seconds(1), repeating: 1)
dispatchSource.activate()
status = .scanning
}

open func refresh() {
stopScanning()
peripherals.removeAll()
tmpPeripherals.removeAll()
rescan()
}

open func stopScanning() {
Expand All @@ -138,6 +145,13 @@ open class PeripheralScanner: NSObject {
stopScanning()
status = .connecting(peripheral)
}

private func rescan() {
let services = serviceFilterEnabled ? scanServices : nil
centralManager.scanForPeripherals(withServices: services, options:
[CBCentralManagerScanOptionAllowDuplicatesKey:true])
status = .scanning
}
}

extension PeripheralScanner: CBCentralManagerDelegate {
Expand Down
16 changes: 11 additions & 5 deletions nRF Toolbox/Profiles/UART/PeripheralView/PeripheralView.xib
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<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">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15706"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="18093"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<customFonts key="customFonts">
Expand Down Expand Up @@ -34,7 +35,7 @@
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<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">
<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">
<rect key="frame" x="282" y="0.0" width="100" height="30"/>
<constraints>
<constraint firstAttribute="width" constant="100" id="ioW-iM-rLn"/>
Expand All @@ -47,15 +48,20 @@
</subviews>
</stackView>
</subviews>
<color key="backgroundColor" systemColor="secondarySystemBackgroundColor" red="0.94901960780000005" green="0.94901960780000005" blue="0.96862745100000003" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<viewLayoutGuide key="safeArea" id="vUN-kp-3ea"/>
<color key="backgroundColor" systemColor="secondarySystemBackgroundColor"/>
<constraints>
<constraint firstItem="IQ6-Gq-bqQ" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="centerY" id="VYs-uZ-htY"/>
<constraint firstItem="IQ6-Gq-bqQ" firstAttribute="leading" secondItem="vUN-kp-3ea" secondAttribute="leading" constant="16" id="gUu-rX-qIZ"/>
<constraint firstItem="IQ6-Gq-bqQ" firstAttribute="centerX" secondItem="iN0-l3-epB" secondAttribute="centerX" id="yGT-YI-W95"/>
</constraints>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<viewLayoutGuide key="safeArea" id="vUN-kp-3ea"/>
<point key="canvasLocation" x="-277" y="31"/>
</view>
</objects>
<resources>
<systemColor name="secondarySystemBackgroundColor">
<color red="0.94901960784313721" green="0.94901960784313721" blue="0.96862745098039216" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
</resources>
</document>

0 comments on commit 0300d58

Please sign in to comment.