diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/pjctl.c | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/src/pjctl.c b/src/pjctl.c index 3c2ab96..293bcd1 100644 --- a/src/pjctl.c +++ b/src/pjctl.c @@ -67,6 +67,7 @@ struct queue_command { char *op, char *param); char *prefix; int (*toggle)(struct pjctl *pjctl, union pjctl_param_parse *parse); + void *user_data; struct queue_command *prev, *next; }; @@ -375,16 +376,51 @@ source_response(struct pjctl *pjctl, struct queue_command *cmd, } static int +source(struct pjctl *pjctl, union pjctl_param_parse *p); + +static void +switch_to_first_input_type(struct pjctl *pjctl, struct queue_command *cmd, + char *op, char *param) +{ + union pjctl_param_parse *p = cmd->user_data; + int i, num, len = strlen(param); + + if (len % 3 != 2) + return; + + for (i = 0; i < len; i+=3) { + if (param[i] == ('0' + p->source.type)) { + num = param[i+1] - '0'; + if (num < 0 || num > 9) { + return; + } + p->source.num = num; + source(pjctl, p); + free(p); + } + } +} + +static int source(struct pjctl *pjctl, union pjctl_param_parse *p) { struct queue_command *cmd; - uint8_t type = p->source.type, num = p->source.num; + uint8_t type = p->source.type; + int num = p->source.num; const char *switches[] = { "rgb", "video", "digital", "storage", "net" }; cmd = calloc(1, sizeof *cmd); if (!cmd) return -1; + if (num == -1) { + cmd->response_func = switch_to_first_input_type; + cmd->user_data = p; + insert_at_head(&pjctl->queue, cmd); + + return 0; + } + if (asprintf(&cmd->command, "%%1INPT %d%d\r", type, num) < 0) return -1; cmd->response_func = source_response; @@ -702,7 +738,7 @@ static struct pjctl_command { { "power", power, P{ P_SWITCH, P_END } }, { "source", source, P{ P_ATOM("rgb", "video", "digital", "storage", "net"), - P_RANGE(1,9,1), P_END } + P_RANGE(1,9,-1), P_END } }, { "mute", avmute, P{ P_ATOM("video", "audio", "av"), P_SWITCH, P_END }}, { "status", status, NULL }, |