#![cfg_attr(not(test), no_std)]
#![deny(missing_docs)]
pub mod behaviors;
pub mod engine;
pub use smart_leds::colors;
pub use smart_leds::RGB8;
pub trait LossyIntoF32 {
fn lossy_into(&self) -> f32;
}
impl LossyIntoF32 for u64 {
fn lossy_into(&self) -> f32 {
*self as f32
}
}
impl LossyIntoF32 for u32 {
fn lossy_into(&self) -> f32 {
*self as f32
}
}
impl LossyIntoF32 for u16 {
fn lossy_into(&self) -> f32 {
(*self).into()
}
}
impl LossyIntoF32 for u8 {
fn lossy_into(&self) -> f32 {
(*self).into()
}
}
#[macro_export]
macro_rules! script {
(| action | (color) | (duration_ms) | (period_ms_f) | (phase_offset_ms) | repeat | $(| $action:ident | ($color:expr) | ($duration_ms:expr) | ($period_ms_f:expr) | ($phase_offset_ms:expr) | $repeat:ident |)+) => {
{
#[allow(unused_imports)]
use $crate::{
colors::*,
engine::PhaseIncr::*,
};
[
$(
$crate::engine::Action::build()
.$action()
.color($color)
.for_ms($duration_ms)
.period_ms($period_ms_f)
.phase_offset_ms($phase_offset_ms.into())
.$repeat()
.finish(),
)+
]
}
};
(| action | color | duration_ms | period_ms_f | phase_offset_ms | repeat | $(| $action:ident | $color:ident | $duration_ms:literal | $period_ms_f:literal | $phase_offset_ms:literal | $repeat:ident |)+) => {
{
#[allow(unused_imports)]
use $crate::{
colors::*,
engine::PhaseIncr::*,
};
[
$(
$crate::engine::Action::build()
.$action()
.color($color)
.for_ms($duration_ms)
.period_ms($period_ms_f)
.phase_offset_ms($phase_offset_ms.into())
.$repeat()
.finish(),
)+
]
}
};
}
#[cfg(test)]
mod tests {
use crate::{
engine::{LoopBehavior, Sequence},
script,
};
use groundhog::std_timer::Timer;
use std::thread::sleep;
use std::time::Duration;
type MicroTimer = Timer<1_000_000>;
#[test]
fn foo() {
let mut script: Sequence<MicroTimer, 8> = Sequence::empty();
script.set(
&script! {
| action | color | duration_ms | period_ms_f | phase_offset_ms | repeat |
| solid | BLACK | 1000 | 0.0 | 0 | once |
| sin | WHITE | 2500 | 2500.0 | 0 | once |
| solid | BLACK | 1000 | 0.0 | 0 | once |
},
LoopBehavior::OneShot,
);
while let Some(_color) = script.poll() {
sleep(Duration::from_millis(10));
}
}
}