Crates.io | pwlp |
lib.rs | pwlp |
version | 1.0.0 |
source | src |
created_at | 2021-08-22 13:29:30.844152 |
updated_at | 2021-08-22 13:29:30.844152 |
description | Control LED strips wirelessly by sending them short animation programs |
homepage | https://github.com/pixelspark/pwlp |
repository | https://github.com/pixelspark/pwlp |
max_upload_size | |
id | 440696 |
size | 183,727 |
cargo build
cargo build --target=arm-unknown-linux-musleabi --features=raspberrypi
To streamline building and uploading to a Raspberry Pi, use build_pi.sh. Add the following to your SSH config file (~/.ssh/config):
Host rpi
HostName raspberrypi.local
User pi
IdentityFile ~/.ssh/id_rsa
StrictHostKeyChecking no
UserKnownHostsFile /dev/null
After adding your SSH public key (~/.ssh/id_rsa.pub
) to ~/.ssh/authorized_keys
on the Pi, you will be able to upload
without using a password. If you don't have an SSH key yet, run ssh-keygen
.
cargo install wasm-pack
wasm-pack build --target=web --release -- --no-default-features --features=wasm
See index.html for a usage example. To test:
npm install -g http-server
http-server
The binaries will include several default programs as binaries; these are in the src/programs folder
and can be rebuilt using ./generate_programs.sh
:
off.{txt, bin}
: the program that is sent to strips to turn offdefault_serve.{txt, bin}
: the default program served when no other program is specified in settings/command line# Compile a script
cargo run -- compile test/random.txt test/random.bin
# Test run a script
cat test/random.txt | cargo run -- run
# Serve programs to devices (configure using config.toml)
cargo run -- serve
# Run a client (configure using config.toml)
cargo run -- client
# Run a program
cargo run -- run --binary test/clock.bin
# Run a program on an actual strip with 100 LEDs (SPI bus 0 SS 0) on a Raspberry
cargo run -- run --binary --hardware -l 100 test/clock.bin
# Run a program on an actual strip with 100 LEDs connected to SPI bus 1 slave select 1 on a Raspberry
cargo run -- run --binary --hardware --bus 1 --ss 1 -l 100 test/clock.bin
The PLWP protocol devices a message format as well as an instruction architecture. Scripts are compiled to this architecture and transmitted using the message format to the devices, who will execute them.
For more information see protocol.md.
Example scripts can be found in the test folder.
Consecutive statements are separated by ";". Supported constructs:
if(comparison) { statements }
loop { statements }
: loops statements
foreverfor(var=expression) { statements }
: counts var
down from expression
to 1 (inclusive), e.g. for(n=5)
will loop with n=5, 4, 3, 2, 1./* may span multiple lines */
// single line
(should end in \n
)\r
, \n
, \t
and
are whitespaceyield
get_pixel(index)
: gets the current value for a pixel (may not be blitted yet); formatted as 0x00BBGGRRset_pixel(i, r, g, b)
: set pixel at index i
to color (r, g, b)
random(max)
: return a random number between zero and max
, inclusiveget_length
: returns the length of the stripget_precise_time
: returns a monotonic time in milliseconds. In deterministic mode, uses the number of instructions to return an approximate time.get_wall_time
: returns the number of seconds elapsed since the Unix epoch time (possibly wrapping around in the future!).rgb(r, g, b)
translates to (r & 0xFF) | (g & 0xFF) << 8 | (b & 0xFF) << 16
red(c)
translates to c & 0xFF
green(c)
translates to (c >> 8) & 0xFF
blue(c)
translates to (c >> 16) & 0xFF
Supported operators:
a+b
, a/b
, a*b
, a-b
, a%b
a|b
, a&b
, a^b
(XOR)!a
a==b
, a!=b
, a<b
, a>b
, a<=b
, a>=b
/
Get server status. Can be used for health checking.
{}
/devices
Returns a list of devices currently or previously connected.
{
"devices": {
"aa-bb-cc-dd-ee-ff": {
"address": "1.2.3.4:5678",
"program": [10, 11, 12, ...]
}
}
}
/devices/<mac>
Returns information on a specific device
{
"address": "1.2.3.4:5678",
"program": [10, 11, 12, ...]
}
/devices/<mac>/<program_name>
Send a built-in program to the device. Built-in program names:
{}