1.1.3 • Published 4 months ago

ps-move v1.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

ps-move

Interface with the Playstation Move motion controller. This module can receive inputs and set the LED color and rumble.

Example

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();
    }

});

Pairing

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:

  1. Download and extract a PS Move API GitHub Release.
  2. Run a terminal as administrator.
  3. Navigate to the bin directory inside of the extracted folder.
  4. Connect your controller with USB.
  5. Execute psmove pair.
  6. Done!

If you have any trouble, consult the PS Move API Documentation.

Installation

Install using npm:

npm i ps-move

API

PSMove

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.

Properties

battery

Returns the last known Battery data.

console.log(move.battery); // { level: 4, chargingStatus: 'not_charging' }

Methods

hex(), rgb(), hsl()

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);

rumble()

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);

update()

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

destroy()

End the connection with the controller.

await move.destroy();

Events

data

Emits a Data object about the controller. This happens multiple times per second.

move.on('data', data=>{
    // Do something
});

buttonDown, buttonUp

Emits a ButtonEvent object when a button is pressed.

move.on('buttonDown', e=>{
    console.log(e); // { button: 'square', state: true, data: { ... } }
});

triggerChange

Emits a TriggerEvent object when the pressure on the trigger button is changed.

move.on('triggerChange', e=>{
    console.log(e.amount); // 0.8653
});

error

Emits any error received from the controller connection.

move.on('error', error=>{
    // Uh oh!
});

Interfaces

Data

NameTypeDescription
selectbooleanSELECT button
startbooleanSTART button
squareboolean button
crossboolean button
circleboolean button
triangleboolean button
psboolean button
moveboolean button
triggernumberTrigger (T) button pressure from 0 to 1
batteryBatteryBattery information
accelerometerVector3Vector of the accelerometer
gyroscopeVector3Vector of the gyroscope

Battery

NameTypeDescription
levelnumber or nullThe battery level from 0 to 5. When charging, it is unknown so it is null.
chargingStatusstringReturns not_charging, charging or fully_charged.

Vector3

NameType
xnumber
ynumber
znumber

ButtonEvent

NameTypeDescription
buttonstringReturns select, start, square, cross, circle, triangle, ps or move.
statebooleanReturns true if the button is pressed.
dataDataThe related Data object.

TriggerEvent

NameTypeDescription
amountnumberTrigger (T) button pressure from 0 to 1
dataDataThe related Data object.

Changelog

Consult the changelog here: CHANGELOG.md

Acknowledgments

This project wouldn't be possible without the help of the PS Move API. Thank you to @thp! ❤️

License

MIT © bernzrdo

1.1.3

4 months ago

1.1.2

4 months ago

1.1.1

4 months ago

1.1.0

4 months ago

1.0.4

4 months ago

1.0.3

4 months ago

1.0.2

4 months ago

1.0.1

4 months ago

1.0.0

4 months ago