use std::{mem, ptr};
use libc::c_int;
use {ffi, Strip};
use super::Channel;
pub struct Builder(ffi::ws2811_channel_t);
impl Builder {
pub fn new() -> Self {
unsafe {
Builder(mem::zeroed())
}
}
pub fn pin(&mut self, value: i32) -> &mut Self {
self.0.gpionum = value as c_int;
self
}
pub fn count(&mut self, value: usize) -> &mut Self {
self.0.count = value as c_int;
self
}
pub fn invert(&mut self, value: bool) -> &mut Self {
self.0.invert = if value { 1 } else { 0 };
self
}
pub fn brightness(&mut self, value: i32) -> &mut Self {
self.0.brightness = value as c_int;
self
}
pub fn strip(&mut self, value: Strip) -> &mut Self {
self.0.strip_type = value.into();
self
}
pub fn build(&mut self) -> Result<Channel, ()> {
unsafe {
Channel::new(ptr::read(&self.0))
}
}
}