Skip to content

Commit 9d11f25

Browse files
committed
examples: use id based APIs to get endpoint, cluster, attribute handle
1 parent f00fb9b commit 9d11f25

File tree

3 files changed

+16
-29
lines changed

3 files changed

+16
-29
lines changed

examples/light/main/app_main.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -180,16 +180,14 @@ extern "C" void app_main()
180180
ESP_LOGI(TAG, "Light created with endpoint_id %d", light_endpoint_id);
181181

182182
/* Mark deferred persistence for some attributes that might be changed rapidly */
183-
cluster_t *level_control_cluster = cluster::get(endpoint, LevelControl::Id);
184-
attribute_t *current_level_attribute = attribute::get(level_control_cluster, LevelControl::Attributes::CurrentLevel::Id);
183+
attribute_t *current_level_attribute = attribute::get(light_endpoint_id, LevelControl::Id, LevelControl::Attributes::CurrentLevel::Id);
185184
attribute::set_deferred_persistence(current_level_attribute);
186185

187-
cluster_t *color_control_cluster = cluster::get(endpoint, ColorControl::Id);
188-
attribute_t *current_x_attribute = attribute::get(color_control_cluster, ColorControl::Attributes::CurrentX::Id);
186+
attribute_t *current_x_attribute = attribute::get(light_endpoint_id, ColorControl::Id, ColorControl::Attributes::CurrentX::Id);
189187
attribute::set_deferred_persistence(current_x_attribute);
190-
attribute_t *current_y_attribute = attribute::get(color_control_cluster, ColorControl::Attributes::CurrentY::Id);
188+
attribute_t *current_y_attribute = attribute::get(light_endpoint_id, ColorControl::Id, ColorControl::Attributes::CurrentY::Id);
191189
attribute::set_deferred_persistence(current_y_attribute);
192-
attribute_t *color_temp_attribute = attribute::get(color_control_cluster, ColorControl::Attributes::ColorTemperatureMireds::Id);
190+
attribute_t *color_temp_attribute = attribute::get(light_endpoint_id, ColorControl::Id, ColorControl::Attributes::ColorTemperatureMireds::Id);
193191
attribute::set_deferred_persistence(color_temp_attribute);
194192

195193
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD && CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION

examples/light_wifi_prov/main/app_driver.cpp

+8-17
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,7 @@ static void app_driver_button_toggle_cb(void *arg, void *data)
9696
uint32_t cluster_id = OnOff::Id;
9797
uint32_t attribute_id = OnOff::Attributes::OnOff::Id;
9898

99-
node_t *node = node::get();
100-
endpoint_t *endpoint = endpoint::get(node, endpoint_id);
101-
cluster_t *cluster = cluster::get(endpoint, cluster_id);
102-
attribute_t *attribute = attribute::get(cluster, attribute_id);
99+
attribute_t *attribute = attribute::get(endpoint_id, cluster_id, attribute_id);
103100

104101
esp_matter_attr_val_t val = esp_matter_invalid(NULL);
105102
attribute::get_val(attribute, &val);
@@ -139,43 +136,37 @@ esp_err_t app_driver_light_set_defaults(uint16_t endpoint_id)
139136
esp_err_t err = ESP_OK;
140137
void *priv_data = endpoint::get_priv_data(endpoint_id);
141138
led_indicator_handle_t handle = (led_indicator_handle_t)priv_data;
142-
node_t *node = node::get();
143-
endpoint_t *endpoint = endpoint::get(node, endpoint_id);
144-
cluster_t *cluster = NULL;
145139
attribute_t *attribute = NULL;
146140
esp_matter_attr_val_t val = esp_matter_invalid(NULL);
147141

148142
/* Setting brightness */
149-
cluster = cluster::get(endpoint, LevelControl::Id);
150-
attribute = attribute::get(cluster, LevelControl::Attributes::CurrentLevel::Id);
143+
attribute = attribute::get(endpoint_id, LevelControl::Id, LevelControl::Attributes::CurrentLevel::Id);
151144
attribute::get_val(attribute, &val);
152145
err |= app_driver_light_set_brightness(handle, &val);
153146

154147
/* Setting color */
155-
cluster = cluster::get(endpoint, ColorControl::Id);
156-
attribute = attribute::get(cluster, ColorControl::Attributes::ColorMode::Id);
148+
attribute = attribute::get(endpoint_id, ColorControl::Id, ColorControl::Attributes::ColorMode::Id);
157149
attribute::get_val(attribute, &val);
158150
if (val.val.u8 == (uint8_t)ColorControl::ColorMode::kCurrentHueAndCurrentSaturation) {
159151
/* Setting hue */
160-
attribute = attribute::get(cluster, ColorControl::Attributes::CurrentHue::Id);
152+
attribute = attribute::get(endpoint_id, ColorControl::Id, ColorControl::Attributes::CurrentHue::Id);
161153
attribute::get_val(attribute, &val);
162154
err |= app_driver_light_set_hue(handle, &val);
163155
/* Setting saturation */
164-
attribute = attribute::get(cluster, ColorControl::Attributes::CurrentSaturation::Id);
156+
attribute = attribute::get(endpoint_id, ColorControl::Id, ColorControl::Attributes::CurrentSaturation::Id);
165157
attribute::get_val(attribute, &val);
166158
err |= app_driver_light_set_saturation(handle, &val);
167159
} else if (val.val.u8 == (uint8_t)ColorControl::ColorMode::kColorTemperature) {
168160
/* Setting temperature */
169-
attribute = attribute::get(cluster, ColorControl::Attributes::ColorTemperatureMireds::Id);
161+
attribute = attribute::get(endpoint_id, ColorControl::Id, ColorControl::Attributes::ColorTemperatureMireds::Id);
170162
attribute::get_val(attribute, &val);
171163
err |= app_driver_light_set_temperature(handle, &val);
172164
} else {
173165
ESP_LOGE(TAG, "Color mode not supported");
174166
}
175167

176168
/* Setting power */
177-
cluster = cluster::get(endpoint, OnOff::Id);
178-
attribute = attribute::get(cluster, OnOff::Attributes::OnOff::Id);
169+
attribute = attribute::get(endpoint_id, OnOff::Id, OnOff::Attributes::OnOff::Id);
179170
attribute::get_val(attribute, &val);
180171
err |= app_driver_light_set_power(handle, &val);
181172

@@ -189,7 +180,7 @@ app_driver_handle_t app_driver_light_init()
189180
led_indicator_handle_t leds[CONFIG_BSP_LEDS_NUM];
190181
ESP_ERROR_CHECK(bsp_led_indicator_create(leds, NULL, CONFIG_BSP_LEDS_NUM));
191182
led_indicator_set_hsv(leds[0], SET_HSV(DEFAULT_HUE, DEFAULT_SATURATION, DEFAULT_BRIGHTNESS));
192-
183+
193184
return (app_driver_handle_t)leds[0];
194185
#else
195186
return NULL;

examples/light_wifi_prov/main/app_main.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -240,18 +240,16 @@ extern "C" void app_main()
240240
ESP_LOGI(TAG, "Light created with endpoint_id %d", light_endpoint_id);
241241

242242
/* Mark deferred persistence for some attributes that might be changed rapidly */
243-
cluster_t *level_control_cluster = cluster::get(endpoint, LevelControl::Id);
244243
attribute_t *current_level_attribute =
245-
attribute::get(level_control_cluster, LevelControl::Attributes::CurrentLevel::Id);
244+
attribute::get(light_endpoint_id, LevelControl::Id, LevelControl::Attributes::CurrentLevel::Id);
246245
attribute::set_deferred_persistence(current_level_attribute);
247246

248-
cluster_t *color_control_cluster = cluster::get(endpoint, ColorControl::Id);
249-
attribute_t *current_x_attribute = attribute::get(color_control_cluster, ColorControl::Attributes::CurrentX::Id);
247+
attribute_t *current_x_attribute = attribute::get(light_endpoint_id, ColorControl::Id, ColorControl::Attributes::CurrentX::Id);
250248
attribute::set_deferred_persistence(current_x_attribute);
251-
attribute_t *current_y_attribute = attribute::get(color_control_cluster, ColorControl::Attributes::CurrentY::Id);
249+
attribute_t *current_y_attribute = attribute::get(light_endpoint_id, ColorControl::Id, ColorControl::Attributes::CurrentY::Id);
252250
attribute::set_deferred_persistence(current_y_attribute);
253251
attribute_t *color_temp_attribute =
254-
attribute::get(color_control_cluster, ColorControl::Attributes::ColorTemperatureMireds::Id);
252+
attribute::get(light_endpoint_id, ColorControl::Id, ColorControl::Attributes::ColorTemperatureMireds::Id);
255253
attribute::set_deferred_persistence(color_temp_attribute);
256254

257255
err = esp_event_loop_create_default();

0 commit comments

Comments
 (0)