From: Scott Worley Date: Mon, 9 Oct 2023 07:49:54 +0000 (-0700) Subject: client: Work in 1-second granularity X-Git-Tag: v0.1.0~53 X-Git-Url: http://git.scottworley.com/tattlekey/commitdiff_plain/de14b62cf9b6042f77a7d41caf5eef99a64a4331?ds=inline;hp=ff379463e38b1cebd43d5c2ab8a0a0ae8e7a9b53 client: Work in 1-second granularity --- diff --git a/client/config.c b/client/config.c index de300ea..a9dc66e 100644 --- a/client/config.c +++ b/client/config.c @@ -20,7 +20,7 @@ uint button_pin = 18; /* Don't bother reporting each separate button press when it is pressed many * times in short succession. (We also use this to de-bounce. :) */ -u32_t minimum_microseconds_between_button_presses = 1000000; +u32_t minimum_seconds_between_button_presses = 1; /* Send each report multiple times. */ uint resend_count = 5; diff --git a/client/config.h b/client/config.h index fefe7e9..66e33a4 100644 --- a/client/config.h +++ b/client/config.h @@ -23,7 +23,7 @@ extern uint button_pin; /* Don't bother reporting each separate button press when it is pressed many * times in short succession. (We also use this to de-bounce. :) */ -extern u32_t minimum_microseconds_between_button_presses; +extern u32_t minimum_seconds_between_button_presses; /* Send each report multiple times. */ extern uint resend_count; diff --git a/client/tattlekey.c b/client/tattlekey.c index 9e7b4b5..842561d 100644 --- a/client/tattlekey.c +++ b/client/tattlekey.c @@ -9,12 +9,14 @@ queue_t queue; +uint32_t time_s() { return time_us_64() / 1000000ul; } + static void button_pressed() { /* This runs in interrupt context; don't linger. */ static uint64_t last_button_press_time = 0; - uint64_t now = time_us_64(); - uint64_t time_since_last_press = now - last_button_press_time; - if (time_since_last_press > minimum_microseconds_between_button_presses) { + uint32_t now = time_s(); + uint32_t time_since_last_press = now - last_button_press_time; + if (time_since_last_press >= minimum_seconds_between_button_presses) { last_button_press_time = now; char zero = '\0'; /* We don't check for failure (full queue) here because there's not much to