Commit 16d5d0b1 authored by Astro's avatar Astro
Browse files

light_sensor

parent 6a50161e
...@@ -9,6 +9,7 @@ fn main() { ...@@ -9,6 +9,7 @@ fn main() {
writeln!(UART, "Hello from Rust\r").unwrap(); writeln!(UART, "Hello from Rust\r").unwrap();
let display = Display::open(); let display = Display::open();
let light = LightSensor::start();
for t in 0..Display::W { for t in 0..Display::W {
display.clear(Color::yellow()); display.clear(Color::yellow());
display.print(160 - t, 10, b"Hello Rust\0", Color::white(), Color::black()); display.print(160 - t, 10, b"Hello Rust\0", Color::white(), Color::black());
...@@ -29,6 +30,7 @@ fn main() { ...@@ -29,6 +30,7 @@ fn main() {
if b.right_top() { if b.right_top() {
display.print(80, 30, b"Reset\0", Color::red(), Color::black()); display.print(80, 30, b"Reset\0", Color::red(), Color::black());
} }
writeln!(UART, "Light: {:?}\r", light.get());
display.update(); display.update();
} }
......
...@@ -67,9 +67,10 @@ mod display; ...@@ -67,9 +67,10 @@ mod display;
pub use display::{Display, Color, LineStyle}; pub use display::{Display, Color, LineStyle};
mod buttons; mod buttons;
pub use buttons::Buttons; pub use buttons::Buttons;
pub mod uart; pub mod uart;
pub const UART: uart::Uart = uart::Uart; pub const UART: uart::Uart = uart::Uart;
mod light_sensor;
pub use light_sensor::LightSensor;
pub fn exit(ret: i32) -> ! { pub fn exit(ret: i32) -> ! {
unsafe { unsafe {
......
use super::bindings::*;
pub struct LightSensor;
impl LightSensor {
pub fn start() -> Self {
if unsafe { epic_light_sensor_run() } != 0 {
panic!("Cannot start light sensor");
}
LightSensor
}
pub fn get(&self) -> Option<u16> {
let mut result = 0;
if unsafe { epic_light_sensor_get(&mut result) } == 0 {
Some(result)
} else {
None
}
}
}
impl Drop for LightSensor {
fn drop(&mut self) {
unsafe { epic_light_sensor_stop(); }
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment