Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ds4

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ds4 - npm Package Compare versions

Comparing version 0.0.1 to 0.1.0

.npmignore

69

bin/ds4-dump.js

@@ -8,3 +8,2 @@ #!/usr/bin/env node

var ds4 = require('..');
var optimist = require('optimist').argv;

@@ -14,21 +13,22 @@ var parseDS4HIDData = ds4.parseDS4HIDData;

var devices = hid.devices();
var controller = _(devices)
.filter(isDS4HID)
.filter(isUSBHID)
.map(createHID)
.first();
.filter(isDS4HID)
.first();
if (!controller)
throw new Error('Could not find desired controller.');
if (!controller) {
throw new Error('Could not find desired controller.');
}
controller.on('data', function(buf) {
console.log(parseDS4HIDData(buf));
});
var hidDevice = new hid.HID(controller.path);
var offset = 0;
if (isBluetoothHID(controller)) {
offset = 2;
hidDevice.getFeatureReport(0x04, 128);
}
hidDevice.on('data', function(buf) {
console.log(parseDS4HIDData(buf.slice(offset)));
});
// HIDDesciptor -> Boolean

@@ -48,42 +48,1 @@ function isDS4HID(descriptor) {

}
// HIDDescriptor -> HID
function createHID(descriptor) {
return new hid.HID(descriptor.path);
}
//
// Debug & pretty printing
//
function showIndexedBufferSlice(buffer, start, end) {
return _.zipObject(_.times(end - start).map(function(n) {
return [start + n, buffer[start + n]];
}));
}
function showBar(length, barchar) {
if (!barchar) barchar = '|';
return _.times(length, _.constant(barchar)).join('');
}
function showPos(min, max, width, value) {
var scale = (max - min) / width; // -> 32
var l = Math.floor((value - min) / scale);
var r = Math.floor((max - value) / scale);
return showBar(l, '.') + 'O' + showBar(r, '.');
}
function showBits(word) {
return pad(parseInt(word).toString(2), 8);
}
function showHex(word) {
return pad(parseInt(word).toString(16), 2);
}
function pad(n, width, z) {
z = z || '0';
n = n + '';
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
}

@@ -37,6 +37,2 @@ 'use strict';

//
// USB only, doesn't work via bluetooth?
//
// ACCEL/GYRO

@@ -66,4 +62,4 @@ motionY: buf.readInt16LE(13),

//batteryShort2: buf[12] & 0xf0,
batteryLevel: buf[12] & 0xf0
batteryLevel: buf[12]
};
}
{
"name": "ds4",
"version": "0.0.1",
"version": "0.1.0",
"description": "Stream events from DualShock 4 controllers",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -7,12 +7,18 @@ # node-ds4

__Understand HID(API)/node-hid?__ Please tell me how I can get all 64 bytes from Bluetooth instead of just 8!
Supports:
- Left & right analog stick
- D-pad
- Buttons: x, circle, square, triangle, share, options
- __(New)__ Left & right analog triggers
- __(New)__ 2 touches on the trackpad & trackpad button
- D-pad: up, down, left, right (also intermediate positions)
- Buttons: x, circle, square, triangle, share, options, (__DS4__) trackpad button
- Left & right analog triggers
- __(DS4)__ 2 touches on the trackpad (X, Y, active, ID) & trackpad button
- Gryoscope (absolute orientation) & accelerometer (relative movement)
- Battery status
Compared to the DS3 the DS4 dropped most pressure sensitive buttons.
Only L2 and R2 are still also analog.
I guess someone had to make room for the trackpad...
TODO:

@@ -38,2 +44,10 @@

``` js
var ds4 = require('ds4');
var through = require('through');
// controller is a node-hid HID object representing the controller
hid.pipe(through(ds4.parseDS4HIDData)).pipe(process.stdout);
```
Example output frame:

@@ -84,4 +98,11 @@

## Thanks
## Caveat
As long as this is pre 1.0 I'll rename property names.
¯\\\_(ツ)\_/¯
## Thanks & References
- http://www.psdevwiki.com/ps4/Talk:DualShock_4 http://www.psdevwiki.com/ps4/DualShock_4
- @johndrinkwater [protocol gist](https://gist.github.com/johndrinkwater/7708901)

@@ -88,0 +109,0 @@ - @rdepena [node-dualshock-controller](https://github.com/rdepena/node-dualshock-controller)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc