Пример #1
0
Joystick::Joystick(VRDevice::Factory* sFactory,VRDeviceManager* sDeviceManager,Misc::ConfigurationFile& configFile)
    :VRDevice(sFactory,sDeviceManager,configFile),
     joystickDeviceFd(open(configFile.retrieveString("./joystickDeviceFile").c_str(),O_RDONLY)),
     axisGains(0),
     reportEvents(false),
     buttonStates(0),valuatorStates(0)
{
    /* Check if the joystick device port was properly opened: */
    if(joystickDeviceFd<0)
        Misc::throwStdErr("Joystick: Unable to open joystick device port");

    /* Query the joystick's geometry: */
    char cNumButtons,cNumAxes;
    ioctl(joystickDeviceFd,JSIOCGBUTTONS,&cNumButtons);
    ioctl(joystickDeviceFd,JSIOCGAXES,&cNumAxes);
#ifdef VERBOSE
    /* Query the joystick's name: */
    char joystickName[256];
    if(ioctl(joystickDeviceFd,JSIOCGNAME(sizeof(joystickName)),joystickName)>=0)
    {
        joystickName[sizeof(joystickName)-1]='\0';
        printf("Joystick: %s with %d buttons and %d axes found\n",joystickName,int(cNumButtons),int(cNumAxes));
    }
    else
        printf("Joystick: Unknown joystick with %d buttons and %d axes found\n",int(cNumButtons),int(cNumAxes));
#endif

    /* Set device configuration: */
    setNumTrackers(0,configFile);
    setNumButtons(cNumButtons,configFile);
    setNumValuators(cNumAxes,configFile);

    /* Initialize gain arrays: */
    axisGains=new float[getNumValuators()];
    for(int i=0; i<getNumValuators(); ++i)
    {
        char axisGainTag[40];
        snprintf(axisGainTag,sizeof(axisGainTag),"./axisGain%d",i);
        axisGains[i]=configFile.retrieveValue<float>(axisGainTag,1.0f);
    }

    /* Initialize state arrays: */
    buttonStates=new bool[getNumButtons()];
    for(int i=0; i<getNumButtons(); ++i)
        buttonStates[i]=false;
    valuatorStates=new float[getNumValuators()];
    for(int i=0; i<getNumValuators(); ++i)
        valuatorStates[i]=0.0f;

    /* Start device thread (joystick device cannot be disabled): */
    startDeviceThread();
}
Пример #2
0
void CButtonGroup::addButton(IButton * button, int pos)
{
    if (button == nullptr)
        return;

    int nbr = getNumButtons();

    // On vérifie que le bouton n'est pas déjà dans la liste
    std::list<IButton *>::iterator it = std::find(m_buttons.begin(), m_buttons.end(), button);

    if (it == m_buttons.end())
    {
        if (pos < 0 || pos >= nbr)
        {
            m_buttons.push_back(button);
        }
        else
        {
            it = m_buttons.begin();
            std::advance(it, pos);
            m_buttons.insert(it, button);
        }

        button->setGroup(this);

        // Si c'est le seul bouton et que le groupe est exclusif, il doit être enfoncé
        if (nbr == 0 && m_exclusive)
        {
            button->setDown();
        }
    }
}
Пример #3
0
KeyID
OSXKeyState::CUCHRKeyResource::getKey(UInt32 table, UInt32 button) const
{
	assert(table < getNumTables());
	assert(button < getNumButtons());

	const UInt8* base   = reinterpret_cast<const UInt8*>(m_resource);
	const UCKeyOutput* cPtr = reinterpret_cast<const UCKeyOutput*>(base +
								m_cti->keyToCharTableOffsets[table]);

  const UCKeyOutput c = cPtr[button];

	KeySequence keys;
	switch (c & kUCKeyOutputTestForIndexMask) {
	case kUCKeyOutputStateIndexMask:
		if (!getDeadKey(keys, c & kUCKeyOutputGetIndexMask)) {
			return kKeyNone;
		}
		break;

	case kUCKeyOutputSequenceIndexMask:
	default:
		if (!addSequence(keys, c)) {
			return kKeyNone;
		}
		break;
	}

	// XXX -- no support for multiple characters
	if (keys.size() != 1) {
		return kKeyNone;
	}

	return keys.front();
}
Пример #4
0
IButton * CButtonGroup::getButton(int pos) const
{
    if (pos < 0 || pos >= getNumButtons())
    {
        return nullptr;
    }

    std::list<IButton *>::const_iterator it = m_buttons.begin();
    std::advance(it, pos);

    return (it == m_buttons.end() ? nullptr : *it);
}
Пример #5
0
void CButtonGroup::removeButton(int pos)
{
    if (pos < 0 || pos >= getNumButtons())
        return;

    std::list<IButton *>::iterator it = m_buttons.begin();
    std::advance(it, pos);

    if (it != m_buttons.end())
    {
        (*it)->setGroup(nullptr);
        m_buttons.erase(it);
    }
}
Пример #6
0
void HIDDevice::start(void)
	{
	/* Set device manager's button and valuator states to current states: */
	{
	Threads::Mutex::Lock stateLock(stateMutex);
	for(int i=0;i<getNumButtons();++i)
		setButtonState(i,buttonStates[i]);
	for(int i=0;i<getNumValuators();++i)
		setValuatorState(i,valuatorStates[i]);
	
	/* Start reporting events to the device manager: */
	reportEvents=true;
	}
	}
Пример #7
0
void ofxGamepad::draw(int x, int y)
{
	int curX=0;
	int highestY;

	ofPushMatrix();
	ofTranslate(x, y);
	ofSetColor(255);
	ofPushMatrix();
	ofRotate(90);
	ofDrawBitmapString(name+" ("+ofToString(id)+")", 0, 0);
	ofPopMatrix();
	curX=17;

	int margin=3;
	ofRectangle axisSize(curX,0,85, 17);
	for(int i=0; i<getNumAxis(); i++) {
		ofSetColor(70);
		ofRect(axisSize);
		ofSetColor(255);
		float x =  ofMap(getAxisValue(i), -1, 1, axisSize.x, axisSize.width+axisSize.x);
		ofLine(x, axisSize.y, x, axisSize.y+axisSize.height);
		ofSetColor(20);
		ofDrawBitmapString(ofToString(i), axisSize.x, axisSize.y+axisSize.height-1);
		axisSize.y+=axisSize.height+margin;
		if(axisSize.y>highestY)
			highestY=axisSize.y;
	}

	curX+=axisSize.width+margin;
	ofRectangle btnSize(curX,0,17,17);
	for(int i=0; i<getNumButtons(); i++) {
		if(getButtonValue(i))
			ofSetColor(255);
		else
			ofSetColor(70);
		ofRect(btnSize);
		btnSize.y+=btnSize.height+margin;
		ofSetColor(20);
		ofDrawBitmapString(ofToString(i), btnSize.x, btnSize.y-4);
		if(btnSize.y>highestY)
			highestY=axisSize.y;
	}
	curX+=btnSize.width;

	ofPopMatrix();

	drawSize.x=curX;
	drawSize.y=highestY;
}
Пример #8
0
	bool Joystick::isDown(int index, int * buttonlist)
	{
		if (!verifyJoystick(index))
			return false;

		int num = getNumButtons(index);

		for (int button = *buttonlist; button != -1; button = *(++buttonlist))
		{
			if (button >= 0 && button < num && SDL_JoystickGetButton(joysticks[index], button) == 1)
				return true;
		}

		return false;
	}
Пример #9
0
bool Joystick::connect() {
    if (joystickId < 0 || joystickId >= SdlWrap::getNumJoysticks()) return false;

    sdlJoystick = SDL_JoystickOpen(joystickId);
    if (sdlJoystick == NULL) {
        connected = false;
        return connected;
    }

    SDL_JoystickUpdate();

    axes.clear();
    axesZero.clear();
    buttons.clear();

    numAxes = getNumAxes();
    numButtons = getNumButtons();

    for (int i = 0; i < numAxes; i++) {
        axes.append(0);
    }


    for (int i = 0; i < numAxes; i++) {
        int threshold = 5000;
        qint16 axisOffset = SDL_JoystickGetAxis(sdlJoystick, i);
        if (axisOffset < threshold && axisOffset > -threshold) {
            axesZero.append(-axisOffset);
        } else {
            axesZero.append(0);
        }
    }


    for (int i = 0; i < numButtons; i++) {
        ButtonState state;
        state.lastState = false;
        state.currentState = false;
        buttons.append(state);
    }

    connected = true;
    return connected;
}
Пример #10
0
ofxGamepadLinux::ofxGamepadLinux(string f):ofxGamepad() {
	filename=f;

	if ((fd = open(filename.c_str(), O_RDONLY)) < 0) {
		std::ostringstream str;
		str << filename << ": " << strerror(errno);
		throw std::runtime_error(str.str());
	} else {
		// ok
		uint8_t num_axis   = 0;
		uint8_t num_button = 0;
		ioctl(fd, JSIOCGAXES,    &num_axis);
		ioctl(fd, JSIOCGBUTTONS, &num_button);
		setNumAxis(num_axis);
		setNumButtons(num_button);

		// Get Name
		char name_c_str[1024];
		if (ioctl(fd, JSIOCGNAME(sizeof(name_c_str)), name_c_str) < 0) {
			std::ostringstream str;
			str << filename << ": " << strerror(errno);
			throw std::runtime_error(str.str());
		} else {
			name = name_c_str;
		}
		setName(name);

		fcntl( fd, F_SETFL, O_NONBLOCK );
	}

	string msg=name;
	msg += ": "+ofToString(getNumAxis())+" axis";
	msg += ", "+ofToString(getNumButtons())+" buttons";
	ofLog(OF_LOG_NOTICE, msg);

	// setup force feedback
	setupFF();
}
Пример #11
0
	QPixmap ThymioMoveAction::image(bool on)
	{
		QPixmap pixmap(256, 256);
		pixmap.fill(buttonColor);
		QPainter painter(&pixmap);
		painter.setRenderHint(QPainter::Antialiasing);

		painter.translate(QPointF(128,128));
		painter.scale(0.4,0.4);
		painter.rotate(thymioBody->rotation());
		thymioBody->paint(&painter, 0, 0);
		painter.resetTransform();

		for(int i=0; i<getNumButtons(); i++)
		{
			painter.translate(widgets[i]->pos());
			painter.scale(2.0, 2.3);
			sliders[i]->render(&painter);
			painter.resetTransform();
		}

		return pixmap;
	}
Пример #12
0
	void ThymioColorAction::setClicked(int i, int status) 
	{ 
		if(i<getNumButtons()) 
			sliders[i]->setSliderPosition(status); 		
	}
Пример #13
0
HIDDevice::HIDDevice(VRDevice::Factory* sFactory,VRDeviceManager* sDeviceManager,Misc::ConfigurationFile& configFile)
	:VRDevice(sFactory,sDeviceManager,configFile),
	 deviceFd(-1),
	 keyMap(0),
	 absAxisMap(0),relAxisMap(0),axisConverters(0),
	 reportEvents(false),
	 buttonStates(0),valuatorStates(0)
	{
	/* First option: Open device by explicit event device file name: */
	if(deviceFd<0)
		{
		std::string deviceFileName=configFile.retrieveString("./deviceFileName","");
		if(deviceFileName!="")
			{
			#ifdef VERBOSE
			printf("HIDDevice: Opening device %s\n",deviceFileName.c_str());
			fflush(stdout);
			#endif
			deviceFd=open(deviceFileName.c_str(),O_RDONLY);
			if(deviceFd<0)
				Misc::throwStdErr("HIDDevice: Unable to open device file \"%s\"",deviceFileName.c_str());
			}
		}
	
	/* Second option: Open device by vendor ID / product ID: */
	if(deviceFd<0)
		{
		std::string deviceVendorProductId=configFile.retrieveString("./deviceVendorProductId","");
		if(deviceVendorProductId!="")
			{
			/* Split ID string into vendor ID / product ID: */
			char* colonPtr;
			int vendorId=strtol(deviceVendorProductId.c_str(),&colonPtr,16);
			char* endPtr;
			int productId=strtol(colonPtr+1,&endPtr,16);
			if(*colonPtr!=':'||*endPtr!='\0'||vendorId<0||productId<0)
				Misc::throwStdErr("HIDDevice: Malformed vendorId:productId string \"%s\"",deviceVendorProductId.c_str());
			#ifdef VERBOSE
			printf("HIDDevice: Searching device %04x:%04x\n",vendorId,productId);
			fflush(stdout);
			#endif
			deviceFd=findDevice(vendorId,productId);
			if(deviceFd<0)
				Misc::throwStdErr("HIDDevice: No device with vendorId:productId %04x:%04x found",vendorId,productId);
			}
		}
	
	/* Third option: Open device by device name: */
	if(deviceFd<0)
		{
		std::string deviceName=configFile.retrieveString("./deviceName","");
		if(deviceName!="")
			{
			#ifdef VERBOSE
			printf("HIDDevice: Searching device %s\n",deviceName.c_str());
			fflush(stdout);
			#endif
			deviceFd=findDevice(deviceName.c_str());
			if(deviceFd<0)
				Misc::throwStdErr("HIDDevice: No device with name \"%s\" found",deviceName.c_str());
			}
		}
	
	/* Bail out if no device was found: */
	if(deviceFd<0)
		Misc::throwStdErr("HIDDevice: No device specified");
	
	/* Set number of trackers on device: */
	setNumTrackers(0,configFile);
	
	/* Query all feature types of the device: */
	unsigned char featureTypeBits[EV_MAX/8+1];
	memset(featureTypeBits,0,EV_MAX/8+1);
	if(ioctl(deviceFd,EVIOCGBIT(0,sizeof(featureTypeBits)),featureTypeBits)<0)
		Misc::throwStdErr("HIDDevice: Unable to query device feature types");
	
	/* Query the number of keys on the device: */
	if(featureTypeBits[EV_KEY/8]&(1<<(EV_KEY%8)))
		{
		#ifdef VERBOSE
		printf("HIDDevice: Initializing buttons...\n");
		fflush(stdout);
		#endif
		
		/* Query key features: */
		unsigned char keyBits[KEY_MAX/8+1];
		memset(keyBits,0,KEY_MAX/8+1);
		if(ioctl(deviceFd,EVIOCGBIT(EV_KEY,sizeof(keyBits)),keyBits)<0)
			Misc::throwStdErr("HIDDevice: Unable to query device key features");
		
		/* Initialize the key translation array: */
		keyMap=new int[KEY_MAX+1];
		int numKeys=0;
		for(int i=0;i<=KEY_MAX;++i)
			{
			if(keyBits[i/8]&(1<<(i%8)))
				{
				keyMap[i]=numKeys;
				++numKeys;
				}
			else
				keyMap[i]=-1;
			}
		
		/* Set number of buttons on device: */
		#ifdef VERBOSE
		printf("HIDDevice: %d buttons found\n",numKeys);
		fflush(stdout);
		#endif
		setNumButtons(numKeys,configFile);
		}
	else
		setNumButtons(0,configFile);
	
	/* Count the number of absolute and relative axes: */
	int numAxes=0;
	
	/* Query the number of absolute axes on the device: */
	if(featureTypeBits[EV_ABS/8]&(1<<(EV_ABS%8)))
		{
		#ifdef VERBOSE
		printf("HIDDevice: Initializing absolute axes...\n");
		fflush(stdout);
		#endif
		
		/* Query absolute axis features: */
		unsigned char absAxisBits[ABS_MAX/8+1];
		memset(absAxisBits,0,ABS_MAX/8+1);
		if(ioctl(deviceFd,EVIOCGBIT(EV_ABS,sizeof(absAxisBits)),absAxisBits)<0)
			Misc::throwStdErr("HIDDevice: Unable to query device absolute axis features");
		
		/* Initialize the axis translation array: */
		absAxisMap=new int[ABS_MAX+1];
		int numAbsAxes=0;
		for(int i=0;i<=ABS_MAX;++i)
			{
			if(absAxisBits[i/8]&(1<<(i%8)))
				{
				absAxisMap[i]=numAxes;
				++numAxes;
				++numAbsAxes;
				}
			else
				absAxisMap[i]=-1;
			}
		
		#ifdef VERBOSE
		printf("HIDDevice: %d absolute axes found\n",numAbsAxes);
		fflush(stdout);
		#endif
		}
	
	/* Query the number of relative axes on the device: */
	if(featureTypeBits[EV_REL/8]&(1<<(EV_REL%8)))
		{
		#ifdef VERBOSE
		printf("HIDDevice: Initializing relative axes...\n");
		fflush(stdout);
		#endif
		
		/* Query relative axis features: */
		unsigned char relAxisBits[REL_MAX/8+1];
		memset(relAxisBits,0,REL_MAX/8+1);
		if(ioctl(deviceFd,EVIOCGBIT(EV_REL,sizeof(relAxisBits)),relAxisBits)<0)
			Misc::throwStdErr("HIDDevice: Unable to query device relative axis features");
		
		/* Initialize the axis translation array: */
		relAxisMap=new int[REL_MAX+1];
		int numRelAxes=0;
		for(int i=0;i<=REL_MAX;++i)
			{
			if(relAxisBits[i/8]&(1<<(i%8)))
				{
				relAxisMap[i]=numAxes;
				++numAxes;
				++numRelAxes;
				}
			else
				relAxisMap[i]=-1;
			}
		
		#ifdef VERBOSE
		printf("HIDDevice: %d relative axes found\n",numRelAxes);
		fflush(stdout);
		#endif
		}
	
	/* Set number of valuators on device: */
	setNumValuators(numAxes,configFile);
		
	/* Initialize axis converters: */
	axisConverters=new AxisConverter[numAxes];
	
	if(absAxisMap!=0)
		{
		/* Initialize absolute axis converters: */
		#ifdef VERBOSE
		printf("HIDDevice: Initializing absolute axis converters\n");
		fflush(stdout);
		#endif
		for(int i=0;i<=ABS_MAX;++i)
			if(absAxisMap[i]>=0)
				{
				/* Query configuration of this axis: */
				input_absinfo absAxisConf;
				if(ioctl(deviceFd,EVIOCGABS(i),&absAxisConf)<0)
					Misc::throwStdErr("HIDDevice: Unable to query device absolute axis configuration");
				
				#ifdef VERBOSE
				printf("Axis %2d: min %d, max %d, fuzz %d, flat %d\n",absAxisMap[i],absAxisConf.minimum,absAxisConf.maximum,absAxisConf.fuzz,absAxisConf.flat);
				fflush(stdout);
				#endif
				
				/* Initialize converter with queried values: */
				AxisConverter& converter=axisConverters[absAxisMap[i]];
				float mid=Math::mid(absAxisConf.minimum,absAxisConf.maximum);
				converter=AxisConverter(absAxisConf.minimum,mid-absAxisConf.flat,mid+absAxisConf.flat,absAxisConf.maximum);
				
				/* Override axis settings from configuration file: */
				char axisSettingsTag[20];
				snprintf(axisSettingsTag,sizeof(axisSettingsTag),"axis%dSettings",absAxisMap[i]);
				converter=configFile.retrieveValue<AxisConverter>(axisSettingsTag,converter);
				
				#ifdef VERBOSE
				printf("Axis %2d: %s\n",absAxisMap[i],Misc::ValueCoder<AxisConverter>::encode(converter).c_str());
				fflush(stdout);
				#endif
				}
		}
	
	if(relAxisMap!=0)
		{
		/* Initialize relative axis converters: */
		#ifdef VERBOSE
		printf("HIDDevice: Initializing relative axis converters\n");
		fflush(stdout);
		#endif
		for(int i=0;i<=REL_MAX;++i)
			if(relAxisMap[i]>=0)
				{
				/* Initialize converter with default values: */
				AxisConverter& converter=axisConverters[relAxisMap[i]];
				converter=AxisConverter(-1.0f,1.0f);
				
				/* Override axis settings from configuration file: */
				char axisSettingsTag[20];
				snprintf(axisSettingsTag,sizeof(axisSettingsTag),"axis%dSettings",relAxisMap[i]);
				converter=configFile.retrieveValue<AxisConverter>(axisSettingsTag,converter);
				
				#ifdef VERBOSE
				printf("Axis %2d: %s\n",relAxisMap[i],Misc::ValueCoder<AxisConverter>::encode(converter).c_str());
				fflush(stdout);
				#endif
				}
		}
	
	#if 0
	/* Initialize gain arrays: */
	valuatorGains=new float[getNumValuators()];
	for(int i=0;i<getNumValuators();++i)
		{
		char valuatorGainTag[40];
		snprintf(valuatorGainTag,sizeof(valuatorGainTag),"./valuatorGain%d",i);
		valuatorGains[i]=configFile.retrieveValue<float>(valuatorGainTag,1.0f);
		}
	#endif
	
	/* Initialize state arrays: */
	buttonStates=new bool[getNumButtons()];
	for(int i=0;i<getNumButtons();++i)
		buttonStates[i]=false;
	valuatorStates=new float[getNumValuators()];
	for(int i=0;i<getNumValuators();++i)
		valuatorStates[i]=0.0f;
	
	/* Start device thread (HID device cannot be disabled): */
	startDeviceThread();
	}
Пример #14
0
bool JVMInputFunctions::init( JNIEnv* _env, jclass rfdynhudClass, jobject _rfdynhudObject )
{
    env = _env;
    rfdynhudObject = _rfdynhudObject;
    
    unsigned short numKeys = getNumKeys();
    unsigned char maxKeyNameLength = getMaxKeyNameLength();
    
    unsigned int bufferSize = 2 + 1 + numKeys * ( maxKeyNameLength + 1 );
    
    unsigned char numJoysticks = getNumJoysticks();
    unsigned char* numButtons = (unsigned char*)malloc( numJoysticks );
    bufferSize += 1 + numJoysticks * MAX_JOYSTICK_NAME_LENGTH;
    for ( unsigned char i = 0; i < numJoysticks; i++ )
    {
        numButtons[i] = getNumButtons( i );
        bufferSize += 1 + numButtons[i] * MAX_JOYSTICK_BUTTON_NAME_LENGTH;
    }
    
    jbyteArray arr = env->NewByteArray( bufferSize );
    char* buffer = (char*)env->GetPrimitiveArrayCritical( arr, &isCopy );
    
    unsigned int bufferOffset = 0;
    *( (unsigned short*)( buffer + bufferOffset ) ) = numKeys;
    bufferOffset += 2;
    *( (unsigned char*)( buffer + bufferOffset ) ) = maxKeyNameLength;
    bufferOffset += 1;
    getAllKeyNames( buffer + bufferOffset );
    bufferOffset += numKeys * ( maxKeyNameLength + 1 );
    
    *( (unsigned char*)( buffer + bufferOffset ) ) = numJoysticks;
    bufferOffset += 1;
    
    getJoystickNames( (char*)( buffer + bufferOffset ) );
    bufferOffset += numJoysticks * MAX_JOYSTICK_NAME_LENGTH;
    
    for ( unsigned char i = 0; i < numJoysticks; i++ )
    {
        *( (unsigned char*)( buffer + bufferOffset ) ) = numButtons[i];
        bufferOffset += 1;
        
        getJoystickButtonNames( i, (char*)( buffer + bufferOffset ) );
        bufferOffset += numButtons[i] * MAX_JOYSTICK_BUTTON_NAME_LENGTH;
    }
    
    env->ReleasePrimitiveArrayCritical( arr, buffer, 0 );
    
    jmethodID mid = env->GetMethodID( rfdynhudClass, "initInput", "([B)V" );
    
    if ( mid == 0 )
    {
        logg( "ERROR: Failed to find the initInput() method." );
        return ( false );
    }
    
    logg( "Initializing input bindings..." );
    env->CallVoidMethod( _rfdynhudObject, mid, arr );
    logg( "Finished initialization of input bindings." );
    
    env->DeleteLocalRef( arr );
    
    mid = env->GetMethodID( rfdynhudClass, "getInputBuffer", "()Ljava/nio/ByteBuffer;" );
    
    if ( mid == 0 )
    {
        logg( "ERROR: Failed to find the getInputBuffer() method." );
        return ( false );
    }
    
    inputBufferObj = env->CallObjectMethod( _rfdynhudObject, mid );
    
    if ( inputBufferObj == NULL )
    {
        logg( "ERROR: Failed to get the input buffer." );
        return ( false );
    }
    
    inputBuffer = (char*)env->GetDirectBufferAddress( inputBufferObj );
    
    if ( inputBuffer == NULL )
    {
        logg( "ERROR: Input buffer is null." );
        return ( false );
    }
    
    updateInputMethod = env->GetMethodID( rfdynhudClass, "updateInput", "(I)B" );
    
    if ( updateInputMethod == 0 )
    {
        logg( "ERROR: Failed to find the updateInput() method." );
        return ( false );
    }
    
    return ( true );
}
Пример #15
0
	int ThymioColorAction::isClicked(int i) 
	{ 
		if(i<getNumButtons()) 
			return sliders[i]->value(); 		
		return -1;
	}
Пример #16
0
VRPNClient::VRPNClient(VRDevice::Factory* sFactory,VRDeviceManager* sDeviceManager,Misc::ConfigurationFile& configFile)
	:VRDevice(sFactory,sDeviceManager,configFile),
	 VRPNConnection(configFile.retrieveString("./serverName").c_str(),configFile.retrieveValue<int>("./serverPort",3883)),
	 reportEvents(false),
	 trackerStates(0),trackerFlags(0),buttonStates(0),valuatorStates(0)
	{
	#ifdef VERBOSE
	printf("VRPNClient: Initializing senders...");
	fflush(stdout);
	#endif
	
	/* Check if the z axis if incoming position data needs to be flipped: */
	setFlipZAxis(configFile.retrieveValue<bool>("./flipZAxis",false));
	
	/* Retrieve list of sender names: */
	typedef std::vector<std::string> StringList;
	StringList senderNames=configFile.retrieveValue<StringList>("./senderNames");
	
	/* Process all senders: */
	int totalNumTrackers=0;
	int totalNumButtons=0;
	int totalNumValuators=0;
	for(StringList::const_iterator snIt=senderNames.begin();snIt!=senderNames.end();++snIt)
		{
		/* Go to the sender's section: */
		configFile.setCurrentSection(snIt->c_str());
		
		/* Read the number of trackers, buttons, and valuators for this sender: */
		int numTrackers=configFile.retrieveValue<int>("./numTrackers",0);
		if(numTrackers>0)
			{
			requestTrackers(snIt->c_str(),totalNumTrackers,numTrackers);
			totalNumTrackers+=numTrackers;
			}
		int numButtons=configFile.retrieveValue<int>("./numButtons",0);
		if(numButtons>0)
			{
			requestButtons(snIt->c_str(),totalNumButtons,numButtons);
			totalNumButtons+=numButtons;
			}
		int numValuators=configFile.retrieveValue<int>("./numValuators",0);
		if(numValuators>0)
			{
			requestValuators(snIt->c_str(),totalNumValuators,numValuators);
			totalNumValuators+=numValuators;
			}
		
		/* Go back to device's section: */
		configFile.setCurrentSection("..");
		}
	
	#ifdef VERBOSE
	printf(" done\n");
	fflush(stdout);
	#endif
	
	/* Set number of trackers, buttons, and valuators: */
	setNumTrackers(totalNumTrackers,configFile);
	setNumButtons(totalNumButtons,configFile);
	setNumValuators(totalNumValuators,configFile);
	
	/* Read the initial position/orientation for all trackers: */
	PositionOrientation defaultPosition=configFile.retrieveValue<PositionOrientation>("./defaultPosition",PositionOrientation::identity);
	
	/* Initialize the local state arrays: */
	trackerStates=new TrackerState[getNumTrackers()];
	trackerFlags=new int[getNumTrackers()];
	for(int i=0;i<getNumTrackers();++i)
		{
		trackerStates[i].positionOrientation=defaultPosition;
		trackerStates[i].linearVelocity=LinearVelocity::zero;
		trackerStates[i].angularVelocity=AngularVelocity::zero;
		trackerFlags[i]=0x0;
		}
	buttonStates=new ButtonState[getNumButtons()];
	for(int i=0;i<getNumButtons();++i)
		buttonStates[i]=false;
	valuatorStates=new ValuatorState[getNumValuators()];
	for(int i=0;i<getNumValuators();++i)
		valuatorStates[i]=ValuatorState(0);
	
	/* Start device communication thread: */
	startDeviceThread();
	}
Пример #17
0
OSXKeyState::CUCHRKeyResource::CUCHRKeyResource(const void* resource,
				UInt32 keyboardType) :
	m_m(NULL),
	m_cti(NULL),
	m_sdi(NULL),
	m_sri(NULL),
	m_st(NULL)
{
	m_resource = reinterpret_cast<const UCKeyboardLayout*>(resource);
	if (m_resource == NULL) {
		return;
	}

	// find the keyboard info for the current keyboard type
	const UCKeyboardTypeHeader* th = NULL;
	const UCKeyboardLayout* r = m_resource;
	for (ItemCount i = 0; i < r->keyboardTypeCount; ++i) {
		if (keyboardType >= r->keyboardTypeList[i].keyboardTypeFirst &&
			keyboardType <= r->keyboardTypeList[i].keyboardTypeLast) {
			th = r->keyboardTypeList + i;
			break;
		}
		if (r->keyboardTypeList[i].keyboardTypeFirst == 0) {
			// found the default.  use it unless we find a match.
			th = r->keyboardTypeList + i;
		}
	}
	if (th == NULL) {
		// cannot find a suitable keyboard type
		return;
	}

	// get tables for keyboard type
	const UInt8* base = reinterpret_cast<const UInt8*>(m_resource);
	m_m   = reinterpret_cast<const UCKeyModifiersToTableNum*>(base +
								th->keyModifiersToTableNumOffset);
	m_cti = reinterpret_cast<const UCKeyToCharTableIndex*>(base +
								th->keyToCharTableIndexOffset);
	m_sdi = reinterpret_cast<const UCKeySequenceDataIndex*>(base +
								th->keySequenceDataIndexOffset);
	if (th->keyStateRecordsIndexOffset != 0) {
		m_sri = reinterpret_cast<const UCKeyStateRecordsIndex*>(base +
								th->keyStateRecordsIndexOffset);
	}
	if (th->keyStateTerminatorsOffset != 0) {
		m_st = reinterpret_cast<const UCKeyStateTerminators*>(base +
								th->keyStateTerminatorsOffset);
	}

	// find the space key, but only if it can combine with dead keys.
	// a dead key followed by a space yields the non-dead version of
	// the dead key.
	m_spaceOutput = 0xffffu;
	UInt32 table  = getTableForModifier(0);
	for (UInt32 button = 0, n = getNumButtons(); button < n; ++button) {
		KeyID id = getKey(table, button);
		if (id == 0x20) {
			UCKeyOutput c =
				reinterpret_cast<const UCKeyOutput*>(base +
								m_cti->keyToCharTableOffsets[table])[button];
			if ((c & kUCKeyOutputTestForIndexMask) ==
								kUCKeyOutputStateIndexMask) {
				m_spaceOutput = (c & kUCKeyOutputGetIndexMask);
				break;
			}
		}
	}
}
Пример #18
0
int UimToolbar::preferedWidthForHeight()
{
    return BUTTON_SIZE * getNumButtons();
}
Пример #19
0
void Joystick::setButtonB(int button) {
	if (button >= 0 && button < (signed) getNumButtons()) {
		buttonB = 1 << button;
	}
}