JavaScript library for interacting with a Playdate console over USB, wherever WebUSB is supported.
- Get Playdate device stats such as its version info, serial, cpu stats, memory usage, etc
- Take a screenshot of the Playdate's screen and draw it to a HTML5 canvas, or send an image to be previewed
- Read the Playdate's button and crank input state
- Execute secret commands!
- Extensive error handling with helpful error messages
- Exports full Typescript types, has zero dependencies, and only ~4kb minified and gzipped
WebUSB is only supported in Secure Contexts, and only in certain browsers (currently Google Chrome, Microsoft Edge, and Opera).
The commands that this library wraps with functions (such as getVersion()
or getScreen()
) are known to be safe, are used by the Playdate Simulator, and have been tested on actual Playdate hardware. However, some of the commands that you can potentially run with runCommand()
could be dangerous, and might even harm your favorite yellow handheld if you don't know what you're doing. Please don't execute any commands that you're unsure about.
Also, due to the asynchronous nature of WebUSB, this library uses async/await
a lot. If you're not already familiar with that, now would be a good time to catch up!
TODO
npm install playdate-usb --save
Then assuming you're using a module-compatible system (like Webpack, Rollup, etc):
import { requestConnectPlaydate } from 'playdate-usb';
async function connectToPlaydate() {
const playdate = await requestConnectPlaydate();
}
Using the modules directly via Unpkg:
<script type="module">
import { requestConnectPlaydate } from 'https://unpkg.com/playdate-usb?module';
async function connectToPlaydate() {
const playdate = await requestConnectPlaydate();
}
</script>
Using an external script reference
<script src="https://unpkg.com/playdate-usb/dist/playdate-usb.min.js"></script>
<script>
async function connectToPlaydate() {
const playdate = await playdateUsb.requestConnectPlaydate();
}
</script>
When using the library this way, a global called playdateUsb
will be created containing all the exports from the module version.
isUsbSupported()
Opens the device for communication. This will throw an error if the device cannot be opened
npm install
npm start
npm run build
If you have any questions or just want to say hi, you can reach me on Twitter (@rakujira), on Discord (@jaames#9860
), or via email (mail at jamesdaniel dot dev
).
- Matt Sephton for helping me get access to the Playdate Developer Preview
- This blogpost from Secure Systems Lab on reverse-engineering USB with WireShark and translating from captured packets to WebUSB calls
- Suz Hinton's fun talk about WebUSB at JSConf 2018
- The folks at Panic for making such a wonderful and fascinating handheld
2021 James Daniel
Playdate is © Panic Inc. This project isn't affiliated with or endorsed by them in any way