void switch_auto_calib(data_t *data) { /* Try to swith autocalibration with a timeout of 100 ms */ int new_mode = !data->auto_calib; if(gestic_set_auto_calibration(data->gestic, new_mode, 100) != 0) return; data->auto_calib = new_mode; }
void init_device(data_t *data) { /* Bitmask later used for starting a stream with * SD-, position- and gesture-data */ const int stream_flags = gestic_data_mask_dsp_status | gestic_data_mask_gesture | gestic_data_mask_touch | gestic_data_mask_airwheel | gestic_data_mask_position | gestic_data_mask_sd; /* Allocate a new gestic_t-instance */ data->gestic = gestic_create(); /* Initialize the gestic_t-instance */ gestic_initialize(data->gestic); /* Open a connection to the device */ if(gestic_open(data->gestic) < 0) { fprintf(stderr, "Could not open connection to device.\n"); exit(-1); } /* Get pointers to the result-buffers */ data->gestic_pos = gestic_get_position(data->gestic, 0); data->gestic_sd = gestic_get_sd(data->gestic, 0); data->gestic_calib = gestic_get_calibration(data->gestic, 0); data->gestic_gesture = gestic_get_gesture(data->gestic, 0); data->gestic_touch = gestic_get_touch(data->gestic, 0); data->gestic_air_wheel = gestic_get_air_wheel(data->gestic, 0); /* Reset the device to the default state: * - Automatic calibration enabled * - All frequencies allowed * - Approach detection enabled for power saving * - Enable all gestures ( bit 1 to 6 set to 1 = 126 ) */ if(gestic_set_auto_calibration(data->gestic, data->auto_calib, 100) < 0 || gestic_select_frequencies(data->gestic, gestic_all_freq, 100) < 0 || gestic_set_approach_detection(data->gestic, 1, 100) < 0 || gestic_set_enabled_gestures(data->gestic, 126, 100) < 0) { fprintf(stderr, "Could not reset device to default state.\n"); exit(-1); } /* Set output-mask to the bitmask defined aboveand stream only changes */ if(gestic_set_output_enable_mask(data->gestic, stream_flags, 0, gestic_data_mask_all, 100) < 0) { fprintf(stderr, "Could not start data-streaming from device.\n"); exit(-1); } }
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; }