linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bartosz Golaszewski <brgl@bgdev.pl>
To: Ben Hutchings <ben.hutchings@mind.be>
Cc: "open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>
Subject: Re: [PATCH libgpiod-v2] gpiomon: Add option to set debounce period
Date: Mon, 20 Sep 2021 16:28:53 +0200	[thread overview]
Message-ID: <CAMRc=MeiWTBSx1S4Ez_pr-fJaq1NsyPE=Dp0uoyz--kDVzNjHw@mail.gmail.com> (raw)
In-Reply-To: <20210728234640.GD14442@cephalopod>

On Thu, Jul 29, 2021 at 1:46 AM Ben Hutchings <ben.hutchings@mind.be> wrote:
>
> With the v2 API it's now possible to enable debouncing of an input.
> Add an option to enable debouncing with a specific period.
>
> Signed-off-by: Ben Hutchings <ben.hutchings@mind.be>
> ---
>  tools/gpiomon.c | 12 +++++++++++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/tools/gpiomon.c b/tools/gpiomon.c
> index df86a46..074af6d 100644
> --- a/tools/gpiomon.c
> +++ b/tools/gpiomon.c
> @@ -22,6 +22,7 @@ static const struct option longopts[] = {
>         { "version",            no_argument,            NULL,   'v' },
>         { "active-low",         no_argument,            NULL,   'l' },
>         { "bias",               required_argument,      NULL,   'B' },
> +       { "debounce",           required_argument,      NULL,   'd' },
>         { "num-events",         required_argument,      NULL,   'n' },
>         { "silent",             no_argument,            NULL,   's' },
>         { "rising-edge",        no_argument,            NULL,   'r' },
> @@ -31,7 +32,7 @@ static const struct option longopts[] = {
>         { GETOPT_NULL_LONGOPT },
>  };
>
> -static const char *const shortopts = "+hvlB:n:srfbF:";
> +static const char *const shortopts = "+hvlB:d:n:srfbF:";
>
>  static void print_help(void)
>  {
> @@ -46,6 +47,7 @@ static void print_help(void)
>         printf("  -l, --active-low:\tset the line active state to low\n");
>         printf("  -B, --bias=[as-is|disable|pull-down|pull-up] (defaults to 'as-is'):\n");
>         printf("                set the line bias\n");
> +       printf("  -d, --debounce=PERIOD: enable debouncing with period in microseconds\n");
>         printf("  -n, --num-events=NUM:\texit after processing NUM events\n");
>         printf("  -s, --silent:\t\tdon't print event info\n");
>         printf("  -r, --rising-edge:\tonly process rising edge events\n");
> @@ -157,6 +159,7 @@ int main(int argc, char **argv)
>         unsigned int offsets[64], num_lines = 0, offset, events_wanted = 0,
>                      events_done = 0;
>         bool watch_rising = false, watch_falling = false, active_low = false;
> +       unsigned long debounce_period = 0;
>         struct gpiod_edge_event_buffer *event_buffer;
>         int optc, opti, ret, i, edge, bias = 0;
>         uint64_t timeout = 10 * 1000000000LLU;
> @@ -195,6 +198,11 @@ int main(int argc, char **argv)
>                 case 'B':
>                         bias = parse_bias(optarg);
>                         break;
> +               case 'd':
> +                       debounce_period = strtoul(optarg, &end, 10);
> +                       if (*end != '\0')
> +                               die("invalid number: %s", optarg);
> +                       break;
>                 case 'n':
>                         events_wanted = strtoul(optarg, &end, 10);
>                         if (*end != '\0')
> @@ -263,6 +271,8 @@ int main(int argc, char **argv)
>         if (active_low)
>                 gpiod_line_config_set_active_low(line_cfg);
>         gpiod_line_config_set_edge_detection(line_cfg, edge);
> +       if (debounce_period)
> +               gpiod_line_config_set_debounce_period(line_cfg, debounce_period);
>
>         req_cfg = gpiod_request_config_new();
>         if (!req_cfg)
> --
> 2.20.1

Queued for post libgpiod v2.

Bart

      reply	other threads:[~2021-09-20 14:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-28 23:46 [PATCH libgpiod-v2] gpiomon: Add option to set debounce period Ben Hutchings
2021-09-20 14:28 ` Bartosz Golaszewski [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAMRc=MeiWTBSx1S4Ez_pr-fJaq1NsyPE=Dp0uoyz--kDVzNjHw@mail.gmail.com' \
    --to=brgl@bgdev.pl \
    --cc=ben.hutchings@mind.be \
    --cc=linux-gpio@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).