nRF Connect SDK API 2.8.99
Loading...
Searching...
No Matches
generic_switch.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5 */
6
7#pragma once
8
9#include "matter_bridged_device.h"
10
11class GenericSwitchDevice : public Nrf::MatterBridgedDevice {
12public:
13 GenericSwitchDevice(const char *nodeLabel);
14
15 uint16_t GetDeviceType() const override { return Nrf::MatterBridgedDevice::DeviceType::GenericSwitch; }
16 CHIP_ERROR HandleRead(chip::ClusterId clusterId, chip::AttributeId attributeId, uint8_t *buffer,
17 uint16_t maxReadLength) override;
18 CHIP_ERROR HandleAttributeChange(chip::ClusterId clusterId, chip::AttributeId attributeId, void *data,
19 size_t dataSize) override;
20 CHIP_ERROR HandleWrite(chip::ClusterId clusterId, chip::AttributeId attributeId, uint8_t *buffer,
21 size_t size) override
22 {
23 if (clusterId != chip::app::Clusters::BridgedDeviceBasicInformation::Id) {
24 return CHIP_ERROR_INVALID_ARGUMENT;
25 }
26
27 switch (attributeId) {
28 case chip::app::Clusters::BridgedDeviceBasicInformation::Attributes::NodeLabel::Id:
29 return HandleWriteDeviceBasicInformation(clusterId, attributeId, buffer, size);
30 default:
31 return CHIP_ERROR_INVALID_ARGUMENT;
32 }
33 return CHIP_NO_ERROR;
34 };
35
36private:
37 CHIP_ERROR HandleReadSwitch(chip::AttributeId attributeId, uint8_t *buffer, uint16_t maxReadLength);
38
39 static constexpr uint16_t GetSwitchClusterRevision() { return 1; }
40 /* According to the Matter 1.2 specification: Bit 1 -> MomentarySwitch in the Switch Cluster section. */
41 static constexpr uint32_t GetSwitchClusterFeatureMap() { return 2; }
42 static constexpr uint32_t GetSwitchClusterNumberOfPositions() { return 2; }
43
44 uint8_t mCurrentPosition{};
45};
GenericSwitchDevice(const char *nodeLabel)
uint16_t GetDeviceType() const override
Definition generic_switch.h:15
CHIP_ERROR HandleRead(chip::ClusterId clusterId, chip::AttributeId attributeId, uint8_t *buffer, uint16_t maxReadLength) override
CHIP_ERROR HandleWrite(chip::ClusterId clusterId, chip::AttributeId attributeId, uint8_t *buffer, size_t size) override
Definition generic_switch.h:20
CHIP_ERROR HandleAttributeChange(chip::ClusterId clusterId, chip::AttributeId attributeId, void *data, size_t dataSize) override
Definition generic_switch.h:11