1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

use apigpio::*;
use apigpio::Level::*;

use tokio::time::{Duration,delay_for};

pub const RGB : [Pin;3] = [20,21,16];

pub const XMIT : u32 = 27;

pub const FLASH_NORMAL  : Duration = Duration::from_millis(500);
pub const FLASH_SPECIAL : Duration = Duration::from_millis(100);

pub async fn setled(pi : &Connection, rgb : [Level;3]) -> Result<()> {
  for (i, &pin) in RGB.iter().enumerate() {
    pi.gpio_write(pin, rgb[i]).await?
  }
  Ok(())
}

pub async fn flashled(pi : &Connection, rgb : [Level;3],
                      each : Duration) -> Result<()> {
  loop {
    setled(&pi, [L;3]).await?;
    delay_for(each).await;
    setled(&pi, rgb).await?;
    delay_for(each).await;
  }
}