void check_quit_action() { // this is where we loop and check for joystick quit event (buttons 8 and 9); int i, status; const char *device = "/dev/input/js0"; const char *calib = "/home/spike/.joystick.bak"; js_data_struct jsd; signal(SIGINT, MySignalHandler); status = JSInit(&jsd, device, calib, JSFlagNonBlocking); if (status != JSSuccess) { printf("ERROR with joystick!\n"); JSClose(&jsd); exit(EXIT_FAILURE); } printf("Initialized joystick: %s\n", jsd.name); runlevel = 2; while(runlevel >= 2) { if (JSUpdate(&jsd) == JSGotEvent && (JSGetButtonState(&jsd, 8) && JSGetButtonState(&jsd, 9))) { JSClose(&jsd); return; } usleep(16000); } }
/* this can be a script, or a shader, take your pick */ struct Shader_Script* new_Shader_Script(struct X3D_Node *node) { struct Shader_Script* ret=MALLOC(struct Shader_Script *, sizeof(struct Shader_Script)); ASSERT(ret); ret->loaded=FALSE; ret->fields=newVector(struct ScriptFieldDecl*, 4); ret->ShaderScriptNode = node; /* pointer back to the node that this is associated with */ ret->num = -1; #ifdef HAVE_JAVASCRIPT /* X3D XML protos do not have a node defined when parsed, Shaders and Scripts do */ if (node!=NULL) { /* printf ("new_Shader_Script, node %s\n",stringNodeType(node->_nodeType)); */ if (node->_nodeType == NODE_Script) { ret->num=nextScriptHandle(); #ifdef CPARSERVERBOSE printf("newScript: created new script nodePtr %u with num %d\n", node, ret->num); #endif JSInit(ret->num); } } #endif /* HAVE_JAVASCRIPT */ /* printf ("new_Shader_Script - num %d, Shader_Script is %u\n",ret->num,ret); */ return ret; }
static int init_stick( int which, const char *const device, const char *const calibration ) { switch( JSInit( &jsd[which], device, calibration, JSFlagNonBlocking ) ) { case JSSuccess: if( JSLoadCalibrationUNIX( &jsd[which] ) && errno != ENOENT ) { ui_error( UI_ERROR_ERROR, "failed to read calibration for joystick %i: %s", which + 1, strerror( errno ) ); break; } if( jsd[which].total_axises < 2 || jsd[which].total_buttons < 1 ) { ui_error( UI_ERROR_ERROR, "sorry, joystick %i (%s) is inadequate!", which + 1, device ); break; } return 0; case JSBadValue: ui_error( UI_ERROR_ERROR, "failed to initialise joystick %i: %s", which + 1, "invalid parameter/value"); break; case JSNoAccess: /* FIXME: why is this commented out? */ /* ui_error (UI_ERROR_ERROR, "failed to initialise joystick %i: %s", which + 1, "cannot access device"); */ break; case JSNoBuffers: ui_error( UI_ERROR_ERROR, "failed to initialise joystick %i: %s", which + 1, "not enough memory" ); break; default: ui_error( UI_ERROR_ERROR, "failed to initialise joystick %i", which + 1 ); break; } JSClose( &jsd[which] ); return 1; }
/*============================================================================*/ bool VistaJswJoystickDriver::Connect() { int status = 0; const char *device = JSDefaultDevice; const char *calib = JSDefaultCalibration; IVistaDriverProtocolAspect::_cVersionTag tag; if( m_pProtocol->GetProtocol(tag) ) { if(!tag.m_strProtocolName.empty()) device = tag.m_strProtocolName.c_str(); if(!tag.m_strProtocolRevision.empty()) calib = tag.m_strProtocolRevision.c_str(); } status = JSInit( &m_jsd, device, calib, JSFlagNonBlocking ); if(status != JSSuccess) { JSClose(&m_jsd); return false; } VistaPropertyList &oWrite = m_pInfo->GetInfoPropsWrite(); oWrite.SetValue("NAME", (m_jsd.name ? std::string(m_jsd.name) : "<none>")); oWrite.SetValue("DEVICENAME", (m_jsd.device_name ? std::string(m_jsd.device_name) : "<none>")); oWrite.SetValue("CALIBRATIONFILE", (m_jsd.calibration_file ? std::string(m_jsd.calibration_file) : "<none>")); for(unsigned int n=0; n < 16; ++n) { if(JSIsAxisAllocated(&m_jsd, n)) { // ok, we have that axis js_axis_struct *axis_ptr = m_jsd.axis[n]; float nMin[3], nMax[3]; nMin[0] = nMin[1] = nMin[2] = 0.0f; nMax[0] = nMax[1] = nMax[2] = 0.0f; nMin[0] = axis_ptr->min; nMax[0] = axis_ptr->max; m_pWorkspace->SetWorkspace("AXIS_"+VistaAspectsConversionStuff::ConvertToString(n), VistaBoundingBox(nMin, nMax)); nMin[0] = axis_ptr->dz_min; nMax[0] = axis_ptr->dz_max; m_pWorkspace->SetWorkspace("DEADZONE_"+VistaAspectsConversionStuff::ConvertToString(n), VistaBoundingBox(nMin, nMax)); nMin[0] = axis_ptr->corr_coeff_min1; nMax[0] = axis_ptr->corr_coeff_max1; m_pWorkspace->SetWorkspace("CORR_COEFF1_"+VistaAspectsConversionStuff::ConvertToString(n), VistaBoundingBox(nMin, nMax)); nMin[0] = axis_ptr->corr_coeff_min2; nMax[0] = axis_ptr->corr_coeff_max2; m_pWorkspace->SetWorkspace("CORR_COEFF2_"+VistaAspectsConversionStuff::ConvertToString(n), VistaBoundingBox(nMin, nMax)); } } m_bOpened = true; return true; }