summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@diac24.net>2016-05-15 14:15:39 +0200
committerDavid Lamparter <equinox@diac24.net>2016-05-15 14:15:39 +0200
commit0591adffc658d9e5a7b47feb59282b2505a32209 (patch)
tree857a5587be1b56f56def688f4c33ebd432b2cd78
parent5c553ecfbda79bb6f0f3204f1e1d10862885b3f2 (diff)
cethcan: hook up ttydmx on RPC
-rw-r--r--cethcan/cethcan.h7
-rw-r--r--cethcan/rpc.c20
2 files changed, 25 insertions, 2 deletions
diff --git a/cethcan/cethcan.h b/cethcan/cethcan.h
index 4d215f0..b272766 100644
--- a/cethcan/cethcan.h
+++ b/cethcan/cethcan.h
@@ -96,6 +96,13 @@ extern int espnet_set(struct espnet_device *dev,
extern void espnet_get(struct espnet_device *dev,
unsigned *r, unsigned *g, unsigned *b);
+struct ttydmx_device;
+struct ttydmx_device *ttydmx_find(const char *name);
+extern int ttydmx_set(struct ttydmx_device *dev,
+ unsigned r, unsigned g, unsigned b);
+extern void ttydmx_get(struct ttydmx_device *dev,
+ unsigned *r, unsigned *g, unsigned *b);
+
extern void json_bump_longpoll(void);
extern int socan_init(json_t *config);
diff --git a/cethcan/rpc.c b/cethcan/rpc.c
index bfe6026..9ccbf07 100644
--- a/cethcan/rpc.c
+++ b/cethcan/rpc.c
@@ -13,6 +13,7 @@ static int rpc_light_set(void *apparg, json_t *json_params, json_t **result)
{
struct light *l;
struct espnet_device *esp;
+ struct ttydmx_device *dmx;
const char *name = json_string_value(json_array_get(json_params, 0));
const char *emsg;
@@ -31,7 +32,8 @@ static int rpc_light_set(void *apparg, json_t *json_params, json_t **result)
}
esp = espnet_find(name);
- if (esp) {
+ dmx = ttydmx_find(name);
+ if (esp || dmx) {
unsigned r, g, b;
json_t *val = json_array_get(json_params, 1);
@@ -49,7 +51,10 @@ static int rpc_light_set(void *apparg, json_t *json_params, json_t **result)
goto out_err;
}
- *result = json_boolean(!espnet_set(esp, r, g, b));
+ if (dmx)
+ *result = json_boolean(!ttydmx_set(dmx, r, g, b));
+ else if (esp)
+ *result = json_boolean(!espnet_set(esp, r, g, b));
return 0;
}
@@ -64,6 +69,7 @@ static int rpc_light_get(void *apparg, json_t *json_params, json_t **result)
{
struct light *l;
struct espnet_device *esp;
+ struct ttydmx_device *dmx;
const char *name = json_string_value(json_array_get(json_params, 0));
unsigned set, actual;
@@ -87,6 +93,16 @@ static int rpc_light_get(void *apparg, json_t *json_params, json_t **result)
return 0;
}
+ dmx = ttydmx_find(name);
+ if (dmx) {
+ unsigned r, g, b;
+ ttydmx_get(dmx, &r, &g, &b);
+
+ *result = json_pack("{s:i,s:i,s:i}",
+ "r", r, "g", g, "b", b);
+ return 0;
+ }
+
*result = jsonrpc_error_object(JSONRPC_INVALID_PARAMS,
json_string("cannot find specified light"));
return JSONRPC_INVALID_PARAMS;