Skip to main content

Elc

Struct Elc 

Source
pub struct Elc { /* private fields */ }
Expand description

Represent the rgb controller
If the device has a kernel driver it will be detached.
It will be reattached when the drop occurs.

Implementations§

Source§

impl Elc

Source

pub fn new() -> Elc

Create a new rgb controller handler.

Examples found in repository?
examples/clear.rs (line 11)
10fn main() {
11    let mut elc = Elc::new();
12    let status = elc.execute(&Commands::EraseFlash);
13    println!("{status:#?}");
14}
More examples
Hide additional examples
examples/play.rs (line 8)
3fn main() {
4    let animation_id: u16 = std::env::var("ANIMATION_ID")
5        .unwrap_or("1".to_owned())
6        .parse()
7        .unwrap_or(1);
8    let mut elc = Elc::new();
9    play(&mut elc, animation_id).unwrap();
10}
examples/status.rs (line 13)
12fn main() {
13    let mut elc = Elc::new();
14    let status = elc.execute(&Commands::Query(alienrgb::QuerySub::AnimationCount));
15    println!("{status:#?}");
16    std::thread::sleep(Duration::from_secs(1));
17    let status = elc.execute(&Commands::Query(alienrgb::QuerySub::Status));
18    println!("{status:#?}");
19}
examples/save.rs (line 37)
13fn main() {
14    let animation = std::env::var("ANIMATION").unwrap_or("SPECIAL".to_owned());
15    let animation_id: u16 = std::env::var("ANIMATION_ID")
16        .unwrap_or("1".to_owned())
17        .parse()
18        .unwrap_or(1);
19    let red: u8 = std::env::var("RED")
20        .unwrap_or("255".to_owned())
21        .parse()
22        .unwrap_or(255);
23    let green: u8 = std::env::var("GREEN")
24        .unwrap_or("0".to_owned())
25        .parse()
26        .unwrap_or(0);
27    let blue: u8 = std::env::var("BLUE")
28        .unwrap_or("0".to_owned())
29        .parse()
30        .unwrap_or(0);
31    let color = Rgb::new(red, green, blue);
32    let duration_millis: u64 = std::env::var("DURATION")
33        .unwrap_or("1000".to_owned())
34        .parse()
35        .unwrap_or(1000);
36    let duration = Duration::from_millis(duration_millis);
37    let mut elc = Elc::new();
38    let commands = match animation.as_str() {
39        "SPECIAL" => special(animation_id),
40        "BREATHE" => breathe(color, animation_id),
41        "SPECTRUM" => spectrum(duration, animation_id),
42        "WAVE" => wave(color, animation_id),
43        "RAINBOW" => rainbow(duration, animation_id),
44        "BACK_AND_FORTH" => back_and_forth(color, animation_id),
45        _ => special(animation_id),
46    };
47    save(&mut elc, commands).unwrap();
48}
Source

pub fn execute(&mut self, command: &impl Command) -> Result<Response, Error>

Execute a command.
Too many sequential command could crash the device. To reboot it, a power cycle is needed.
The controller may not reboot at the first power cycle.

Examples found in repository?
examples/clear.rs (line 12)
10fn main() {
11    let mut elc = Elc::new();
12    let status = elc.execute(&Commands::EraseFlash);
13    println!("{status:#?}");
14}
More examples
Hide additional examples
examples/save.rs (line 52)
50fn save(elc: &mut Elc, commands: Vec<Commands>) -> Result<(), rusb::Error> {
51    for command in commands {
52        let r = elc.execute(&command)?;
53        println!("{command:#?}:\n{r:#?}");
54    }
55    Ok(())
56}
examples/play.rs (line 14)
12fn play(elc: &mut Elc, id: u16) -> Result<(), rusb::Error> {
13    let command = Commands::Animation(AnimationSub::Play, id);
14    let status = elc.execute(&command)?;
15    println!("{command:#?}:\n{status:#?}");
16    Ok(())
17}
examples/status.rs (line 14)
12fn main() {
13    let mut elc = Elc::new();
14    let status = elc.execute(&Commands::Query(alienrgb::QuerySub::AnimationCount));
15    println!("{status:#?}");
16    std::thread::sleep(Duration::from_secs(1));
17    let status = elc.execute(&Commands::Query(alienrgb::QuerySub::Status));
18    println!("{status:#?}");
19}

Trait Implementations§

Source§

impl Debug for Elc

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Elc

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl !Freeze for Elc

§

impl RefUnwindSafe for Elc

§

impl Send for Elc

§

impl Sync for Elc

§

impl Unpin for Elc

§

impl UnsafeUnpin for Elc

§

impl UnwindSafe for Elc

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.