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

touch-sdk

v0.6.1

Published

Doublepoint Touch SDK

Downloads

258

Readme

Touch SDK Web

npm npm bundle size NPM npm downloads Discord

Connects to Doublepoint Touch SDK compatible Bluetooth devices – like this WearOS app.

Works with Chrome-based browsers. (more info)

Importing (URL)

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/main.js"></script>
const Watch = TouchSDK.Watch

Importing (NPM)

npm install touch-sdk
import { Watch } from 'touch-sdk'

Example using URL import

<!DOCTYPE html>
<html>
    <head>
        <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/main.js"></script>
    </head>
    <body>
        <script>
            const watch = new TouchSDK.Watch()

            const connectButton = watch.createConnectButton()
            document.body.appendChild(connectButton)

            watch.addEventListener('tap', () => {
                console.log('tap')
            })
        </script>
    </body>
</html>

Reference

Connection

watch.createConnectButton

Returns a button element with the following properties:

  • onclick calls watch.requestConnection
  • Text: Connect Touch SDK Controller
  • Class (for CSS): touch-sdk-connect-button
  • When the user selects a Touch SDK compatible device, the button is hidden.
  • When the watch disconnects, the button is shown again.

This function does not add the button to the DOM.

watch.requestConnection

Can only be called as a result of a user action, for example a button click. Otherwise doesn't do anything.

watch.requestConnection().then(() => {
    console.log('connected')
}, error => {
    alert(error.message)
})

Input events

Gesture prediction

watch.addEventListener('tap', (event) => {
    console.log('tap')
})

```javascript
watch.addEventListener('probability', (event) => {
    console.log("gesture probability:", event.detail)
})

Ray casting (arm direction)

watch.addEventListener('armdirectionchanged', event => {
    const { dx, dy } = event.detail
    console.log(dx, dy)
})

Raw motion (IMU)

All applicable units are SI-based.

Acceleration
watch.addEventListener('accelerationchanged', (event) => {
    const { x, y, z } = event.detail
    console.log(x, y, z)
})
Rotation (gyroscope)
watch.addEventListener('angularvelocitychanged', (event) => {
    const { x, y, z } = event.detail
    console.log(x, y, z)
})
Gravity Vector
watch.addEventListener('gravityvectorchanged', (event) => {
    const { x, y, z } = event.detail
    console.log(x, y, z)
})
Orientation (quaternion)
watch.addEventListener('orientationchanged', (event) => {
    const { x, y, z, w } = event.detail
    console.log(x, y, z, w)
})

Touch Screen

Touch Start
watch.addEventListener('touchstart', (event) => {
    const { x, y } = event.detail
    console.log(x, y)
})
Touch Move
watch.addEventListener('touchmove', (event) => {
    const { x, y } = event.detail
    console.log(x, y)
})
Touch End
watch.addEventListener('touchend', (event) => {
    const { x, y } = event.detail
    console.log(x, y)
})
Touch Cancel

For example the user swiped from the edge of the screen, and triggered an operating system gesture. Usually touchcancel should be handled the same way as touchend.

watch.addEventListener('touchcancel', (event) => {
    const { x, y } = event.detail
    console.log(x, y)
})

Mechanical

Rotary Dial
watch.addEventListener('rotary', (event) => {
    const { step } = event.detail
    console.log(step)
})
Button

In Wear OS this is the back button. Only clicks are registered, no button down and button up events.

watch.addEventListener('button', (event) => {
    console.log('button')
})

Miscellaneous

After the connected event, several watch properties become available.

watch.addEventListener('connected', (event) => {
    watch.hand // 'left' or 'right'
    watch.hapticsAvailable // true or false
    watch.touchScreenResolution // (width, height). (0, 0) if no touch screen
    watch.batteryPercentage // 0-100
})

Output

Haptics

Intensity is between 0 and 1. Length is milliseconds, between 0 and 5000.

watch.triggerHaptics(intensity, length)

Developing: build a new version

npm install
npm run build
npm publish