Esempio n. 1
0
void free_device(data_t *data)
{
    /* Close the connection to the device */
    gestic_close(data->gestic);

    /* Release resources that were associated with the gestic_t-instance */
    gestic_cleanup(data->gestic);

    /* Release the gestic_t-instance itself */
    gestic_free(data->gestic);
}
int main() {
    int i;

    /* Create GestIC-Instance */
    gestic_t *gestic = gestic_create();

    /* Bitmask later used for starting a stream with SD- and position-data */
    const int stream_flags = gestic_data_mask_position | gestic_data_mask_sd;

    /* Pointer to the internal data-buffers */
    const gestic_signal_t * sd = NULL;
    const gestic_position_t * pos = NULL;

    printf("GestIC-Stream-Demo version %s\n", gestic_version_str());

    /* Initialize all variables and required resources of gestic */
    gestic_initialize(gestic);

    /* Aquire the pointers to the data-buffers */
    sd = gestic_get_sd(gestic, 0);
    pos = gestic_get_position(gestic, 0);

    /* Try to open a connection to the device */
    if(gestic_open(gestic) < 0) {
        fprintf(stderr, "Could not open connection to device.\n");
        return -1;
    }

    /* Try to reset the device to the default state:
     * - Automatic calibration enabled
     * - All frequencies allowed
     * - Approach detection disabled
     */
    if(gestic_set_auto_calibration(gestic, 1, 100) < 0 ||
       gestic_select_frequencies(gestic, gestic_all_freq, 100) < 0 ||
       gestic_set_approach_detection(gestic, 0, 100) < 0)
    {
        fprintf(stderr, "Could not reset device to default state.\n");
        return -1;
    }

    /* Set output-mask to the bitmask defined above and stream all data */
    if(gestic_set_output_enable_mask(gestic, stream_flags, stream_flags,
                                     gestic_data_mask_all, 100) < 0)
    {
        fprintf(stderr, "Could not set output-mask for streaming.\n");
        return -1;
    }

    /* Listens for about 10 seconds to incoming messages */
    for(i = 0; i < 200; ++i) {
        /* Try to fetch stream-data until no more messages are available*/
        while(!gestic_data_stream_update(gestic, 0)) {
            /* Output the position */
            printf("Position: %5d %5d %5d\n", pos->x, pos->y, pos->z);

            /* Output the SD-data */
            printf("SD-Data:  %5.0f %5.0f %5.0f %5.0f %5.0f\n",
                   sd->channel[0], sd->channel[1], sd->channel[2],
                    sd->channel[3], sd->channel[4]);
        }
        Sleep(50);
    }

    /* Close connection to device */
    gestic_close(gestic);

    /* Release further resources that were used by gestic */
    gestic_cleanup(gestic);
    gestic_free(gestic);

    return 0;
}