Skip to content

Commit 2e0eaf6

Browse files
committed
Merge branch 'fix/generic_switch' into 'main'
examples/generic_switch: Update generic switch wrt spec changes. See merge request app-frameworks/esp-matter!893
2 parents 53da97b + 447e0b1 commit 2e0eaf6

File tree

8 files changed

+129
-146
lines changed

8 files changed

+129
-146
lines changed

components/esp_matter/esp_matter_feature.cpp

+54-15
Original file line numberDiff line numberDiff line change
@@ -2761,16 +2761,15 @@ namespace latching_switch {
27612761

27622762
uint32_t get_id()
27632763
{
2764-
// The SwitchFeature enum class is not added in the upstream code.
2765-
// Return the code according to the SPEC
2766-
return (uint32_t)0x01;
2764+
return (uint32_t)Switch::Feature::kLatchingSwitch;
27672765
}
27682766

27692767
esp_err_t add(cluster_t *cluster)
27702768
{
27712769
VerifyOrReturnError((get_feature_map_value(cluster) & feature::momentary_switch::get_id()) != feature::momentary_switch::get_id(), ESP_ERR_NOT_SUPPORTED, ESP_LOGE(TAG, "Latching switch is not supported because momentary switch is present"));
27722770
update_feature_map(cluster, get_id());
27732771

2772+
event::create_switch_latched(cluster);
27742773
return ESP_OK;
27752774
}
27762775

@@ -2780,16 +2779,15 @@ namespace momentary_switch {
27802779

27812780
uint32_t get_id()
27822781
{
2783-
// The SwitchFeature enum class is not added in the upstream code.
2784-
// Return the code according to the SPEC
2785-
return (uint32_t)0x02;
2782+
return (uint32_t)Switch::Feature::kMomentarySwitch;
27862783
}
27872784

27882785
esp_err_t add(cluster_t *cluster)
27892786
{
27902787
VerifyOrReturnError((get_feature_map_value(cluster) & feature::latching_switch::get_id()) != feature::latching_switch::get_id(), ESP_ERR_NOT_SUPPORTED, ESP_LOGE(TAG, "Momentary switch is not supported because latching switch is present"));
27912788
update_feature_map(cluster, get_id());
27922789

2790+
event::create_initial_press(cluster);
27932791
return ESP_OK;
27942792
}
27952793

@@ -2799,16 +2797,19 @@ namespace momentary_switch_release {
27992797

28002798
uint32_t get_id()
28012799
{
2802-
// The SwitchFeature enum class is not added in the upstream code.
2803-
// Return the code according to the SPEC
2804-
return (uint32_t)0x04;
2800+
return (uint32_t)Switch::Feature::kMomentarySwitchRelease;
28052801
}
28062802

28072803
esp_err_t add(cluster_t *cluster)
28082804
{
28092805
VerifyOrReturnError((get_feature_map_value(cluster) & feature::momentary_switch::get_id()) == feature::momentary_switch::get_id(), ESP_ERR_NOT_SUPPORTED, ESP_LOGE(TAG, "Momentary switch release is not supported because momentary is absent"));
2806+
uint32_t as_feature_map = feature::action_switch::get_id();
2807+
uint32_t ms_feature_map = feature::momentary_switch::get_id();
2808+
uint32_t feature_map = get_feature_map_value(cluster);
2809+
VerifyOrReturnError(((feature_map & ms_feature_map) != ms_feature_map) || ((feature_map & as_feature_map) == as_feature_map), ESP_ERR_NOT_SUPPORTED, ESP_LOGE(TAG, "Momentary switch release is not supported."));
28102810
update_feature_map(cluster, get_id());
28112811

2812+
event::create_short_release(cluster);
28122813
return ESP_OK;
28132814
}
28142815

@@ -2818,17 +2819,23 @@ namespace momentary_switch_long_press {
28182819

28192820
uint32_t get_id()
28202821
{
2821-
// The SwitchFeature enum class is not added in the upstream code.
2822-
// Return the code according to the SPEC
2823-
return (uint32_t)0x08;
2822+
return (uint32_t)Switch::Feature::kMomentarySwitchLongPress;
28242823
}
28252824

28262825
esp_err_t add(cluster_t *cluster)
28272826
{
28282827
uint32_t momentary_and_momentart_switch_release_feature_map = feature::momentary_switch::get_id() | feature::momentary_switch_release::get_id();
28292828
VerifyOrReturnError((get_feature_map_value(cluster) & momentary_and_momentart_switch_release_feature_map) == momentary_and_momentart_switch_release_feature_map, ESP_ERR_NOT_SUPPORTED, ESP_LOGE(TAG, "Momentary switch long press is not supported because momentary switch and/or momentary switch release is absent"));
2829+
uint32_t msr_feature_map = feature::momentary_switch_release::get_id();
2830+
uint32_t as_feature_map = feature::action_switch::get_id();
2831+
uint32_t ms_feature_map = feature::momentary_switch::get_id();
2832+
uint32_t feature_map = get_feature_map_value(cluster);
2833+
VerifyOrReturnError((feature_map & ms_feature_map) != ms_feature_map, ESP_ERR_NOT_SUPPORTED, ESP_LOGE(TAG, "Momentary switch long press is not supported."));
2834+
VerifyOrReturnError(((feature_map & msr_feature_map) != msr_feature_map) && ((feature_map & as_feature_map) != as_feature_map), ESP_ERR_NOT_SUPPORTED, ESP_LOGE(TAG, "Momentary switch long press is not supported."));
28302835
update_feature_map(cluster, get_id());
28312836

2837+
event::create_long_press(cluster);
2838+
event::create_long_release(cluster);
28322839
return ESP_OK;
28332840
}
28342841

@@ -2838,23 +2845,55 @@ namespace momentary_switch_multi_press {
28382845

28392846
uint32_t get_id()
28402847
{
2841-
// The SwitchFeature enum class is not added in the upstream code.
2842-
// Return the code according to the SPEC
2843-
return (uint32_t)0x10;
2848+
return (uint32_t)Switch::Feature::kMomentarySwitchMultiPress;
28442849
}
28452850

28462851
esp_err_t add(cluster_t *cluster, config_t *config)
28472852
{
28482853
uint32_t momentary_and_momentart_switch_release_feature_map = feature::momentary_switch::get_id() | feature::momentary_switch_release::get_id();
28492854
VerifyOrReturnError((get_feature_map_value(cluster) & momentary_and_momentart_switch_release_feature_map) == momentary_and_momentart_switch_release_feature_map, ESP_ERR_NOT_SUPPORTED, ESP_LOGE(TAG, "Momentary switch multi press is not supported because momentary switch and/or momentary switch releaseis absent"));
2855+
uint32_t as_feature_map = feature::action_switch::get_id();
2856+
VerifyOrReturnError((get_feature_map_value(cluster) & as_feature_map) != as_feature_map, ESP_ERR_NOT_SUPPORTED, ESP_LOGE(TAG, "Momentary switch multi press is not supported because action switch is absent"));
2857+
uint32_t ms_feature_map = feature::momentary_switch::get_id();
2858+
uint32_t msr_feature_map = feature::momentary_switch_release::get_id();
2859+
uint32_t ms_and_msr = ms_feature_map | msr_feature_map;
2860+
if ((get_feature_map_value(cluster) & as_feature_map) != as_feature_map) {
2861+
if ((get_feature_map_value(cluster) & ms_and_msr) != ms_and_msr) {
2862+
ESP_LOGE(TAG, "Momentary switch multi press is not supported.");
2863+
return ESP_ERR_NOT_SUPPORTED;
2864+
}
2865+
event::create_multi_press_ongoing(cluster);
2866+
}
28502867
update_feature_map(cluster, get_id());
28512868

28522869
attribute::create_multi_press_max(cluster, config->multi_press_max);
28532870

2871+
event::create_multi_press_complete(cluster);
28542872
return ESP_OK;
28552873
}
28562874

28572875
} /* momentary_switch_multi_press */
2876+
2877+
namespace action_switch {
2878+
2879+
uint32_t get_id()
2880+
{
2881+
return (uint32_t)Switch::Feature::kActionSwitch;
2882+
}
2883+
2884+
esp_err_t add(cluster_t *cluster)
2885+
{
2886+
if ((get_feature_map_value(cluster) & feature::momentary_switch::get_id()) != feature::momentary_switch::get_id()) {
2887+
ESP_LOGE(TAG, "Momentary switch is present");
2888+
return ESP_ERR_NOT_SUPPORTED;
2889+
}
2890+
update_feature_map(cluster, get_id());
2891+
2892+
return ESP_OK;
2893+
}
2894+
2895+
} /* action_switch */
2896+
28582897
} /* feature */
28592898
} /* switch_cluster */
28602899

components/esp_matter/esp_matter_feature.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -1536,7 +1536,14 @@ typedef struct config {
15361536
uint32_t get_id();
15371537
esp_err_t add(cluster_t *cluster, config_t *config);
15381538

1539-
} /* momentary_switch_multi_pressy */
1539+
} /* momentary_switch_multi_press */
1540+
1541+
namespace action_switch {
1542+
1543+
uint32_t get_id();
1544+
esp_err_t add(cluster_t *cluster);
1545+
1546+
} /* action_switch */
15401547
} /* feature */
15411548
} /* switch_cluster */
15421549

examples/generic_switch/README.md

+6-50
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,10 @@
33
This example creates a Generic Switch device using the ESP
44
Matter data model.
55
This example demonstrates the use of few optional data model elements like :
6-
- Fixed Label Cluster : provides a feature for the device to tag an endpoint with zero or more read only labels (demonstrated through nvs).
7-
- User Label Cluster : This cluster provides a feature to tag an endpoint with zero or more labels.
86
- Taglist Feature of Descriptor Cluster : used to disambiguate sibling endpoints where two or more sibling
97
endpoints have an overlap in the supported device types with each such endpoint having a unique TagList.
108

119

12-
Note:
13-
In order to retrieve the label-list from the fixed-label cluster the two options:
14-
``CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER`` and ``CONFIG_ENABLE_ESP32_DEVICE_INFO_PROVIDER`` have been set through sdkconfig.defaults.
15-
1610
See the [docs](https://docs.espressif.com/projects/esp-matter/en/latest/esp32/developing.html) for more information about building and flashing the firmware.
1711

1812
## 1. Additional Environment Setup
@@ -31,73 +25,35 @@ through menuconfig:
3125

3226
Follow the steps mentioned [here](https://docs.espressif.com/projects/esp-matter/en/latest/esp32/insights.html)
3327

34-
### 1.3 Flash the factory partition
35-
36-
The steps below should be followed in order to access the fixed-labels.
37-
- If monitoring the device using ``idf.py monitor``,press `` Ctrl + ]`` to stop the process.
38-
- The following command must be executed to flash the mfg partition:
39-
40-
```
41-
esptool.py -p [port-name] write_flash 0x10000 mfg_binaries/20202020_3841.bin
42-
```
43-
44-
- Execute the command ``idf.py monitor``
45-
4628
## 2.Commissioning and Control
47-
- Commission the device with ``discriminator: 3841``and `` passcode: 20202020``
29+
- Commission the device with ``discriminator: 3840``and `` passcode: 20202021``
4830

4931
```
50-
chip-tool pairing ble-wifi 0x7283 [ssid] [password] 20202020 3841
51-
```
52-
53-
- Alternatively, below QR Code or Manual pairing code can be used for commissioning
54-
- Manualcode : 34970012334
55-
- QRCode :
56-
- ![QRCode](mfg_binaries/matter_qrcode_20202020_3841.png)
57-
58-
### 2.1 Fixed-Labels
59-
- To read the fixed-labels, use chip-tool.
60-
32+
chip-tool pairing ble-wifi 0x7283 [ssid] [password] 20202021 3840
6133
```
62-
chip-tool fixedlabel read label-list 0x7283 1
63-
```
64-
65-
### 2.2 User-Labels
66-
- The example command given below should be executed to write to the label-list of User Label Cluster.
67-
68-
```
69-
chip-tool userlabel write label-list '[{"label":"room", "value":"bedroom 1"}, {"label":"orientation", "value":"east"}]' 0x7283 1
70-
```
71-
72-
- To read label-list of User Label Cluster execute the command given below.
73-
74-
```
75-
chip-tool userlabel read label-list 0x7283 1
76-
```
77-
78-
### 2.3 Using the TagList Feature
34+
### 2.1 Using the TagList Feature
7935
8036
To read the taglist of the Descriptor cluster execute the command given below.
8137
8238
```
8339
chip-tool descriptor read tag-list 0x7283 1
8440
```
8541
86-
## 2. Post Commissioning Setup
42+
## 3. Post Commissioning Setup
8743
8844
This should be followed by: Commission the generic switch device
8945
- Turn on chip-tool interactive mode. ``./chip-tool interactive start``
9046
- By default momentary switch is enabled so subscribe to long-press event via chip-tool.
9147
``switch subscribe-event long-press <min-interval> <max-interval> <destination-id> <endpoint-id>``
9248
- `Double press the boot button` on device so that client will receive event after max-interval.
9349
94-
### 2.1 Latching switch
50+
### 3.1 Latching switch
9551
9652
Following are latching switch events mapped with boot button on device.
9753
9854
- `Double Press` -----------> `switch-latched`
9955
100-
### 2.2 Momentary switch
56+
### 3.2 Momentary switch
10157
10258
Following are momentary switch events mapped with boot button on device.
10359

0 commit comments

Comments
 (0)