本文整理汇总了C++中JSIOCGNAME函数的典型用法代码示例。如果您正苦于以下问题:C++ JSIOCGNAME函数的具体用法?C++ JSIOCGNAME怎么用?C++ JSIOCGNAME使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了JSIOCGNAME函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: malloc
char *ljoy_GetName(int id)
{
char *name = malloc(128);
if(ioctl(id,JSIOCGNAME(128),name) < 0)
strcpy(name,"Unknown");
return(name);
}
开发者ID:pez2001,项目名称:libjoy,代码行数:7,代码来源:libjoy.c
示例2: vrpn_Analog
vrpn_Joylin::vrpn_Joylin(char * name,
vrpn_Connection * c,
char *portname):
vrpn_Analog(name, c), vrpn_Button_Filter(name, c)
{
namelen = 128;
num_channel = 2; // inherited : default for generic me-know-nothing PC joystick
num_buttons = 2; // inherited : this value is corrected by the ioctl call below.
fd = -1;
version = 0x000800;
name = new char[namelen];
strncpy(name, "Unknown", namelen); // paranoia for future changes of namelen
name[namelen-1] = 0;
if ((fd = open(portname, O_RDONLY)) < 0) { /* FIX LATER */
fprintf(stderr, "vrpn_Joylin constructor could not open %s", portname);
perror(" joystick device");
exit(1);
}
ioctl(fd, JSIOCGVERSION, &version);
ioctl(fd, JSIOCGAXES, &num_channel);
ioctl(fd, JSIOCGBUTTONS, &num_buttons);
ioctl(fd, JSIOCGNAME(namelen), name);
fprintf(stderr, "Joystick (%s) has %d axes and %d buttons. Driver version is %d.%d.%d.\n",
name, num_channel, num_buttons, version >> 16, (version >> 8) & 0xff, version & 0xff);
}
开发者ID:ajmontag,项目名称:vrpn,代码行数:29,代码来源:vrpn_Joylin.C
示例3: isJoyName
static bool isJoyName(ifc_type_t ifc, int fd, void *param)
{
const char *joystickName = (const char *)param;
char name[NAME_LENGTH] = "Unknown";
switch(ifc){
case e_JS:
if(ioctl(fd, JSIOCGNAME(NAME_LENGTH), name) < 0){
ltr_int_my_perror("ioctl(JSIOCGNAME)");
return false;
}
break;
case e_EVDEV:
if(ioctl(fd, EVIOCGNAME(NAME_LENGTH), name) < 0){
ltr_int_my_perror("ioctl(EVIOCGNAME)");
return false;
}
break;
}
//printf("Received name '%s'.\n", name);
size_t max_len = (strlen(joystickName) < NAME_LENGTH) ? strlen(joystickName) : NAME_LENGTH;
if(strncmp(name, joystickName, max_len) == 0){
return true;
}
return false;
}
开发者ID:uglyDwarf,项目名称:linuxtrack,代码行数:25,代码来源:joy.c
示例4: nglInputDeviceInstance
nglInputDeviceLinux::nglInputDeviceLinux (const nglPath& rDevice) : nglInputDeviceInstance(), nglEvent()
{
mFlags = Read|Error;
mFD = open((char*)rDevice.GetPathName().GetChars(), O_RDONLY);
if (mFD == -1)
return;
char byte;
char name[128];
// Get number of axes
ioctl(mFD, JSIOCGAXES, &byte);
mAxes.resize(byte);
// Get number of buttons
ioctl(mFD, JSIOCGBUTTONS, &byte);
mButtons.resize(byte);
// Fetch name
if (ioctl(mFD, JSIOCGNAME(sizeof(name)), name) < 0)
mName = "unkown";
else
mName = name;
// Synthetize port name
mPort.Format("%s", rDevice.GetPathName().GetChars());
App->AddEvent(this);
}
开发者ID:JamesLinus,项目名称:nui3,代码行数:29,代码来源:nglInputDevice_Linux.cpp
示例5: m_joy_fd
JoystickDriverLinux::JoystickDriverLinux() :
m_joy_fd(0),
m_initialized(false)
{
if ((m_joy_fd = open("/dev/input/js0", O_RDONLY)) < 0)
{
return; // This will keep the driver uninitialized and reporting 0 joysticks
}
// Set to non-blocking reads
fcntl(m_joy_fd, F_SETFL, O_NONBLOCK);
char name[NAME_LENGTH] = "Unknown";
ioctl(m_joy_fd, JSIOCGNAME(NAME_LENGTH), name);
m_name = name;
unsigned char axis = 0;
unsigned char buttons = 0;
ioctl(m_joy_fd, JSIOCGAXES, &axis);
ioctl(m_joy_fd, JSIOCGBUTTONS, &buttons);
m_numberOfAxis = (unsigned int) axis;
m_numberOfButtons = (unsigned int) buttons;
m_initialized = true;
}
开发者ID:michaelgregorius,项目名称:ode2joy,代码行数:26,代码来源:JoystickDriverLinux.cpp
示例6: storeJoyNames
static bool storeJoyNames(ifc_type_t ifc, int fd, void *param)
{
joystickNames_t *jsNames = (joystickNames_t *)param;
char name[NAME_LENGTH] = "Unknown";
switch(ifc){
case e_JS:
if(ioctl(fd, JSIOCGNAME(NAME_LENGTH), name) < 0){
ltr_int_my_perror("ioctl(JSIOCGNAME)");
return false;
}
break;
case e_EVDEV:
if(ioctl(fd, EVIOCGNAME(NAME_LENGTH), name) < 0){
ltr_int_my_perror("ioctl(EVIOCGNAME)");
return false;
}
break;
}
if(!arrayBigEnough((void ***)&(jsNames->nameList), &(jsNames->nameListSize), &(jsNames->namesFound), sizeof(char *))){
return false;
}
jsNames->nameList[jsNames->namesFound] = strdup(name);
++jsNames->namesFound;
return false;
}
开发者ID:uglyDwarf,项目名称:linuxtrack,代码行数:29,代码来源:joy.c
示例7: window
InputDeviceProvider_LinuxJoystick::InputDeviceProvider_LinuxJoystick(X11Window *window, const std::string &device)
: window(window), device(device), fd(-1), new_event(false)
{
fd = open(device.c_str(), O_RDONLY | O_NONBLOCK);
if (fd == -1)
{
throw Exception("Cannot Open Joystick");
}
char number_of_axes;
char number_of_buttons;
ioctl(fd, JSIOCGBUTTONS, &number_of_buttons);
ioctl(fd, JSIOCGAXES, &number_of_axes);
char name_cstr[256] = { '\0' };
if (ioctl(fd, JSIOCGNAME(sizeof(name_cstr)), name_cstr) < 0)
strncpy(name_cstr, "Unknown", sizeof(name_cstr));
_name = name_cstr;
axis_states.resize(number_of_axes);
button_states.resize(number_of_buttons);
}
开发者ID:rombust,项目名称:UICore,代码行数:25,代码来源:input_device_provider_linuxjoystick.cpp
示例8: stjoystick_sys_get_name
const char* stjoystick_sys_get_name(int index)
{
int fd;
static char namebuf[128];
char *name;
SDL_logical_joydecl(int oindex = index);
#ifndef NO_LOGICAL_JOYSTICKS
SDL_joylist_head(index, index);
#endif
name = NULL;
fd = open(SDL_joylist[index].fname, O_RDONLY, 0);
if ( fd >= 0 ) {
if (
#if SDL_INPUT_LINUXEV
(ioctl(fd, EVIOCGNAME(sizeof(namebuf)), namebuf) <= 0) &&
#endif
(ioctl(fd, JSIOCGNAME(sizeof(namebuf)), namebuf) <= 0) ) {
name = SDL_joylist[index].fname;
} else {
name = namebuf;
}
close(fd);
#ifndef NO_LOGICAL_JOYSTICKS
if (SDL_joylist[oindex].prev || SDL_joylist[oindex].next || index!=oindex)
{
LogicalSuffix(SDL_joylist[oindex].logicalno, namebuf, 128);
}
#endif
}
return name;
}
开发者ID:sdunham,项目名称:cs315-Katamari,代码行数:34,代码来源:STJoystick_linux.cpp
示例9: joystick_load
bool joystick_load(int id)
{
checkPositiveId(false);
if (size_t(id) >= enigma::joysticks.size())
enigma::joysticks.resize(id+1, 0);
else
delete enigma::joysticks[id];
char sps[32]; sprintf(sps,"/dev/input/js%d",id);
string devn(sps);
int device = open(devn.c_str(), O_RDONLY|O_NONBLOCK);
if (device == -1)
return false;
int ac = 4, bc = 4;
ioctl(device, I_SRDOPT, RMSGN);
if (ioctl(device, JSIOCGAXES, &ac) or ioctl(device, JSIOCGBUTTONS, &bc))
return (close(device), false);
char name[256]; name[0] = 0;
if (ioctl(device, JSIOCGNAME(256), name) > 0)
devn = name;
printf("Joystick name: %s\n",name);
enigma::e_joystick* const jsn = new enigma::e_joystick(device, devn, ac, bc);
enigma::joysticks[id] = jsn;
enigma::handle_joystick(jsn);
return true;
}
开发者ID:DarkAceZ,项目名称:enigma-dev,代码行数:29,代码来源:LINUXjoystick.cpp
示例10: ioctl
MJoystickLinux::MJoystickLinux(const char* joydev)
{
if(joydev == NULL)
{
return;
}
m_numAxes = 0;
m_numButtons = 0;
m_axis = NULL;
m_button = NULL;
m_dAxis = NULL;
if((m_file = open(joydev, O_RDONLY)) == -1)
{
return;
}
ioctl(m_file, JSIOCGAXES, &m_numAxes);
ioctl(m_file, JSIOCGBUTTONS, &m_numButtons);
ioctl(m_file, JSIOCGNAME(80), &m_joystickName);
m_axis = (int*) calloc(m_numAxes, sizeof(int));
m_dAxis = (float*) calloc(m_numAxes, sizeof(float));
m_button = (char*) calloc(m_numButtons, sizeof(char));
fcntl(m_file, F_SETFL, O_NONBLOCK);
}
开发者ID:Sponk,项目名称:maratis,代码行数:28,代码来源:MJoystickLinux.cpp
示例11: other
/*---------------------------------------------------------------
Name : SetJoystick
Argument : void
Return : 0 (succeed), other (failed)
About : Set up the Joystick controler
Version : Ver 1.0
Date : 2014/03/21
Author : Ryodo Tanaka (Kyushu Institute of Technology)
----------------------------------------------------------------- */
int SetJoystick(void)
{
//File open
if( (JSfd=open(PORT, O_RDONLY)) == -1){
printLOG("File Open JoyStick");
return 1;
}
//Get JoyStick information
ioctl(JSfd, JSIOCGAXES, &num_of_axis);
ioctl(JSfd, JSIOCGBUTTONS, &num_of_buttons);
ioctl(JSfd, JSIOCGNAME(80), &JSname);
//Get data space for axis & buttons
axis = (int*)calloc(num_of_axis, sizeof(int));
if(!axis){
printLOG("calloc JoyStick axis");
return 2;
}
button = (char*)calloc(num_of_buttons, sizeof(char));
if(!button){
printLOG("calloc JoyStick axis");
return 3;
}
//Use non-blocking mode
fcntl(JSfd, F_SETFL, O_NONBLOCK);
printf("%s\tis Connected ...\n", JSname);
return 0;
}
开发者ID:CIR-KIT,项目名称:4thRobot_C,代码行数:42,代码来源:control.c
示例12: clean
void Controler::update()
{
char tmp;
std::stringstream stm;
stm << "/dev/input/js" << _id;
if (access(stm.str().c_str(), R_OK) == -1)
clean();
if (_fd != -1)
return ;
_fd = open(stm.str().c_str(), O_RDONLY);
if (_fd == -1)
clean();
ioctl(_fd, JSIOCGAXES, &tmp);
if (tmp < 2 || tmp > 50)
clean();
_axe.resize(tmp);
ioctl(_fd, JSIOCGBUTTONS, &tmp);
if (tmp < 6 || tmp > 80)
clean();
_but.resize(tmp);
ioctl(_fd, JSIOCGNAME(sizeof(_name)), &_name);
fcntl(_fd, F_SETFL, O_NONBLOCK);
//std::cout << _name << " Axe[" << _axe.size() <<
// "] Buttons [" << _but.size() << "]" << std::endl;
}
开发者ID:Yax42,项目名称:havetofly,代码行数:27,代码来源:Controler.cpp
示例13: updateCapabilities
void updateCapabilities(int joystick)
{
if (joystick<0 || MAXJOYSTICKS<=joystick) {
return;
}
capabilities[joystick].povs=0;
capabilities[joystick].axes=0;
capabilities[joystick].buttons=0;
capabilities[joystick].version=0;
strcpy(capabilities[joystick].name, "Unknown");
if (fd[joystick]<0 && openJoystick(joystick)<0)
return;
ioctl(fd[joystick], JSIOCGAXES, &capabilities[joystick].axes);
ioctl(fd[joystick], JSIOCGBUTTONS, &capabilities[joystick].buttons);
ioctl(fd[joystick], JSIOCGVERSION, &capabilities[joystick].version);
int nameLen = ioctl(fd[joystick], JSIOCGNAME(JOYSTICK_NAME_SIZE), capabilities[joystick].name);
if (nameLen > 0) {
// NULL terminate just in case.
capabilities[joystick].name[JOYSTICK_NAME_SIZE - 1] = 0;
}
else {
strcpy(capabilities[joystick].name, "Unknown");
}
}
开发者ID:Canardou,项目名称:ptut,代码行数:28,代码来源:LinuxJoystick.cpp
示例14: Initialize
// Private methods -----------------------------------------------
// Runs all the necessary functions to ensure connectivity
void Initialize(Controller controller){
int fd = open(JOYSTICK_DEVICE, O_RDONLY);
if(fd > 0){
char name[128];
int version;
js_fd = fd;
controller->active = true;
// store driver version, if it is less than
// version 1.0 there will be no support for it
ioctl(fd, JSIOCGVERSION, &version);
if (version < 0x010000){
return;
}
controller->version = version;
// store size of the name and makes sure its not null
// if its valid store the name into our struct.
int ret = ioctl(fd, JSIOCGNAME(sizeof(name)), name);
if (ret < 0){
return;
}
controller->name = strdup(name);
deviceInfo(controller);
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_create(&controller->thread,&attr, Loop, (void*)controller);
}
}
开发者ID:ReevMich,项目名称:RC-Car-With-Vision-Tracking,代码行数:35,代码来源:DS4.c
示例15: joystick_init
int joystick_init(const char* device)
{
if((joy.fd = open(device, O_RDONLY)) < 0)
return 1;
joy.mapping = 0;
joy.calibration = 0;
ioctl(joy.fd, JSIOCGNAME(JOYSTICK_NAME_LEN), joy.name);
ioctl(joy.fd, JSIOCGAXES, &joy.axes);
ioctl(joy.fd, JSIOCGBUTTONS, &joy.buttons);
ioctl(joy.fd, JSIOCGVERSION, &joy.version);
/*MSG("Joystick (%s) has %d axes and %d buttons. Driver version is %d.%d.%d.\n",*/
/*joy.name, joy.axes, joy.buttons,*/
/*joy.version >> 16, (joy.version >> 8) & 0xff, joy.version & 0xff);*/
joy.axis = calloc(joy.axes, sizeof(int));
joy.button = calloc(joy.buttons, sizeof(int));
/*if(pthread_mutex_init(&js_update_mtx, NULL))*/
/*return 2;*/
if(pthread_create(&joystick_update_tid, NULL, &joystick_update_thread, NULL))
return 3;
MSG("Joystick %s opened\n", device);
return 0;
}
开发者ID:kasikS,项目名称:CTdrone,代码行数:30,代码来源:joystick.c
示例16: string
bool joystick::connect(const unsigned id)
{
string str = string("/dev/input/js") << string::dec(id);
if((descriptor_ = open(str(), O_RDONLY)) > 0)
{
fcntl(descriptor_, F_SETFL, O_NONBLOCK);
char axis_count, button_count, name[128];
ioctl(descriptor_, JSIOCGAXES, &axis_count);
ioctl(descriptor_, JSIOCGBUTTONS, &button_count);
if(ioctl(descriptor_, JSIOCGNAME(sizeof(name)), name))
name_ = name;
for(signed pos = name_.find(" "); pos != -1; pos = name_.find(" "))
name_.erase(pos, 1);
while(name_.substr(-1) == " ")
name_.erase(-1);
axes_ = axis_count;
buttons_ = button_count;
id_ = static_cast<signed>(id);
events_.clear();
return true;
}
return false;
}
开发者ID:rexso,项目名称:battleai,代码行数:32,代码来源:joystick.cpp
示例17: QString
void Joystick::create(const char* deviceFileName)
{
int axes = 0;
int buttons = 0;
char deviceName[JS_NAME_LENGTH + 1];
/* Init the poll thread to NULL */
m_thread = 0;
m_fd = ::open(deviceFileName, O_RDONLY);
if (m_fd != -1)
{
/* Copy the device file name to struct */
m_fdName = QString(deviceFileName);
/* Get number of axes */
if (ioctl(m_fd, JSIOCGAXES, &axes) == -1)
{
axes = 0;
perror("ioctl");
}
else
{
fillAxisNames(axes);
}
/* Get number of buttons */
if (ioctl(m_fd, JSIOCGBUTTONS, &buttons) == -1)
{
buttons = 0;
perror("ioctl");
}
else
{
fillButtonNames(buttons);
}
/* Get the name of the joystick device */
if (ioctl(m_fd, JSIOCGNAME(JS_NAME_LENGTH), &deviceName) == -1)
{
strcpy(deviceName, "Unknown");
perror("ioctl");
}
m_name = QString(deviceName);
printf("Device: %s\nName: %s\nAxes: %d\nButtons: %d\n",
(const char*) m_fdName, (const char*) m_name, axes, buttons);
/* Close this joystick until we really want to use it */
close();
m_valid = true;
}
else
{
m_valid = false;
}
}
开发者ID:speakman,项目名称:qlc,代码行数:59,代码来源:joystick.cpp
示例18: GetProductName
wxString wxJoystick::GetProductName() const
{
char name[128];
if (ioctl(m_device, JSIOCGNAME(sizeof(name)), name) < 0)
strcpy(name, "Unknown");
return wxString(name, wxConvLibc);
}
开发者ID:70michal19,项目名称:dolphin,代码行数:8,代码来源:joystick.cpp
示例19: identifier
/*
Function: joy_open
Opens a USB joystick and fills its information.
Parameters:
joynumber - Joystick's identifier (0 reserved for GP2X's builtin Joystick).
Returns:
Filled usbjoy structure.
*/
struct usbjoy *joy_open(int joynumber)
{
int fd;
char path [128];
struct usbjoy * joy = NULL;
struct js_event event;
static char insmod_done = 0;
// notaz: on my system I get unresolved input_* symbols, so have to 'insmod input' too
// also we should insmod only once, not on every joy_open() call.
if (!insmod_done) {
system ("insmod input");
system ("insmod joydev"); // Loads joydev module
insmod_done = 1;
}
if (joynumber == 0) {
}
else if (joynumber > 0) {
sprintf (path, "/dev/input/js%d", joynumber-1);
fd = open(path, O_RDONLY, 0);
if (fd > 0) {
joy = (struct usbjoy *) malloc(sizeof(*joy));
if (joy == NULL) { close(fd); return NULL; }
memset(joy, 0, sizeof(*joy));
// Set the joystick to non-blocking read mode
fcntl(fd, F_SETFL, O_NONBLOCK);
// notaz: maybe we should flush init events now.
// My pad returns axis as active when I plug it in, which is kind of annoying.
while (read(fd, &event, sizeof(event)) > 0);
// Joystick's file descriptor
joy->fd = fd;
// Joystick's name
ioctl(joy->fd, JSIOCGNAME(128*sizeof(char)), joy->name);
// Joystick's device
strcpy(joy->device, path);
// Joystick's buttons
ioctl(joy->fd, JSIOCGBUTTONS, &joy->numbuttons);
// Joystick's axes
ioctl(joy->fd, JSIOCGAXES, &joy->numaxes);
// Joystick's type (derived from name)
if (strncasecmp(joy->name, "logitech", strlen("logitech")) == 0)
joy->type = JOY_TYPE_LOGITECH;
else joy->type = JOY_TYPE_GENERIC;
} else {
// printf ("ERROR: No Joystick found\n");
}
}
return joy;
}
开发者ID:clach04,项目名称:picodrive-rzx50,代码行数:72,代码来源:usbjoy.c
示例20: main
int main()
{
int joy_fd, *axis=NULL, num_of_axis=0, num_of_buttons=0, x;
char *button=NULL, name_of_joystick[80];
struct js_event js;
if( ( joy_fd = open( JOY_DEV , O_RDONLY)) == -1 )
{
printf( "Couldn't open joystick\n" );
return -1;
}
ioctl( joy_fd, JSIOCGAXES, &num_of_axis );
ioctl( joy_fd, JSIOCGBUTTONS, &num_of_buttons );
ioctl( joy_fd, JSIOCGNAME(80), &name_of_joystick );
axis = (int *) calloc( num_of_axis, sizeof( int ) );
button = (char *) calloc( num_of_buttons, sizeof( char ) );
printf("Joystick detected: %s\n\t%d axis\n\t%d buttons\n\n"
, name_of_joystick
, num_of_axis
, num_of_buttons );
fcntl( joy_fd, F_SETFL, O_NONBLOCK ); /* use non-blocking mode */
while( 1 ) /* infinite loop */
{
/* read the joystick state */
read(joy_fd, &js, sizeof(struct js_event));
/* see what to do with the event */
switch (js.type & ~JS_EVENT_INIT)
{
case JS_EVENT_AXIS:
axis [ js.number ] = js.value;
break;
case JS_EVENT_BUTTON:
button [ js.number ] = js.value;
break;
}
/* print the results */
printf( "X1: %6d Y1: %6d ", (int)((axis[0]+32767)*0.00091554131), (int)((axis[1]+32767)*0.00091554131));
printf( "X2: %6d Y2: %6d ", (int)((axis[2]+32767)*0.00091554131), (int)((axis[3]+32767)*0.00091554131));
printf( "X3: %6d Y3: %6d ", (int)((axis[4]+32767)*0.00091554131), (int)((axis[5]+32767)*0.00091554131));
for( x=0 ; x<num_of_buttons ; ++x )
printf("B%d: %d ", x, button[x] );
printf(" \r");
fflush(stdout);
}
close( joy_fd ); /* too bad we never get here */
return 0;
}
开发者ID:aprgl,项目名称:jtag_socket,代码行数:58,代码来源:joystick.c
注:本文中的JSIOCGNAME函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论