Node API to interface your Oculus Touch controllers and headset
npm install node_oculus_touchbash
npm install node_oculus_touch
`
Example Usage
Below is a short program that will vibrate both controllers for 1 second whenever the X button is pressed while the headset is being worn.
`javascript
const OculusTouch = require("node_oculus_touch");
const { OculusTouchControllerEnum } = OculusTouch;
const oculus = new OculusTouch.default();
async function main() {
while (true) {
console.log("\n");
const wearing = oculus.Wearing();
console.log(Headset is ${wearing ? "ON" : "OFF"} your head);
const x = oculus.GetPositionX(OculusTouchControllerEnum.Head);
const y = oculus.GetPositionY(OculusTouchControllerEnum.Head);
const z = oculus.GetPositionZ(OculusTouchControllerEnum.Head);
const yaw = oculus.GetYaw(OculusTouchControllerEnum.Head);
const pitch = oculus.GetPitch(OculusTouchControllerEnum.Head);
const roll = oculus.GetRoll(OculusTouchControllerEnum.Head);
console.log(
Headset Position: (${x}, ${y}, ${z}), Yaw: ${yaw}, Pitch: ${pitch}, Roll: ${roll}
);
const buttonsDown = oculus.GetButtonsDownList(); // Get a list of buttons that are currently held down
const sensorsTouched = oculus.GetTouchDownList(); // Get a list of capacitive sensors that are currently being touched
console.log(These buttons are down: ${buttonsDown});
console.log(These sensors are touched: ${sensorsTouched});
console.log("Here's a vibration for fun");
oculus.Vibrate(OculusTouchControllerEnum.Left); // Vibrate the left controller
oculus.Vibrate(OculusTouchControllerEnum.Right); // Vibrate the right controller
await oculus.PollAndSleep(1.0); // Poll and wait for 1 second
}
}
main();
`
This is a smaple output from the above program:
`
Headset is ON your head
Headset Position: (-0.013414621353149414, -0.026262708008289337, 0.032742977142333984), Yaw: -17.002450942993164, Pitch: 44.2700309753418, Roll: 5.435980319976807
These buttons are down: A,X
These sensors are touched: A,RIndexTrigger,X,Y
Here's a vibration for fun
Headset is ON your head
Headset Position: (-0.014403924345970154, -0.026353243738412857, 0.0328700989484787), Yaw: -17.314512252807617, Pitch: 44.31072235107422, Roll: 5.154298782348633
These buttons are down: A,B,X,Y
These sensors are touched: A,B,RIndexTrigger,X,Y
Here's a vibration for fun
Headset is ON your head
Headset Position: (-0.011598184704780579, -0.025795966386795044, 0.031615033745765686), Yaw: -16.28270721435547, Pitch: 44.75285339355469, Roll: 5.78907585144043
These buttons are down:
These sensors are touched: A,X,Y,LIndexTrigger
Here's a vibration for fun
Headset is ON your head
Headset Position: (-0.021077744662761688, -0.02522127330303192, 0.021070241928100586), Yaw: -15.96435832977295, Pitch: 44.116947174072266, Roll: 4.646905899047852
These buttons are down:
These sensors are touched:
Here's a vibration for fun
`
API Reference
InitOculus
Initialize the Oculus API.
$3
- poll: boolean (Optional): If true, polls the Oculus API after initializing. Defaults to true.
$3
- number: Return code from the initialization process.
Poll
Polls the Oculus Touch API for state updates.
$3
_None_
$3
_None_
Sleep
Blocks the runtime and waits for the specified length. Useful for sleeping between polls.
$3
- length: number (Optional): Length of time to sleep in seconds. Defaults to 0.1.
$3
- Promise: A Promise that resolves after the specified length of time.
PollAndSleep
Combines the Poll() and Sleep() functions.
$3
- length: number (Optional): Length of time to sleep in seconds. Defaults to 0.1.
$3
- Promise: A Promise that resolves after the specified length of time.
Wearing
Checks if the user is wearing the headset.
$3
_None_
$3
- boolean: True if the user is wearing the headset, false otherwise.
IsPressed
Checks if the specified button was pressed in the current poll. "Pressed" and "Down" are not the same thing.
$3
- button: OculusTouchButtonEnum: The button to check.
$3
- boolean: True if the button was pressed, false otherwise.
IsReleased
Checks if the specified button was released in the current poll.
$3
- button: OculusTouchButtonEnum: The button to check.
$3
- boolean: True if the button was released, false otherwise.
IsDown
Checks if the specified button is currently held down. "Pressed" and "Down" are not the same thing.
$3
- button: OculusTouchButtonEnum: The button to check.
$3
- boolean: True if the button is held down, false otherwise.
IsTouchPressed
Checks if the specified button's capacitor was touched in the current poll. "Pressed" and "Down" are not the same thing.
$3
- sensor: OculusTouchSensorEnum: The sensor to check.
$3
- boolean: True if the button's capacitor was touched, false otherwise.
IsTouchReleased
Checks if the specified button's capacitor was released in the current poll.
$3
- sensor: OculusTouchSensorEnum: The sensor to check.
$3
- boolean: True if the button's capacitor was released, false otherwise.
IsTouchDown
Checks if the specified button's capacitor is currently being touched. "Pressed" and "Down" are not the same thing.
$3
- sensor: OculusTouchSensorEnum: The sensor to check.
$3
- boolean: True if the button's capacitor is being touched, false otherwise.
Reached
Checks whether a specified axis has reached a specified threshold value in between the last poll.
$3
- axis: OculusTouchAxisEnum: The axis to check.
- value: number: The threshold value to check against.
$3
- number: Return code indicating if the axis has reached the threshold. 0 if the threshold wasn't crossed. 1 if the threshold was crossed in the positive direction. -1 if it was crossed in the negative direction.
GetAxis
Returns the value of the specified axis.
$3
- axis: OculusTouchAxisEnum: The axis to query.
$3
- number: The current value of the specified axis.
GetButtonsDown
Returns a bitmask of all buttons currently held down. "Pressed" and "Down" are not the same thing.
$3
_None_
$3
- number: Bitmask representing buttons currently held down.
GetButtonsDownList
Returns a list of all buttons currently held down. "Pressed" and "Down" are not the same thing.
$3
_None_
$3
- OculusTouchButtonEnum[]: List of buttons currently held down.
GetButtonsReleased
Returns a bitmask of all buttons released in the current poll.
$3
_None_
Returns
- number: Bitmask representing buttons released in the current poll.
GetButtonsReleasedList
Returns a list of all buttons released in the current poll.
$3
_None_
$3
- OculusTouchButtonEnum[]: List of buttons released in the current poll.
GetButtonsPressed
Returns a bitmask of all buttons pressed in the current poll. "Pressed" and "Down" are not the same thing.
$3
_None_
$3
- number: Bitmask representing buttons pressed in the current poll.
GetButtonsPressedList
Returns a list of all buttons pressed in the current poll. "Pressed" and "Down" are not the same thing.
$3
_None_
$3
- OculusTouchButtonEnum[]: List of buttons pressed in the current poll.
GetTouchDown
Returns a bitmask of all buttons whose capacitors are currently being touched. "Pressed" and "Down" are not the same thing.
$3
_None_
$3
- number: Bitmask representing buttons whose capacitors are currently being touched.
GetTouchDownList
Returns a list of all buttons whose capacitors are currently being touched. "Pressed" and "Down" are not the same thing.
$3
_None_
$3
- OculusTouchSensorEnum[]: List of buttons whose capacitors are currently being touched.
GetTouchPressed
Returns a bitmask of all buttons whose capacitors were touched in the current poll. "Pressed" and "Down" are not the same thing.
$3
_None_
$3
- number: Bitmask representing buttons whose capacitors were touched in the current poll.
GetTouchPressedList
Returns a list of all buttons whose capacitors were touched in the current poll. "Pressed" and "Down" are not the same thing.
$3
_None_
$3
- OculusTouchSensorEnum[]: List of buttons whose capacitors were touched in the current poll.
GetTouchReleased
Returns a bitmask of all buttons whose capacitors were released in the current poll.
$3
_None_
$3
- number: Bitmask representing buttons whose capacitors were released in the current poll.
GetTouchReleasedList
Returns a list of all buttons whose capacitors were released in the current poll.
$3
_None_
$3
- OculusTouchSensorEnum[]: List of buttons whose capacitors were released in the current poll.
GetTrigger
Returns the value of a specified trigger.
$3
- hand: OculusTouchHandEnum: The hand (left or right) of the trigger.
- trigger: OculusTouchTriggerEnum: The trigger (index or hand) to query.
$3
- number: The value of the specified trigger.
GetThumbStick
Returns the value of a specified thumbstick's axis.
$3
- hand: OculusTouchHandEnum: The hand (left or right) of the thumbstick.
- axis: OculusTouchAxisEnum: The axis (x or y) of the thumbstick to query.
$3
- number: The value of the specified thumbstick's axis.
Vibrate
Vibrates a specified controller.
$3
- controller: OculusTouchControllerEnum: The controller to vibrate.
- frequency: OculusTouchVibrationFrequencyEnum (Optional): The vibration frequency. Default is OculusTouchVibrationFrequencyEnum.Medium.
- amplitude: number (Optional): The amplitude of the vibration, range [0, 255]. Default is 128.
- length: number (Optional): The length of the vibration in seconds, 0 for infinite. Default is 1.0.
$3
- Error: If the amplitude is not in the range [0, 255].
$3
_None_
GetYaw
Returns the yaw of a specified controller. Yaw is rotation around the y-axis.
$3
- controller: OculusTouchControllerEnum: The controller to query.
$3
- number: The yaw (rotation around the y-axis) of the specified controller.
GetPitch
Returns the pitch of a specified controller. Pitch is rotation around the x-axis.
$3
- controller: OculusTouchControllerEnum: The controller to query.
$3
- number: The pitch (rotation around the x-axis) of the specified controller.
GetRoll
Returns the roll of a specified controller. Roll is rotation around the z-axis.
$3
- controller: OculusTouchControllerEnum: The controller to query.
$3
- number: The roll (rotation around the z-axis) of the specified controller.
GetPositionX
Returns the x position of a specified controller.
$3
- controller: OculusTouchControllerEnum: The controller to query.
$3
- number: The x position of the specified controller.
GetPositionY
Returns the y position of a specified controller.
$3
- controller: OculusTouchControllerEnum: The controller to query.
$3
- number: The y position of the specified controller.
GetPositionZ
Returns the z position of a specified controller.
$3
- controller: OculusTouchControllerEnum: The controller to query.
$3
- number: The z position of the specified controller.
SetTrackingOrigin
Sets the tracking origin of the headset. This is the point in space that the headset will consider to be the origin (0, 0, 0).
$3
- origin: OculusTouchTrackingOriginEnum: The tracking origin to set.
$3
_None_
ResetFacing
Resets the yaw of a specified controller. Yaw is rotation around the y-axis.
$3
- controller: OculusTouchControllerEnum: The controller for which to reset the yaw.
$3
_None_
InitvJoy
Initializes the vJoy driver. This must be called before any vJoy functions can be used.
$3
- device: number: The vJoy device number to initialize.
$3
- Error: If there is an error during initialization.
$3
_None_
SetvJoyAxis
Sets the value of a specified vJoy axis.
$3
- axis: OculusTouchvJoyDeviceEnum: The vJoy axis to set.
- value: number: The value to set, range [0.0, 1.0].
$3
_None_
SetvJoyAxisU
Sets the value of a specified vJoy axis using a different range.
$3
- axis: OculusTouchvJoyDeviceEnum: The vJoy axis to set.
- value: number: The value to set, range [0.0, 1.0], mapped to [-1.0, 1.0].
$3
_None_
SetvJoyButton
Sets the value of a specified vJoy button.
$3
- button: OculusTouchButtonEnum: The vJoy button to set.
- value: number: The value to set, range [0, 1].
$3
_None_
SendRawMouseMove
Sends a raw mouse move event to the host computer.
$3
- x: number: The relative movement in the x direction.
- y: number: The relative movement in the y direction.
- z: number: The relative movement in the z direction.
$3
_None_
SendRawMouseButtonDown
Sends a raw mouse button down event to the host computer.
$3
- button: OculusTouchRawMouseButtonEnum: The button to press.
$3
_None_
SendRawMouseButtonUp
Sends a raw mouse button up event to the host computer.
$3
- button: OculusTouchRawMouseButtonEnum`: The button to release.