Skip to content

Instantly share code, notes, and snippets.

@alevy
Created October 26, 2017 00:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alevy/68cd893329fbaa4f09c3586eddc11b07 to your computer and use it in GitHub Desktop.
Save alevy/68cd893329fbaa4f09c3586eddc11b07 to your computer and use it in GitHub Desktop.
//! 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