diff options
author | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2014-01-11 16:02:00 +0100 |
---|---|---|
committer | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2014-01-11 16:02:00 +0100 |
commit | 7bbfc8aeafb2bd75a31da8b459d6515b0af80c8c (patch) | |
tree | 9cc8d8639b0d2747d14753d8fd24756da62ca364 /src | |
parent | 32e4f4f7b32b6a50ebd20a70ccdf8a0df1709e56 (diff) | |
download | pjctl-7bbfc8aeafb2bd75a31da8b459d6515b0af80c8c.tar.gz pjctl-7bbfc8aeafb2bd75a31da8b459d6515b0af80c8c.tar.bz2 pjctl-7bbfc8aeafb2bd75a31da8b459d6515b0af80c8c.zip |
[WIP] Allow source command to obtain default value
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 }, |