Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No game controller support #54

Merged
merged 16 commits into from
Dec 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ If you need support for older Ultimarc boards, please look at the following util

Required Libraries
To build this tool the following libraries need to be install on your system.
autoreconf,
automake,
libudev-dev,
json-c (0.11),
libusb-dev (1.0.18)
libtool
Expand All @@ -18,8 +21,8 @@ Building Utility:
To build this project, at the base directory run the following commands
./configure
make
The executable will be in src/umtool directory and named umtool.out.
./umtool.out ipac2.json
The executable will be in src/umtool directory and named umtool.
./umtool ipac2.json

Configuration Files:
There are example configuration files for each of the boards in the src/umtool directory. The following is information about each configuration file.
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ This utility will configure the following Ultimarc boards; ServoStik, PACDrive,
This library and command line utility support 2012 through 2015 boards. If you need support for older Ultimarc boards, please look at the following utility developed by Travis, <a href='http://www.zumbrovalley.net/articles.php?catid=3'>Ipacutil</a> or use the Windows WinIpac v1 from <a href='http://www.ultimarc.com'>Ultimarc</a>

#### Required Libraries
To build this tool the following libraries need to be install on your system.
To build this tool the following libraries need to be install on your system.
* autoreconf
* automake
* libudev-dev
* json-c (0.11), <a href='https://github.com/json-c/json-c/wiki'>site</a>
* libusb-1.0 (1.0.18), <a href='http://libusb.info'>site</a>
* libtool
Expand All @@ -27,7 +30,7 @@ If you need extra debug statements for the IPac boards then run the following
* ./configure CFLAGS='-DDEBUG'
* make

The executable will be in src/umtool directory and named umtool.out.
The executable will be in src/umtool directory and named umtool.
* ./umtool ipac2.json

#### Donations:
Expand Down
31 changes: 24 additions & 7 deletions src/libs/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,28 @@ openUSB(libusb_context *ctx, uint16_t vendor, uint16_t product, int interface, i
goto error;
}

if (interface != -1)
{
if (!claimInterface(handle, interface, autoconnect))
{
goto error;
}
}

exit:
return handle;

error:
closeUSB(ctx, handle, interface);
return NULL;
}

bool
claimInterface(struct libusb_device_handle *handle, int interface, bool autoconnect)
{
int ret = 0;
bool success = true;

if (autoconnect == 0)
{
/* detach the kernel driver */
Expand All @@ -66,16 +88,11 @@ openUSB(libusb_context *ctx, uint16_t vendor, uint16_t product, int interface, i
if (ret < 0)
{
log_err ("Unable to claim interface.");
goto error;
success = false;
}
}

exit:
return handle;

error:
closeUSB(ctx, handle, interface);
return NULL;
return success;
}

void
Expand Down
8 changes: 7 additions & 1 deletion src/libs/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,21 @@ typedef struct json_object json_object;
* Will attempt to open the USB product and claim the interface specified.
* If successful ctx variable will be populated and the return handle will be populated,
* otherwise they will be NULL;
* interface = -1 the calling function will need to claim the interface this function will not
* autoconnect = 1 the kernel driver will be attached after we are done with the device
* Only needed when changing the ID of the ultistik board
*/
struct libusb_device_handle* openUSB(libusb_context *ctx,
uint16_t vendor,
uint16_t product,
int interface,
int autoconnect);

/**
* Attempt to claim the interface
* autoconnect = 1 the kernel driver will be attached after we are done with the device
*/
bool claimInterface(struct libusb_device_handle *handle, int interface, bool autoconnect);

/**
* Releases the interface, closes the context pointer and the handle pointer
*/
Expand Down
8 changes: 5 additions & 3 deletions src/libs/ipac.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ bool validateIPAC4Data (json_object* jobj, ulboard* board)
log_err ("'3/4 shift key' is not defined in the configuration");
valid = false;
}

/* Required */
if (json_object_object_get_ex(jobj, "pins", &pins))
{
Expand Down Expand Up @@ -312,7 +312,7 @@ bool updateBoardIPAC (json_object *jobj, ulboard *board)
bool result = false;
int bprod = 0;
unsigned char* barray = NULL;

switch (board->version)
{
case ulboard_version_pre2015:
Expand Down Expand Up @@ -397,8 +397,9 @@ bool updateBoardIPAC (json_object *jobj, ulboard *board)

if (bprod != 0)
{
/* Send -1 for interface value, function will figure out which interface to write to */
result = writeIPACSeriesUSB(barray, IPACSERIES_SIZE, IPAC_VENDOR_2015,
bprod, IPACSERIES_INTERFACE, 1, true);
bprod, -1, 1, true);
}

free(barray);
Expand Down Expand Up @@ -621,3 +622,4 @@ void update2015JPACBoard (json_object *jobj, unsigned char* barray)
json_object_object_get_ex(jobj, "macros", &macros);
populateMacrosPosition(JPAC_BOARD, macros, &barray[3]);
}

33 changes: 33 additions & 0 deletions src/libs/ipacseries.c
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,11 @@ void populateMacrosPosition (enum ipac_boards_t bid, json_object* macros, unsign
bool writeIPACSeriesUSB (unsigned char* barray, int size, uint16_t vendor, uint16_t product, int interface, int autoconnect, bool transfer)
{
libusb_context *ctx = NULL;
libusb_device *device = NULL;

struct libusb_device_descriptor descriptor;
struct libusb_device_handle *handle = NULL;

unsigned char mesg[IPACSERIES_MESG_LENGTH] = {0x03,0,0,0,0};

bool result = true;
Expand All @@ -1112,6 +1116,34 @@ bool writeIPACSeriesUSB (unsigned char* barray, int size, uint16_t vendor, uint1
result = false;
goto error;
}

debug ("Determine which interface to use...");
device = libusb_get_device(handle);

if (!device)
{
result = false;
goto error;
}

libusb_get_device_descriptor (device, &descriptor);
if ((descriptor.bcdDevice & 0x40) != 0)
{
debug ("No Game Controller interface");
interface = IPACSERIES_NGC_INTERFACE;
}
else
{
debug ("Game Controller interface");
interface = IPACSERIES_INTERFACE;
}
}

debug ("Claiming interface...");
if (!claimInterface(handle, interface, true))
{
result = false;
goto error;
}

while (pos < size)
Expand Down Expand Up @@ -1148,3 +1180,4 @@ bool writeIPACSeriesUSB (unsigned char* barray, int size, uint16_t vendor, uint1
error:
return result;
}

11 changes: 6 additions & 5 deletions src/libs/ipacseries.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
extern "C" {
#endif

#define IPACSERIES_VERSION 2
#define IPACSERIES_VALUE 0x0203
#define IPACSERIES_MESG_LENGTH 5
#define IPACSERIES_INTERFACE 3
#define IPACSERIES_SIZE 260
#define IPACSERIES_VERSION 2
#define IPACSERIES_VALUE 0x0203
#define IPACSERIES_MESG_LENGTH 5
#define IPACSERIES_NGC_INTERFACE 2
#define IPACSERIES_INTERFACE 3
#define IPACSERIES_SIZE 260

typedef struct json_object json_object;

Expand Down
Loading