diff options
author | David Lamparter <equinox@diac24.net> | 2013-06-29 02:28:04 +0200 |
---|---|---|
committer | David Lamparter <equinox@diac24.net> | 2013-06-29 02:28:04 +0200 |
commit | 389696f57cb232806380daf016fbf58d5d242415 (patch) | |
tree | 9aea432baaba2c19c97d87ab87c2e658699b2f06 /cethcan/light.c | |
parent | 8cb56d41caf68d69a643687175235c439dc63deb (diff) | |
parent | fa21bedc238b77a3c6bfe4a4a6a5b3a13f0a4b9a (diff) |
Merge remote-tracking branch 'bbone/master'
Diffstat (limited to 'cethcan/light.c')
-rw-r--r-- | cethcan/light.c | 36 |
1 files changed, 36 insertions, 0 deletions
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; } |