diff options
Diffstat (limited to 'res/controllers/common-hid-packet-parser.js')
-rw-r--r-- | res/controllers/common-hid-packet-parser.js | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/res/controllers/common-hid-packet-parser.js b/res/controllers/common-hid-packet-parser.js index a7f6becd3a..ace9ad57d9 100644 --- a/res/controllers/common-hid-packet-parser.js +++ b/res/controllers/common-hid-packet-parser.js @@ -334,8 +334,10 @@ HIDPacket.prototype.removeControl = function(group, name) { * @param pack control packing format for unpack(), one of b/B, h/H, i/I * @param bitmask bitmask size, undefined for byte(s) controls * NOTE: Parsing bitmask with multiple bits is not supported yet. - * @param isEncoder indicates if this is an encoder which should be wrapped and delta reported */ -HIDPacket.prototype.addControl = function(group, name, offset, pack, bitmask, isEncoder) { + * @param isEncoder indicates if this is an encoder which should be wrapped and delta reported + * @param callback callback function for the control + */ +HIDPacket.prototype.addControl = function(group, name, offset, pack, bitmask, isEncoder, callback) { var control_group = this.getGroup(group, true) var bitvector = undefined if (control_group == undefined) { @@ -358,6 +360,13 @@ HIDPacket.prototype.addControl = function(group, name, offset, pack, bitmask, is } bitvector = field.value bitvector.addBitMask(group, name, bitmask) + if (callback !== undefined) { + if (typeof callback !== "function") { + HIDDebug("ERROR callback provided for " + group + "." + name + " is not a function."); + return; + } + this.setCallback(group, name, callback); + } return } @@ -415,6 +424,14 @@ HIDPacket.prototype.addControl = function(group, name, offset, pack, bitmask, is // Add the new field to the packet control_group[field.id] = field + + if (callback !== undefined) { + if (typeof callback !== "function") { + HIDDebug("ERROR callback provided for " + group + "." + name + " is not a function."); + return; + } + this.setCallback(group, name, callback); + } } /** Register a Output control field or Output control bit to output packet |