Skip to content

Commit

Permalink
Merge pull request #609 from NordicSemiconductor/feature/group-light-lc
Browse files Browse the repository at this point in the history
Group controls for Light LC Server model
  • Loading branch information
philips77 authored Feb 29, 2024
2 parents a208996 + 987a1e5 commit 6369af8
Show file tree
Hide file tree
Showing 10 changed files with 546 additions and 46 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : " groups_light_lc_occupancy_mode.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "groups_light_lc_mode.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
258 changes: 220 additions & 38 deletions Example/Source/UI/Base.lproj/Groups.storyboard

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import NordicMesh

private class Section {
let applicationKey: ApplicationKey
var items: [(modelId: UInt32, models: [Model])] = []
var items: [(modelId: UInt32, messageIndex: Int, models: [Model])] = []

init(_ applicationKey: ApplicationKey) {
self.applicationKey = applicationKey
Expand Down Expand Up @@ -71,7 +71,8 @@ class GroupControlViewController: ProgressCollectionViewController {
+ "- Generic OnOff Server,\n"
+ "- Generic Level Server,\n"
+ "- Scene Server,\n"
+ "- Scene Setup Server.\n\n"
+ "- Scene Setup Server,\n"
+ "- Light LC Server.\n\n"
+ "This limitation only applies to the app,\n"
+ "not the underlying mesh library.",
messageImage: #imageLiteral(resourceName: "baseline-groups"))
Expand All @@ -89,10 +90,12 @@ class GroupControlViewController: ProgressCollectionViewController {
section = Section(key)
sections.append(section)
}
if let index = section.items.firstIndex(where: { $0.modelId == model.modelId }) {
section.items[index].models.append(model)
} else {
section.items.append((modelId: model.modelId, models: [model]))
for messageIndex in 0..<model.messageCount {
if let index = section.items.firstIndex(where: { $0.modelId == model.modelId && $0.messageIndex == messageIndex }) {
section.items[index].models.append(model)
} else {
section.items.append((modelId: model.modelId, messageIndex: messageIndex, models: [model]))
}
}
}
}
Expand Down Expand Up @@ -152,7 +155,7 @@ class GroupControlViewController: ProgressCollectionViewController {
cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let section = sections[indexPath.section]
let item = section.items[indexPath.row]
let identifier = String(format: "%08X", item.modelId)
let identifier = String(format: "%08X_%d", item.modelId, item.messageIndex)
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: identifier, for: indexPath) as! ModelGroupCell
cell.group = group
cell.applicationKey = section.applicationKey
Expand Down Expand Up @@ -242,13 +245,28 @@ extension GroupControlViewController: MeshNetworkDelegate {

private extension Model {

// Whether the model has dedicated UI for sending messages.
var isSupported: Bool {
return modelIdentifier == .genericOnOffServerModelId ||
modelIdentifier == .genericLevelServerModelId ||
modelIdentifier == .sceneServerModelId ||
modelIdentifier == .sceneSetupServerModelId
modelIdentifier == .sceneSetupServerModelId ||
modelIdentifier == .lightLCServerModelId
}

// Number of different messages which may be sent to a model
// using dedicated UI.
var messageCount: Int {
guard isSupported else { return 0 }
if modelIdentifier == .lightLCServerModelId {
// Light LC Mode, Light LC Occupancy Mode, Light LC Light OnOff
return 3
}
return 1
}

// The 32-bit Model Identifier, including the Company ID (or 0x0000)
// for Bluetooth SIG assigned models.
var modelId: UInt32 {
let companyId = isBluetoothSIGAssigned ? 0 : companyIdentifier!
return (UInt32(companyId) << 16) | UInt32(modelIdentifier)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright (c) 2019, 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
import NordicMesh

class LightLCLightOnOffGroupCell: ModelGroupCell {

// MARK: - Outlets and Actions

@IBOutlet weak var icon: UIImageView!
@IBOutlet weak var title: UILabel!

@IBOutlet weak var onButton: UIButton!
@IBAction func onTapped(_ sender: UIButton) {
sendLightLCLightOnOffMessage(turnOn: true)
}
@IBOutlet weak var offButton: UIButton!
@IBAction func offTapped(_ sender: UIButton) {
sendLightLCLightOnOffMessage(turnOn: false)
}

// MARK: - Implementation

override func reload() {
// On iOS 12.x tinted icons are initially black.
// Forcing adjustment mode fixes the bug.
icon.tintAdjustmentMode = .normal

let numberOfDevices = models.count
if numberOfDevices == 1 {
title.text = "1 device"
} else {
title.text = "\(numberOfDevices) devices"
}

let localProvisioner = MeshNetworkManager.instance.meshNetwork?.localProvisioner
let isEnabled = localProvisioner?.hasConfigurationCapabilities ?? false

onButton.isEnabled = isEnabled
offButton.isEnabled = isEnabled
}
}

private extension LightLCLightOnOffGroupCell {

func sendLightLCLightOnOffMessage(turnOn: Bool) {
let label = turnOn ? "Enabling occupancy sensor binging..." : "Disabling occupancy sensor binging..."
delegate?.send(LightLCLightOnOffSetUnacknowledged(turnOn),
description: label, using: applicationKey)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright (c) 2019, 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
import NordicMesh

class LightLCModeGroupCell: ModelGroupCell {

// MARK: - Outlets and Actions

@IBOutlet weak var icon: UIImageView!
@IBOutlet weak var title: UILabel!

@IBOutlet weak var onButton: UIButton!
@IBAction func onTapped(_ sender: UIButton) {
sendLightLCModeMessage(turnOn: true)
}
@IBOutlet weak var offButton: UIButton!
@IBAction func offTapped(_ sender: UIButton) {
sendLightLCModeMessage(turnOn: false)
}

// MARK: - Implementation

override func reload() {
// On iOS 12.x tinted icons are initially black.
// Forcing adjustment mode fixes the bug.
icon.tintAdjustmentMode = .normal

let numberOfDevices = models.count
if numberOfDevices == 1 {
title.text = "1 device"
} else {
title.text = "\(numberOfDevices) devices"
}

let localProvisioner = MeshNetworkManager.instance.meshNetwork?.localProvisioner
let isEnabled = localProvisioner?.hasConfigurationCapabilities ?? false

onButton.isEnabled = isEnabled
offButton.isEnabled = isEnabled
}
}

private extension LightLCModeGroupCell {

func sendLightLCModeMessage(turnOn: Bool) {
let label = turnOn ? "Enabling binding..." : "Disabling binding..."
delegate?.send(LightLCModeSetUnacknowledged(turnOn),
description: label, using: applicationKey)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright (c) 2019, 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
import NordicMesh

class LightLCOccupancyModeGroupCell: ModelGroupCell {

// MARK: - Outlets and Actions

@IBOutlet weak var icon: UIImageView!
@IBOutlet weak var title: UILabel!

@IBOutlet weak var onButton: UIButton!
@IBAction func onTapped(_ sender: UIButton) {
sendLightLCOccupancyModeMessage(turnOn: true)
}
@IBOutlet weak var offButton: UIButton!
@IBAction func offTapped(_ sender: UIButton) {
sendLightLCOccupancyModeMessage(turnOn: false)
}

// MARK: - Implementation

override func reload() {
// On iOS 12.x tinted icons are initially black.
// Forcing adjustment mode fixes the bug.
icon.tintAdjustmentMode = .normal

let numberOfDevices = models.count
if numberOfDevices == 1 {
title.text = "1 device"
} else {
title.text = "\(numberOfDevices) devices"
}

let localProvisioner = MeshNetworkManager.instance.meshNetwork?.localProvisioner
let isEnabled = localProvisioner?.hasConfigurationCapabilities ?? false

onButton.isEnabled = isEnabled
offButton.isEnabled = isEnabled
}
}

private extension LightLCOccupancyModeGroupCell {

func sendLightLCOccupancyModeMessage(turnOn: Bool) {
let label = turnOn ? "Enabling occupancy sensor binging..." : "Disabling occupancy sensor binging..."
delegate?.send(LightLCOccupancyModeSetUnacknowledged(turnOn),
description: label, using: applicationKey)
}

}
Loading

0 comments on commit 6369af8

Please sign in to comment.