14
14
#include < esp_matter_console.h>
15
15
#include < esp_matter_ota.h>
16
16
#include < app_bridged_device.h>
17
+ #include < common_macros.h>
17
18
#include < app_priv.h>
18
19
#include < app_espnow.h>
19
20
#include < app_reset.h>
@@ -141,12 +142,9 @@ extern "C" void app_main()
141
142
142
143
/* Create a Matter node and add the mandatory Root Node device type on endpoint 0 */
143
144
node::config_t node_config;
145
+ // node handle can be used to add/modify other endpoints.
144
146
node_t *node = node::create (&node_config, app_attribute_update_cb, app_identification_cb);
145
-
146
- /* This node handle can be used to create/add other endpoints and clusters. */
147
- if (!node) {
148
- ESP_LOGE (TAG, " Matter node creation failed" );
149
- }
147
+ ABORT_APP_ON_FAILURE (node != nullptr , ESP_LOGE (TAG, " Failed to create Matter node" ));
150
148
151
149
color_temperature_light::config_t light_config;
152
150
light_config.on_off .on_off = DEFAULT_POWER;
@@ -156,22 +154,20 @@ extern "C" void app_main()
156
154
light_config.color_control .color_mode = (uint8_t )ColorControl::ColorMode::kColorTemperature ;
157
155
light_config.color_control .enhanced_color_mode = (uint8_t )ColorControl::ColorMode::kColorTemperature ;
158
156
light_config.color_control .color_temperature .startup_color_temperature_mireds = nullptr ;
157
+
158
+ // endpoint handles can be used to add/modify clusters.
159
159
endpoint_t *endpoint = color_temperature_light::create (node, &light_config, ENDPOINT_FLAG_NONE, light_handle);
160
- if (!endpoint) {
161
- ESP_LOGE (TAG, " Matter color temperature light endpoint creation failed" );
162
- }
160
+ ABORT_APP_ON_FAILURE (endpoint != nullptr , ESP_LOGE (TAG, " Failed to create color temperature light endpoint" ));
163
161
164
162
aggregator::config_t aggregator_config;
165
163
endpoint_t *aggregator = endpoint::aggregator::create (node, &aggregator_config, ENDPOINT_FLAG_NONE, NULL );
166
- if (!aggregator) {
167
- ESP_LOGE (TAG, " Matter aggregator endpoint creation failed" );
168
- }
164
+ ABORT_APP_ON_FAILURE (aggregator != nullptr , ESP_LOGE (TAG, " Failed to create aggregator endpoint" ));
169
165
170
166
light_endpoint_id = endpoint::get_id (endpoint);
171
167
ESP_LOGI (TAG, " Light created with endpoint_id %d" , light_endpoint_id);
172
168
173
169
aggregator_endpoint_id = endpoint::get_id (aggregator);
174
- ESP_LOGI (TAG, " Switch created with endpoint id %d" , aggregator_endpoint_id);
170
+ ESP_LOGI (TAG, " Aggregator created with endpoint id %d" , aggregator_endpoint_id);
175
171
176
172
/* Add additional features to the node */
177
173
cluster_t *cluster = cluster::get (endpoint, ColorControl::Id);
@@ -182,14 +178,10 @@ extern "C" void app_main()
182
178
183
179
/* Matter start */
184
180
err = esp_matter::start (app_event_cb);
185
- if (err != ESP_OK) {
186
- ESP_LOGE (TAG, " Matter start failed: %d" , err);
187
- }
181
+ ABORT_APP_ON_FAILURE (err == ESP_OK, ESP_LOGE (TAG, " Failed to start Matter, err:%d" , err));
188
182
189
183
err = app_bridge_initialize (node, create_bridge_devices);
190
- if (err != ESP_OK) {
191
- ESP_LOGE (TAG, " Failed to resume the bridged endpoints: %d" , err);
192
- }
184
+ ABORT_APP_ON_FAILURE (err == ESP_OK, ESP_LOGE (TAG, " Failed to resume the bridged endpoints: %d" , err));
193
185
194
186
app_espnow_init ();
195
187
0 commit comments