Last active
August 18, 2017 03:53
-
-
Save alevy/798d11dbfa5409e0aa56d870b4b7afcf to your computer and use it in GitHub Desktop.
Tock capsule periodic accelerometer reading
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
use kernel::hil::time::{self, Alarm, Frequency}; | |
use kernel::hil::sensors::{NineDof, NineDofClient}; | |
pub struct Accelerate<'a, A: Alarm + 'a> { | |
alarm: &'a A, | |
ninedof: &'a NineDof | |
} | |
impl<'a, A: Alarm> Accelerate<'a, A> { | |
pub fn new(alarm: &'a A, ninedof: &'a NineDof) -> Accelerate<'a, A> { | |
Accelerate { | |
alarm: alarm, | |
ninedof: ninedof, | |
} | |
} | |
pub fn start(&self) { | |
self.alarm.set_alarm( | |
self.alarm.now().wrapping_add(<A::Frequency>::frequency())) | |
} | |
} | |
impl<'a, A: Alarm> time::Client for Accelerate<'a, A> { | |
fn fired(&self) { | |
self.ninedof.read_accelerometer(); | |
} | |
} | |
impl<'a, A: Alarm> NineDofClient for Accelerate<'a, A> { | |
fn callback(&self, x: usize, y: usize, z: usize) { | |
debug!("{} {} {}", x, y, z); | |
self.start(); | |
} | |
} |
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
let accelerate_virtual_alarm = static_init!( | |
VirtualMuxAlarm<'static, sam4l::ast::Ast>, | |
VirtualMuxAlarm::new(mux_alarm)); | |
let accelerate = static_init!( | |
capsules::accelerate::Accelerate<'static, | |
VirtualMuxAlarm<'static, sam4l::ast::Ast<'static>>>, | |
capsules::accelerate::Accelerate::new(accelerate_virtual_alarm, fxos8700)); | |
accelerate_virtual_alarm.set_client(accelerate); | |
{ | |
use kernel::hil::sensors::NineDof; | |
fxos8700.set_client(accelerate); | |
} | |
accelerate.start(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment