summaryrefslogtreecommitdiff
path: root/cethcan/light.c
diff options
context:
space:
mode:
Diffstat (limited to 'cethcan/light.c')
-rw-r--r--cethcan/light.c36
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;
}