Generic Devices PS4 Dualshock

here is the code for all button mappings for Dualshock
although I am not able to configure the triggers correctly
maybe we could share effort here

    if(reportBuffer.readUInt8(5) === 0x28) {
        log('x!');
        bttTriggerDeviceTrigger(targetDevice, 'x');
    }
    if(reportBuffer.readUInt8(5) === 0x18) {
        log('s!');
        bttTriggerDeviceTrigger(targetDevice, 's');
    }
    if(reportBuffer.readUInt8(5) === 0x48) {
        log('o!');
        bttTriggerDeviceTrigger(targetDevice, 'o');
    }
    if(reportBuffer.readUInt8(5) === 0x88) {
        log('t!');
        bttTriggerDeviceTrigger(targetDevice, 't');
    }

    if(reportBuffer.readUInt8(6) === 0x20) {
        log('options!');
        bttTriggerDeviceTrigger(targetDevice, 'options');
    }
    if(reportBuffer.readUInt8(6) === 0x10) {
        log('share!');
        bttTriggerDeviceTrigger(targetDevice, 'share');
    }

    if(reportBuffer.readUInt8(6) === 0x01) {
        log('L1!');
        bttTriggerDeviceTrigger(targetDevice, 'L1');
    }
    if(reportBuffer.readUInt8(6) === 0x02) {
        log('R1!');
        bttTriggerDeviceTrigger(targetDevice, 'R1');
    }

    if(reportBuffer.readUInt8(5) === 0x00) {
        log('up!');
        bttTriggerDeviceTrigger(targetDevice, 'up');
    }
    if(reportBuffer.readUInt8(5) === 0x04) {
        log('down!');
        bttTriggerDeviceTrigger(targetDevice, 'down');
    }
    if(reportBuffer.readUInt8(5) === 0x06) {
        log('left!');
        bttTriggerDeviceTrigger(targetDevice, 'left');
    }
    if(reportBuffer.readUInt8(5) === 0x02) {
        log('right!');
        bttTriggerDeviceTrigger(targetDevice, 'right');
    }

    if(reportBuffer.readUInt8(8) === 0xff) {
        log('L2!');
        bttTriggerDeviceTrigger(targetDevice, 'L2');
    }
    if(reportBuffer.readUInt8(9) === 0xff) {
        log('R2!');
        bttTriggerDeviceTrigger(targetDevice, 'R2');
    }

    if(reportBuffer.readUInt8(7) === 0x01) {
        log('home!');
        bttTriggerDeviceTrigger(targetDevice, 'home');
    }
    if(reportBuffer.readUInt8(7) === 0x02) {
        log('touchpad!');
        bttTriggerDeviceTrigger(targetDevice, 'touchpad');
    }
x
s
t
o
options
share
up
down
left
right
L1
R1
L2
R2
home
touchpad

what kind of issue do you encounter configuring them?


The UI does not help very much, maybe it is the controller fault though,
I have this code embedded by I cannot figure the condition that should happen so the triggers are appearing on the list

have succeded sometimes to use the controller to trigger triggers, but not consistently

Does your input analyzer provide all the triggers so BTT can show them in the UI?


yes, have successfully triggered sometimes.
when I reconnect the controller, the list is not there for example.

image

That is very strange, the list should even show without anything connected. Does it show after restarting BTT?

no they are gone,
the only solution is to click the generic device again

if this happens again, can you go to help-> export diagnostic debug info and send the result to me? (andreas@folivora.ai)

sent the diagnostic info

Ageorgios,

I thought you may be interested in my version of button mappings for the DualShock. Since the controller is capable of having multiple buttons selected at once, I created a structure that allows one to determine any/all buttons that are being pressed. I also included the joystick positions and the trigger positions, though I'm not sure how I would utilize those with the current Generic Device support.

function analyzeDeviceInput(targetDevice, reportID, reportDataHex) {

    let reportBuffer = buffer.Buffer.from(reportDataHex, 'hex');
    
    // Initialize a button object to track the state of each button.
    let buttons = {};
    
    //--------------------------------------------------------------------------------
    // Get the integer values of the joysticks;
    // These are values from 0 to 255.
    // Note: Joystick drift could cause this script to be called a lot.
    //       If you don't intend to use it, don't enable those bytes for monitoring.
    //--------------------------------------------------------------------------------
    buttons['left_x'] = reportBuffer.readUInt8(1);
    buttons['left_y'] = reportBuffer.readUInt8(2);
    buttons['right_x'] = reportBuffer.readUInt8(3);
    buttons['right_y'] = reportBuffer.readUInt8(4);

    //--------------------------------------------------------------------------------
    // Get the integer values of the L2 and R2 Triggers;
    // These are values from 0 to 255.
    //--------------------------------------------------------------------------------
    buttons['l2_value'] = reportBuffer.readUInt8(8);
    buttons['r2_value'] = reportBuffer.readUInt8(9);
    
    //--------------------------------------------------------------------------------
    // Interpret the Index 5 Buttons.
    //--------------------------------------------------------------------------------
     
    // Get the integer value of Index 5.
    let val = reportBuffer.readUInt8(5);

    // Convert it to binary. The controller uses a bitmask to track the button states.
    let binVal = val.toString(2).padStart(8,'0');

    // Get the four right-most bits. These are for the dpad.
    let dpadVal = parseInt(binVal.substring(4,8),2)

    // Determine the state of each button.
    buttons['triangle'] = (binVal.substring(0,1) == '1');
    buttons['circle'] = (binVal.substring(1,2) == '1');
    buttons['x'] = (binVal.substring(2,3) == '1');
    buttons['square'] = (binVal.substring(3,4) == '1');
    buttons['up'] = (dpadVal == 0 || dpadVal == 1 || dpadVal == 7);
    buttons['right'] = (dpadVal == 1 || dpadVal == 2 || dpadVal == 3);
    buttons['down'] = (dpadVal == 3 || dpadVal == 4 || dpadVal == 5);
    buttons['left'] = (dpadVal == 5 || dpadVal == 6 || dpadVal == 7);

    //--------------------------------------------------------------------------------
    // Interpret the Index 6 Buttons.
    //--------------------------------------------------------------------------------
     
    // Get the integer value of Index 6.
    val = reportBuffer.readUInt8(6);

    // Convert it to binary. The controller uses a bitmask to track the button states.
    binVal = val.toString(2).padStart(8,'0');
 
    // Determine the state of each button.
    buttons['r3'] = (binVal.substring(0,1) == '1');
    buttons['l3'] = (binVal.substring(1,2) == '1');
    buttons['options'] = (binVal.substring(2,3) == '1');
    buttons['share'] = (binVal.substring(3,4) == '1');
    buttons['r2'] = (binVal.substring(4,5) == '1');
    buttons['l2'] = (binVal.substring(5,6) == '1');
    buttons['r1'] = (binVal.substring(6,7) == '1');
    buttons['l1'] = (binVal.substring(7,8) == '1');

    //--------------------------------------------------------------------------------
    // Interpret the Index 7 Buttons.
    //--------------------------------------------------------------------------------
     
    // Get the integer value of Index 7.
    val = reportBuffer.readUInt8(7);

    // Convert it to binary. The controller uses a bitmask to track the button states.
    binVal = val.toString(2).padStart(2,'0');
    
    // Determine the state of each button.
    buttons['touchpad'] = (binVal.substring(0,1) == '1');
    buttons['home'] = (binVal.substring(1,2) == '1');
    
    //--------------------------------------------------------------------------------
    // Output the Button States.
    //--------------------------------------------------------------------------------
    log(JSON.stringify(buttons,null,4));

    //--------------------------------------------------------------------------------
    // Determine which triggers to fire.
    // This example shows a one-to-one mapping of the buttons to the trigger calls.
    // However, it could just as easily look for combinations of buttons
    // (e.g. L2 and X held down at the same time).
    //--------------------------------------------------------------------------------
    if(buttons['triangle']) bttTriggerDeviceTrigger(targetDevice, 'triangle');
    if(buttons['circle'])   bttTriggerDeviceTrigger(targetDevice, 'circle');
    if(buttons['x'])        bttTriggerDeviceTrigger(targetDevice, 'x');
    if(buttons['square'])   bttTriggerDeviceTrigger(targetDevice, 'square');
    if(buttons['up'])       bttTriggerDeviceTrigger(targetDevice, 'up');
    if(buttons['right'])    bttTriggerDeviceTrigger(targetDevice, 'right');
    if(buttons['down'])     bttTriggerDeviceTrigger(targetDevice, 'down');
    if(buttons['left'])     bttTriggerDeviceTrigger(targetDevice, 'left');
    if(buttons['l1'])       bttTriggerDeviceTrigger(targetDevice, 'l1');
    if(buttons['l2'])       bttTriggerDeviceTrigger(targetDevice, 'l2');
    if(buttons['l3'])       bttTriggerDeviceTrigger(targetDevice, 'l3');
    if(buttons['r1'])       bttTriggerDeviceTrigger(targetDevice, 'r1');
    if(buttons['r2'])       bttTriggerDeviceTrigger(targetDevice, 'r2');
    if(buttons['r3'])       bttTriggerDeviceTrigger(targetDevice, 'r3');
    if(buttons['options'])  bttTriggerDeviceTrigger(targetDevice, 'options');
    if(buttons['share'])    bttTriggerDeviceTrigger(targetDevice, 'share');
    if(buttons['touchpad']) bttTriggerDeviceTrigger(targetDevice, 'touchpad');
    if(buttons['home'])     bttTriggerDeviceTrigger(targetDevice, 'home');
    
}

1 Like

Super!
I have sent diagnostic information to Andreas_Hegenberg

Perhaps it's best to wait for his evaluation of the feature's worth before we consider adding more effort to it