@@ -285,31 +285,48 @@ void blue_h_close(esp_hidh_event_data_t *p) {
285285}
286286
287287static void blue_handle_button (uint8_t buttons ) {
288+ static bool locked = false;
289+ static bool releasable = true;
288290 static bool status = BLUE_BUTTON_N ; // Keep state
289291
290292 buttons = buttons & (BLUE_BUTTON_1 | BLUE_BUTTON_2 | BLUE_BUTTON_3 );
291293
292294 if (status && buttons )
293295 return ;
294- if (status == BLUE_BUTTON_N && buttons == BLUE_BUTTON_N )
296+ if (status == BLUE_BUTTON_N && buttons == BLUE_BUTTON_N && ! locked )
295297 return ;
298+ if (buttons == BLUE_BUTTON_2 && locked && !releasable )
299+ return ;
300+ if (status == BLUE_BUTTON_N && buttons == BLUE_BUTTON_N && locked ) {
301+ releasable = true;
302+ return ;
303+ }
296304
297305 /* release button */
298- if (status && buttons == BLUE_BUTTON_N ) {
306+ if (status && buttons == BLUE_BUTTON_N && ! locked ) {
299307 xTaskNotify (t_click , 0 , eSetValueWithOverwrite );
300308 status = 0 ;
301309 ESP_LOGD (TAG , "button released" );
302310 return ;
303311 }
304312
305- /* press button */
313+ /* stick button on right click */
314+ if (status == BLUE_BUTTON_N && buttons == BLUE_BUTTON_2 && !locked ) {
315+ xTaskNotify (t_click , 1 , eSetValueWithOverwrite );
316+ locked = true;
317+ releasable = false;
318+ ESP_LOGD (TAG , "button locked" );
319+ return ;
320+ }
321+
322+ /* press button (simple click) */
306323 if (status == BLUE_BUTTON_N && buttons ) {
307324 xTaskNotify (t_click , 1 , eSetValueWithOverwrite );
325+ locked = false;
308326 status = 1 ;
309327 ESP_LOGD (TAG , "button pressed" );
310328 return ;
311329 }
312-
313330}
314331
315332static void blue_h_init (void ) {
@@ -346,13 +363,16 @@ void blue_init(void)
346363 /* complains about wrong data len on BOOT mode and CCONTROL */
347364 esp_log_level_set ("BT_HIDH" , ESP_LOG_ERROR );
348365
349- /*
350- * at this point, everything but bluetooth is started.
351- * put green steady, start blinking blue and keep scanning until a device is found
352- */
366+ /*
367+ * at this point, everything but bluetooth is started.
368+ * put green steady, start blinking blue and keep scanning until a device is found
369+ *
370+ * starting IDF 5.2.2, sometimes the first xTaskNotify() call may be lost. why ?
371+ */
353372
354- xTaskNotify (t_green , LED_ON , eSetValueWithOverwrite );
355- xTaskNotify (t_blue , LED_FAST , eSetValueWithOverwrite );
373+ xTaskNotify (t_green , LED_ON , eSetValueWithOverwrite );
374+ xTaskNotify (t_green , LED_ON , eSetValueWithOverwrite );
375+ xTaskNotify (t_blue , LED_FAST , eSetValueWithOverwrite );
356376
357377 if (adb_is_host ())
358378 blue_d_init ();
@@ -384,7 +404,7 @@ void blue_h_input(esp_hidh_dev_t *dev, uint8_t *data, uint16_t length) {
384404
385405 /*
386406 * A friend of mine did this for a beer, it helps a little with high DPI mouses
387- * This is a precalculated table that looks like a squadhed arctan()
407+ * This is a precalculated table that looks like a squared arctan()
388408 */
389409
390410 const unsigned char hid2quad [] = {
@@ -467,11 +487,11 @@ void blue_h_input(esp_hidh_dev_t *dev, uint8_t *data, uint16_t length) {
467487}
468488
469489void blue_h_open (esp_hidh_event_data_t * p ) {
470- const uint8_t * bda = NULL ;
490+ const uint8_t * bda = NULL ;
471491
472492 configASSERT (p != NULL );
473- bda = esp_hidh_dev_bda_get (p -> open .dev );
474- ESP_LOGI (TAG , "opened connection with " ESP_BD_ADDR_STR , ESP_BD_ADDR_HEX (bda ));
493+ bda = esp_hidh_dev_bda_get (p -> open .dev );
494+ ESP_LOGI (TAG , "opened connection with " ESP_BD_ADDR_STR , ESP_BD_ADDR_HEX (bda ));
475495
476496 /* Dump various info on console */
477497 blue_hid_rm_get (p -> open .dev );
@@ -482,8 +502,8 @@ void blue_h_open(esp_hidh_event_data_t *p) {
482502 }
483503
484504 blue_pointers ++ ;
485- xTaskNotify (t_blue , LED_ON , eSetValueWithOverwrite );
486- gpio_output_enable ();
505+ xTaskNotify (t_blue , LED_ON , eSetValueWithOverwrite );
506+ gpio_output_enable ();
487507}
488508
489509/* get specific report from report map matching specified usage + type + protocol */
0 commit comments