# Generic Devices PS4 Dualshock

**URL:** <https://community.folivora.ai/t/generic-devices-ps4-dualshock/34868>\
**Category:** Configuration Help & General Discussion\
**Tags:** generic-devices\
**Created:** [December 19, 2023, 8:04am UTC](https://community.folivora.ai/t/generic-devices-ps4-dualshock/34868 "2023-12-19T08:04:55Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![ageorgios](https://community.folivora.ai/user_avatar/community.folivora.ai/ageorgios/32/5272_2.png) [@ageorgios](https://community.folivora.ai/u/ageorgios)\
**Post date:** [December 19, 2023, 8:04am UTC](https://community.folivora.ai/t/generic-devices-ps4-dualshock/34868/1 "2023-12-19T08:04:56Z")

</div>

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

```auto
    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');
    }

```

```auto
x
s
t
o
options
share
up
down
left
right
L1
R1
L2
R2
home
touchpad

```

---

<div class="post-metadata">

**Author:** ![Andreas\_Hegenberg](https://community.folivora.ai/user_avatar/community.folivora.ai/andreas_hegenberg/32/39221_2.png) [@Andreas\_Hegenberg](https://community.folivora.ai/u/Andreas_Hegenberg)\
**Post date:** [December 19, 2023, 8:09am UTC](https://community.folivora.ai/t/generic-devices-ps4-dualshock/34868/2 "2023-12-19T08:09:09Z")

</div>

what kind of issue do you encounter configuring them?

---

<div class="post-metadata">

**Author:** ![ageorgios](https://community.folivora.ai/user_avatar/community.folivora.ai/ageorgios/32/5272_2.png) [@ageorgios](https://community.folivora.ai/u/ageorgios)\
**Post date:** [December 19, 2023, 8:14am UTC](https://community.folivora.ai/t/generic-devices-ps4-dualshock/34868/3 "2023-12-19T08:14:16Z")

</div>

![Screenshot 2023-12-19 at 10.13.11](https://community.folivora.ai/uploads/default/original/3X/5/d/5da6a75d937d8ef9397d007eaeef4eece3fa7f22.jpeg)  
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

---

<div class="post-metadata">

**Author:** ![Andreas\_Hegenberg](https://community.folivora.ai/user_avatar/community.folivora.ai/andreas_hegenberg/32/39221_2.png) [@Andreas\_Hegenberg](https://community.folivora.ai/u/Andreas_Hegenberg)\
**Post date:** [December 19, 2023, 8:19am UTC](https://community.folivora.ai/t/generic-devices-ps4-dualshock/34868/4 "2023-12-19T08:19:25Z")

</div>

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

 ![image](https://community.folivora.ai/uploads/default/original/3X/d/6/d6e6c69ae55a50b2b5816b14f2a9acd510b7fb87.jpeg)

---

<div class="post-metadata">

**Author:** ![ageorgios](https://community.folivora.ai/user_avatar/community.folivora.ai/ageorgios/32/5272_2.png) [@ageorgios](https://community.folivora.ai/u/ageorgios)\
**Post date:** [December 19, 2023, 8:25am UTC](https://community.folivora.ai/t/generic-devices-ps4-dualshock/34868/5 "2023-12-19T08:25:51Z")

</div>

![image](https://community.folivora.ai/uploads/default/original/3X/7/d/7db0219f188fdedfaf8ae4c986b6cf2760545fa7.jpeg)  
yes, have successfully triggered sometimes.  
when I reconnect the controller, the list is not there for example.

![image](https://community.folivora.ai/uploads/default/original/3X/4/1/41fa74302f01171b6086117ed901cdf49a5fcff3.png)

---

<div class="post-metadata">

**Author:** ![Andreas\_Hegenberg](https://community.folivora.ai/user_avatar/community.folivora.ai/andreas_hegenberg/32/39221_2.png) [@Andreas\_Hegenberg](https://community.folivora.ai/u/Andreas_Hegenberg)\
**Post date:** [December 19, 2023, 8:31am UTC](https://community.folivora.ai/t/generic-devices-ps4-dualshock/34868/6 "2023-12-19T08:31:41Z")

</div>

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

 ![image](https://community.folivora.ai/uploads/default/original/3X/0/1/0127a271d3e8a45b3bd5935a845723d85c88f82f.jpeg)

---

<div class="post-metadata">

**Author:** ![ageorgios](https://community.folivora.ai/user_avatar/community.folivora.ai/ageorgios/32/5272_2.png) [@ageorgios](https://community.folivora.ai/u/ageorgios)\
**Post date:** [December 19, 2023, 8:38am UTC](https://community.folivora.ai/t/generic-devices-ps4-dualshock/34868/7 "2023-12-19T08:38:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Andreas\_Hegenberg](https://community.folivora.ai/user_avatar/community.folivora.ai/andreas_hegenberg/32/39221_2.png) [@Andreas\_Hegenberg](https://community.folivora.ai/u/Andreas_Hegenberg)\
**Post date:** [December 19, 2023, 8:45am UTC](https://community.folivora.ai/t/generic-devices-ps4-dualshock/34868/8 "2023-12-19T08:45:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ageorgios](https://community.folivora.ai/user_avatar/community.folivora.ai/ageorgios/32/5272_2.png) [@ageorgios](https://community.folivora.ai/u/ageorgios)\
**Post date:** [December 19, 2023, 11:29am UTC](https://community.folivora.ai/t/generic-devices-ps4-dualshock/34868/9 "2023-12-19T11:29:32Z")

</div>

sent the diagnostic info

---

<div class="post-metadata">

**Author:** ![CRJ2000](https://community.folivora.ai/letter_avatar_proxy/v4/letter/c/7ba0ec/32.png) [@CRJ2000](https://community.folivora.ai/u/CRJ2000)\
**Post date:** [December 24, 2023, 5:18am UTC](https://community.folivora.ai/t/generic-devices-ps4-dualshock/34868/10 "2023-12-24T05:18:41Z")

</div>

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.

```auto
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');
    
}

```

---

<div class="post-metadata">

**Author:** ![ageorgios](https://community.folivora.ai/user_avatar/community.folivora.ai/ageorgios/32/5272_2.png) [@ageorgios](https://community.folivora.ai/u/ageorgios)\
**Post date:** [December 24, 2023, 7:02am UTC](https://community.folivora.ai/t/generic-devices-ps4-dualshock/34868/11 "2023-12-24T07:02:26Z")

</div>

Super!  
I have sent diagnostic information to [Andreas\_Hegenberg](https://community.folivora.ai/u/Andreas_Hegenberg)

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

---

<div class="post-metadata">

**Author:** ![mkozjak](https://community.folivora.ai/user_avatar/community.folivora.ai/mkozjak/32/27484_2.png) [@mkozjak](https://community.folivora.ai/u/mkozjak)\
**Post date:** [August 2, 2024, 8:11am UTC](https://community.folivora.ai/t/generic-devices-ps4-dualshock/34868/13 "2024-08-02T08:11:17Z")

</div>

Hey, guys, thanks for this work so far!

Regarding the drift - the Touchpad button drifts a lot, but I'd like to use it. What should I do in this case? The trigger runs like hell all the time because of the drift.
