Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 30, 2009, 2:22:00 AM (15 years ago)
Author:
rgrieder
Message:

Merged resource2 branch back to trunk.

IMPORTANT NOTE:
Upon this merge you need to specifically call your data directory "data_extern" when checking it out (when you don't provide a name, it will be just called 'trunk').
The new CMake variable is EXTERNAL_DATA_DIRECTORY. DATA_DIRECTORY now points to the one the source part of the repository.
UPDATE YOUR DATA DIRECTORY AS WELL!!!

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/ois/linux/EventHelpers.cpp

    r1505 r5695  
    3434#ifdef OIS_LINUX_JOY_DEBUG
    3535# include <iostream>
    36   using namespace std;
    37 #endif
    38 
     36#endif
     37
     38// Fixes for missing macros in input.h
     39#ifndef FF_EFFECT_MIN
     40#define FF_EFFECT_MIN FF_RUMBLE
     41#endif
     42#ifndef FF_EFFECT_MAX
     43#define FF_EFFECT_MAX FF_RAMP
     44#endif
     45#ifndef FF_WAVEFORM_MIN
     46#define FF_WAVEFORM_MIN FF_SQUARE
     47#endif
     48#ifndef FF_WAVEFORM_MAX
     49#define FF_WAVEFORM_MAX FF_CUSTOM
     50#endif
     51
     52using namespace std;
    3953using namespace OIS;
    4054
     
    4256{
    4357public:
    44         std::vector<int> buttons, relAxes, absAxes, hats;
     58        vector<int> buttons, relAxes, absAxes, hats;
    4559};
    4660
    47 bool inline isBitSet(unsigned long bits[], unsigned int bit)
    48 {
    49         return (bits[bit/(sizeof(long)*8)] >> ((bit)%(sizeof(long)*8))) & 1;
    50 }
     61bool inline isBitSet(unsigned char bits[], unsigned int bit)
     62{
     63  return (bits[(bit)/(sizeof(unsigned char)*8)] >> ((bit)%(sizeof(unsigned char)*8))) & 1;
     64}
     65
    5166//-----------------------------------------------------------------------------//
    5267DeviceComponentInfo getComponentInfo( int deviceID )
    5368{
    54         unsigned long info[2][((KEY_MAX-1)/(sizeof(long)*8)) +1];
    55         memset( info, 0, sizeof(info) );
     69        unsigned char ev_bits[1 + EV_MAX/8/sizeof(unsigned char)];
     70        memset( ev_bits, 0, sizeof(ev_bits) );
     71
     72        //Read "all" (hence 0) components of the device
     73#ifdef OIS_LINUX_JOY_DEBUG
     74        cout << "EventUtils::getComponentInfo(" << deviceID
     75                 << ") : Reading device events features" << endl;
     76#endif
     77        if (ioctl(deviceID, EVIOCGBIT(0, sizeof(ev_bits)), ev_bits) == -1)
     78                OIS_EXCEPT( E_General, "Could not read device events features");
    5679
    5780        DeviceComponentInfo components;
    58 
    59         //Read "all" (hence 0) components of the device - read into first entry
    60         ioctl(deviceID, EVIOCGBIT(0, EV_MAX), info[0]);
    6181
    6282        for (int i = 0; i < EV_MAX; i++)
    6383        {
    64                 if( isBitSet(info[0], i) )
     84                if( isBitSet(ev_bits, i) )
    6585                {
    66                         memset( info[1], 0, sizeof(info) / 2 );
    67                         ioctl(deviceID, EVIOCGBIT(i, KEY_MAX), info[1]);
    68                         for (int j = 0; j < KEY_MAX; j++)
     86                    // Absolute axis.
     87                    if(i == EV_ABS)
    6988                        {
    70                                 if( isBitSet(info[1], j) )
     89                            unsigned char abs_bits[1 + ABS_MAX/8/sizeof(unsigned char)];
     90                            memset( abs_bits, 0, sizeof(abs_bits) );
     91
     92#ifdef OIS_LINUX_JOY_DEBUG
     93                                cout << "EventUtils::getComponentInfo(" << deviceID
     94                                         << ") : Reading device absolute axis features" << endl;
     95#endif
     96
     97                                if (ioctl(deviceID, EVIOCGBIT(i, sizeof(abs_bits)), abs_bits) == -1)
     98                                    OIS_EXCEPT( E_General, "Could not read device absolute axis features");
     99
     100                                for (int j = 0; j < ABS_MAX; j++)
    71101                                {
    72                                         if(i == EV_ABS)
     102                                    if( isBitSet(abs_bits, j) )
    73103                                        {
    74104                                                //input_absinfo abInfo;
     
    89119                                                }
    90120                                        }
    91                                         else if(i == EV_REL)
     121                                }
     122                        }
     123                        else if(i == EV_REL)
     124                        {
     125                            unsigned char rel_bits[1 + REL_MAX/8/sizeof(unsigned char)];
     126                                memset( rel_bits, 0, sizeof(rel_bits) );
     127                               
     128#ifdef OIS_LINUX_JOY_DEBUG
     129                                cout << "EventUtils::getComponentInfo(" << deviceID
     130                                         << ") : Reading device relative axis features" << endl;
     131#endif
     132
     133                                if (ioctl(deviceID, EVIOCGBIT(i, sizeof(rel_bits)), rel_bits) == -1)
     134                                    OIS_EXCEPT( E_General, "Could not read device relative axis features");
     135                               
     136                                for (int j = 0; j < REL_MAX; j++)
     137                                {
     138                                    if( isBitSet(rel_bits, j) )
    92139                                        {
    93                                                 components.relAxes.push_back(j);
     140                                            components.relAxes.push_back(j);
    94141                                        }
    95                                         else if(i == EV_KEY)
     142                                }
     143                        }
     144                        else if(i == EV_KEY)
     145                        {
     146                            unsigned char key_bits[1 + KEY_MAX/8/sizeof(unsigned char)];
     147                                memset( key_bits, 0, sizeof(key_bits) );
     148                               
     149#ifdef OIS_LINUX_JOY_DEBUG
     150                                cout << "EventUtils::getComponentInfo(" << deviceID
     151                                         << ") : Reading device buttons features" << endl;
     152#endif
     153
     154                                if (ioctl(deviceID, EVIOCGBIT(i, sizeof(key_bits)), key_bits) == -1)
     155                                    OIS_EXCEPT( E_General, "Could not read device buttons features");
     156                               
     157                                for (int j = 0; j < KEY_MAX; j++)
     158                                {
     159                                    if( isBitSet(key_bits, j) )
    96160                                        {
    97                                                 components.buttons.push_back(j);
     161                                            components.buttons.push_back(j);
    98162                                        }
    99163                                }
     
    108172bool EventUtils::isJoyStick( int deviceID, JoyStickInfo &js )
    109173{
    110         if( deviceID == -1 ) OIS_EXCEPT( E_General, "Error with File Descriptor" );
     174        if( deviceID == -1 )
     175                OIS_EXCEPT( E_General, "Error with File Descriptor" );
    111176
    112177        DeviceComponentInfo info = getComponentInfo( deviceID );
     
    117182
    118183        #ifdef OIS_LINUX_JOY_DEBUG
    119           cout << "\n\nDisplaying ButtonMapping Status:";
     184        cout << endl << "Displaying ButtonMapping Status:" << endl;
    120185        #endif
    121         for(std::vector<int>::iterator i = info.buttons.begin(), e = info.buttons.end(); i != e; ++i )
     186        for(vector<int>::iterator i = info.buttons.begin(), e = info.buttons.end(); i != e; ++i )
    122187        {
    123188                //Check to ensure we find at least one joy only button
    124                 if( (*i >= BTN_JOYSTICK && *i <= BTN_THUMBR) || (*i >= BTN_WHEEL && *i <= BTN_GEAR_UP ) )
     189                if( (*i >= BTN_JOYSTICK && *i < BTN_GAMEPAD) 
     190                        || (*i >= BTN_GAMEPAD && *i < BTN_DIGI)
     191                        || (*i >= BTN_WHEEL && *i < KEY_OK) )
    125192                        joyButtonFound = true;
    126193
     
    128195
    129196                #ifdef OIS_LINUX_JOY_DEBUG
    130                   cout << "\nButton Mapping ID (hex): " << hex << *i << " OIS Button Num: " << dec << (buttons-1);
     197                  cout << "Button Mapping ID (hex): " << hex << *i
     198                           << " OIS Button Num: " << dec << buttons-1 << endl;
    131199                #endif
    132200        }
     201        #ifdef OIS_LINUX_JOY_DEBUG
     202        cout << endl;
     203        #endif
    133204
    134205        //Joy Buttons found, so it must be a joystick or pad
     
    140211                js.axes = info.relAxes.size() + info.absAxes.size();
    141212                js.hats = info.hats.size();
     213                #ifdef OIS_LINUX_JOY_DEBUG
     214                  cout << endl << "Device name:" << js.vendor << endl;
     215                  cout << "Device unique Id:" << getUniqueId(deviceID) << endl;
     216                  cout << "Device physical location:" << getPhysicalLocation(deviceID) << endl;
     217                #endif
    142218
    143219                //Map the Axes
    144220                #ifdef OIS_LINUX_JOY_DEBUG
    145                   cout << "\n\nDisplaying AxisMapping Status:";
     221                  cout << endl << "Displaying AxisMapping Status:" << endl;
    146222                #endif
    147223                int axes = 0;
    148                 for(std::vector<int>::iterator i = info.absAxes.begin(), e = info.absAxes.end(); i != e; ++i )
     224                for(vector<int>::iterator i = info.absAxes.begin(), e = info.absAxes.end(); i != e; ++i )
    149225                {
    150226                        js.axis_map[*i] = axes;
    151227
     228#ifdef OIS_LINUX_JOY_DEBUG
     229                        cout << "EventUtils::isJoyStick(" << deviceID
     230                                          << ") : Reading device absolute axis #" << *i << " features" << endl;
     231#endif
     232
    152233                        input_absinfo absinfo;
    153                         ioctl(deviceID, EVIOCGABS(*i), &absinfo);
     234                        if (ioctl(deviceID, EVIOCGABS(*i), &absinfo) == -1)
     235                                OIS_EXCEPT( E_General, "Could not read device absolute axis features");
    154236                        js.axis_range[axes] = Range(absinfo.minimum, absinfo.maximum);
    155237
    156238                        #ifdef OIS_LINUX_JOY_DEBUG
    157                           cout << "\nAxis Mapping ID (hex): " << hex << *i << " OIS Axis Num: " << dec << axes;
     239                          cout << "Axis Mapping ID (hex): " << hex << *i
     240                                   << " OIS Axis Num: " << dec << axes << endl;
    158241                        #endif
    159242
     
    166249
    167250//-----------------------------------------------------------------------------//
    168 std::string EventUtils::getName( int deviceID )
    169 {
     251string EventUtils::getName( int deviceID )
     252{
     253#ifdef OIS_LINUX_JOY_DEBUG
     254        cout << "EventUtils::getName(" << deviceID
     255                 << ") : Reading device name" << endl;
     256#endif
     257
    170258        char name[OIS_DEVICE_NAME];
    171         ioctl(deviceID, EVIOCGNAME(OIS_DEVICE_NAME), name);
    172         return std::string(name);
     259        if (ioctl(deviceID, EVIOCGNAME(OIS_DEVICE_NAME), name) == -1)
     260                OIS_EXCEPT( E_General, "Could not read device name");
     261        return string(name);
     262}
     263
     264//-----------------------------------------------------------------------------//
     265string EventUtils::getUniqueId( int deviceID )
     266{
     267#ifdef OIS_LINUX_JOY_DEBUG
     268        cout << "EventUtils::getUniqueId(" << deviceID
     269                 << ") : Reading device unique Id" << endl;
     270#endif
     271
     272#define OIS_DEVICE_UNIQUE_ID 128
     273        char uId[OIS_DEVICE_UNIQUE_ID];
     274        if (ioctl(deviceID, EVIOCGUNIQ(OIS_DEVICE_UNIQUE_ID), uId) == -1)
     275                OIS_EXCEPT( E_General, "Could not read device unique Id");
     276        return string(uId);
     277}
     278
     279//-----------------------------------------------------------------------------//
     280string EventUtils::getPhysicalLocation( int deviceID )
     281{
     282#ifdef OIS_LINUX_JOY_DEBUG
     283        cout << "EventUtils::getPhysicalLocation(" << deviceID
     284                 << ") : Reading device physical location" << endl;
     285#endif
     286
     287#define OIS_DEVICE_PHYSICAL_LOCATION 128
     288        char physLoc[OIS_DEVICE_PHYSICAL_LOCATION];
     289        if (ioctl(deviceID, EVIOCGPHYS(OIS_DEVICE_PHYSICAL_LOCATION), physLoc) == -1)
     290                OIS_EXCEPT( E_General, "Could not read device physical location");
     291        return string(physLoc);
    173292}
    174293
     
    177296{
    178297        //Linux Event to OIS Event Mappings
    179         std::map<int, Effect::EType> typeMap;
     298        map<int, Effect::EType> typeMap;
    180299        typeMap[FF_CONSTANT] = Effect::Constant;
    181300        typeMap[FF_RAMP]     = Effect::Ramp;
     
    191310        typeMap[FF_CUSTOM]   = Effect::Custom;
    192311
    193         std::map<int, Effect::EForce> forceMap;
     312        map<int, Effect::EForce> forceMap;
    194313        forceMap[FF_CONSTANT] = Effect::ConstantForce;
    195         forceMap[FF_RAMP] = Effect::RampForce;
    196         forceMap[FF_PERIODIC] = Effect::PeriodicForce;
    197         forceMap[FF_CUSTOM] = Effect::CustomForce;
     314        forceMap[FF_RAMP]     = Effect::RampForce;
     315        forceMap[FF_SPRING]   = Effect::ConditionalForce;
     316        forceMap[FF_FRICTION] = Effect::ConditionalForce;
     317        forceMap[FF_SQUARE]   = Effect::PeriodicForce;
     318        forceMap[FF_TRIANGLE] = Effect::PeriodicForce;
     319        forceMap[FF_SINE]     = Effect::PeriodicForce;
     320        forceMap[FF_SAW_UP]   = Effect::PeriodicForce;
     321        forceMap[FF_SAW_DOWN] = Effect::PeriodicForce;
     322        forceMap[FF_DAMPER]   = Effect::ConditionalForce;
     323        forceMap[FF_INERTIA]  = Effect::ConditionalForce;
     324        forceMap[FF_CUSTOM]   = Effect::CustomForce;
    198325
    199326        //Remove any previously existing memory and create fresh
    200327        removeForceFeedback( ff );
    201         *ff = new LinuxForceFeedback();
    202 
    203         unsigned long info[4] = {0,0,0,0};
    204         unsigned long subinfo[4]= {0,0,0,0};
    205 
    206         //Read overall force feedback components of the device
    207         ioctl(deviceID, EVIOCGBIT(EV_FF, sizeof(long)*4), info);
     328        *ff = new LinuxForceFeedback(deviceID);
     329
     330        //Read overall force feedback features
     331        unsigned char ff_bits[1 + FF_MAX/8/sizeof(unsigned char)];
     332        memset(ff_bits, 0, sizeof(ff_bits));
     333
     334#ifdef OIS_LINUX_JOY_DEBUG
     335        cout << "EventUtils::enumerateForceFeedback(" << deviceID
     336                 << ") : Reading device force feedback features" << endl;
     337#endif
     338
     339        if (ioctl(deviceID, EVIOCGBIT(EV_FF, sizeof(ff_bits)), ff_bits) == -1)
     340                OIS_EXCEPT( E_General, "Could not read device force feedback features");
     341
     342
     343    #ifdef OIS_LINUX_JOY_DEBUG
     344        cout << "FF bits: " << hex;
     345        for (int i = 0; i < sizeof(ff_bits); i++)
     346                cout << (int)ff_bits[i];
     347        cout << endl << dec;
     348    #endif
    208349
    209350        //FF Axes
    210         //if( isBitSet(info, ABS_X) ) //X Axis
    211         //if( isBitSet(info, ABS_Y) ) //Y Axis
    212         //if( isBitSet(info, ABS_WHEEL) ) //Wheel
     351        //if( isBitSet(ff_bits, ABS_X) ) //X Axis
     352        //if( isBitSet(ff_bits, ABS_Y) ) //Y Axis
     353        //if( isBitSet(ff_bits, ABS_WHEEL) ) //Wheel
    213354
    214355        //FF Effects
    215         for( int effect = ABS_WHEEL+1; effect < FF_MAX; effect++ )
     356        for( int effect = FF_EFFECT_MIN; effect <= FF_WAVEFORM_MAX; effect++ )
    216357        {
    217                 if(isBitSet(info, effect))
     358                // The RUMBLE force type is ignored, as periodic force one is more powerfull.
     359                // The PERIODIC force type is processed later, for each associated periodic effect type.
     360                if (effect == FF_RUMBLE || effect == FF_PERIODIC)
     361                        continue;
     362
     363                if(isBitSet(ff_bits, effect))
    218364                {
    219                         //std::cout << "\tEffect Type: " << effect << std::endl;
    220                         memset(subinfo, 0, sizeof(subinfo));
    221                         //Read any info about this supported effect
    222                         ioctl(deviceID, EVIOCGBIT(effect, sizeof(long)*4), subinfo);
    223                         for( int force = 0; force < FF_MAX; force++ )
    224                         {
    225                                 if(isBitSet(subinfo, force))
    226                                         (*ff)->_addEffectTypes( forceMap[force], typeMap[effect] );
    227                         }
     365                        #ifdef OIS_LINUX_JOY_DEBUG
     366                    cout << "  Effect Type: " << Effect::getEffectTypeName(typeMap[effect]) << endl;
     367                        #endif
     368
     369                        (*ff)->_addEffectTypes( forceMap[effect], typeMap[effect] );
    228370                }
    229371        }
     372
     373        //FF device properties
     374        if (isBitSet(ff_bits, FF_GAIN))
     375                (*ff)->_setGainSupport(true);
     376               
     377        if (isBitSet(ff_bits, FF_AUTOCENTER))
     378                (*ff)->_setAutoCenterSupport(true);
    230379
    231380        //Check to see if any effects were added, else destroy the pointer
Note: See TracChangeset for help on using the changeset viewer.