Created
October 26, 2017 00:07
-
-
Save alevy/68cd893329fbaa4f09c3586eddc11b07 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//! Sample capsule for Tock course at SOSP. It handles an alarm to | |
//! sample the ambient light sensor. | |
use kernel::hil::time::{self, Alarm, Frequency}; | |
use kernel::hil::sensors::{AmbientLight, AmbientLightClient}; | |
pub struct Sosp<'a, A: Alarm + 'a> { | |
alarm: &'a A, | |
light: &'a AmbientLight, | |
} | |
impl<'a, A: Alarm> Sosp<'a, A> { | |
pub fn new(alarm: &'a A, light: &'a AmbientLight) -> Sosp<'a, A> { | |
Sosp { | |
alarm: alarm, | |
light: light, | |
} | |
} | |
pub fn start(&self) { | |
self.alarm.set_alarm( | |
self.alarm.now().wrapping_add(<A::Frequency>::frequency())); | |
} | |
} | |
impl<'a, A: Alarm> time::Client for Sosp<'a, A> { | |
fn fired(&self) { | |
self.light.read_light_intensity(); | |
} | |
} | |
impl<'a, A: Alarm> AmbientLightClient for Sosp<'a, A> { | |
fn callback(&self, lux: usize) { | |
debug!("Light reading: {}", lux); | |
self.start(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment