void update_device(data_t *data) { int i; /* Abbreviations for the electrodes */ const char source[] = { 'S', 'W', 'N', 'E', 'C' }; while(gestic_data_stream_update(data->gestic, NULL) == 0) { /* Print update of the position */ gotoxy(0, 4); if(data->gestic_pos != NULL) printf("Position: X %5d Y %5d Z %5d \n", data->gestic_pos->x, data->gestic_pos->y, data->gestic_pos->z); else printf("Position: Not available\n"); /* Print update of gestures */ gotoxy(0, 5); if(data->gestic_gesture != NULL) { /* Remember last gesture and reset it after 1s = 200 updates */ if(data->gestic_gesture->gesture > 0 && data->gestic_gesture->gesture <= 6) data->last_gesture = data->gestic_gesture->gesture; else if(data->gestic_gesture->last_event > 200) data->last_gesture = 0; printf("Gesture: %s \n", gestures[data->last_gesture]); } else { printf("Gesture: Not available\n"); } /* Print update of touch */ gotoxy(0, 6); printf("Touch: "); for(i = 0; i < 5; ++i) { if(data->gestic_touch->flags & (1<<i)) printf("%c ", source[i]); } printf(" \n"); /* Print update of AirWheel */ gotoxy(0, 7); if(data->gestic_air_wheel != NULL) { printf("Air Wheel: %d \n", data->gestic_air_wheel->counter); } else { printf("Air Wheel: Not available\n"); } /* Print update of Signal Deviation */ gotoxy(0, 8); if(data->gestic_sd != NULL) { printf("Signal Deviation:"); for(i = 0; i < 5; ++i) printf(" %c %5.0f ", source[i], data->gestic_sd->channel[i]); if(data->gestic_calib != NULL) printf("\nLast Calibration: %7d", data->gestic_calib->last_event); } else { printf("Signal Deviation: Not available\n"); } } }
void update_device(data_t *data) { int i; /* Abbreviations for the electrodes */ const char source[] = { 'S', 'W', 'N', 'E', 'C' }; while(gestic_data_stream_update(data->gestic, NULL) == 0) { /* Print update of the position */ gotoxy(0, 4); if(data->gestic_pos != NULL) { printf("Position: X %5d Y %5d Z %5d \n", data->gestic_pos->x, data->gestic_pos->y, data->gestic_pos->z); /* counts++; if (counts == 10) { if((lastz != data->gestic_pos->z)) { tcpData[0]='Z'; sprintf(&tcpData[1],"%d",data->gestic_pos->z); tcpSendData(tcpData); lastz = data->gestic_pos->z; counts = 0; } }*/ } else printf("Position: Not available\n"); /* Print update of gestures */ gotoxy(0, 5); if(data->gestic_gesture != NULL) { /* Remember last gesture and reset it after 1s = 200 updates */ if(data->gestic_gesture->gesture > 0 && data->gestic_gesture->gesture <= 6) data->last_gesture = data->gestic_gesture->gesture; else if(data->gestic_gesture->last_event > 1) //Shrenik data->last_gesture = 0; printf("Gesture: %s \n", gestures[data->last_gesture]); //*tcpData = (char *)gestures[data->last_gesture]; if(strcmp(gestures[data->last_gesture],"DNULL")) { tcpSendData(gestures[data->last_gesture]); } else if((lastz != data->gestic_pos->z)) { if(((lastz-data->gestic_pos->z) > 1000) | ((data->gestic_pos->z - lastz) > 1000)) { tcpData[0]='Z'; sprintf(&tcpData[1],"%d",data->gestic_pos->z); // tcpSendData(tcpData); lastz = data->gestic_pos->z; //counts = 0; //Sleep(10); } } } else { printf("Gesture: Not available\n"); } /* Print update of touch */ gotoxy(0, 6); printf("Touch: "); for(i = 0; i < 5; ++i) { if(data->gestic_touch->flags & (1<<i)) printf("%c ", source[i]); } printf(" \n"); /* Print update of AirWheel */ gotoxy(0, 7); if(data->gestic_air_wheel != NULL) { printf("Air Wheel: %d \n", data->gestic_air_wheel->counter); } else { printf("Air Wheel: Not available\n"); } /* Print update of Signal Deviation */ gotoxy(0, 8); if(data->gestic_sd != NULL) { printf("Signal Deviation:"); for(i = 0; i < 5; ++i) printf(" %c %5.0f ", source[i], data->gestic_sd->channel[i]); if(data->gestic_calib != NULL) printf("\nLast Calibration: %7d", data->gestic_calib->last_event); } else { printf("Signal Deviation: Not available\n"); } } }
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; }