Skip to content

Commit

Permalink
Merge pull request #11 from fauxmight/master
Browse files Browse the repository at this point in the history
Correct warnings on BUTTON_SIZE, AXES_SIZE and related comments
  • Loading branch information
Vantskruv authored Aug 13, 2019
2 parents 426cb1a + 25ca5d1 commit 2bf2e16
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 15 deletions.
4 changes: 2 additions & 2 deletions CVirtualJoy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ CVirtualJoy::CVirtualJoy(unsigned int _buttons, unsigned int _axes)


//Setup buttons for device
if(_buttons>=BUTTONS_SIZE) std::cout << "WARNING: Number of buttons (" << _buttons << ") for virtual device " << deviceid << " exceeds maximum allowable buttons which is " << (BUTTONS_SIZE - 1) << ".\n";
if(_buttons>BUTTONS_SIZE) std::cout << "WARNING: Number of buttons (" << _buttons << ") for virtual device " << deviceid << " exceeds maximum allowable buttons which is " << (BUTTONS_SIZE - 1) << ".\n";
for(unsigned int i=0; i<_buttons && i<BUTTONS_SIZE; i++)
{
if(suinput_enable_event(fd, EV_KEY, buttons_ref::BUTTONS[i])<0)
Expand All @@ -32,7 +32,7 @@ CVirtualJoy::CVirtualJoy(unsigned int _buttons, unsigned int _axes)

//Setup axes for device

if(_axes>=AXES_SIZE) std::cout << "WARNING: Number of axes (" << _axes << ") for virtual device " << deviceid << " exceeds maximum allowable axes which is " << (AXES_SIZE - 1) << ".\n";
if(_axes>AXES_SIZE) std::cout << "WARNING: Number of axes (" << _axes << ") for virtual device " << deviceid << " exceeds maximum allowable axes which is " << (AXES_SIZE - 1) << ".\n";
for(unsigned int i=0; i<_axes && i<AXES_SIZE; i++)
{
if(suinput_enable_event(fd, EV_ABS, buttons_ref::AXES[i])<0)
Expand Down
2 changes: 1 addition & 1 deletion example.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ devices =
}
}

--Virtual devices to create, current limit is maximum 54 (0 to 53) buttons and 19 (0 to 18) axes. Note that not every button or axis is fully tested to work.
--Virtual devices to create, current limit is maximum 53 (0 to 52) buttons and 19 (0 to 18) axes. Note that not every button or axis is fully tested to work.
--Creating more than one virtual devices is possible, making room for more buttons and axes.
v_devices =
{
Expand Down
31 changes: 22 additions & 9 deletions joystick.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@

#define KEY_MAX 0x2ff
#define BTN_MISC 0x100
typedef unsigned char __u8;
typedef uint16_t __u16;
#define JSIOCGAXES _IOR('j', 0x11, __u8) /* get number of axes */
#define JSIOCGBUTTONS _IOR('j', 0x12, __u8) /* get number of buttons */
#define JSIOCGBTNMAP _IOR('j', 0x34, __u16[KEY_MAX - BTN_MISC + 1]) /* get button mapping */
#define JSIOCGAXMAP _IOR('j', 0x32, __u8[ABS_CNT]) /* get axis mapping */
typedef unsigned char __u8;
typedef uint16_t __u16;
#define JSIOCGAXES _IOR('j', 0x11, __u8) /* get number of axes */
#define JSIOCGBUTTONS _IOR('j', 0x12, __u8) /* get number of buttons */
#define JSIOCGBTNMAP _IOR('j', 0x34, __u16[KEY_MAX - BTN_MISC + 1]) /* get button mapping */
#define JSIOCGAXMAP _IOR('j', 0x32, __u8[ABS_CNT]) /* get axis mapping */


Joystick::Joystick(int joystickNumber)
Expand All @@ -55,7 +55,7 @@ Joystick::Joystick(int joystickNumber)
axesData.resize(axisMappings.size(), 0);
}

Joystick::Joystick(int _vendorid, int _productid)
Joystick::Joystick(int _vendorid, int _productid, std::vector<Joystick*> currentList)
{
std::vector<unsigned int> lJSDevices;
std::string dir("/dev/input/");
Expand All @@ -67,12 +67,25 @@ Joystick::Joystick(int _vendorid, int _productid)
{
std::cout << "Error(" << errno << ") opening " << dir << '\n';
return;
}
}//if

//Read '/dev/input' directory
while ((dirp = readdir(dp)) != NULL)
{
std::string cFile(dirp->d_name);

//In case identical model devices are being used, don't add same model INSTANCE twice
bool duplicateDevicePathDetected = false;
for(unsigned int i=0; i<currentList.size(); i++)
{
if(currentList[i]->getDevicePath().compare("/dev/input/" + cFile) == 0)
{
duplicateDevicePathDetected = true;
break;
}//if
}//for
if(duplicateDevicePathDetected) continue;

//If a file that begins with 'js' is found
if(cFile.compare(0, 2, "js") == 0)
{
Expand All @@ -89,7 +102,7 @@ Joystick::Joystick(int _vendorid, int _productid)
}
lJSDevices.push_back(num);
}//if
}
}//while
closedir(dp);


Expand Down
3 changes: 2 additions & 1 deletion joystick.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class Joystick
* zero-indexed number.
*/
Joystick(int joystickNumber);
Joystick(int, int);
Joystick(int, int, std::vector<Joystick*>);

/**
* Initialises an instance for the joystick device specified.
Expand All @@ -130,6 +130,7 @@ class Joystick
unsigned int getJoyNum(){return joyNum;};
int getVendorID(){return vendorid;};
int getProductID(){return productid;};
std::string getDevicePath(){return _devicePath;};
void addListener(void(*)(void*, int, int, int), int, int); //Listener, event and type

unsigned int get_num_buttons();
Expand Down
2 changes: 1 addition & 1 deletion main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ bool populate_devices(LuaScript& lScript)
//Populate the list of found joysticks
for(unsigned int i=0; i<dList.size(); i++)
{
Joystick* cJoy = new Joystick(dList[i][0], dList[i][1]);
Joystick* cJoy = new Joystick(dList[i][0], dList[i][1], GLOBAL::joyList);
if(!cJoy->isFound())
{
std::cout << "WARNING: Joystick " << std::hex << dList[i][0] << ":" << std::hex << dList[i][1] << " is not found.\n";
Expand Down
2 changes: 1 addition & 1 deletion warthog_throttle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ devices =
}
}

--Virtual devices to create, current limit is maximum 54 (0 to 53) buttons and 19 (0 to 18) axes. Note that not every button or axis is fully tested to work.
--Virtual devices to create, current limit is maximum 53 (0 to 52) buttons and 19 (0 to 18) axes. Note that not every button or axis is fully tested to work.
v_devices =
{
v0 =
Expand Down

0 comments on commit 2bf2e16

Please sign in to comment.