예제 #1
0
파일: dmxd.c 프로젝트: sgielen/schaeckeling
void
flush_dmxout_sendbuf(void) {
	pthread_mutex_lock(&dmxout_sendbuf_mtx);
	if(dmxout_dirty) {
		send_dmx(dmxout_sendbuf);
		update_websockets(1, 0);
		dmxout_dirty = 0;
	}
	pthread_mutex_unlock(&dmxout_sendbuf_mtx);
}
예제 #2
0
파일: vt_lua.c 프로젝트: elionne/lutopia
/* This function
 * TODO comment it!
 */
int update_lights(lua_State *L, const char *universe, int dmx)
{
    int err;

    lua_getglobal(L, universe);
    if( !lua_istable(L, -1) ){
        printf("%s not found\n", universe);
        return 0;
    }

    lua_pushnil(L);
    while( lua_next(L, -2) ){
        if( lua_istable(L, -1) ){

            lua_getfield(L, -1, "is_changed");
            if( lua_isnil(L, -1) ){

                lua_pop(L, 2);
                continue;
            }

            /* push self first argument */
            lua_pushvalue(L, -2);

            err = lua_pcall(L, 1, 1, 0);
            dbg_lua(L, err, "is_changed");

            /*
            printf("light : %s, changed %i\n", lua_tostring(L, 2),
                                               lua_tointeger(L, -1));
            */

            if( lua_toboolean(L, -1) ){
                /* pops the result of 'is_changed' */
                lua_pop(L, 1);

                /* send dmx data */
                send_dmx(L, dmx_data);

                /* pops light */
                lua_pop(L, 1);
            }else
                lua_pop(L, 2);

        }else{
            lua_pop(L, 1);
            printf("Warning: %s is not a light. Check assignement in your code\n",
                   lua_tostring(L, -1));
        }
    }
    lua_pop(L, 1);

    int len = send(dmx, dmx_data, 513, 0);
    if( len != 513 ){
        printf("socket error, too few data sent, %i\n", len);
        puts(strerror(errno));
        return 0;
    }

    return 1;
}