- Timestamp:
- Oct 7, 2010, 8:21:33 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ois_update/src/external/ois/linux/LinuxJoyStickEvents.cpp
r5781 r7506 96 96 //We are in non blocking mode - we just read once, and try to fill up buffer 97 97 input_event js[JOY_BUFFERSIZE]; 98 int ret = read(mJoyStick, &js, sizeof(struct input_event) * JOY_BUFFERSIZE); 99 if( ret <= 0 ) 100 return; 101 102 //Determine how many whole events re read up 103 ret /= sizeof(struct input_event); 104 for(int i = 0; i < ret; ++i) 98 while(true) 105 99 { 106 switch(js[i].type) 100 int ret = read(mJoyStick, &js, sizeof(struct input_event) * JOY_BUFFERSIZE); 101 if( ret < 0 ) 102 break; 103 104 //Determine how many whole events re read up 105 ret /= sizeof(struct input_event); 106 for(int i = 0; i < ret; ++i) 107 107 { 108 case EV_KEY: //Button 109 { 110 int button = mButtonMap[js[i].code]; 111 112 #ifdef OIS_LINUX_JOY_DEBUG 113 cout << "\nButton Code: " << js[i].code << ", OIS Value: " << button << endl; 114 #endif 115 116 //Check to see whether push or released event... 117 if(js[i].value) 118 { 119 mState.mButtons[button] = true; 120 if( mBuffered && mListener ) 121 if(!mListener->buttonPressed(JoyStickEvent(this,mState), button)) return; 122 } 123 else 124 { 125 mState.mButtons[button] = false; 126 if( mBuffered && mListener ) 127 if(!mListener->buttonReleased(JoyStickEvent(this,mState), button)) return; 128 } 129 break; 130 } 131 132 case EV_ABS: //Absolute Axis 133 { 134 //A Stick (BrakeDefine is the highest possible Axis) 135 if( js[i].code <= ABS_BRAKE ) 136 { 137 int axis = mAxisMap[js[i].code]; 138 assert( axis < 32 && "Too many axes (Max supported is 32). Report this to OIS forums!" ); 139 140 axisMoved[axis] = true; 141 142 //check for rescaling: 143 if( mRanges[axis].min == JoyStick::MIN_AXIS && mRanges[axis].max != JoyStick::MAX_AXIS ) 144 { //Scale is perfect 145 mState.mAxes[axis].abs = js[i].value; 108 switch(js[i].type) 109 { 110 case EV_KEY: //Button 111 { 112 int button = mButtonMap[js[i].code]; 113 114 #ifdef OIS_LINUX_JOY_DEBUG 115 cout << "\nButton Code: " << js[i].code << ", OIS Value: " << button << endl; 116 #endif 117 118 //Check to see whether push or released event... 119 if(js[i].value) 120 { 121 mState.mButtons[button] = true; 122 if( mBuffered && mListener ) 123 if(!mListener->buttonPressed(JoyStickEvent(this,mState), button)) return; 146 124 } 147 125 else 148 { //Rescale 149 float proportion = (float)(js[i].value-mRanges[axis].max)/(float)(mRanges[axis].min-mRanges[axis].max); 150 mState.mAxes[axis].abs = (int)(32767.0f - (65535.0f * proportion)); 126 { 127 mState.mButtons[button] = false; 128 if( mBuffered && mListener ) 129 if(!mListener->buttonReleased(JoyStickEvent(this,mState), button)) return; 151 130 } 152 } 153 else if( js[i].code <= ABS_HAT3Y ) //A POV - Max four POVs allowed 154 { 155 //Normalise the POV to between 0-7 156 //Even is X Axis, Odd is Y Axis 157 unsigned char LinuxPovNumber = js[i].code - 16; 158 short OIS_POVIndex = POV_MASK[LinuxPovNumber]; 159 160 //Handle X Axis first (Even) (left right) 161 if((LinuxPovNumber & 0x0001) == 0) 131 break; 132 } 133 134 case EV_ABS: //Absolute Axis 135 { 136 //A Stick (BrakeDefine is the highest possible Axis) 137 if( js[i].code <= ABS_BRAKE ) 162 138 { 163 //Why do this? Because, we use a bit field, and when this axis is east, 164 //it can't possibly be west too. So clear out the two X axes, then refil 165 //it in with the new direction bit. 166 //Clear the East/West Bit Flags first 167 mState.mPOV[OIS_POVIndex].direction &= 0x11110011; 168 if( js[i].value == -1 ) //Left 169 mState.mPOV[OIS_POVIndex].direction |= Pov::West; 170 else if( js[i].value == 1 ) //Right 171 mState.mPOV[OIS_POVIndex].direction |= Pov::East; 139 int axis = mAxisMap[js[i].code]; 140 assert( axis < 32 && "Too many axes (Max supported is 32). Report this to OIS forums!" ); 141 142 axisMoved[axis] = true; 143 144 //check for rescaling: 145 if( mRanges[axis].min == JoyStick::MIN_AXIS && mRanges[axis].max != JoyStick::MAX_AXIS ) 146 { //Scale is perfect 147 mState.mAxes[axis].abs = js[i].value; 148 } 149 else 150 { //Rescale 151 float proportion = (float)(js[i].value-mRanges[axis].max)/(float)(mRanges[axis].min-mRanges[axis].max); 152 mState.mAxes[axis].abs = (int)(32767.0f - (65535.0f * proportion)); 153 } 172 154 } 173 //Handle Y Axis (Odd) (up down) 174 else 155 else if( js[i].code <= ABS_HAT3Y ) //A POV - Max four POVs allowed 175 156 { 176 //Clear the North/South Bit Flags first 177 mState.mPOV[OIS_POVIndex].direction &= 0x11111100; 178 if( js[i].value == -1 ) //Up 179 mState.mPOV[OIS_POVIndex].direction |= Pov::North; 180 else if( js[i].value == 1 ) //Down 181 mState.mPOV[OIS_POVIndex].direction |= Pov::South; 157 //Normalise the POV to between 0-7 158 //Even is X Axis, Odd is Y Axis 159 unsigned char LinuxPovNumber = js[i].code - 16; 160 short OIS_POVIndex = POV_MASK[LinuxPovNumber]; 161 162 //Handle X Axis first (Even) (left right) 163 if((LinuxPovNumber & 0x0001) == 0) 164 { 165 //Why do this? Because, we use a bit field, and when this axis is east, 166 //it can't possibly be west too. So clear out the two X axes, then refil 167 //it in with the new direction bit. 168 //Clear the East/West Bit Flags first 169 mState.mPOV[OIS_POVIndex].direction &= 0x11110011; 170 if( js[i].value == -1 ) //Left 171 mState.mPOV[OIS_POVIndex].direction |= Pov::West; 172 else if( js[i].value == 1 ) //Right 173 mState.mPOV[OIS_POVIndex].direction |= Pov::East; 174 } 175 //Handle Y Axis (Odd) (up down) 176 else 177 { 178 //Clear the North/South Bit Flags first 179 mState.mPOV[OIS_POVIndex].direction &= 0x11111100; 180 if( js[i].value == -1 ) //Up 181 mState.mPOV[OIS_POVIndex].direction |= Pov::North; 182 else if( js[i].value == 1 ) //Down 183 mState.mPOV[OIS_POVIndex].direction |= Pov::South; 184 } 185 186 if( mBuffered && mListener ) 187 if( mListener->povMoved( JoyStickEvent(this,mState), OIS_POVIndex) == false ) 188 return; 182 189 } 183 184 if( mBuffered && mListener ) 185 if( mListener->povMoved( JoyStickEvent(this,mState), OIS_POVIndex) == false ) 186 return; 187 } 188 break; 189 } 190 191 192 case EV_REL: //Relative Axes (Do any joystick actually have a relative axis?) 193 #ifdef OIS_LINUX_JOY_DEBUG 194 cout << "\nWarning: Relatives axes not supported yet" << endl; 195 #endif 196 break; 197 default: break; 190 break; 191 } 192 193 194 case EV_REL: //Relative Axes (Do any joystick actually have a relative axis?) 195 #ifdef OIS_LINUX_JOY_DEBUG 196 cout << "\nWarning: Relatives axes not supported yet" << endl; 197 #endif 198 break; 199 default: break; 200 } 198 201 } 199 202 }
Note: See TracChangeset
for help on using the changeset viewer.