This is an automatic generated email to let you know that the following patch 
were queued at the 
http://git.linuxtv.org/cgit.cgi/v4l-utils.git tree:

Subject: ir-ctl: allow for different gaps to be specified
Author:  Sean Young <s...@mess.org>
Date:    Mon Dec 6 17:38:59 2021 +0000

For example:

ir-ctl --send=part1 --gap=10000 --send=part2 --gap=20000 --send=part3

This would introduce a gap of 10000 microseconds between part1 and
part2, and 20000 microseconds between part2 and part3.

Signed-off-by: Sean Young <s...@mess.org>

 utils/ir-ctl/ir-ctl.c | 126 +++++++++++++++++++++++++-------------------------
 1 file changed, 63 insertions(+), 63 deletions(-)

---

http://git.linuxtv.org/cgit.cgi/v4l-utils.git/commit/?id=b22fc9e53051a7da903b3906826a527ee57ba92c
diff --git a/utils/ir-ctl/ir-ctl.c b/utils/ir-ctl/ir-ctl.c
index 34cde11e45b2..27c309f9449d 100644
--- a/utils/ir-ctl/ir-ctl.c
+++ b/utils/ir-ctl/ir-ctl.c
@@ -66,14 +66,20 @@
 const char *argp_program_version = "IR ctl version " V4L_UTILS_VERSION;
 const char *argp_program_bug_address = "Sean Young <s...@mess.org>";
 
+enum send_ty {
+       SEND_RAW,
+       SEND_SCANCODE,
+       SEND_KEYCODE,
+       SEND_GAP,
+};
+
 /*
  * Since this program drives the lirc interface, use the same terminology
  */
 struct send {
        struct send *next;
        const char *fname;
-       bool is_scancode;
-       bool is_keycode;
+       enum send_ty ty;
        union {
                struct {
                        unsigned carrier;
@@ -84,7 +90,8 @@ struct send {
                        unsigned scancode;
                        unsigned protocol;
                };
-               char    keycode[1];
+               char keycode[1];
+               unsigned gap;
        };
 };
 
@@ -223,8 +230,7 @@ static struct send *read_file_pulse_space(struct arguments 
*args, const char *fn
                fprintf(stderr, _("Failed to allocate memory\n"));
                return NULL;
        }
-       f->is_scancode = false;
-       f->is_keycode = false;
+       f->ty = SEND_RAW;
        f->carrier = UNSET;
        f->fname = fname;
 
@@ -393,8 +399,7 @@ static struct send *read_file_raw(struct arguments *args, 
const char *fname, FIL
                fclose(input);
                return NULL;
        }
-       f->is_scancode = false;
-       f->is_keycode = false;
+       f->ty = SEND_RAW;
        f->carrier = UNSET;
        f->fname = fname;
 
@@ -549,14 +554,33 @@ static struct send *read_scancode(const char *name)
                return NULL;
        }
 
-       f->is_scancode = true;
-       f->is_keycode = false;
+       f->ty = SEND_SCANCODE;
        f->scancode = scancode;
        f->protocol = proto;
 
        return f;
 }
 
+static void add_to_send_list(struct arguments *arguments, struct send *send)
+{
+       send->next = NULL;
+
+       if (arguments->send == NULL)
+               arguments->send = send;
+       else {
+               // introduce gap
+               struct send *gap = malloc(sizeof(*gap));
+               gap->ty = SEND_GAP;
+               gap->fname= NULL;
+               gap->gap = arguments->gap;
+               gap->next = send;
+
+               struct send *p = arguments->send;
+               while (p->next) p = p->next;
+               p->next = gap;
+       }
+}
+
 static error_t parse_opt(int k, char *arg, struct argp_state *state)
 {
        struct arguments *arguments = state->input;
@@ -664,14 +688,7 @@ static error_t parse_opt(int k, char *arg, struct 
argp_state *state)
                if (s == NULL)
                        exit(EX_DATAERR);
 
-               s->next = NULL;
-               if (arguments->send == NULL)
-                       arguments->send = s;
-               else {
-                       struct send *p = arguments->send;
-                       while (p->next) p = p->next;
-                       p->next = s;
-               }
+               add_to_send_list(arguments, s);
                break;
        case 'S':
                if (arguments->receive || arguments->features)
@@ -680,14 +697,7 @@ static error_t parse_opt(int k, char *arg, struct 
argp_state *state)
                if (s == NULL)
                        exit(EX_DATAERR);
 
-               s->next = NULL;
-               if (arguments->send == NULL)
-                       arguments->send = s;
-               else {
-                       struct send *p = arguments->send;
-                       while (p->next) p = p->next;
-                       p->next = s;
-               }
+               add_to_send_list(arguments, s);
                break;
 
        case 'K':
@@ -696,18 +706,10 @@ static error_t parse_opt(int k, char *arg, struct 
argp_state *state)
                s = malloc(sizeof(*s) + strlen(arg));
                if (s == NULL)
                        exit(EX_DATAERR);
-
-               s->next = NULL;
                strcpy(s->keycode, arg);
-               s->is_scancode = false;
-               s->is_keycode = true;
-               if (arguments->send == NULL)
-                       arguments->send = s;
-               else {
-                       struct send *p = arguments->send;
-                       while (p->next) p = p->next;
-                       p->next = s;
-               }
+               s->ty = SEND_KEYCODE;
+
+               add_to_send_list(arguments, s);
                break;
 
        case 'k':
@@ -757,8 +759,7 @@ static struct send* convert_keycode(struct keymap *map, 
const char *keycode)
                                s = malloc(sizeof(*s) + re->raw_length * 
sizeof(int));
                                s->len = re->raw_length;
                                memcpy(s->buf, re->raw, s->len * sizeof(int));
-                               s->is_scancode = false;
-                               s->is_keycode = false;
+                               s->ty = SEND_RAW;
                                s->carrier = keymap_param(map, "carrier", 0);
                                s->next = NULL;
                        }
@@ -783,16 +784,14 @@ static struct send* convert_keycode(struct keymap *map, 
const char *keycode)
                                s = malloc(sizeof(*s));
                                s->protocol = proto;
                                s->scancode = se->scancode;
-                               s->is_scancode = true;
-                               s->is_keycode = false;
+                               s->ty = SEND_SCANCODE;
                                s->next = NULL;
                        } else if (encode_bpf_protocol(map, se->scancode,
                                                       buf, &length)) {
                                s = malloc(sizeof(*s) + sizeof(int) * length);
                                s->len = length;
                                memcpy(s->buf, buf, length * sizeof(int));
-                               s->is_scancode = false;
-                               s->is_keycode = false;
+                               s->ty = SEND_RAW;
                                s->carrier = keymap_param(map, "carrier", 0);
                                s->next = NULL;
                        } else {
@@ -1049,7 +1048,7 @@ static int lirc_send(struct arguments *args, int fd, 
unsigned features, struct s
                return EX_UNAVAILABLE;
        }
 
-       if (f->is_scancode) {
+       if (f->ty == SEND_SCANCODE) {
                if (args->verbose)
                        printf("Sending to kernel encoder protocol:%s 
scancode:0x%x\n",
                               protocol_name(f->protocol), f->scancode);
@@ -1075,7 +1074,7 @@ static int lirc_send(struct arguments *args, int fd, 
unsigned features, struct s
                return EX_UNAVAILABLE;
        }
 
-       if (f->is_scancode) {
+       if (f->ty == SEND_SCANCODE) {
                // encode scancode
                enum rc_proto proto = f->protocol;
                if (!protocol_encoder_available(proto)) {
@@ -1265,29 +1264,30 @@ int main(int argc, char *argv[])
        struct send *s = args.send;
        while (s) {
                struct send *next = s->next;
-               if (s != args.send)
-                       usleep(args.gap);
-
-               if (s->is_keycode) {
-                       struct send *k;
+               if (s->ty == SEND_GAP) {
+                       usleep(s->gap);
+               } else {
+                       if (s->ty == SEND_KEYCODE) {
+                               struct send *k;
 
-                       if (!args.keymap) {
-                               fprintf(stderr, _("error: no keymap 
specified\n"));
-                               exit(EX_DATAERR);
-                       }
+                               if (!args.keymap) {
+                                       fprintf(stderr, _("error: no keymap 
specified\n"));
+                                       exit(EX_DATAERR);
+                               }
 
-                       k = convert_keycode(args.keymap, s->keycode);
-                       if (!k)
-                               exit(EX_DATAERR);
+                               k = convert_keycode(args.keymap, s->keycode);
+                               if (!k)
+                                       exit(EX_DATAERR);
 
-                       free(s);
-                       s = k;
-               }
+                               free(s);
+                               s = k;
+                       }
 
-               rc = lirc_send(&args, fd, features, s);
-               if (rc) {
-                       close(fd);
-                       exit(rc);
+                       rc = lirc_send(&args, fd, features, s);
+                       if (rc) {
+                               close(fd);
+                               exit(rc);
+                       }
                }
 
                free(s);

_______________________________________________
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

Reply via email to