Ejemplo n.º 1
0
function dmx_connect()
{
    global $debug, $dmx, $read_buffer;
    $r = trim(`ls -1 /dev/serial/by-id 2>/dev/null |grep "DMX"`);
    if ($r == '') {
        logformat("No USB DMX Interface appears to be connected!\n");
        exit(1);
    }
    $t = explode("-", $r);
    if (isset($t[1])) {
        logformat(sprintf("Found a %s\n", $t[1]));
    }
    $interface = "/dev/serial/by-id/" . $r;
    `stty -F {$interface} 230400 raw -echo`;
    if ($dmx = fopen($interface, 'w+')) {
        stream_set_blocking($dmx, 0);
        stream_set_read_buffer($dmx, 2048);
        $data = '';
        dmx_set_levels($data);
        dmx_set_dmx_receive_mode(SEND_ON_CHANGE_ONLY);
        sleep(1);
        while ($b = fread($dmx, 2048)) {
        }
        //empty the buffer
        $data = "Hello World!";
        dmx_set_parameters(27, 4, 40, $data);
        if (!($c = dmx_request_parameters($read_buffer))) {
            dmx_close();
            return 0;
        }
        return $c;
    }
    return 0;
}
Ejemplo n.º 2
0
            //something changed in shm
            for ($i = 0; $i < 128; $i++) {
                if (substr($do1, $i * 2, 2) != substr($dmx_outputs1, $i * 2, 2)) {
                    //send xap dmx level change message for universe 1
                    send_dmx_output_level_event_message($i, XAPSRC_DMX_OUT1, XAPUID_DMX_OUT1, $do1, $donames1);
                    $outs1_changed = 1;
                }
                if (substr($do2, $i * 2, 2) != substr($dmx_outputs2, $i * 2, 2)) {
                    //send xap dmx level change message for universe 2
                    send_dmx_output_level_event_message($i, XAPSRC_DMX_OUT2, XAPUID_DMX_OUT2, $do2, $donames2);
                    $outs2_changed = 1;
                }
            }
        }
        if ($outs1_changed) {
            $dmx_outputs1 = $do1;
            dmx_set_levels_U1(bcd_to_chr($dmx_outputs1));
        }
        if ($outs2_changed) {
            $dmx_outputs2 = $do2;
            dmx_set_levels_U2(bcd_to_chr($dmx_outputs2));
        }
        usleep(5000);
    }
}
dmx_set_dmx_receive_mode(SEND_ON_CHANGE_ONLY);
dmx_close();
dmx_write_state_file($dstate_file, $dmx_inputs, $dmx_outputs1, $dmx_outputs2);
socket_close($xap_sock_in);
shmop_close($shm_id);
logformat("hac_dmx exiting cleanly.\n");