예제 #1
0
파일: testmonitor.c 프로젝트: EQ4/libmapper
void loop()
{
    int i = 0;
    while ((!terminate || i++ < 200) && !done)
    {
        mapper_monitor_poll(mon, 0);
        usleep(polltime_ms * 1000);

        if (update++ < 0)
            continue;
        update = -10;

        // clear screen & cursor to home
        printf("\e[2J\e[0;0H");
        fflush(stdout);

        printf("Registered devices:\n");
        mapper_db_device *pdev = mapper_db_get_all_devices(db);
        while (pdev) {
            printdevice(*pdev);
            pdev = mapper_db_device_next(pdev);
        }

        printf("------------------------------\n");

        printf("Registered signals:\n");
        mapper_db_signal *psig =
            mapper_db_get_all_inputs(db);
        while (psig) {
            printsignal(*psig);
            psig = mapper_db_signal_next(psig);
        }
        psig = mapper_db_get_all_outputs(db);
        while (psig) {
            printsignal(*psig);
            psig = mapper_db_signal_next(psig);
        }

        printf("------------------------------\n");

        printf("Registered links:\n");
        mapper_db_link *plink = mapper_db_get_all_links(db);
        while (plink) {
            printlink(*plink);
            plink = mapper_db_link_next(plink);
        }

        printf("------------------------------\n");

        printf("Registered connections:\n");
        mapper_db_connection *pcon = mapper_db_get_all_connections(db);
        while (pcon) {
            printconnection(*pcon);
            pcon = mapper_db_connection_next(pcon);
        }

        printf("------------------------------\n");
    }
}
예제 #2
0
void recmonitor_poll()
{
    mapper_monitor_poll(mon, 0);
    if (!dev_ready && mdev_ready(recdev)) {
        mapper_monitor_request_devices(mon);
        dev_ready = 1;
    }
    record_signals_on_stack();
}
예제 #3
0
int main(int argc, char *argv[])
{
    if (argc > 1)
        id = atoi(argv[1]);

    signal(SIGINT, ctrlc);

    struct _agentInfo *info = agentInit();
    if (!info->dev)
        goto done;

    float pos[2];
    pos[0] = rand()%WIDTH/2+WIDTH/4;
    pos[1] = rand()%HEIGHT/2+HEIGHT/4;
    float gain = 0.2;
    float damping = 0.9;
    float limit = 1;
    float vel[2] = {0,0};
    int counter = 0;

    while (!done) {
        mapper_monitor_poll(info->mon, 0);
        if (mdev_poll(info->dev, 10)) {
            vel[0] += obs[0] * gain;
            vel[1] += obs[1] * gain;
            pos[0] += vel[0];
            pos[1] += vel[1];
            vel[0] *= damping;
            vel[1] *= damping;

            if (vel[0] >  limit) vel[0] =  limit;
            if (vel[0] < -limit) vel[0] = -limit;
            if (vel[1] >  limit) vel[1] =  limit;
            if (vel[1] < -limit) vel[1] = -limit;

            if (pos[0] < 0) {
                pos[0] = 0;
                vel[0] *= -0.95;
            }

            if (pos[0] >= WIDTH) {
                pos[0] = WIDTH-1;
                vel[0] *= -0.95;
            }

            if (pos[1] < 0) {
                pos[1] = 0;
                vel[1] *= -0.95;
            }

            if (pos[1] >= HEIGHT) {
                pos[1] = HEIGHT-1;
                vel[1] *= -0.95;
            }

            int p[2];
            p[0] = (int)pos[0];
            p[1] = (int)pos[1];
            msig_update(info->sig_pos, p);

            counter = 0;
        }
        else {
            if (counter++ > 100) {
                int p[2];
                p[0] = (int)pos[0];
                p[1] = (int)pos[1];
                msig_update(info->sig_pos, p);
                counter = 0;
            }
        }
    }

done:
    agentLogout();
    return 0;
}