-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Playdate integration #1816
Comments
As a playdate user: very cool! From a systems perspective, I completely agree with your first point in Open Questions. I’ve interfaced some other generic serial devices with norns (Arduinos, rs422 ptz controllers) and it’s a little tricky to do reliably with just lua and shell calls. A generic serial core API that manages the Linux bookkeeping and allows lua to interface with arbitrary devices would be a great core addition imo, and then playdate support could be provided as a mod or script lib. |
generic serial device is an interesting prospect, i agree. (and also, playdate seems like a fun interface!) here's where we differentiate TTY devices: https://github.com/monome/norns/blob/main/matron/src/device/device_monitor.c#L270 |
Nice! I'm gonna take a stab at the generic serial device, although it might be a little bit beyond my skills. @Dewb, do you have any of these scripts on GitHub, or examples you can share? |
Here’s a script that uses a couple of serial devices (“servo” is an Arduino Uno, and “camera” is a USB to RS422 adapter.) https://gist.github.com/Dewb/12c09eb5cf80c8b432c7b4a0f9287d13 (NB: I am also not an expert on Linux serial, this was a “just enough to work for the performance” last-minute script.) |
What do folks think about adding Playdate integration to Norns? I have a feature complete implementation running on my Norns, but I'd like to get some feedback on the big picture before I ask anyone to look at the code.
Motivation
From the perspective of Norns, Playdate is basically a retro game controller with two notable exceptions: it has a crank and it runs Lua. I'm primarily interested in using the crank to interact with Norns and Crow. There are lots of possibilities in the other direction too, such as controlling Playdate music apps with a midi keyboard, a grid or control voltage signals.
Implementation
The Playdate supports serial connections over USB. Official documentation for the serial connection can be found in the Playdate Lua serial API docs and Playdate C serial API docs. There is also unofficial documentation of the USB serial capabilities by the Playdate Reverse Engineering project.
The serial connection can be used to enable a controller mode that streams the button, crank and accelerometer state over serial. It does not (to my knowledge) support the HID protocol, so it could not be used with the Norns
gamecontroller
API without modifications.Proposed API
Methods
playdate.connected()
: true if Playdate is connectedplaydate.send( line )
: send a string message to Playdate using themsg
serial commandplaydate.run( path )
: launch the PDX at the given path on Playdateplaydate.controller_start()
: start controller modeplaydate.controller_stop()
: stop controller modeprint()
in Lua orplaydate->system->logToConsole()
in C with the expected message format.Device Management Callbacks
function playdate.add( id, name, dev )
function playdate.remove( id )
Controller Event Callbacks
function playdate.accel( x, y, z )
function playdate.button( b, s )
A
,B
,U
,D
,L
,R
orM
, and s is 1 if depressed and 0 if releasedfunction playdate.crank( d )
function playdate.crankdock( s )
Serial Event Callbacks
function playdate.event( line )
Other interesting serial APIs:
buttons
bitmap
screen
eval
msg
serial events.stream
btn
/changecrank
/dockcrank
/accel
autolock
Open Questions / Other Considerations
playdate.event( line )
callback would be called for all messages logged from the Playdate. I debated if it should only be called for messages that use some sort of prefix like~msg:
, similar to how the controller protocol works (~ctl:
). Ultimately I'm leaning towards leaving this up to the script/PDX author.msg
, these are not officially documented outside of using thehelp
command. I'm not sure if commands likecontroller start
andcontroller stop
can be considered stable.Thanks for considering my proposal!
The text was updated successfully, but these errors were encountered: