Input on two indices confuses my generic device config - what can I do?

Hi,

I've been configuring a small "XP Pen" brand keypad/rotary input device (basically a 10-key macro keypad with a scroll-wheel).

All went well, I used the usual steps in the analyser to sniff what was being sent on each keypress and added in the relevant index/values into the JavaScript.

However when I got to keys 5 & 6 I noticed something odd. Key 6 always triggered the "Key 5 trigger!" log message (i.e; key 6 was being interpreted as key 5). Here's the relevant code:

if(reportBuffer.readUInt8(1) === 0x01) {
        log('Key 5 trigger!');
        bttTriggerDeviceTrigger(targetDevice, 'key5');
    } else 
     if(reportBuffer.readUInt8(2) === 0x11) {
        log('Key 6 trigger!');
        bttTriggerDeviceTrigger(targetDevice, 'key6');
    }
  • KEY 5: index 1 : value 01
  • KEY 6: index 2 : value 11

In theory they should be totally separate. Different values on different indices.

However on closer inspection in the analyser, I noticed that key 6 is actually sending values on both index 1 and index 2 at the same time when it's pressed. It sends 01 on index 1 and 11 on index 2.

As a result the javascript for key 5 that's listening for 01 on index 1 seems to be triggered when I press either key 5 or key 6 and key 6 is ignored.

Is there a way I can get around this please?

Thanks

You could just modify your code slightly:

if(reportBuffer.readUInt8(1) === 0x01 && reportBuffer.readUInt8(2) === 0x00 ){
        log('Key 5 trigger!');
        bttTriggerDeviceTrigger(targetDevice, 'key5');
    } else 
     if(reportBuffer.readUInt8(2) === 0x11) {
        log('Key 6 trigger!');
        bttTriggerDeviceTrigger(targetDevice, 'key6');
    }

Note the added && reportBuffer.readUInt8(2) === 0x00

Thanks Andreas - so is the new code basically saying to match values on both indices (and therefore make a unique match when key 5 & key 6 are pressed?

Steve

correct, the key5 if is only true if there is a 1 at index 1 and a 0 at index 2