Espressif ESP32-S2 Programming Manual page 613

Table of Contents

Advertisement

Chapter 2. API Reference
.ctx
.ctx_free_fn
};
/* Now register the property */
esp_local_ctrl_add_property(&timestamp);
Also notice that there is a ctx field, which is set to point to some custom func_get_time(). This can be used inside the
property get / set handlers to retrieve timestamp.
Here is an example of get_prop_values() handler, which is used for retrieving the timestamp.
static
esp_err_t
values,
{
for
(uint32_t
ESP_LOGI(TAG,
if
(props[i].type
/* Obtain the timer function from ctx */
int32_t
/* Use static variable for saving the value.
* This is essential because the value has to be
* valid even after this function returns.
* Alternative is to use dynamic allocation
* and set the free_fn field */
static
prop_values[i].data
}
}
return
ESP_OK;
}
Here is an example of set_prop_values() handler. Notice how we restrict from writing to read-only properties.
static
esp_err_t
*prop_values,
{
for
(uint32_t
if
(props[i].flags
ESP_LOGE(TAG,
props[i].name);
return
}
else
ESP_LOGI(TAG,
/* For keeping it simple, lets only log the incoming data */
ESP_LOG_BUFFER_HEX_LEVEL(TAG, prop_values[i].data,
}
}
return
ESP_OK;
}
For complete example see
Espressif Systems
=
func_get_time,
=
NULL
get_property_values(size_t
i
=
0; i
<
props_count; i++) {
"Reading
%s", props[i].name);
==
TYPE_TIMESTAMP) {
(*func_get_time)(void)
int32_t
ts
=
func_get_time();
=
&ts;
set_property_values(size_t
i
=
0; i
<
props_count; i++) {
&
READONLY) {
"Cannot write to read-only property
ESP_ERR_INVALID_ARG;
{
"Setting
protocols/esp_local_ctrl
Submit Document Feedback
props_count,
const
esp_local_ctrl_prop_t *props,
esp_local_ctrl_prop_val_t *prop_
void
*usr_ctx)
=
props[i].ctx;
props_count,
const
esp_local_ctrl_prop_t *props,
const
esp_local_ctrl_prop_val_t␣
void
*usr_ctx)
%s", props[i].name);
prop_values[i].size, ESP_LOG_INFO);
602
(continued from previous page)
%s",␣
Release v4.4

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the ESP32-S2 and is the answer not in the manual?

Subscribe to Our Youtube Channel

Table of Contents

Save PDF