rgb/
rgb.rs

1//           DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
2//                   Version 2, December 2004
3//
4// Copyright (C) 2017 Gilberto Bertin <me@jibi.io>
5//
6// Everyone is permitted to copy and distribute verbatim or modified
7// copies of this license document, and changing it is allowed as long
8// as the name is changed.
9//
10//            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
11//   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
12//
13//  0. You just DO WHAT THE FUCK YOU WANT TO.
14//
15
16extern crate unicornd_client;
17
18use std::thread::sleep;
19use std::time::Duration;
20use unicornd_client::{UnicorndClient, Pos, Pixel};
21
22fn gen_solid(pixel: Pixel) -> [Pixel; 64] {
23    let mut pixels = [Pixel{r:0, g:0, b:0}; 64];
24    for x in 0..64 {
25        pixels[x] = pixel.clone()
26    }
27    pixels
28}
29
30fn main() {
31    let mut u = UnicorndClient::new("/var/run/unicornd.socket".to_string()).unwrap();
32    u.set_brightness(128).unwrap();
33
34    let rgb = [
35        Pixel{r: 255, g:   0, b:   0},
36        Pixel{r:   0, g: 255, b:   0},
37        Pixel{r:   0, g:   0, b: 255}
38    ];
39
40    loop {
41        for p in rgb.iter() {
42            u.set_all_pixels(gen_solid(*p)).unwrap();
43            for x in 3..5 {
44                for y in 3..5 {
45                    u.set_pixel(Pos{x, y}, Pixel{r: 255, g: 255, b: 255}).unwrap();
46                }
47            }
48
49            u.show().unwrap();
50            sleep(Duration::new(1, 0));
51        }
52    }
53}