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

esp_bt_hidh_init() (IDFGH-5393) #7139

Closed
guo-max opened this issue Jun 11, 2021 · 6 comments
Closed

esp_bt_hidh_init() (IDFGH-5393) #7139

guo-max opened this issue Jun 11, 2021 · 6 comments
Labels
Awaiting Response awaiting a response from the author Resolution: Done Issue is done internally Status: Done Issue is done internally Type: Feature Request Feature request for IDF

Comments

@guo-max
Copy link

guo-max commented Jun 11, 2021

Is your feature request related to a problem? Please describe.

esp_err_t esp_bt_hidh_init(const esp_hidh_config_t *config)
{
    if (config == NULL) {
        ESP_LOGE(TAG, "Config is NULL");
        return ESP_FAIL;
    }
    esp_event_loop_args_t event_task_args = {
        .queue_size = 5,
        .task_name = "esp_bt_hidh_events",
        .task_priority = uxTaskPriorityGet(NULL),
        .task_stack_size = 2048,
        .task_core_id = tskNO_AFFINITY
    };
    esp_err_t ret = esp_event_loop_create(&event_task_args, &event_loop_handle);
    if (ret != ESP_OK) {
        ESP_LOGE(TAG, "esp_event_loop_create failed!");
        return ret;
    }
    esp_event_handler_register_with(event_loop_handle, ESP_HIDH_EVENTS, ESP_EVENT_ANY_ID, config->callback, NULL);
    BTA_HhEnable(0, bta_hh_cb);
    return ESP_OK;
}

In the function

esp_err_t esp_bt_hidh_init(const esp_hidh_config_t *config)

there is a function call

 esp_event_handler_register_with(event_loop_handle, ESP_HIDH_EVENTS, ESP_EVENT_ANY_ID, config->callback, NULL);

And the last param "void* event_handler_arg" is given "NULL".

Because of this, the callback function is always has a "NULL" for the "void* event_handler_arg"

typedef void         (*esp_event_handler_t)(void* event_handler_arg,
                                        esp_event_base_t event_base,
                                        int32_t event_id,
                                        void* event_data); /**< function called when an event is posted to the queue */

Describe the solution you'd like

Can you add another member to the config like config->event_handler_arg and pass it to the function?

@guo-max guo-max added the Type: Feature Request Feature request for IDF label Jun 11, 2021
@espressif-bot espressif-bot added the Status: Opened Issue is new label Jun 11, 2021
@github-actions github-actions bot changed the title esp_bt_hidh_init() esp_bt_hidh_init() (IDFGH-5393) Jun 11, 2021
@boblane1
Copy link
Collaborator

Hi guo-max,

Your suggestion is reasonable, but adding config->event_handler_arg will cause the change of interface. Would you mind working around the problem by software?

Thanks!

@guo-max
Copy link
Author

guo-max commented Jun 15, 2021

I need to use the callback function and the "void* event_handler_arg" argument. But the esp_bt_hidh_init function is always set it to NULL. I do not know how to work around this problem by software except make my own hidh_init function and not use the library.
Do you have a easier way to solve this problem?

@boblane1
Copy link
Collaborator

boblane1 commented Jun 16, 2021

Hi guo-max,

I think there are two ways to solve this problem:

  1. You can just change the esp_hidh_config_t structure and code on your local branch, the code is open source;
  2. Replace event_handler_arg with a global variable in the callback function.

What about?

@Alvin1Zhang
Copy link
Collaborator

Alvin1Zhang commented Jul 14, 2021

@guo-max Thanks for reporting. Would you please help share if any updates or details for this feature request? Thanks.

@Alvin1Zhang
Copy link
Collaborator

@guo-max Thanks for reporting. Would you please help share if any updates or details for this feature request? Thanks.

@Alvin1Zhang Alvin1Zhang added the Awaiting Response awaiting a response from the author label Nov 30, 2021
@Alvin1Zhang
Copy link
Collaborator

Alvin1Zhang commented Nov 30, 2021

Thanks for reporting, this has been implemented in 5c95024, and will be part of IDF v4.4 release, you could update to the latest release/4.4 branch to have a try, feel free to reopen.

@espressif-bot espressif-bot added Resolution: Done Issue is done internally Status: Done Issue is done internally and removed Status: Opened Issue is new labels Nov 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Response awaiting a response from the author Resolution: Done Issue is done internally Status: Done Issue is done internally Type: Feature Request Feature request for IDF
Projects
None yet
Development

No branches or pull requests

4 participants