Interface with the Playstation Move motion controller. This module can receive inputs and set the LED color and rumble.
import { PSMove } from 'ps-move';
const move = new PSMove(()=>console.log('Ready!'));
move.on('data', data=>{
if(data.triangle){
move.hex('d64462');
move.update();
}
if(data.square){
move.hsl(35, .95, .63);
move.update();
}
if(data.circle){
move.rumble(.5);
move.update();
}
});
You can pair using the PS Move API. It is recommended to follow their documentation, although here's a summary of the steps I took:
- Download and extract a PS Move API GitHub Release.
- Run a terminal as administrator.
- Navigate to the bin directory inside of the extracted folder.
- Connect your controller with USB.
- Execute
psmove pair
. - Done!
If you have any trouble, consult the PS Move API Documentation.
Install using npm:
npm i ps-move
The main class representing the PlayStation Move motion controller.
const move = new PSMove(()=>console.log('Ready!'));
On the constructor, you can pass a function that will be triggered when the instance is ready.
Returns the last known Battery data.
console.log(move.battery); // { level: 4, chargingStatus: 'not_charging' }
Gets and sets the color of the LED. Use update()
to apply the set color.
move.hex() // #000000
move.hex('#b16570');
move.rgb() // [177, 101, 112]
move.rgb(199, 210, 39);
move.hsl() // [63.85, 0.68, 0.48]
move.hsl(124, .76, .7);
Gets and sets the rumble (vibration) of the controller. Must be a number from 0 to 1. Use update()
to apply the set rumble.
move.rumble() // 0
move.rumble(.75);
Send a message to the controller with the set color and the set rumble. It returns a Promise<boolean>
to inform the success of the update.
if(await move.update()){
console.log('Success!');
}else{
console.log('Fail!');
}
End the connection with the controller.
await move.destroy();
Emits a Data
object about the controller. This happens multiple times per second.
move.on('data', data=>{
// Do something
});
Emits a ButtonEvent
object when a button is pressed.
move.on('buttonDown', e=>{
console.log(e); // { button: 'square', state: true, data: { ... } }
});
Emits a TriggerEvent
object when the pressure on the trigger button is changed.
move.on('triggerChange', e=>{
console.log(e.amount); // 0.8653
});
Emits any error received from the controller connection.
move.on('error', error=>{
// Uh oh!
});
Name | Type | Description |
---|---|---|
select |
boolean |
SELECT button |
start |
boolean |
START button |
square |
boolean |
|
cross |
boolean |
|
circle |
boolean |
|
triangle |
boolean |
|
ps |
boolean |
|
move |
boolean |
|
trigger |
number |
Trigger (T) button pressure from 0 to 1 |
battery |
Battery |
Battery information |
accelerometer |
Vector3 |
Vector of the accelerometer |
gyroscope |
Vector3 |
Vector of the gyroscope |
Name | Type | Description |
---|---|---|
level |
number or null |
The battery level from 0 to 5. When charging, it is unknown so it is null . |
chargingStatus |
string |
Returns not_charging , charging or fully_charged . |
Name | Type |
---|---|
x |
number |
y |
number |
z |
number |
Name | Type | Description |
---|---|---|
button |
string |
Returns select , start , square , cross , circle , triangle , ps or move . |
state |
boolean |
Returns true if the button is pressed. |
data |
Data |
The related Data object. |
Name | Type | Description |
---|---|---|
amount |
number |
Trigger (T) button pressure from 0 to 1 |
data |
Data |
The related Data object. |
Consult the changelog here: CHANGELOG.md
This project wouldn't be possible without the help of the PS Move API. Thank you to @thp! ❤️