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

Add Normal State, Fix C++ Compatibilty (AEGHB-337) #206

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
11 changes: 9 additions & 2 deletions components/button/include/iot_button.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@ typedef void *button_handle_t;
* @brief Button events
*
*/
typedef enum {
BUTTON_PRESS_DOWN = 0,
#ifdef __cplusplus
typedef enum button_event_e : int { //C++ Definition
#else
typedef enum button_event_e { //C Definition
#endif
BUTTON_PRESS_INVALID = -1, //to enforce signed int also in C.
BUTTON_PRESS_NORMAL = 0,
BUTTON_PRESS_DOWN,
BUTTON_PRESS_UP,
BUTTON_PRESS_REPEAT,
BUTTON_PRESS_REPEAT_DONE,
Expand Down Expand Up @@ -110,6 +116,7 @@ esp_err_t iot_button_delete(button_handle_t btn_handle);
* @return
* - ESP_OK on success
* - ESP_ERR_INVALID_ARG Arguments is invalid.
* - ESP_ERR_INVALID_STATE the Callback is already registered. No free Space for another Callback.
*/
esp_err_t iot_button_register_cb(button_handle_t btn_handle, button_event_t event, button_cb_t cb, void *usr_data);

Expand Down
6 changes: 6 additions & 0 deletions components/button/iot_button.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ static void button_handler(button_dev_t *btn)
if (btn->button_level == btn->active_level) {
btn->event = (uint8_t)BUTTON_PRESS_DOWN;
CALL_EVENT_CB(BUTTON_PRESS_DOWN);
CALL_EVENT_CB(BUTTON_PRESS_NORMAL);
btn->ticks = 0;
btn->repeat = 1;
btn->state = 1;
Expand All @@ -109,6 +110,7 @@ static void button_handler(button_dev_t *btn)
if (btn->button_level != btn->active_level) {
btn->event = (uint8_t)BUTTON_PRESS_UP;
CALL_EVENT_CB(BUTTON_PRESS_UP);
CALL_EVENT_CB(BUTTON_PRESS_NORMAL);
btn->ticks = 0;
btn->state = 2;

Expand All @@ -123,6 +125,7 @@ static void button_handler(button_dev_t *btn)
if (btn->button_level == btn->active_level) {
btn->event = (uint8_t)BUTTON_PRESS_DOWN;
CALL_EVENT_CB(BUTTON_PRESS_DOWN);
CALL_EVENT_CB(BUTTON_PRESS_NORMAL);
btn->repeat++;
CALL_EVENT_CB(BUTTON_PRESS_REPEAT); // repeat hit
btn->ticks = 0;
Expand All @@ -145,6 +148,7 @@ static void button_handler(button_dev_t *btn)
if (btn->button_level != btn->active_level) {
btn->event = (uint8_t)BUTTON_PRESS_UP;
CALL_EVENT_CB(BUTTON_PRESS_UP);
CALL_EVENT_CB(BUTTON_PRESS_NORMAL);
if (btn->ticks < SHORT_TICKS) {
btn->ticks = 0;
btn->state = 2; //repeat press
Expand All @@ -165,6 +169,7 @@ static void button_handler(button_dev_t *btn)
} else { //releasd
btn->event = (uint8_t)BUTTON_PRESS_UP;
CALL_EVENT_CB(BUTTON_PRESS_UP);
CALL_EVENT_CB(BUTTON_PRESS_NORMAL);
btn->state = 0; //reset
btn->long_press_hold_cnt = 0;
}
Expand Down Expand Up @@ -326,6 +331,7 @@ esp_err_t iot_button_register_cb(button_handle_t btn_handle, button_event_t even
BTN_CHECK(NULL != btn_handle, "Pointer of handle is invalid", ESP_ERR_INVALID_ARG);
BTN_CHECK(event < BUTTON_EVENT_MAX, "event is invalid", ESP_ERR_INVALID_ARG);
button_dev_t *btn = (button_dev_t *) btn_handle;
BTN_CHECK(NULL == btn->cb[event], "Callback is already registered", ESP_ERR_INVALID_STATE);
btn->cb[event] = cb;
btn->usr_data[event] = usr_data;
return ESP_OK;
Expand Down
1 change: 1 addition & 0 deletions examples/camera/camera_components/esp32-camera
Submodule esp32-camera added at 108a33