pimoroni / mote

Mote - drivers for the plug and play USB APA102 controller
https://shop.pimoroni.com/products/mote
MIT License
24 stars 14 forks source link

Anybody using WebSerial to talk from a web page to a mote? #31

Closed dglaude closed 3 months ago

dglaude commented 2 years ago

Did anybody attempted that or know someone that did?

I guess that by understanding the protocol, it should be possible to do the same thing as this:


        self.port.write(b'o')
        self.port.write(buf)```

But in javascript...
Gadgetoid commented 2 years ago

This should be possible, yes.

The protocol is not very complicated.

Channel configuration consists of eight bytes, starting with motec followed by the channel number, followed by the number of pixels, followed by the channel flags- currently only values 1 and 0 are supported to enable/disable gamma correction.

There are a maximum of four channels with sixteen LEDs so most of the time you just want to send:

b'motec\x00\x10\x01'
b'motec\x01\x10\x01'
b'motec\x02\x10\x01'
b'motec\x03\x10\x01'

Then updating a channel consists of 54 bytes (assuming 16 LEDs). motec followed by the channel number, followed by the RGB triplets for each pixel.

b'moteo\x00\xff\x80@\xff\x80@\xff\x80@\xff\x80@\xff\x80@\xff\x80@\xff\x80@\xff\x80@\xff\x80@\xff\x80@\xff\x80@\xff\x80@\xff\x80@\xff\x80@\xff\x80@\xff\x80@'