/* JoystickController.cpp a module for trackd to use a standard joystick as a controller. (c) 2003 ben chang (ben@bcchang.com) */ #ifndef WIN32 #include #include #include #include #include #include "MessageH.h" #include "BaseMod.h" #include "JoystickController.h" #include #include #include #include #else #include #include #include "MessageH.h" #include "BaseMod.h" #include "JoystickController.h" #include #include #include #include #include #endif // Please don't modify functions below, createDev and deleteDev, // EXCEPT FOR THE NAME OF THE CLASS. #ifndef _NO_DLL extern "C" LINKAGE CBase *createDev(void *config, CMessageH *p_msgh) { CBase *tempDev=NULL; tempDev = new JoystickController(config, p_msgh); return tempDev; } extern "C" LINKAGE bool deleteDev(CBase *dev) { if (dev==NULL) return false; JoystickController *tempDev = (JoystickController *)dev; delete tempDev; return true; } #endif // JoystickController Constructor // This can be used to initialize member variables. // The member variables of CBaseMod are initialized in its own constructor. // Therefore they dont need to be initialized here. JoystickController::JoystickController(void *_config, CMessageH *p_msgh) :CBaseMod(_config, p_msgh) { // initialize all controllers to be not used for (int i=0;idef.token[0]==NULL) { m_numCons = 1; } // Check if proper number of controllers is entered and if correct, assigns // m_numCons the actual no of controllers based on user input. else if ((unsigned int)atoi(config->def.token[0])>=1 && (unsigned int)atoi(config->def.token[0])<=m_maxNumCons) { m_numCons = (int)atoi(config->def.token[0]); } // The value for the number of sensors are invalid. else { cout << "Invalid Number of Controllers on Line " << config->def.lineNum << "." << endl; return -1; } // Read config info, such as the the name of the port and scaling for the valuators for (i=0;i<16;++i) valScale[i]=1; numVals = 2; numBut = 6; strcpy (port,defaultPort); for (i=0;inumOpts;i++) { // port if (strcmp(config->opt[i].name,"port")==0) { strcpy (port,config->opt[i].token[0]); } // scale else if (strcmp(config->opt[i].name,"scale")==0) { for (j=0;jopt[i].numTokens;j++) valScale[j]=atof(config->opt[i].token[j]); } // number of valuators else if (strcmp(config->opt[i].name,"valuators")==0) { numVals = atoi(config->opt[i].token[0]); } // number of buttons else if (strcmp(config->opt[i].name,"buttons")==0) { numBut = atoi(config->opt[i].token[0]); } } // InitTables initialize internal tables based on the info received from // config and m_numTras, m_numCons, m_maxNumTras, m_maxNumCons etc. if (!initTables()) { return -1; } // initialize controller datatable for each controller con[0]=true; j=1; for (i=0; iprintInfoMsg("DEVICE TYPE : JoystickController"); // Print version number mp_msgh->printInfoMsg("VERSION : ", false); cout << JoystickController_VERSION << endl; // Print port mp_msgh->printfInfoMsg("Port : %s\n", port); // Valuator Scaling mp_msgh->printfInfoMsg("Scaling : %f, %f, %f\n", valScale[0],valScale[1],valScale[2]); // call this to print common config return printBaseConfig(); }