faster tick rate for button check

This commit is contained in:
Simon Wörner
2017-03-31 18:26:00 +02:00
parent 54a27c508a
commit 48b4310a67

View File

@@ -102,16 +102,17 @@ fn run(rdone: chan::Receiver<()>) {
set_direction(GPIO_PORT_BTN, GPIO_DIRECTION_IN);
set_direction(GPIO_PORT_LED, GPIO_DIRECTION_OUT);
let tick = chan::tick(Duration::from_millis(1000 / 5));
let btn_tick = chan::tick(Duration::from_millis(50));
let led_tick = chan::tick(Duration::from_millis(1000 / 5));
let mut btn_last = false;
let mut led_on = false;
let mut enabled = true;
loop {
chan_select! {
tick.recv() => {
#[cfg(debug_assertions)]
println!("tick");
btn_tick.recv() => {
//#[cfg(debug_assertions)]
//println!("btn_tick");
// switch enabled if button state changed
let btn = get_value(GPIO_PORT_BTN) == GPIO_BTN_ON;
@@ -119,7 +120,13 @@ fn run(rdone: chan::Receiver<()>) {
enabled = !enabled;
}
// blink led
btn_last = btn;
},
led_tick.recv() => {
#[cfg(debug_assertions)]
println!("led_tick");
// blink led if enabled
if enabled {
led_on = !led_on;
} else {
@@ -133,8 +140,6 @@ fn run(rdone: chan::Receiver<()>) {
else {
set_value(GPIO_PORT_LED, GPIO_LED_OFF);
}
btn_last = btn;
},
rdone.recv() => {
// unexport