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

@systemic-games/pixels-web-connect

v1.2.2

Published

Connect to Pixels dice using Web Bluetooth.

Downloads

97

Readme

Pixels Web Connect

This is the Pixels package for front end web developers. It enables communications between Pixels dice and a web browser using Bluetooth Low Energy.

Find the latest published version on NPM.

Foreword

Pixels are full of LEDs, smarts and no larger than regular dice, they can be customized to light up when and how you desire. Check our website for more information.

Warning Before jumping into programming please make sure to read our Pixels developer's guide.

Please open a ticket on GitHub if you're having any issue.

Browser Support

This package relies on the Web Bluetooth API for accessing Bluetooth from the browser. At the time of writing only Chromium based browsers such as Chrome, Edge and Opera have support for these APIs.

On Linux, you need to enable Web Bluetooth support with this flag: chrome://flags/#enable-web-bluetooth.

Note: Currently all our testing is being done with Chrome on Windows.

Getting Started

To install the package:

npm i @systemic-games/pixels-web-connect

Start by calling the requestPixel function to request the user to select a Pixel die to connect to.

This function returns a Pixel object. Call the connect asynchronous method to initiate a Bluetooth connection with the die.

The Pixel class has a number of methods to retrieve information about the die state. It also let you add a listener for any Pixel message.

Communicating With Pixels

import {
    repeatConnect,
	requestPixel,
	Color,
} from "@systemic-games/pixels-web-connect";

// Ask user to select a Pixel
const pixel = await requestPixel();

// Connect to die
console.log("Connecting...");
await repeatConnect(pixel);

// Get last roll state
const rollState = pixel.rollState;
console.log(`=> roll state: ${rollState.state}, face up: ${rollState.face}`);

// Read RSSI (signal strength)
const rssi = await pixel.queryRssi();
console.log(`=> rssi: ${rssi}`);
// And battery level
console.log(`=> Battery: ${pixel.batteryLevel}%`);

// Make LEDs flash a color
await pixel.blink(Color.red);

// Add listener to get notified on rolls
pixel.addEventListener("roll", (face) => {
	console.log(`=> rolled face: ${face}`);
});

Playing Animations

Classes to manipulate animation data are available in a separate package: @systemic-games/pixels-edit-animation.

import {
  createDataSetForAnimation,
  EditAnimationRainbow,
} from "@systemic-games/pixels-edit-animation";

// Create a simple rainbow animation
const editDataSet = createDataSetForAnimation(
    new EditAnimationRainbow({
        duration: 3,
        count: 2,
        fade: 0.5,
    })
);

// And play it on the Pixel die
await pixel.playTestAnimation(editDataSet.toDataSet());

React Hooks

See the @systemic-games/pixels-react package.

Example

We've made a mini dice game "Odd Or Even", checkout the source code here.

Module documentation

To get more in depth information about this package see the module's export documentation here.

Documentation generated with TypeDoc.

Known Issues

On Windows 10, the OS notifies of a Bluetooth peripheral being disconnected a few seconds (around 4) before the peripheral actually gets the disconnection event. This will make a re-connection attempt to fail if made before that delay as the peripheral will still disconnect after this 4 seconds delay. Using repeatConnect() function is a good workaround as it will attempt to connect a few times before failing.

License

MIT


Made with Example TypeScript Package.