当前位置: 首页>>代码示例>>C++>>正文


C++ JSIOCGNAME函数代码示例

本文整理汇总了C++中JSIOCGNAME函数的典型用法代码示例。如果您正苦于以下问题:C++ JSIOCGNAME函数的具体用法?C++ JSIOCGNAME怎么用?C++ JSIOCGNAME使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了JSIOCGNAME函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的JSIOCGNAME函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。