From fa21bedc238b77a3c6bfe4a4a6a5b3a13f0a4b9a Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Sat, 29 Jun 2013 00:26:39 +0000 Subject: cethcan: light_{get,set} RPC --- cethcan/light.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'cethcan/light.c') diff --git a/cethcan/light.c b/cethcan/light.c index cd646d8..da6aefb 100644 --- a/cethcan/light.c +++ b/cethcan/light.c @@ -6,6 +6,7 @@ struct value { }; struct light { + struct light *next; struct can_user *u; char *name; @@ -14,6 +15,38 @@ struct light { struct value set, actual; }; +static struct light *lights = NULL, **plights = &lights; + +struct light *light_find(const char *name) +{ + struct light *l; + for (l = lights; l; l = l->next) + if (!strcmp(l->name, name)) + break; + return l; +} + +int light_set(struct light *l, unsigned value) +{ + struct can_message msg; + msg.daddr = CANA_LIGHT_F(0, l->logical_addr); + msg.dlc = 1; + msg.bytes[0] = value; + can_broadcast(l->u, &msg); + + return 0; +} + +unsigned light_getset(struct light *l) +{ + return l->set.val; +} + +unsigned light_getact(struct light *l) +{ + return l->actual.val; +} + static void light_json_handler(void *arg, json_t *json, enum json_subtype type) { struct light *l = arg; @@ -89,5 +122,8 @@ int light_init_conf(json_t *config) l->u = can_register_alloc(l, light_can_handler, "light[%s]", l->name); l->u->json = light_json_handler; + + *plights = l; + plights = &l->next; return 0; } -- cgit v1.2.1