summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2013-08-20 19:27:20 +0200
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2013-08-21 22:52:56 +0200
commit52243841a73a34990859b3c01161b78b9419041d (patch)
tree56484287b068e336970baefe239e664168289687
parent5f50ccabc018fd75fd61f0a643cc85e1ea3807dc (diff)
downloadpjctl-52243841a73a34990859b3c01161b78b9419041d.tar.gz
pjctl-52243841a73a34990859b3c01161b78b9419041d.tar.bz2
pjctl-52243841a73a34990859b3c01161b78b9419041d.zip
Support toggle in power command
First retrieves power status, and sets the inverse afterwards.
-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, ""},