From bf928144bdaa9f330b7ec6054e330e7e3f1ff620 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sun, 9 Jun 2019 14:27:31 +0200 Subject: Scan out DMX for real --- src/scanout.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/scanout.c b/src/scanout.c index cbb990f..1c5823b 100644 --- a/src/scanout.c +++ b/src/scanout.c @@ -23,31 +23,49 @@ #include #include -#include #include #include "nanolight.h" -gboolean scanout_all(struct nanolight *nl) +int scanout_all(struct nanolight *nl) { SoupSession *sess; SoupMessage *msg; int i; + int dmx[512]; char str[8200]; - strcpy(str, "u=0, d="); + /* Start from zero */ + for ( i=0; i<512; i++ ) dmx[i] = 0; + + /* Loop over fixtures and set values */ + for ( i=0; in_fixtures; i++ ) { + int j; + struct fixture *fix = &nl->fixtures[i]; + for ( j=0; jcls->n_attrs; j++ ) { + int pos = fix->base_addr + fix->cls->attrs[j].addr_offset; + if ( fix->cls->attrs[j].props & ATTR_16BIT ) { + dmx[pos] = (fix->attr_vals[j] & 0xff00) >> 8; + dmx[pos+1] = fix->attr_vals[j] & 0xff; + } else { + dmx[pos] = fix->attr_vals[j]; + } + } + } + + /* Loop over DMX channels and prepare request */ + strcpy(str, "u=1&d="); for ( i=0; i<512; i++ ) { char tmp[6]; - snprintf(tmp, 5, "%i,", 255); + snprintf(tmp, 5, "%i,", dmx[i]); strcat(str, tmp); } - printf("req='%s'\n", str); + /* Send request to OLA */ sess = soup_session_new(); msg = soup_message_new("POST", "http://127.0.0.1:9090/set_dmx"); - soup_message_set_request(msg, "text/plain", SOUP_MEMORY_TEMPORARY, str, - strlen(str)); - + soup_message_set_request(msg, "application/x-www-form-urlencoded", + SOUP_MEMORY_TEMPORARY, str, strlen(str)); soup_session_send_message(sess, msg); g_object_unref(msg); -- cgit v1.2.3