summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/pjctl.c34
1 files changed, 25 insertions, 9 deletions
diff --git a/src/pjctl.c b/src/pjctl.c
index d93f791..0c5c7b1 100644
--- a/src/pjctl.c
+++ b/src/pjctl.c
@@ -60,6 +60,7 @@ struct queue_command {
void (*response_func)(struct pjctl *pjctl, struct queue_command *cmd,
char *op, char *param);
char *prefix;
+ int toggle;
struct queue_command *prev, *next;
};
@@ -318,28 +319,39 @@ read_cb(struct pjctl *pjctl)
return 0;
}
+static int
+power(struct pjctl *pjctl, char **argv, int argc);
+
static void
power_response(struct pjctl *pjctl, struct queue_command *cmd,
char *op, char *param)
{
int ret;
+ char *params[2][2] = {
+ { "power", "off" },
+ { "power", "on" }
+ };
fputs(cmd->prefix, stdout);
free(cmd->prefix);
ret = handle_pjlink_error(param);
- if (ret == 1)
+ if (ret == 1) {
printf("OK\n");
- else if (ret == 0)
+ } else if (ret == 0) {
printf("%s\n", param[0] == '1' ? "on" : "off" );
+
+ if (cmd->toggle)
+ power(pjctl, param[0] == '1' ? params[0]:params[1], 2);
+ }
}
static int
power(struct pjctl *pjctl, char **argv, int argc)
{
struct queue_command *cmd;
- int on;
+ char code;
cmd = calloc(1, sizeof *cmd);
if (!cmd)
@@ -349,18 +361,22 @@ power(struct pjctl *pjctl, char **argv, int argc)
}
if (strcmp(argv[1], "on") == 0)
- on = 1;
+ code = '1';
else if (strcmp(argv[1], "off") == 0)
- on = 0;
- else {
+ code = '0';
+ else if (strcmp(argv[1], "toggle") == 0) {
+ code = '?';
+ cmd->toggle = 1;
+ } else {
fprintf(stderr, "invalid power parameter\n");
return -1;
}
- if (asprintf(&cmd->command, "%%1POWR %c\r", on ? '1' : '0') < 0)
+ if (asprintf(&cmd->command, "%%1POWR %c\r", code) < 0)
return -1;
cmd->response_func = power_response;
- if (asprintf(&cmd->prefix, "power %s: ", argv[1]) < 0)
+ if (asprintf(&cmd->prefix, "power %s: ",
+ cmd->toggle ? "status" : argv[1]) < 0)
return -1;
insert_at_head(&pjctl->queue, cmd);
@@ -743,7 +759,7 @@ static struct pjctl_command {
int (*func)(struct pjctl *pjctl, char **argv, int argc);
char *help;
} commands[] = {
- { "power", power, "<on|off>" },
+ { "power", power, "<on|off|toggle>" },
{ "source", source, "<rgb|video|digital|storage|net>[1-9]" },
{ "mute", avmute, "<video|audio|av> <on|off>" },
{ "status", status, ""},