Skip to content

Instantly share code, notes, and snippets.

@alevy

alevy/accelerate.rs

Last active Aug 18, 2017
Embed
What would you like to do?
Tock capsule periodic accelerometer reading
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();
}
}
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
You can’t perform that action at this time.