How do I implement a long press button event?
I currently have the following and coming from an arduino environment I would normally use millis() to time the button presses.
static void user_app_button_press_cb(void) { uint8_t next_btn_event = 0; // Read button state if(GPIO_GetPinStatus(GPIO_BUTTON_PORT, GPIO_BUTTON_PIN)) { app_sleep_env.custs1_btn_state = CUSTS1_BTN_STATE_RELEASED; next_btn_event = WKUPCT_PIN_POLARITY_LOW; } else { app_sleep_env.custs1_btn_state = CUSTS1_BTN_STATE_PRESSED; next_btn_event = WKUPCT_PIN_POLARITY_HIGH; } // Update button characteristic struct custs1_val_ntf_ind_req *req = KE_MSG_ALLOC_DYN(CUSTS1_VAL_NTF_REQ, prf_get_task_from_id(TASK_ID_CUSTS1), TASK_APP, custs1_val_ntf_ind_req, DEF_SVC1_BUTTON_STATE_CHAR_LEN); req->conidx = app_env->conidx; req->notification = true; req->handle = SVC1_IDX_BUTTON_STATE_VAL; req->length = DEF_SVC1_BUTTON_STATE_CHAR_LEN; req->value[0] = app_sleep_env.custs1_btn_state; ke_msg_send(req); // Configure next button event user_app_set_button_event(next_btn_event); }
Keywords:
Device:
Hi Hdhdh Ddjek,
Thanks for your question. Do you want to get a callback triggered upon the button release? Do you need this button to wake up the device when is sleep mode? If yes, take a look at the ble_app_sleepmode example of the SKD and check app_button_enable() function. This example uses the wake-up controller to configure a wake-up pin.
Probably you might check out some past forum threads regarding the long press button:
https://support.dialog-semiconductor.com/forums/post/dialog-smartbond-da1458x-bt42-%E2%80%93-software/button-long-press-detection
https://support.dialog-semiconductor.com/forums/post/dialog-smartbond-bluetooth-low-energy-42-%E2%80%93-software/button-press-time
Please let me know if you need further support on this/
Thanks, PM_Dialog
the above didnt help, so what I would like is the button state to only show a 01 in the app when the 3 secs have elapsed.
Hi There,
Can you please share your implementation?
Thanks, PM_Dialog