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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use std::slice;
use std::marker::PhantomData;
use {ffi, Led, Strip};

/// An immutable reference to a `Channel`.
#[derive(Debug)]
pub struct Ref<'a>(*const ffi::ws2811_channel_t, PhantomData<&'a ()>);

impl<'a> Ref<'a> {
	#[doc(hidden)]
	pub unsafe fn wrap(ptr: *const ffi::ws2811_channel_t) -> Self {
		Ref(ptr, PhantomData)
	}

	/// Get the GPIO pin.
	pub fn pin(&self) -> i32 {
		unsafe {
			(*self.0).gpionum as i32
		}
	}

	/// Get whether the channel is inverted.
	pub fn invert(&mut self) -> bool {
		unsafe {
			if (*self.0).invert == 0 { false } else { true }
		}
	}

	/// Get the brightness.
	pub fn brightness(&mut self) -> i32 {
		unsafe {
			(*self.0).brightness as i32
		}
	}

	/// Get the strip type.
	pub fn strip(&mut self) -> Strip {
		unsafe {
			Strip::from((*self.0).strip_type)
		}
	}

	/// Get the leds.
	pub fn leds(&mut self) -> &[Led] {
		unsafe {
			slice::from_raw_parts((*self.0).leds, (*self.0).count as usize)
		}
	}
}