Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When creating endpoints allow passing in user data #17

Closed
jonsmirl opened this issue Aug 1, 2022 · 3 comments
Closed

When creating endpoints allow passing in user data #17

jonsmirl opened this issue Aug 1, 2022 · 3 comments

Comments

@jonsmirl
Copy link
Contributor

jonsmirl commented Aug 1, 2022

In our keypad I need to create eight identical endpoints containing: dimmable_light, switch and generic switch. So when I am iterating in app_driver_attribute_set_defaults I need to be able to map the endpoint to a pointer into my data structure. This will let me pass the same pointer into the triplets of (light, switch, generic_sw) and associate them with each other.

Do clusters need user data?

endpoint_t *endpoint1 = on_off_switch::create(node, &switch_config, ENDPOINT_FLAG_NONE, (void *)user_data);

endpoint_t *endpoint = endpoint::get_first(node);
while (endpoint) {
    uint16_t endpoint_id = endpoint::get_id(endpoint);
    mydata_t *mydata = endpoint::get_userdata(endpoint);
    cluster_t *cluster = cluster::get_first(endpoint);

You could also allow passing in a function pointers. This could be eliminated if the attributes stored function pointers.

esp_err_t app_driver_attribute_update(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id,
                                      esp_matter_attr_val_t *val)
{
    esp_err_t err = ESP_OK;
    if (endpoint_id == light_endpoint_id) {
        if (cluster_id == OnOff::Id) {
            if (attribute_id == OnOff::Attributes::OnOff::Id) {
                err = app_driver_light_set_power(val);
            }
        } else if (cluster_id == LevelControl::Id) {
            if (attribute_id == LevelControl::Attributes::CurrentLevel::Id) {
                err = app_driver_light_set_brightness(val);
            }
        } else if (cluster_id == ColorControl::Id) {
            if (attribute_id == ColorControl::Attributes::CurrentHue::Id) {
                err = app_driver_light_set_hue(val);
            } else if (attribute_id == ColorControl::Attributes::CurrentSaturation::Id) {
                err = app_driver_light_set_saturation(val);
            } else if (attribute_id == ColorControl::Attributes::ColorTemperature::Id) {
                err = app_driver_light_set_temperature(val);
            }
        }
    }
    return err;
}

Then call like this:
app_driver_light_set_temperature(userdata, value)
app_driver_attribute_set_defaults() could then move into the esp_matter library.

@chiragatal
Copy link
Contributor

Is your end goal to just have a user_data or like a led_handle (similar to the current button_handle) and use it in the driver? Or do you have some other requirement/use-case with the user_data as a part of the endpoint?

@jonsmirl
Copy link
Contributor Author

jonsmirl commented Aug 1, 2022

When I create 8 identical end points I need some mechanism to tell which copy of my internal data is associated with the end point. In the existing samples this is not an issue because you aren't creating multiple, identical endpoints - there is a single data structure.

A handle and user data pointer are basically the same thing. I'm trying to store a pointer to the data structure I allocated to support each copy of the end point. I've allocated 8 copies of this structure, how do I associate them with the end points? If don't want to use a loop and search my structures for matching endpoint numbers, better to let me store a handle/user_pointer in your endpoint structure.

@dhrishi
Copy link
Collaborator

dhrishi commented Aug 4, 2022

Thanks! This is useful and will be applicable in many of the usecases. We have added a provision to pass user data to the endpoints

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants