From 008482812ec291d2e357ac4f77de6829be51598b Mon Sep 17 00:00:00 2001 From: katie-snow <katiej.snow@gmail.com> Date: Wed, 30 Aug 2017 13:56:30 -0600 Subject: [PATCH 01/15] Add header to remove build warning --- src/libs/usbbutton.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/usbbutton.c b/src/libs/usbbutton.c index 3d24126..2c359cd 100644 --- a/src/libs/usbbutton.c +++ b/src/libs/usbbutton.c @@ -21,6 +21,7 @@ #include "ulboard.h" #include "common.h" #include "usbbutton.h" +#include "ipacseries.h" #include "dbg.h" bool isUSBButtonConfig(json_object *jobj, ulboard* board) From 50dbe7b1bc579de1a3c33f0913712d3adb639f96 Mon Sep 17 00:00:00 2001 From: katie-snow <katiej.snow@gmail.com> Date: Wed, 30 Aug 2017 14:12:12 -0600 Subject: [PATCH 02/15] IPAC boards firmware has split. Added "game controller" entry into configurations to determine which fireware is being used. Then sets the correct interface for writing to the boards. --- src/libs/ipac.c | 57 ++++++++- src/libs/ipacseries.h | 11 +- src/libs/ipacultimate.c | 179 +++++++++++++++------------ src/libs/ipacultimate.h | 1 + src/umtool/ipac2_2015_TestMacro.json | 1 + src/umtool/ipac2_2015_default.json | 1 + src/umtool/ipac4_2015_default.json | 1 + src/umtool/ipacultimate_config.json | 5 +- src/umtool/ipacultimate_led.json | 3 +- src/umtool/ipacultimate_pins.json | 1 + 10 files changed, 171 insertions(+), 89 deletions(-) diff --git a/src/libs/ipac.c b/src/libs/ipac.c index 8deadb2..078b71d 100644 --- a/src/libs/ipac.c +++ b/src/libs/ipac.c @@ -60,6 +60,24 @@ bool validateIPACData(json_object* jobj, int size, ulboard* board) char* key = NULL; char* tmpKey = NULL; + /* Required for 2015 boards */ + if (board->version == ulboard_version_2015) + { + if (json_object_object_get_ex(jobj, "game controller", &tmp)) + { + if (!json_object_is_type(tmp, json_type_boolean)) + { + log_err ("'game controller' needs to be of type boolean"); + valid = false; + } + } + else + { + log_err ("'game controller' is not defined in the configuration"); + valid = false; + } + } + /* Required */ if (json_object_object_get_ex(jobj, "1/2 shift key", &tmp)) { @@ -74,7 +92,7 @@ bool validateIPACData(json_object* jobj, int size, ulboard* board) log_err ("'1/2 shift key' is not defined in the configuration"); valid = false; } - + /* Required */ if (json_object_object_get_ex(jobj, "pins", &pins)) { @@ -130,6 +148,24 @@ bool validateIPAC4Data (json_object* jobj, ulboard* board) char* key = NULL; char* tmpKey = NULL; + /* Required for 2015 boards */ + if (board->version == ulboard_version_2015) + { + if (json_object_object_get_ex(jobj, "game controller", &tmp)) + { + if (!json_object_is_type(tmp, json_type_boolean)) + { + log_err ("'game controller' needs to be of type boolean"); + valid = false; + } + } + else + { + log_err ("'game controller' is not defined in the configuration"); + valid = false; + } + } + /* Required */ if (json_object_object_get_ex(jobj, "1/2 shift key", &tmp)) { @@ -158,7 +194,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)) { @@ -312,6 +348,10 @@ bool updateBoardIPAC (json_object *jobj, ulboard *board) bool result = false; int bprod = 0; unsigned char* barray = NULL; + + json_object* tmp = NULL; + const char* str = NULL; + int interface = -1; switch (board->version) { @@ -364,6 +404,17 @@ bool updateBoardIPAC (json_object *jobj, ulboard *board) break; case ulboard_version_2015: + + interface = IPACSERIES_INTERFACE; + if (json_object_object_get_ex(jobj, "game controller", &tmp)) + { + if(!json_object_get_boolean(tmp)) + { + interface = IPACSERIES_NGC_INTERFACE; + } + } + debug ("Write to interface: %i", interface); + barray = calloc(IPACSERIES_SIZE, sizeof(unsigned char)); if (barray != NULL) @@ -398,7 +449,7 @@ bool updateBoardIPAC (json_object *jobj, ulboard *board) if (bprod != 0) { result = writeIPACSeriesUSB(barray, IPACSERIES_SIZE, IPAC_VENDOR_2015, - bprod, IPACSERIES_INTERFACE, 1, true); + bprod, interface, 1, true); } free(barray); diff --git a/src/libs/ipacseries.h b/src/libs/ipacseries.h index 199c718..57588b1 100644 --- a/src/libs/ipacseries.h +++ b/src/libs/ipacseries.h @@ -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; diff --git a/src/libs/ipacultimate.c b/src/libs/ipacultimate.c index dacaaeb..4cbb2c9 100644 --- a/src/libs/ipacultimate.c +++ b/src/libs/ipacultimate.c @@ -19,6 +19,7 @@ #include "common.h" #include "ipacultimate.h" #include "ipacseries.h" +#include "uhid.h" #include "dbg.h" #include "ulboard.h" @@ -41,7 +42,7 @@ bool validateIPacUltimateData(json_object* jobj) const char invalidKey = 0x00; char data; - bool valid = false; + bool valid = true; int idx = 0; int boardID = 0; json_object* tmp = NULL; @@ -55,10 +56,22 @@ bool validateIPacUltimateData(json_object* jobj) pUltimate.boardIDUpdate = false; pUltimate.pins = false; - if (checkBoardID(jobj, "board id")) + if (json_object_object_get_ex(jobj, "game controller", &tmp)) { - valid = true; + if (!json_object_is_type(tmp, json_type_boolean)) + { + log_err ("'game controller' needs to be of type boolean"); + valid = false; + } + } + else + { + log_err ("'game controller' is not defined in the configuration"); + valid = false; + } + if (checkBoardID(jobj, "board id")) + { /* Figure out what items we have in this file */ if (json_object_object_get_ex(jobj, "intensity", &leds)) { @@ -129,50 +142,50 @@ bool validateIPacUltimateData(json_object* jobj) log_err ("'Fade rate' value is not between 0 and 255"); valid = false; } - } - else - { - log_err ("'Fade rate' is not defined as an integer"); - valid = false; - } + } + else + { + log_err ("'Fade rate' is not defined as an integer"); + valid = false; + } } if (json_object_object_get_ex(jobj, "pins", &tmp)) - { - valid = true; + { + //valid = true; if (json_object_get_type(tmp) == json_type_array) { if (json_object_array_length(tmp) == 48) { for (idx = 0; idx < json_object_array_length(tmp); ++ idx) - { - pins = json_object_array_get_idx(tmp, idx); + { + pins = json_object_array_get_idx(tmp, idx); json_object_object_foreach(pins, key, pin) { - if (json_object_get_type(pin) == json_type_array) - { - if (json_object_get_type(json_object_array_get_idx(pin, 0)) != json_type_string || - json_object_get_type(json_object_array_get_idx(pin, 1)) != json_type_string || - json_object_get_type(json_object_array_get_idx(pin, 2)) != json_type_boolean) - { - log_err ("The pin at index %i is not defined as a string, string, boolean", idx); - valid = false; - } - } - else - { - log_err ("'pin' object is not defined as an array"); - valid = false; - } + if (json_object_get_type(pin) == json_type_array) + { + if (json_object_get_type(json_object_array_get_idx(pin, 0)) != json_type_string || + json_object_get_type(json_object_array_get_idx(pin, 1)) != json_type_string || + json_object_get_type(json_object_array_get_idx(pin, 2)) != json_type_boolean) + { + log_err ("The pin at index %i is not defined as a string, string, boolean", idx); + valid = false; + } + } + else + { + log_err ("'pin' object is not defined as an array"); + valid = false; + } } } } else { - log_err ("'pins' array is not the correct size. Size is %i, should be 48", json_object_array_length(tmp)); - valid = false; + log_err ("'pins' array is not the correct size. Size is %i, should be 48", json_object_array_length(tmp)); + valid = false; } } else @@ -185,60 +198,59 @@ bool validateIPacUltimateData(json_object* jobj) valid = validateIPacUltimarcMacros(jobj, valid); if (json_object_object_get_ex(jobj, "x threshold", &tmp)) - { - if (json_object_get_type(tmp) == json_type_int) - { - if (json_object_get_int(tmp) <= 0 || - json_object_get_int(tmp) > 128) { - log_err ("'x threshold' value is not between 0 and 127"); + if (json_object_get_type(tmp) == json_type_int) + { + if (json_object_get_int(tmp) <= 0 || + json_object_get_int(tmp) > 128) + { + log_err ("'x threshold' value is not between 0 and 127"); + valid = false; + } + } + else + { + log_err ("'x threshold' is not defined as an integer"); + valid = false; + } + } + else + { + log_err ("'x threshold' is required when pins array is defined"); valid = false; } - } - else - { - log_err ("'x threshold' is not defined as an integer"); - valid = false; - } - } - else - { - log_err ("'x threshold' is required when pins array is defined"); - valid = false; - } if (json_object_object_get_ex(jobj, "y threshold", &tmp)) - { - if (json_object_get_type(tmp) == json_type_int) - { - if (json_object_get_int(tmp) <= 0 || - json_object_get_int(tmp) >= 128) { - log_err ("'y threshold' value is not between 0 and 127"); + if (json_object_get_type(tmp) == json_type_int) + { + if (json_object_get_int(tmp) <= 0 || + json_object_get_int(tmp) >= 128) + { + log_err ("'y threshold' value is not between 0 and 127"); + valid = false; + } + } + else + { + log_err ("'y threshold' is not defined as an integer"); + valid = false; + } + } + else + { + log_err ("'y threshold' is required when pins array is defined"); valid = false; } - } - else - { - log_err ("'y threshold' is not defined as an integer"); - valid = false; + + pUltimate.pins = true; } } - else + else if (checkBoardID(jobj, "current board id")) { - log_err ("'y threshold' is required when pins array is defined"); - valid = false; - } - - pUltimate.pins = true; - } - } - else if (checkBoardID(jobj, "current board id")) - { if (checkBoardID(jobj, "new board id")) { pUltimate.boardIDUpdate = true; - valid = true; } else { @@ -246,16 +258,17 @@ bool validateIPacUltimateData(json_object* jobj) if (!json_object_object_get_ex(jobj, "new board id", &tmp)) { - log_err ("'new board id' is not defined in the configuration file"); + log_err ("'new board id' is not defined in the configuration file"); } } - } - else - { - log_err ("IPAC Ultimate configuration file is not configured correctly"); - } + } + else + { + valid = false; + log_err ("IPAC Ultimate configuration file is not configured correctly"); + } - return valid; + return valid; } /* @@ -677,6 +690,7 @@ bool updateBoardIPacUltimate(json_object* jobj) int idx = 0; int intensity = 0; int board = 0; + int interface = IPACULTIMATE_INTERFACE; uint16_t product = IPACULTIMATE_PRODUCT; unsigned char data[IPACULTIMATE_DATA_SIZE]; @@ -705,7 +719,16 @@ bool updateBoardIPacUltimate(json_object* jobj) product += (board - 1); } - handle = openUSB(ctx, IPACULTIMATE_VENDOR, product, IPACULTIMATE_INTERFACE, 1); + if (json_object_object_get_ex(jobj, "game controller", &tmp)) + { + if (!json_object_get_boolean(tmp)) + { + interface = IPACSERIES_NGC_INTERFACE; + } + } + debug ("Write Interface: %i", interface); + + handle = openUSB(ctx, IPACULTIMATE_VENDOR, product, interface, 1); if (!handle) { diff --git a/src/libs/ipacultimate.h b/src/libs/ipacultimate.h index 2edd9af..ee4e24e 100644 --- a/src/libs/ipacultimate.h +++ b/src/libs/ipacultimate.h @@ -23,6 +23,7 @@ extern "C" { #define IPACULTIMATE_REPORT 0x03 #define IPACULTIMATE_VALUE 0x0203 #define IPACULTIMATE_INTERFACE 3 +#define IPACULTIMATE_NGC_INTERFACE 2 #define IPACULTIMATE_DATA_SIZE 260 typedef struct json_object json_object; diff --git a/src/umtool/ipac2_2015_TestMacro.json b/src/umtool/ipac2_2015_TestMacro.json index c22b936..499eaa1 100644 --- a/src/umtool/ipac2_2015_TestMacro.json +++ b/src/umtool/ipac2_2015_TestMacro.json @@ -1,6 +1,7 @@ { "version" : 2, "product" : "ipac2", + "game controller" : true, "1/2 shift key" : "1start", "macros": { "m1" : [ "m", "1"], diff --git a/src/umtool/ipac2_2015_default.json b/src/umtool/ipac2_2015_default.json index 51870f5..32bf638 100644 --- a/src/umtool/ipac2_2015_default.json +++ b/src/umtool/ipac2_2015_default.json @@ -1,6 +1,7 @@ { "version" : 2, "product" : "ipac2", + "game controller" : true, "1/2 shift key" : "1start", "macros": { }, diff --git a/src/umtool/ipac4_2015_default.json b/src/umtool/ipac4_2015_default.json index 557cb14..9369fc1 100644 --- a/src/umtool/ipac4_2015_default.json +++ b/src/umtool/ipac4_2015_default.json @@ -1,6 +1,7 @@ { "version" : 2, "product" : "ipac4", + "game controller" : false, "1/2 shift key" : "1start", "3/4 shift key" : "3start", "macros": { diff --git a/src/umtool/ipacultimate_config.json b/src/umtool/ipacultimate_config.json index 12afc54..46be5a7 100644 --- a/src/umtool/ipacultimate_config.json +++ b/src/umtool/ipacultimate_config.json @@ -2,5 +2,6 @@ "version" : 1, "product" : "ultimate", "current board id" : 1, - "new board id" : 2 -} \ No newline at end of file + "new board id" : 2, + "game controller" : false +} diff --git a/src/umtool/ipacultimate_led.json b/src/umtool/ipacultimate_led.json index 4e8dbb4..6133cb2 100644 --- a/src/umtool/ipacultimate_led.json +++ b/src/umtool/ipacultimate_led.json @@ -2,6 +2,7 @@ "version": 1, "product": "ultimate", "board id" : 1, + "game controller" : true, "LED states random" : true, "intensity" : [ {"led": 93, "intensity" : 1 }, @@ -10,4 +11,4 @@ {"led": 4, "intensity" : 111 } ], "fade rate" : 0 -} \ No newline at end of file +} diff --git a/src/umtool/ipacultimate_pins.json b/src/umtool/ipacultimate_pins.json index 7e37512..2058087 100644 --- a/src/umtool/ipacultimate_pins.json +++ b/src/umtool/ipacultimate_pins.json @@ -2,6 +2,7 @@ "version": 1, "product": "ultimate", "board id" : 1, + "game controller" : false, "intensity" : [ {"led": 0, "intensity" : 10 }, {"led": 4, "intensity" : 10 } From 92c8d96d72d0a966cecf73b67379a15338011f66 Mon Sep 17 00:00:00 2001 From: katie-snow <katiej.snow@gmail.com> Date: Wed, 30 Aug 2017 14:27:41 -0600 Subject: [PATCH 03/15] Additional configuration file changes for the fix to issue #51 --- src/umtool/jpac_2015_default.json | 1 + src/umtool/minipac_2015_default.json | 1 + 2 files changed, 2 insertions(+) diff --git a/src/umtool/jpac_2015_default.json b/src/umtool/jpac_2015_default.json index afab4e4..e17d25a 100644 --- a/src/umtool/jpac_2015_default.json +++ b/src/umtool/jpac_2015_default.json @@ -1,6 +1,7 @@ { "version" : 2, "product" : "jpac", + "game controller" : true, "1/2 shift key" : "1start", "macros": { }, diff --git a/src/umtool/minipac_2015_default.json b/src/umtool/minipac_2015_default.json index 499eda4..92406d0 100644 --- a/src/umtool/minipac_2015_default.json +++ b/src/umtool/minipac_2015_default.json @@ -1,6 +1,7 @@ { "version" : 2, "product" : "minipac", + "game controller" : false, "1/2 shift key" : "1start", "macros": { }, From 3ad49f3ad7d3283bf6cc581658212d06a6f3d8fe Mon Sep 17 00:00:00 2001 From: Katie <katiej.snow@gmail.com> Date: Mon, 2 Oct 2017 10:24:30 -0600 Subject: [PATCH 04/15] Update README.md Add required libraries needed for umtool. Updated outdated documentation. --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fdeadae..690f8b5 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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: From 7def60bdd955afe4468a79e41e6b0672732aa2be Mon Sep 17 00:00:00 2001 From: Katie <katiej.snow@gmail.com> Date: Mon, 2 Oct 2017 10:30:32 -0600 Subject: [PATCH 05/15] Update README Add libraries that are needed to build umtool. Update the executable names in the document. Add game controller entry to PAC boards and Ultimate board. --- README | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README b/README index 7f2c0f9..afd848d 100644 --- a/README +++ b/README @@ -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 @@ -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. @@ -27,6 +30,7 @@ There are example configuration files for each of the boards in the src/umtool d PAC boards: version: This should be set to 1(pre 2015 board) or 2(2015 and newer). This is used for determining which version of the board to configure product: This is either 'ipac2', 'ipac4', 'minipac', 'jpac', depending on what board you are configuring +game controller : true or false. This changes which interface is used. If have a no game controller board set to false. True follows the 1.3X firmware version. False follows the 1.4X firmware version. 1/2 shift key: Key that will be used as the shift key for player 1 and 2 3/4 shift key: Key that will be used as the shift key for player 3 and 4 pins: List of all the pins(keys) that are on the board. Please modify the example configuration files. @@ -84,6 +88,7 @@ IPAC Ultimate: version: This should be set to 1 always. This is used for version control of the configuration file in the future product: The IPAC Ultimate product number in string format “0410” board id: This number is 1-4. This states which board this configuration is for +game controller : true or false. This changes which interface is used. If have a no game controller board set to false. True follows the 1.3X firmware version. False follows the 1.4X firmware version. pins: The array size is 48 and each entry is a object (key, value). The value is an array with the format string, string, boolean. The key value matches or closely matches the names printed on the board. x threshold: An integer between 0 and 127 inclusive. This is a required entry when pins array is defined y threshold: An integer between 0 and 127 inclusive. This is a required entry when pins array is defined From b1858b3417e4d15a5a24b9c25dab073aa00270f6 Mon Sep 17 00:00:00 2001 From: katie-snow <katiej.snow@gmail.com> Date: Sun, 29 Oct 2017 15:41:43 -0600 Subject: [PATCH 06/15] Fix issue #51. Didn't pass the interface through all the code that needed to be updated. Corrected this bug. --- src/libs/ipacultimate.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/libs/ipacultimate.c b/src/libs/ipacultimate.c index 4cbb2c9..a4f92a1 100644 --- a/src/libs/ipacultimate.c +++ b/src/libs/ipacultimate.c @@ -754,7 +754,7 @@ bool updateBoardIPacUltimate(json_object* jobj) UM_REQUEST_TYPE, UM_REQUEST, IPACULTIMATE_VALUE, - IPACULTIMATE_INTERFACE, + interface, map, IPACSERIES_MESG_LENGTH, UM_TIMEOUT); @@ -771,7 +771,7 @@ bool updateBoardIPacUltimate(json_object* jobj) UM_REQUEST_TYPE, UM_REQUEST, IPACULTIMATE_VALUE, - IPACULTIMATE_INTERFACE, + interface, map, IPACSERIES_MESG_LENGTH, UM_TIMEOUT); @@ -788,7 +788,7 @@ bool updateBoardIPacUltimate(json_object* jobj) UM_REQUEST_TYPE, UM_REQUEST, IPACULTIMATE_VALUE, - IPACULTIMATE_INTERFACE, + interface, map, IPACSERIES_MESG_LENGTH, UM_TIMEOUT); @@ -806,7 +806,7 @@ bool updateBoardIPacUltimate(json_object* jobj) UM_REQUEST_TYPE, UM_REQUEST, IPACULTIMATE_VALUE, - IPACULTIMATE_INTERFACE, + interface, map, IPACSERIES_MESG_LENGTH, UM_TIMEOUT); @@ -853,7 +853,7 @@ bool updateBoardIPacUltimate(json_object* jobj) UM_REQUEST_TYPE, UM_REQUEST, IPACULTIMATE_VALUE, - IPACULTIMATE_INTERFACE, + interface, map, IPACSERIES_MESG_LENGTH, UM_TIMEOUT); @@ -873,14 +873,14 @@ bool updateBoardIPacUltimate(json_object* jobj) UM_REQUEST_TYPE, UM_REQUEST, IPACULTIMATE_VALUE, - IPACULTIMATE_INTERFACE, + interface, map, IPACSERIES_MESG_LENGTH, UM_TIMEOUT); } exit: - closeUSB(ctx, handle, IPACULTIMATE_INTERFACE); + closeUSB(ctx, handle, interface); return result; error: From e467d7544298328d9494c8e9ae868066d5e77485 Mon Sep 17 00:00:00 2001 From: katie-snow <katiej.snow@gmail.com> Date: Thu, 28 Dec 2017 19:43:56 -0700 Subject: [PATCH 07/15] Took the interface functionality out of openUSB and placed it in its own function. The new interface function will be used by the IPAC functionality. Fixes issue #51 --- src/libs/common.c | 31 ++++++++++++++++++++++++------- src/libs/common.h | 8 +++++++- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/libs/common.c b/src/libs/common.c index 8fedc24..6fd9d98 100644 --- a/src/libs/common.c +++ b/src/libs/common.c @@ -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 */ @@ -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 diff --git a/src/libs/common.h b/src/libs/common.h index e668610..a9fcbf7 100644 --- a/src/libs/common.h +++ b/src/libs/common.h @@ -26,8 +26,8 @@ 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, @@ -35,6 +35,12 @@ struct libusb_device_handle* openUSB(libusb_context *ctx, 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 */ From c8d637ded8456975c0a42e3368a4a189494add48 Mon Sep 17 00:00:00 2001 From: katie-snow <katiej.snow@gmail.com> Date: Thu, 28 Dec 2017 19:59:27 -0700 Subject: [PATCH 08/15] Fixes issue #51 Remove game controller configuration option. Implemented functionality to detect which interface to use when writing to the board. This configuration option no longer needed. --- src/libs/ipac.c | 51 ++-------------------------- src/umtool/ipac2_2015_TestMacro.json | 1 - src/umtool/ipac2_2015_default.json | 1 - src/umtool/ipac4_2015_default.json | 1 - src/umtool/jpac_2015_default.json | 1 - src/umtool/minipac_2015_default.json | 1 - 6 files changed, 3 insertions(+), 53 deletions(-) diff --git a/src/libs/ipac.c b/src/libs/ipac.c index 078b71d..f6d41ff 100644 --- a/src/libs/ipac.c +++ b/src/libs/ipac.c @@ -60,24 +60,6 @@ bool validateIPACData(json_object* jobj, int size, ulboard* board) char* key = NULL; char* tmpKey = NULL; - /* Required for 2015 boards */ - if (board->version == ulboard_version_2015) - { - if (json_object_object_get_ex(jobj, "game controller", &tmp)) - { - if (!json_object_is_type(tmp, json_type_boolean)) - { - log_err ("'game controller' needs to be of type boolean"); - valid = false; - } - } - else - { - log_err ("'game controller' is not defined in the configuration"); - valid = false; - } - } - /* Required */ if (json_object_object_get_ex(jobj, "1/2 shift key", &tmp)) { @@ -148,24 +130,6 @@ bool validateIPAC4Data (json_object* jobj, ulboard* board) char* key = NULL; char* tmpKey = NULL; - /* Required for 2015 boards */ - if (board->version == ulboard_version_2015) - { - if (json_object_object_get_ex(jobj, "game controller", &tmp)) - { - if (!json_object_is_type(tmp, json_type_boolean)) - { - log_err ("'game controller' needs to be of type boolean"); - valid = false; - } - } - else - { - log_err ("'game controller' is not defined in the configuration"); - valid = false; - } - } - /* Required */ if (json_object_object_get_ex(jobj, "1/2 shift key", &tmp)) { @@ -404,17 +368,6 @@ bool updateBoardIPAC (json_object *jobj, ulboard *board) break; case ulboard_version_2015: - - interface = IPACSERIES_INTERFACE; - if (json_object_object_get_ex(jobj, "game controller", &tmp)) - { - if(!json_object_get_boolean(tmp)) - { - interface = IPACSERIES_NGC_INTERFACE; - } - } - debug ("Write to interface: %i", interface); - barray = calloc(IPACSERIES_SIZE, sizeof(unsigned char)); if (barray != NULL) @@ -448,8 +401,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, interface, 1, true); + bprod, -1, 1, true); } free(barray); @@ -672,3 +626,4 @@ void update2015JPACBoard (json_object *jobj, unsigned char* barray) json_object_object_get_ex(jobj, "macros", ¯os); populateMacrosPosition(JPAC_BOARD, macros, &barray[3]); } + diff --git a/src/umtool/ipac2_2015_TestMacro.json b/src/umtool/ipac2_2015_TestMacro.json index 499eaa1..c22b936 100644 --- a/src/umtool/ipac2_2015_TestMacro.json +++ b/src/umtool/ipac2_2015_TestMacro.json @@ -1,7 +1,6 @@ { "version" : 2, "product" : "ipac2", - "game controller" : true, "1/2 shift key" : "1start", "macros": { "m1" : [ "m", "1"], diff --git a/src/umtool/ipac2_2015_default.json b/src/umtool/ipac2_2015_default.json index 32bf638..51870f5 100644 --- a/src/umtool/ipac2_2015_default.json +++ b/src/umtool/ipac2_2015_default.json @@ -1,7 +1,6 @@ { "version" : 2, "product" : "ipac2", - "game controller" : true, "1/2 shift key" : "1start", "macros": { }, diff --git a/src/umtool/ipac4_2015_default.json b/src/umtool/ipac4_2015_default.json index 9369fc1..557cb14 100644 --- a/src/umtool/ipac4_2015_default.json +++ b/src/umtool/ipac4_2015_default.json @@ -1,7 +1,6 @@ { "version" : 2, "product" : "ipac4", - "game controller" : false, "1/2 shift key" : "1start", "3/4 shift key" : "3start", "macros": { diff --git a/src/umtool/jpac_2015_default.json b/src/umtool/jpac_2015_default.json index e17d25a..afab4e4 100644 --- a/src/umtool/jpac_2015_default.json +++ b/src/umtool/jpac_2015_default.json @@ -1,7 +1,6 @@ { "version" : 2, "product" : "jpac", - "game controller" : true, "1/2 shift key" : "1start", "macros": { }, diff --git a/src/umtool/minipac_2015_default.json b/src/umtool/minipac_2015_default.json index 92406d0..499eda4 100644 --- a/src/umtool/minipac_2015_default.json +++ b/src/umtool/minipac_2015_default.json @@ -1,7 +1,6 @@ { "version" : 2, "product" : "minipac", - "game controller" : false, "1/2 shift key" : "1start", "macros": { }, From 41a0fffaff2cdba2d0ee9226b76d61e479f0686e Mon Sep 17 00:00:00 2001 From: katie-snow <katiej.snow@gmail.com> Date: Thu, 28 Dec 2017 20:11:39 -0700 Subject: [PATCH 09/15] Fixes issue #51 Remove game controller configuration entry in the configuration. The code will now figure out which interface to use. --- src/libs/ipacultimate.c | 56 ++++++++++++++++------------- src/umtool/ipacultimate_config.json | 1 - src/umtool/ipacultimate_led.json | 1 - src/umtool/ipacultimate_pins.json | 1 - 4 files changed, 32 insertions(+), 27 deletions(-) diff --git a/src/libs/ipacultimate.c b/src/libs/ipacultimate.c index a4f92a1..95d9eab 100644 --- a/src/libs/ipacultimate.c +++ b/src/libs/ipacultimate.c @@ -56,20 +56,6 @@ bool validateIPacUltimateData(json_object* jobj) pUltimate.boardIDUpdate = false; pUltimate.pins = false; - if (json_object_object_get_ex(jobj, "game controller", &tmp)) - { - if (!json_object_is_type(tmp, json_type_boolean)) - { - log_err ("'game controller' needs to be of type boolean"); - valid = false; - } - } - else - { - log_err ("'game controller' is not defined in the configuration"); - valid = false; - } - if (checkBoardID(jobj, "board id")) { /* Figure out what items we have in this file */ @@ -681,7 +667,10 @@ void populateIPacUltimateMacro(json_object* jobj, unsigned char* barray) bool updateBoardIPacUltimate(json_object* jobj) { libusb_context *ctx = NULL; + libusb_device *device = NULL; + struct libusb_device_handle *handle = NULL; + struct libusb_device_descriptor descriptor; int ipac_idx = 4; int pos = 0; @@ -719,16 +708,7 @@ bool updateBoardIPacUltimate(json_object* jobj) product += (board - 1); } - if (json_object_object_get_ex(jobj, "game controller", &tmp)) - { - if (!json_object_get_boolean(tmp)) - { - interface = IPACSERIES_NGC_INTERFACE; - } - } - debug ("Write Interface: %i", interface); - - handle = openUSB(ctx, IPACULTIMATE_VENDOR, product, interface, 1); + handle = openUSB(ctx, IPACULTIMATE_VENDOR, product, -1, 1); if (!handle) { @@ -736,6 +716,34 @@ bool updateBoardIPacUltimate(json_object* jobj) goto error; } + debug ("Figuring out which interface to use for reading and writing..."); + device = libusb_get_device(handle); + + if (!device) + { + result = false; + goto error; + } + + libusb_get_device_descriptor (device, &descriptor); + if ((descriptor.bcdDevice & 0x40) != 0) + { + log_info ("No Game Controller board"); + interface = IPACULTIMATE_NGC_INTERFACE; + } + else + { + log_info ("Game Controller board"); + interface = IPACULTIMATE_INTERFACE; + } + + debug ("Claiming interface..."); + if (!claimInterface(handle, interface, true)) + { + result = false; + goto error; + } + /* Intensity settings */ if (pUltimate.ledMapIntensity == true) { diff --git a/src/umtool/ipacultimate_config.json b/src/umtool/ipacultimate_config.json index 46be5a7..367f917 100644 --- a/src/umtool/ipacultimate_config.json +++ b/src/umtool/ipacultimate_config.json @@ -3,5 +3,4 @@ "product" : "ultimate", "current board id" : 1, "new board id" : 2, - "game controller" : false } diff --git a/src/umtool/ipacultimate_led.json b/src/umtool/ipacultimate_led.json index 6133cb2..8116aa2 100644 --- a/src/umtool/ipacultimate_led.json +++ b/src/umtool/ipacultimate_led.json @@ -2,7 +2,6 @@ "version": 1, "product": "ultimate", "board id" : 1, - "game controller" : true, "LED states random" : true, "intensity" : [ {"led": 93, "intensity" : 1 }, diff --git a/src/umtool/ipacultimate_pins.json b/src/umtool/ipacultimate_pins.json index 2058087..7e37512 100644 --- a/src/umtool/ipacultimate_pins.json +++ b/src/umtool/ipacultimate_pins.json @@ -2,7 +2,6 @@ "version": 1, "product": "ultimate", "board id" : 1, - "game controller" : false, "intensity" : [ {"led": 0, "intensity" : 10 }, {"led": 4, "intensity" : 10 } From 41dd74f40701f07756c513c0dde81506c0676d7a Mon Sep 17 00:00:00 2001 From: katie-snow <katiej.snow@gmail.com> Date: Thu, 28 Dec 2017 20:13:35 -0700 Subject: [PATCH 10/15] Fixes issue #51 Add functionality to writeIPACSeriesUSB function to determine which interface to use. The libusb information provides bcdDevice value which is the firmware version .3x or .4x. This will determine which interface to use for writing to the board. --- src/libs/ipacseries.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/libs/ipacseries.c b/src/libs/ipacseries.c index 654bf1e..65b95dc 100644 --- a/src/libs/ipacseries.c +++ b/src/libs/ipacseries.c @@ -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; @@ -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) @@ -1148,3 +1180,4 @@ bool writeIPACSeriesUSB (unsigned char* barray, int size, uint16_t vendor, uint1 error: return result; } + From 415a33b39ce2f098e397f04573efc5adda6954a4 Mon Sep 17 00:00:00 2001 From: katie-snow <katiej.snow@gmail.com> Date: Thu, 28 Dec 2017 20:38:10 -0700 Subject: [PATCH 11/15] Fixes issue #52 Exit value now returns 0 success and 1 for failure. Mixed boolean and integer when I shouldn't have. --- src/libs/ultimarc.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/libs/ultimarc.c b/src/libs/ultimarc.c index 7dfbf76..1039b84 100644 --- a/src/libs/ultimarc.c +++ b/src/libs/ultimarc.c @@ -85,6 +85,7 @@ int ulWriteToBoard (json_object* bcfg, ulboard* board) { int retCode = 0; + bool ret = false; if (bcfg && board) { @@ -93,56 +94,57 @@ ulWriteToBoard (json_object* bcfg, ulboard* board) board->type == ulboard_type_jpac || board->type == ulboard_type_minipac) { - retCode = updateBoardIPAC (bcfg, board); + ret = updateBoardIPAC (bcfg, board); } else if (board->type == ulboard_type_ultimate) { log_info("Updating IPAC Ultimate board..."); - retCode = updateBoardIPacUltimate (bcfg); + ret = updateBoardIPacUltimate (bcfg); } else if (board->type == ulboard_type_pacDrive) { log_info("Updating PAC Drive board..."); - retCode = updateBoardPacDrive (bcfg); + ret = updateBoardPacDrive (bcfg); } else if (board->type == ulboard_type_pacLED) { log_info("Updating PAC LED 64 board..."); - retCode = updateBoardPacLED (bcfg); + ret = updateBoardPacLED (bcfg); } else if (board->type == ulboard_type_ultistik) { log_info("Updating Ultistik board..."); - retCode = updateBoardULTISTIK (bcfg, board); + ret = updateBoardULTISTIK (bcfg, board); } else if (board->type == ulboard_type_usbbutton) { log_info("Updating USBButton..."); - retCode = updateUSBButton (bcfg, board); + ret = updateUSBButton (bcfg, board); } else if (board->type == ulboard_type_servostik) { log_info("Updating ServoStik..."); - retCode = updateServoStik (bcfg, board); + ret = updateServoStik (bcfg, board); } else if (board->type == ulboard_type_uhid || board->type == ulboard_type_uhidNano) { - retCode = updateUHid (bcfg, board); + ret = updateUHid (bcfg, board); } - if (retCode) + if (ret) { log_info("Board update successful."); } else { log_info("Board update failed."); + retCode = 1; } } else { - retCode = -1; + retCode = 1; log_info("Board update failed."); } From f1dedd45e09f17e0ed07aab590d00c7b2cebea97 Mon Sep 17 00:00:00 2001 From: katie-snow <katiej.snow@gmail.com> Date: Sat, 30 Dec 2017 22:11:31 -0700 Subject: [PATCH 12/15] Fix debug message for issue #51 --- src/libs/ipacultimate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ipacultimate.c b/src/libs/ipacultimate.c index 95d9eab..5e185c3 100644 --- a/src/libs/ipacultimate.c +++ b/src/libs/ipacultimate.c @@ -716,7 +716,7 @@ bool updateBoardIPacUltimate(json_object* jobj) goto error; } - debug ("Figuring out which interface to use for reading and writing..."); + debug ("Determine which interface to use..."); device = libusb_get_device(handle); if (!device) From 0de8fb78951c51fe2e9438f69336a714ee0a46d1 Mon Sep 17 00:00:00 2001 From: katie-snow <katiej.snow@gmail.com> Date: Sun, 31 Dec 2017 10:42:21 -0700 Subject: [PATCH 13/15] Remove configuration option in the README file. Issue #51 --- README | 2 -- 1 file changed, 2 deletions(-) diff --git a/README b/README index afd848d..dd20687 100644 --- a/README +++ b/README @@ -30,7 +30,6 @@ There are example configuration files for each of the boards in the src/umtool d PAC boards: version: This should be set to 1(pre 2015 board) or 2(2015 and newer). This is used for determining which version of the board to configure product: This is either 'ipac2', 'ipac4', 'minipac', 'jpac', depending on what board you are configuring -game controller : true or false. This changes which interface is used. If have a no game controller board set to false. True follows the 1.3X firmware version. False follows the 1.4X firmware version. 1/2 shift key: Key that will be used as the shift key for player 1 and 2 3/4 shift key: Key that will be used as the shift key for player 3 and 4 pins: List of all the pins(keys) that are on the board. Please modify the example configuration files. @@ -88,7 +87,6 @@ IPAC Ultimate: version: This should be set to 1 always. This is used for version control of the configuration file in the future product: The IPAC Ultimate product number in string format “0410” board id: This number is 1-4. This states which board this configuration is for -game controller : true or false. This changes which interface is used. If have a no game controller board set to false. True follows the 1.3X firmware version. False follows the 1.4X firmware version. pins: The array size is 48 and each entry is a object (key, value). The value is an array with the format string, string, boolean. The key value matches or closely matches the names printed on the board. x threshold: An integer between 0 and 127 inclusive. This is a required entry when pins array is defined y threshold: An integer between 0 and 127 inclusive. This is a required entry when pins array is defined From 03b4cf46c8ddf15e660646084e4d5c7c2b0c924c Mon Sep 17 00:00:00 2001 From: katie-snow <katiej.snow@gmail.com> Date: Sun, 31 Dec 2017 13:37:03 -0700 Subject: [PATCH 14/15] Remove unused variables --- src/libs/ipac.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/libs/ipac.c b/src/libs/ipac.c index f6d41ff..35cbda7 100644 --- a/src/libs/ipac.c +++ b/src/libs/ipac.c @@ -74,7 +74,7 @@ bool validateIPACData(json_object* jobj, int size, ulboard* board) log_err ("'1/2 shift key' is not defined in the configuration"); valid = false; } - + /* Required */ if (json_object_object_get_ex(jobj, "pins", &pins)) { @@ -313,10 +313,6 @@ bool updateBoardIPAC (json_object *jobj, ulboard *board) int bprod = 0; unsigned char* barray = NULL; - json_object* tmp = NULL; - const char* str = NULL; - int interface = -1; - switch (board->version) { case ulboard_version_pre2015: From 4b5935da37cf4808c14ac769b1171673ca2ad9e3 Mon Sep 17 00:00:00 2001 From: katie-snow <katiej.snow@gmail.com> Date: Sun, 31 Dec 2017 13:37:30 -0700 Subject: [PATCH 15/15] Fix formatting in validation function and a few other locations --- src/libs/ipacultimate.c | 500 ++++++++++++++++++++-------------------- 1 file changed, 249 insertions(+), 251 deletions(-) diff --git a/src/libs/ipacultimate.c b/src/libs/ipacultimate.c index 5e185c3..11a603c 100644 --- a/src/libs/ipacultimate.c +++ b/src/libs/ipacultimate.c @@ -58,203 +58,201 @@ bool validateIPacUltimateData(json_object* jobj) if (checkBoardID(jobj, "board id")) { - /* Figure out what items we have in this file */ - if (json_object_object_get_ex(jobj, "intensity", &leds)) - { - if (json_object_get_type(leds) == json_type_array) - { - for (idx = 0; idx < json_object_array_length(leds); ++ idx) - { - led = json_object_array_get_idx(leds, idx); - /* required entries */ - if (!json_object_object_get_ex(led, "led", &tmp) && - !json_object_object_get_ex(led, "intensity", &tmp)) - { - log_err ("Missing required entries. Valid entries 'led' and 'intensity'"); - valid = false; - } - - pUltimate.ledMapIntensity = true; - } - } - else - { - log_err ("'intensity' is not defined as an array"); - } - } - if (json_object_object_get_ex(jobj, "LED intensity all", &tmp)) - { - /* can't have the intensity entry with 'LED intensity all' */ - if (pUltimate.ledMapIntensity == true) - { - log_err ("'intensity' and 'LED intensity all' are not permitted same configuration file"); - valid = false; - } - else if (json_object_get_type(tmp) == json_type_int) - { - pUltimate.allIntensities = true; - } - else - { - log_err ("'LED intensity all' is not defined as an integer"); - valid = false; - } - } - - if (json_object_object_get_ex(jobj, "LED states random", &tmp)) - { - if (json_object_get_type(tmp) == json_type_boolean) - { - pUltimate.random = json_object_get_boolean(tmp); - } - else - { - log_err ("'LED states random' is not defined as a boolean"); - valid = false; - } - } - - if (json_object_object_get_ex(jobj, "fade rate", &tmp)) - { - if (json_object_get_type(tmp) == json_type_int) - { - if (json_object_get_int(tmp) >= 0 && - json_object_get_int(tmp) <= 255) - { - pUltimate.fadeRate = true; - } - else - { - log_err ("'Fade rate' value is not between 0 and 255"); - valid = false; - } - } - else + /* Figure out what items we have in this file */ + if (json_object_object_get_ex(jobj, "intensity", &leds)) + { + if (json_object_get_type(leds) == json_type_array) + { + for (idx = 0; idx < json_object_array_length(leds); ++ idx) + { + led = json_object_array_get_idx(leds, idx); + /* required entries */ + if (!json_object_object_get_ex(led, "led", &tmp) && + !json_object_object_get_ex(led, "intensity", &tmp)) { - log_err ("'Fade rate' is not defined as an integer"); + log_err ("Missing required entries. Valid entries 'led' and 'intensity'"); valid = false; } - } - if (json_object_object_get_ex(jobj, "pins", &tmp)) + pUltimate.ledMapIntensity = true; + } + } + else + { + log_err ("'intensity' is not defined as an array"); + } + } + if (json_object_object_get_ex(jobj, "LED intensity all", &tmp)) + { + /* can't have the intensity entry with 'LED intensity all' */ + if (pUltimate.ledMapIntensity == true) + { + log_err ("'intensity' and 'LED intensity all' are not permitted same configuration file"); + valid = false; + } + else if (json_object_get_type(tmp) == json_type_int) + { + pUltimate.allIntensities = true; + } + else + { + log_err ("'LED intensity all' is not defined as an integer"); + valid = false; + } + } + + if (json_object_object_get_ex(jobj, "LED states random", &tmp)) + { + if (json_object_get_type(tmp) == json_type_boolean) + { + pUltimate.random = json_object_get_boolean(tmp); + } + else + { + log_err ("'LED states random' is not defined as a boolean"); + valid = false; + } + } + + if (json_object_object_get_ex(jobj, "fade rate", &tmp)) + { + if (json_object_get_type(tmp) == json_type_int) + { + if (json_object_get_int(tmp) >= 0 && + json_object_get_int(tmp) <= 255) + { + pUltimate.fadeRate = true; + } + else { - //valid = true; + log_err ("'Fade rate' value is not between 0 and 255"); + valid = false; + } + } + else + { + log_err ("'Fade rate' is not defined as an integer"); + valid = false; + } + } - if (json_object_get_type(tmp) == json_type_array) - { - if (json_object_array_length(tmp) == 48) - { - for (idx = 0; idx < json_object_array_length(tmp); ++ idx) - { - pins = json_object_array_get_idx(tmp, idx); - - json_object_object_foreach(pins, key, pin) - { - if (json_object_get_type(pin) == json_type_array) - { - if (json_object_get_type(json_object_array_get_idx(pin, 0)) != json_type_string || - json_object_get_type(json_object_array_get_idx(pin, 1)) != json_type_string || - json_object_get_type(json_object_array_get_idx(pin, 2)) != json_type_boolean) - { - log_err ("The pin at index %i is not defined as a string, string, boolean", idx); - valid = false; - } - } - else - { - log_err ("'pin' object is not defined as an array"); - valid = false; - } - } - } - } - else - { - log_err ("'pins' array is not the correct size. Size is %i, should be 48", json_object_array_length(tmp)); - valid = false; - } - } - else - { - log_err ("'pins' is not defined as an array"); - valid = false; - } - - /* Macro validation */ - valid = validateIPacUltimarcMacros(jobj, valid); - - if (json_object_object_get_ex(jobj, "x threshold", &tmp)) + if (json_object_object_get_ex(jobj, "pins", &tmp)) + { + if (json_object_get_type(tmp) == json_type_array) + { + if (json_object_array_length(tmp) == 48) + { + for (idx = 0; idx < json_object_array_length(tmp); ++ idx) { - if (json_object_get_type(tmp) == json_type_int) + pins = json_object_array_get_idx(tmp, idx); + + json_object_object_foreach(pins, key, pin) { - if (json_object_get_int(tmp) <= 0 || - json_object_get_int(tmp) > 128) + if (json_object_get_type(pin) == json_type_array) { - log_err ("'x threshold' value is not between 0 and 127"); - valid = false; + if (json_object_get_type(json_object_array_get_idx(pin, 0)) != json_type_string || + json_object_get_type(json_object_array_get_idx(pin, 1)) != json_type_string || + json_object_get_type(json_object_array_get_idx(pin, 2)) != json_type_boolean) + { + log_err ("The pin at index %i is not defined as a string, string, boolean", idx); + valid = false; + } } - } - else - { - log_err ("'x threshold' is not defined as an integer"); - valid = false; - } - } - else - { - log_err ("'x threshold' is required when pins array is defined"); - valid = false; - } - - if (json_object_object_get_ex(jobj, "y threshold", &tmp)) - { - if (json_object_get_type(tmp) == json_type_int) - { - if (json_object_get_int(tmp) <= 0 || - json_object_get_int(tmp) >= 128) + else { - log_err ("'y threshold' value is not between 0 and 127"); + log_err ("'pin' object is not defined as an array"); valid = false; } } - else - { - log_err ("'y threshold' is not defined as an integer"); - valid = false; - } } - else + } + else + { + log_err ("'pins' array is not the correct size. Size is %i, should be 48", json_object_array_length(tmp)); + valid = false; + } + } + else + { + log_err ("'pins' is not defined as an array"); + valid = false; + } + + /* Macro validation */ + valid = validateIPacUltimarcMacros(jobj, valid); + + if (json_object_object_get_ex(jobj, "x threshold", &tmp)) + { + if (json_object_get_type(tmp) == json_type_int) + { + if (json_object_get_int(tmp) <= 0 || + json_object_get_int(tmp) > 128) { - log_err ("'y threshold' is required when pins array is defined"); + log_err ("'x threshold' value is not between 0 and 127"); valid = false; } - - pUltimate.pins = true; } + else + { + log_err ("'x threshold' is not defined as an integer"); + valid = false; + } + } + else + { + log_err ("'x threshold' is required when pins array is defined"); + valid = false; } - else if (checkBoardID(jobj, "current board id")) + + if (json_object_object_get_ex(jobj, "y threshold", &tmp)) { - if (checkBoardID(jobj, "new board id")) - { - pUltimate.boardIDUpdate = true; - } - else - { - valid = false; - - if (!json_object_object_get_ex(jobj, "new board id", &tmp)) - { - log_err ("'new board id' is not defined in the configuration file"); - } - } + if (json_object_get_type(tmp) == json_type_int) + { + if (json_object_get_int(tmp) <= 0 || + json_object_get_int(tmp) >= 128) + { + log_err ("'y threshold' value is not between 0 and 127"); + valid = false; + } + } + else + { + log_err ("'y threshold' is not defined as an integer"); + valid = false; + } } else { + log_err ("'y threshold' is required when pins array is defined"); valid = false; - log_err ("IPAC Ultimate configuration file is not configured correctly"); } - return valid; + pUltimate.pins = true; + } + } + else if (checkBoardID(jobj, "current board id")) + { + if (checkBoardID(jobj, "new board id")) + { + pUltimate.boardIDUpdate = true; + } + else + { + valid = false; + + if (!json_object_object_get_ex(jobj, "new board id", &tmp)) + { + log_err ("'new board id' is not defined in the configuration file"); + } + } + } + else + { + valid = false; + log_err ("IPAC Ultimate configuration file is not configured correctly"); + } + + return valid; } /* @@ -697,23 +695,23 @@ bool updateBoardIPacUltimate(json_object* jobj) if (pUltimate.boardIDUpdate == true) { - json_object_object_get_ex(jobj, "current board id", &tmp); - board = json_object_get_int(tmp); - product += (board - 1); + json_object_object_get_ex(jobj, "current board id", &tmp); + board = json_object_get_int(tmp); + product += (board - 1); } else { - json_object_object_get_ex(jobj, "board id", &tmp); - board = json_object_get_int(tmp); - product += (board - 1); + json_object_object_get_ex(jobj, "board id", &tmp); + board = json_object_get_int(tmp); + product += (board - 1); } handle = openUSB(ctx, IPACULTIMATE_VENDOR, product, -1, 1); if (!handle) { - result = false; - goto error; + result = false; + goto error; } debug ("Determine which interface to use..."); @@ -747,77 +745,77 @@ bool updateBoardIPacUltimate(json_object* jobj) /* Intensity settings */ if (pUltimate.ledMapIntensity == true) { - json_object_object_get_ex(jobj, "intensity", &leds); - for (idx = 0; idx < json_object_array_length(leds); ++ idx) - { - led = json_object_array_get_idx(leds, idx); - json_object_object_get_ex(led, "led", &tmp); - map[1] = convertDecimalToHex(json_object_get_int(tmp)); - - json_object_object_get_ex(led, "intensity", &tmp); - map[2] = convertDecimalToHex (json_object_get_int(tmp)); - - /* ship this data off to the USB device */ - libusb_control_transfer(handle, - UM_REQUEST_TYPE, - UM_REQUEST, - IPACULTIMATE_VALUE, - interface, - map, - IPACSERIES_MESG_LENGTH, - UM_TIMEOUT); - } + json_object_object_get_ex(jobj, "intensity", &leds); + for (idx = 0; idx < json_object_array_length(leds); ++ idx) + { + led = json_object_array_get_idx(leds, idx); + json_object_object_get_ex(led, "led", &tmp); + map[1] = convertDecimalToHex(json_object_get_int(tmp)); + + json_object_object_get_ex(led, "intensity", &tmp); + map[2] = convertDecimalToHex (json_object_get_int(tmp)); + + /* ship this data off to the USB device */ + libusb_control_transfer(handle, + UM_REQUEST_TYPE, + UM_REQUEST, + IPACULTIMATE_VALUE, + interface, + map, + IPACSERIES_MESG_LENGTH, + UM_TIMEOUT); + } } else if (pUltimate.allIntensities == true) { - map[1] = 0x80; // 128 decimal - json_object_object_get_ex(jobj, "LED intensity all", &tmp); - map[2] = convertDecimalToHex (json_object_get_int(tmp)); - - /* ship this data off to the USB device */ - libusb_control_transfer(handle, - UM_REQUEST_TYPE, - UM_REQUEST, - IPACULTIMATE_VALUE, - interface, - map, - IPACSERIES_MESG_LENGTH, - UM_TIMEOUT); + map[1] = 0x80; // 128 decimal + json_object_object_get_ex(jobj, "LED intensity all", &tmp); + map[2] = convertDecimalToHex (json_object_get_int(tmp)); + + /* ship this data off to the USB device */ + libusb_control_transfer(handle, + UM_REQUEST_TYPE, + UM_REQUEST, + IPACULTIMATE_VALUE, + interface, + map, + IPACSERIES_MESG_LENGTH, + UM_TIMEOUT); } /* Random states */ if (pUltimate.random == true) { - map[1] = 0x89; // 137 decimal - map[2] = 0; - - /* ship this data off to the USB device */ - libusb_control_transfer(handle, - UM_REQUEST_TYPE, - UM_REQUEST, - IPACULTIMATE_VALUE, - interface, - map, - IPACSERIES_MESG_LENGTH, - UM_TIMEOUT); + map[1] = 0x89; // 137 decimal + map[2] = 0; + + /* ship this data off to the USB device */ + libusb_control_transfer(handle, + UM_REQUEST_TYPE, + UM_REQUEST, + IPACULTIMATE_VALUE, + interface, + map, + IPACSERIES_MESG_LENGTH, + UM_TIMEOUT); } /* Fade rate */ if (pUltimate.fadeRate == true) { - map[1] = 0xc0; // 192 decimal - json_object_object_get_ex(jobj, "fade rate", &tmp); - map[2] = convertDecimalToHex (json_object_get_int(tmp)); - - /* ship this data off to the USB device */ - libusb_control_transfer(handle, - UM_REQUEST_TYPE, - UM_REQUEST, - IPACULTIMATE_VALUE, - interface, - map, - IPACSERIES_MESG_LENGTH, - UM_TIMEOUT); + map[1] = 0xc0; // 192 decimal + json_object_object_get_ex(jobj, "fade rate", &tmp); + map[2] = convertDecimalToHex (json_object_get_int(tmp)); + + /* ship this data off to the USB device */ + libusb_control_transfer(handle, + UM_REQUEST_TYPE, + UM_REQUEST, + IPACULTIMATE_VALUE, + interface, + map, + IPACSERIES_MESG_LENGTH, + UM_TIMEOUT); } if (pUltimate.pins == true) @@ -873,24 +871,24 @@ bool updateBoardIPacUltimate(json_object* jobj) { /* THIS IS NOT WORKING CORRECTLY */ memcpy (&map[1], &header, sizeof(header)); - json_object_object_get_ex(jobj, "new board id", &tmp); - map[1] = convertDecimalToHex((json_object_get_int(tmp) + 80)); - - /* ship this data off to the USB device */ - ret = libusb_control_transfer(handle, - UM_REQUEST_TYPE, - UM_REQUEST, - IPACULTIMATE_VALUE, - interface, - map, - IPACSERIES_MESG_LENGTH, - UM_TIMEOUT); + json_object_object_get_ex(jobj, "new board id", &tmp); + map[1] = convertDecimalToHex((json_object_get_int(tmp) + 80)); + + /* ship this data off to the USB device */ + ret = libusb_control_transfer(handle, + UM_REQUEST_TYPE, + UM_REQUEST, + IPACULTIMATE_VALUE, + interface, + map, + IPACSERIES_MESG_LENGTH, + UM_TIMEOUT); } exit: - closeUSB(ctx, handle, interface); - return result; + closeUSB(ctx, handle, interface); + return result; error: - return result; + return result; }