/* * scanout.c * * Copyright © 2019 Thomas White * * This file is part of NanoLight. * * NanoLight is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #include #include #include #include #include "nanolight.h" int scanout_all(struct nanolight *nl) { SoupSession *sess; SoupMessage *msg; int i; int dmx[512]; char str[8200]; signed int universe = -1; /* 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++ ) { /* Minus one to convert DMX address to indexing in 'dmx' array */ int pos = fix->base_addr + fix->cls->attrs[j].addr_offset - 1; if ( universe < 0 ) universe = fix->universe; if ( fix->universe != universe ) { fprintf(stderr, "Sorry, only one universe for now!\n"); abort(); } if ( fix->cls->attrs[j].props & ATTR_STOP ) { int v = fix->attr_vals[j]; assert(!(fix->cls->attrs[j].props & ATTR_16BIT)); dmx[pos] = fix->cls->attrs[j].stops[v]; } else 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]; } } } if ( universe == -1 ) return 0; /* Nothing to do! */ /* Loop over DMX channels and prepare request */ snprintf(str, 16, "u=%i&d=", universe); for ( i=0; i<512; i++ ) { char tmp[6]; snprintf(tmp, 5, "%i,", dmx[i]); strcat(str, tmp); } /* 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, "application/x-www-form-urlencoded", SOUP_MEMORY_TEMPORARY, str, strlen(str)); soup_session_send_message(sess, msg); g_object_unref(msg); g_object_unref(sess); return 0; }