Comparing version 0.2.0 to 0.3.0
26
index.js
'use strict'; | ||
exports.parseDS4HIDData = parseDS4HIDData; | ||
exports.emit = emit; | ||
// Buffer -> DS4State | ||
function parseDS4HIDData(buf) { | ||
var dPad = buf[5] & 15; | ||
return { | ||
@@ -15,6 +17,6 @@ leftAnalogX: buf[1], | ||
dPadUp: buf[5] === 0 || buf[5] === 1 || buf [5] === 7, | ||
dPadRight: buf[5] === 1 || buf[5] === 2 || buf [5] === 3, | ||
dPadDown: buf[5] === 3 || buf[5] === 4 || buf [5] === 5, | ||
dPadLeft: buf[5] === 5 || buf[5] === 6 || buf [5] === 7, | ||
dPadUp: dPad === 0 || dPad === 1 || dPad === 7, | ||
dPadRight: dPad === 1 || dPad === 2 || dPad === 3, | ||
dPadDown: dPad === 3 || dPad === 4 || dPad === 5, | ||
dPadLeft: dPad === 5 || dPad === 6 || dPad === 7, | ||
@@ -65,1 +67,17 @@ cross: (buf[5] & 32) !== 0, | ||
} | ||
function emit(hidDevice, data) { | ||
hidDevice.write([ | ||
0x05, | ||
0xff, | ||
0x04, | ||
0x00, | ||
data.rumbleRight || 0, | ||
data.rumbleLeft || 0, | ||
data.r || 0, | ||
data.g || 0, | ||
data.b || 0, | ||
data.flashOn || 0, | ||
data.flashOff || 0 | ||
]); | ||
} |
{ | ||
"name": "ds4", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Stream events from DualShock 4 controllers", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -13,2 +13,4 @@ # node-ds4 | ||
- Gryoscope (absolute orientation) & accelerometer (relative movement) | ||
- Activating motors | ||
- Changing LED color | ||
- Battery status | ||
@@ -22,4 +24,2 @@ | ||
- Activating motors | ||
- Changing LED color | ||
- Microphone/speaker magic | ||
@@ -94,2 +94,18 @@ | ||
Emitting data: | ||
``` js | ||
var ds4 = require('ds4'); | ||
ds4.emit(hid, { | ||
rumbleRight: 0, // 0 ... 255 | ||
rumbleLeft: 0, // 0 ... 255 | ||
r: 0, // 0 ... 255 | ||
g: 0, // 0 ... 255 | ||
b: 0, // 0 ... 255 | ||
flashOn: 0, // 0 ... 255 (flash on duration) | ||
flashOff: 0 // 0 ... 255 (flash off duration) | ||
}); | ||
``` | ||
## Caveat | ||
@@ -96,0 +112,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6692
103
123