use std::{mem, ptr};
use libc::{c_int, uint32_t};
use {ffi, Handle, Channel};
pub struct Builder(ffi::ws2811_t);
impl Builder {
#[doc(hidden)]
pub fn new() -> Self {
unsafe {
let mut handle: ffi::ws2811_t = mem::zeroed();
handle.freq = ffi::WS2811_TARGET_FREQ;
Builder(handle)
}
}
pub fn frequency(&mut self, value: u32) -> &mut Self {
self.0.freq = value as uint32_t;
self
}
pub fn dma(&mut self, value: i32) -> &mut Self {
self.0.dmanum = value as c_int;
self
}
pub fn channel(&mut self, index: usize, value: Channel) -> &mut Self {
unsafe {
self.0.channel[index] = value.into_inner();
}
self
}
pub fn build(&mut self) -> Result<Handle, ()> {
unsafe {
Handle::new(ptr::read(&self.0))
}
}
}