I just set up a Nintendo Switch right Joy-Con as a "generic device". Three points I'd like to make:
- @Andreas_Hegenberg, to set up a generic device it must be a trigger (called e.g. "Joy-Con (R)"), which is confusing because it sits alongside the "triggers" that the device triggers (e.g. "Joy-Con (R): X"). This device pattern needs some UI that reflects how it works. Device setup should be separate from triggers. I'm sure you know this and its in the roadmap.
- I also encountered a bug - if actions are attached to the device configuration "trigger" and then the actions are deleted, they still occur. Until this is fixed: set up the device as a trigger, and then set up trigger/action pairs separately.
- I'd like to share the script I used to map my JoyCon events to BTT events. @Andreas_Hegenberg, the
bufferMaps
abstraction I set up captures the entire complexity of what these Javascript functions should do. Rather than asking users to write Javascript, maybe you can just let them configure "bufferMaps" by mapping registers-value pairs to event names. It took me some time to see that this was what the Javascript function should do, but UI to reflect this concept shouldn't be too complicated.
Here is the Javascript function that captures all events from a right Joy-Con.
function analyzeDeviceInput(targetDevice, reportID, reportDataHex) {
let reportBuffer = buffer.Buffer.from(reportDataHex, "hex");
let event;
let bufferMaps = [
{
buffer: 1,
events: {
0x01: "A",
0x02: "X",
0x04: "B",
0x08: "Y",
0x20: "SR",
0x10: "SL",
},
},
{
buffer: 3,
events: {
0x00: "jW",
0x01: "jNW",
0x02: "jN",
0x03: "jNE",
0x04: "jE",
0x05: "jSE",
0x06: "jS",
0x07: "jSW",
},
},
{
buffer: 2,
events: {
0x40: "R",
0x80: "ZR",
0x02: "Plus",
0x08: "jDown",
0x10: "Home",
},
},
];
for (let bufferMap of bufferMaps) {
event = bufferMap.events[reportBuffer.readUInt8(bufferMap.buffer)];
if (event) {
// log(event)
bttTriggerDeviceTrigger(targetDevice, event);
}
}
return;
// If you want to get the next report even though,
// the data has not changed, call this function:
// bttGetNextEvenWithoutChange(targetDevice, reportID)
}
It returns the following "events" that become triggers:
- A -> "Joy-Con (R): A" # A button
- B -> "Joy-Con (R): B" # B button
- X -> "Joy-Con (R): X" # X button
- Y -> "Joy-Con (R): Y" # Y button
- SR -> "Joy-Con (R): SR" # SR button
- SL -> "Joy-Con (R): SL" # SL button
- R -> "Joy-Con (R): R" # R button
- ZR -> "Joy-Con (R): ZR" # ZR button
- Plus -> "Joy-Con (R): Plus" # Plus button
- Home -> "Joy-Con (R): Home" # Home button
- jDown -> "Joy-Con (R): jDown" # joystick down button
- jW -> "Joy-Con (R): jW" # W joystick direction
- jNW -> "Joy-Con (R): jNW" # NW joystick direction
- jN -> "Joy-Con (R): jN" # N joystick direction
- jNE -> "Joy-Con (R): jNE" # NE joystick direction
- jE -> "Joy-Con (R): jE" # E joystick direction
- jSE -> "Joy-Con (R): jSE" # SE joystick direction
- jS -> "Joy-Con (R): jS" # S joystick direction
- jSW -> "Joy-Con (R): jSW" # SW joystick direction