npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node_oculus_touch

v0.1.0

Published

Node API to interface your Oculus Touch controllers and headset

Downloads

5

Readme

What is it?

This is a node library that allows you to interface with your Oculus Touch controllers and headset. It is a wrapper for the auto_oculus_touch project.

With it, you can read the current state of the controllers and headset, send button presses to the controller, or move the thumbsticks.

Installation

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.

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.

Parameters

  • poll: boolean (Optional): If true, polls the Oculus API after initializing. Defaults to true.

Returns

  • number: Return code from the initialization process.

Poll

Polls the Oculus Touch API for state updates.

Parameters

None

Returns

None

Sleep

Blocks the runtime and waits for the specified length. Useful for sleeping between polls.

Parameters

  • length: number (Optional): Length of time to sleep in seconds. Defaults to 0.1.

Returns

  • Promise<void>: A Promise that resolves after the specified length of time.

PollAndSleep

Combines the Poll() and Sleep() functions.

Parameters

  • length: number (Optional): Length of time to sleep in seconds. Defaults to 0.1.

Returns

  • Promise<void>: A Promise that resolves after the specified length of time.

Wearing

Checks if the user is wearing the headset.

Parameters

None

Returns

  • 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.

Parameters

  • button: OculusTouchButtonEnum: The button to check.

Returns

  • boolean: True if the button was pressed, false otherwise.

IsReleased

Checks if the specified button was released in the current poll.

Parameters

  • button: OculusTouchButtonEnum: The button to check.

Returns

  • 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.

Parameters

  • button: OculusTouchButtonEnum: The button to check.

Returns

  • 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.

Parameters

  • sensor: OculusTouchSensorEnum: The sensor to check.

Returns

  • 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.

Parameters

  • sensor: OculusTouchSensorEnum: The sensor to check.

Returns

  • 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.

Parameters

  • sensor: OculusTouchSensorEnum: The sensor to check.

Returns

  • 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.

Parameters

  • axis: OculusTouchAxisEnum: The axis to check.
  • value: number: The threshold value to check against.

Returns

  • 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.

Parameters

  • axis: OculusTouchAxisEnum: The axis to query.

Returns

  • 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.

Parameters

None

Returns

  • 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.

Parameters

None

Returns

  • OculusTouchButtonEnum[]: List of buttons currently held down.

GetButtonsReleased

Returns a bitmask of all buttons released in the current poll.

Parameters

None

Returns

  • number: Bitmask representing buttons released in the current poll.

GetButtonsReleasedList

Returns a list of all buttons released in the current poll.

Parameters

None

Returns

  • 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.

Parameters

None

Returns

  • 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.

Parameters

None

Returns

  • 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.

Parameters

None

Returns

  • 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.

Parameters

None

Returns

  • 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.

Parameters

None

Returns

  • 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.

Parameters

None

Returns

  • 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.

Parameters

None

Returns

  • 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.

Parameters

None

Returns

  • OculusTouchSensorEnum[]: List of buttons whose capacitors were released in the current poll.

GetTrigger

Returns the value of a specified trigger.

Parameters

  • hand: OculusTouchHandEnum: The hand (left or right) of the trigger.
  • trigger: OculusTouchTriggerEnum: The trigger (index or hand) to query.

Returns

  • number: The value of the specified trigger.

GetThumbStick

Returns the value of a specified thumbstick's axis.

Parameters

  • hand: OculusTouchHandEnum: The hand (left or right) of the thumbstick.
  • axis: OculusTouchAxisEnum: The axis (x or y) of the thumbstick to query.

Returns

  • number: The value of the specified thumbstick's axis.

Vibrate

Vibrates a specified controller.

Parameters

  • 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.

Throws

  • Error: If the amplitude is not in the range [0, 255].

Returns

None

GetYaw

Returns the yaw of a specified controller. Yaw is rotation around the y-axis.

Parameters

  • controller: OculusTouchControllerEnum: The controller to query.

Returns

  • 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.

Parameters

  • controller: OculusTouchControllerEnum: The controller to query.

Returns

  • 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.

Parameters

  • controller: OculusTouchControllerEnum: The controller to query.

Returns

  • number: The roll (rotation around the z-axis) of the specified controller.

GetPositionX

Returns the x position of a specified controller.

Parameters

  • controller: OculusTouchControllerEnum: The controller to query.

Returns

  • number: The x position of the specified controller.

GetPositionY

Returns the y position of a specified controller.

Parameters

  • controller: OculusTouchControllerEnum: The controller to query.

Returns

  • number: The y position of the specified controller.

GetPositionZ

Returns the z position of a specified controller.

Parameters

  • controller: OculusTouchControllerEnum: The controller to query.

Returns

  • 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).

Parameters

  • origin: OculusTouchTrackingOriginEnum: The tracking origin to set.

Returns

None

ResetFacing

Resets the yaw of a specified controller. Yaw is rotation around the y-axis.

Parameters

  • controller: OculusTouchControllerEnum: The controller for which to reset the yaw.

Returns

None

InitvJoy

Initializes the vJoy driver. This must be called before any vJoy functions can be used.

Parameters

  • device: number: The vJoy device number to initialize.

Throws

  • Error: If there is an error during initialization.

Returns

None

SetvJoyAxis

Sets the value of a specified vJoy axis.

Parameters

  • axis: OculusTouchvJoyDeviceEnum: The vJoy axis to set.
  • value: number: The value to set, range [0.0, 1.0].

Returns

None

SetvJoyAxisU

Sets the value of a specified vJoy axis using a different range.

Parameters

  • axis: OculusTouchvJoyDeviceEnum: The vJoy axis to set.
  • value: number: The value to set, range [0.0, 1.0], mapped to [-1.0, 1.0].

Returns

None

SetvJoyButton

Sets the value of a specified vJoy button.

Parameters

  • button: OculusTouchButtonEnum: The vJoy button to set.
  • value: number: The value to set, range [0, 1].

Returns

None

SendRawMouseMove

Sends a raw mouse move event to the host computer.

Parameters

  • 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.

Returns

None

SendRawMouseButtonDown

Sends a raw mouse button down event to the host computer.

Parameters

  • button: OculusTouchRawMouseButtonEnum: The button to press.

Returns

None

SendRawMouseButtonUp

Sends a raw mouse button up event to the host computer.

Parameters

  • button: OculusTouchRawMouseButtonEnum: The button to release.

Returns

None