Skip to content

Commit

Permalink
add the script function
Browse files Browse the repository at this point in the history
  • Loading branch information
kdubious committed Jun 3, 2019
1 parent 812c7fd commit 425f8da
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ gpiod-test

# man pages
*.man

.vscode/
9 changes: 7 additions & 2 deletions tools/gpiomon.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ static const struct option longopts[] = {
{ "falling-edge", no_argument, NULL, 'f' },
{ "line-buffered", no_argument, NULL, 'b' },
{ "format", required_argument, NULL, 'F' },
{ "script", required_argument, NULL, 'S' },
{ GETOPT_NULL_LONGOPT },
};

static const char *const shortopts = "+hvln:srfbF:";
static const char *const shortopts = "+hvln:srfbF:S:";

static void print_help(void)
{
Expand All @@ -55,6 +56,7 @@ static void print_help(void)
printf(" %%e: event type (0 - falling edge, 1 rising edge)\n");
printf(" %%s: seconds part of the event timestamp\n");
printf(" %%n: nanoseconds part of the event timestamp\n");
printf(" -S, --script=SCT\tspecify script to run upon completion\n");
}

struct mon_ctx {
Expand All @@ -64,6 +66,7 @@ struct mon_ctx {

bool silent;
char *fmt;
char *sct;

int sigfd;
};
Expand Down Expand Up @@ -214,8 +217,10 @@ static int event_callback(int event_type, unsigned int line_offset,
return GPIOD_CTXLESS_EVENT_CB_RET_OK;
}

if (ctx->events_wanted && ctx->events_done >= ctx->events_wanted)
if (ctx->events_wanted && ctx->events_done >= ctx->events_wanted) {
system(ctx->sct);
return GPIOD_CTXLESS_EVENT_CB_RET_STOP;
}

return GPIOD_CTXLESS_EVENT_CB_RET_OK;
}
Expand Down

0 comments on commit 425f8da

Please sign in to comment.