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

esp370u

v0.0.3

Published

Javascript library for Hanvon ESP370U E-signature display based on WebHID API

Downloads

14

Readme

ESP370U

Javascript library for Hanvon ESP370U E-signature display based on WebHID API:

  • Plug and play, no os-drivers or browser-extensions required.
  • Cross platform, running on any morden browsers supports WebHID API on any operating system.
  • Support send commands to device, eg open , clear , close .
  • Support listen events from device, eg ready , resign , confirm , up , move , down
  • Events contains raw and normalized data of X coordinate, Y coordinate, Z pressing force.
  • Almost every api of this libarary returns Promise, you can use async operator as you wish.

Install

npm install esp370u

simply import it in ES Modules supported environment:

import { ESP370U } from 'esp370u';

or drictly using it without module system by adding the self excute script index.iife.js:

<html>
  <body>
    <script src="node_modules/esp370u/dist/index.iife.js"></script>
    <script>
      const { ESP370U } = esp370u;
    </script>
  </body>
</html>

Examples

To get started quickly, you can use emulate():

import { emulate } from 'esp370u';

const destroyEmulator = emulate(canvasElement, {
  unsupportedWebHIDAPI: ['Your browser does not support', 'the WebHID API'],
  unconnectedDevice: ['Your device is not connected yet', 'Click me to connect ESP370U'],
  onConfirm: (blob) => {
    destroyEmulator(); // Optional if you want continuous signs.
    const previewURL = URL.createObjectURL(blob);
    window.open(previewURL);
  },
});

See online demo https://sherluok.github.io/ESP370U or code at ./docs/index.html

Commands

send()

send(command: string | ArrayLike): Promise<void | TimeoutError>

The send() method send a command and returns a Promise. The command argument is any ArrayLike data that will be transform into Uint8Array then send to device by WebHID API. It return a Promise that will be resolved after the device replies this command you send. The command argument can also be String, in case it's alias of ArrayLike data, including:

open

Alias of send([0x55])

close

Alias of send([0x55])

clear

Alias of send([0x55])

const esp370u = new ESP370U();

esp370u.send("open").then(async () => {
  await esp370u.send("clear");
  await esp370u.send("close");
});

Events

on()

on(type: string, listener: (e: Event) => void): TeardownLogic

off()

off(type: string, listener: (e: Event) => void): void

once()

once(type: string, timeout?: number): Promise<Event | TimeoutError>

try {
  const event = await esp370u.once('ready', 1000);
  console.log('connected.');
} catch (error) {
  if (error instanceof TimeoutError && error.type === 'ready') {
    console.log('Unable to connect device after %d milliseconds!', error.timeout);
  }
}

emit()

emit(type: string, e: Event)

ready

resign

confirm

up

down

move

?

listen to all events not listed above.

*

listen to all events from device.onreportinput. Note that this event listener has the highest priority, so it will fire before any other event types. By default the event will be pass to other event listeners, call e.stop(#stop) method to prevent this behavior.

esp370u.on('*', (e) => {
  if (e.getUint8(0) === 0x88) {
    e.stop();
  }
});

InputEvent

A DataView containing the data from the device input report:

esp370u.on('*', (e) => {
  const [command, x, y, z] = [
    e.getUint8(0),
    e.getUint16(1, true),
    e.getUint16(3, true),
    e.getUint16(5, true),
  ];
});

normalize()

The normalize() method on InputEvent object returns StylusData:

esp370u.on('move', (e) => {
  const { x, y, z } = e.normalize();
});

StylusData

Object containing stylus's normalized coordinates and pressure data.

x

Float between 0 ~ 1.0 meaning:

const x = e.getUint16(1) / ESP370U.MAX_X;

y

Float between 0 ~ 1.0 meaning:

const y = e.getUint16(3) / ESP370U.MAX_Y;

z

Float between 0 ~ 1.0 meaning:

const z = e.getUint16(5) / ESP370U.MAX_Z;

TimeoutError

type

timeout