// Connect to the P5Glove hardware bool P5GloveStandalone::connectToHardware(const int gloveNumber) { vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL) << "[P5Glove] Connecting To P5Glove Hardware number " << gloveNumber << std::endl << vprDEBUG_FLUSH; for ( unsigned int i = 0 ; i < 4 ; ++i ) { mGlove = p5glove_open(gloveNumber); if ( mGlove == NULL ) { break; } if ( p5glove_sample(mGlove, -1) >= 0 ) { break; } p5glove_close(mGlove); mGlove = NULL; } if ( mGlove == NULL ) { vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_WARNING_LVL) << "[P5Glove] Cannot connect to Hardware glove!\n" << vprDEBUG_FLUSH; return false; } // p5g_reset_prev(mGlove); return true; }
/* Brain-Dead P5 data dump. */ int main(int argc, char **argv) { P5Glove glove; int sample; glove=p5glove_open(0); if (glove == NULL) { fprintf(stderr, "%s: Can't open glove interface\n", argv[0]); return 1; } for (sample=0; sample < 100 ; ) { int i,err; err=p5glove_sample(glove, -1); if (err < 0 && errno == EAGAIN) continue; if (err < 0) { perror("Glove Failure"); exit(1); } printf("%2d: ",sample); sample++; dump_cooked(glove,err); printf("\n"); } p5glove_close(glove); return 0; }
void render_next(void) { int err; /* Get samples here */ err=p5glove_sample(glove, 100); glutPostRedisplay(); }
bool P5GloveStandalone::readRecordsFromHardware(Record& rec) { const int mask = p5glove_sample(mGlove, -1); if ( mask < 0 ) { return false; } if ( mask & P5GLOVE_DELTA_BUTTONS ) { uint32_t buttons; p5glove_get_buttons(mGlove, &buttons); /* Buttons */ rec.buttonA = buttons & P5GLOVE_BUTTON_A; rec.buttonB = buttons & P5GLOVE_BUTTON_B; rec.buttonC = buttons & P5GLOVE_BUTTON_C; } if ( mask & P5GLOVE_DELTA_FINGERS ) { p5glove_get_finger(mGlove, P5GLOVE_FINGER_THUMB, &rec.thumb); p5glove_get_finger(mGlove, P5GLOVE_FINGER_INDEX, &rec.index); p5glove_get_finger(mGlove, P5GLOVE_FINGER_MIDDLE, &rec.middle); p5glove_get_finger(mGlove, P5GLOVE_FINGER_RING, &rec.ring); p5glove_get_finger(mGlove, P5GLOVE_FINGER_PINKY, &rec.pinky); } if ( mask & P5GLOVE_DELTA_POSITION ) { p5glove_get_position(mGlove, &rec.position[0]); } if ( mask & P5GLOVE_DELTA_ROTATION ) { p5glove_get_rotation(mGlove, &rec.rotationAngle, &rec.rotationAxis[0]); } return true; }
void p5_read(t_p5 *p5){ if(p5 == NULL) return; int err = p5glove_sample(p5->glove, -1); if (err < 0 && errno == EAGAIN){ return; } if (err < 0) { error("*** p5 glove failure"); return; } /* Output button data */ uint32_t buttons; p5glove_get_buttons(p5->glove, &buttons); if(err & P5GLOVE_DELTA_BUTTONS){ if(buttons & P5GLOVE_BUTTON_A) outlet_float(p5->btn_a_out, 1); else outlet_float(p5->btn_a_out, 0); if(buttons & P5GLOVE_BUTTON_B) outlet_float(p5->btn_b_out, 1); else outlet_float(p5->btn_b_out, 0); if(buttons & P5GLOVE_BUTTON_C) outlet_float(p5->btn_c_out, 1); else outlet_float(p5->btn_c_out, 0); } /* Output finger data */ if(err & P5GLOVE_DELTA_FINGERS){ double clench; p5glove_get_finger(p5->glove, P5GLOVE_FINGER_THUMB, &clench); outlet_float(p5->thumb_out, clench); p5glove_get_finger(p5->glove, P5GLOVE_FINGER_INDEX ,&clench); outlet_float(p5->index_out, clench); p5glove_get_finger(p5->glove, P5GLOVE_FINGER_MIDDLE ,&clench); outlet_float(p5->middle_out, clench); p5glove_get_finger(p5->glove, P5GLOVE_FINGER_RING ,&clench); outlet_float(p5->ring_out, clench); p5glove_get_finger(p5->glove, P5GLOVE_FINGER_PINKY ,&clench); outlet_float(p5->pinky_out, clench); } if(err & P5GLOVE_DELTA_POSITION){ double pos[3]; p5glove_get_position(p5->glove, pos); outlet_float(p5->xpos_out, pos[0]); outlet_float(p5->ypos_out, pos[1]); outlet_float(p5->zpos_out, pos[2]); } if(err & P5GLOVE_DELTA_ROTATION){ //TODO: Get/send rotation } clock_delay(p5->clock, p5->delaytime); }//p5_read