Skip to content

Commit 53b6750

Browse files
committed
added half click feature (on BT right click)
1 parent 78585fd commit 53b6750

File tree

3 files changed

+45
-18
lines changed

3 files changed

+45
-18
lines changed

ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## v1.4.7
2+
- new feature: half click on right BT click (similar to some ADB devices)
3+
- workarounds for v1.4.6 green led regression
4+
15
## v1.4.6
26
- added support for ADB composite devices (Kensignton and some Joysticks)
37
- fixed ADB start and stop bit times (65 µs vs 70 µs, error in AN591)

main/adb.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,11 @@ void adb_task_host(void *pvParameters) {
246246
int8_t move = 0;
247247
uint8_t state = ADB_S_PROBE;
248248

249-
/* wait a little for the LED tasks to start on the other core */
250-
vTaskDelay(200 / portTICK_PERIOD_MS);
249+
/*
250+
* wait a little for the LED tasks to start on the other core
251+
* starting IDF 5.2.2, we need this. Looks like the init is now too fast on app core
252+
*/
253+
vTaskDelay(200 / portTICK_PERIOD_MS);
251254

252255
/* put green led to steady if BT is disabled. Otherwise BT init will do it */
253256
if (gpio_get_level(GPIO_BTOFF) == 0)

main/blue.c

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -285,31 +285,48 @@ void blue_h_close(esp_hidh_event_data_t *p) {
285285
}
286286

287287
static 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

315332
static 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

469489
void 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

Comments
 (0)