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
use std::io::Write;
use {Result as Res, Controller};

/// Controller led management.
pub struct Led<'a, 'b: 'a> {
	controller: &'a mut Controller<'b>,
}

impl<'a, 'b> Led<'a, 'b> {
	#[doc(hidden)]
	pub fn new(controller: &'a mut Controller<'b>) -> Led<'a, 'b> {
		Led {
			controller: controller,
		}
	}

	/// Change the led luminosity.
	pub fn level(self, value: u8) -> Res<()> {
		self.controller.control_with(0x87, 0x03, |mut buf| {
			buf.write(&[0x2d, value])
		})
	}

	/// Turn the led off.
	pub fn off(self) -> Res<()> {
		self.level(0)
	}

	/// Turn the led on.
	pub fn on(self) -> Res<()> {
		self.level(100)
	}
}