refactor the heartbeat led logic into the driver

This commit is contained in:
Tangent 128 2019-10-27 02:08:48 -04:00
parent 56115d5132
commit 03bd72808a
3 changed files with 19 additions and 19 deletions

View File

@ -10,12 +10,12 @@ use lights::{
Rgb
}
};
use lights_hal::{boot, delay, entry, OutputPin};
use lights_hal::{boot, delay, entry};
#[entry]
fn main() -> ! {
let mut lights = boot();
lights.red_led.set_high().unwrap();
lights.heartbeat();
let pattern =
repeat(&Rgb(255,0,255)).take(150)
@ -24,15 +24,9 @@ fn main() -> ! {
).cycle();
let mut buffer = [HardwareRgb(255,255,0); 200];
let mut light = false;
loop {
// blink light to demonstrate loop is still running
if light {
lights.red_led.set_high().unwrap();
} else {
lights.red_led.set_low().unwrap();
}
light = !light;
lights.heartbeat();
for (i, pixel) in pattern.clone().take(200).enumerate() {
buffer[i] = correct(pixel);

View File

@ -10,12 +10,12 @@ use lights::{
Rgb
}
};
use lights_hal::{boot, delay, entry, OutputPin};
use lights_hal::{boot, delay, entry};
#[entry]
fn main() -> ! {
let mut lights = boot();
lights.red_led.set_high().unwrap();
lights.heartbeat();
let mut pattern =
repeat(&Rgb(255,0,0)).take(5)
@ -34,15 +34,9 @@ fn main() -> ! {
).cycle();
let mut buffer = [HardwareRgb(255,255,0); 200];
let mut light = false;
//delay(48_000_000 * 3);
loop {
if light {
lights.red_led.set_high().unwrap();
} else {
lights.red_led.set_low().unwrap();
}
light = !light;
lights.heartbeat();
for (i, pixel) in pattern.clone().take(200).enumerate() {
buffer[i] = correct(pixel);

View File

@ -37,6 +37,7 @@ pub fn boot() -> NeopixelLights<impl OutputPin<Error = ()>, impl OutputPin<Error
out: pins.d7.into_push_pull_output(&mut pins.port),
high_out: pins.d5.into_push_pull_output(&mut pins.port),
red_led: pins.d13.into_open_drain_output(&mut pins.port),
debug_light: false,
}
}
@ -58,7 +59,8 @@ const LATCH_CYCLES: u32 = 15000; // about 300us
pub struct NeopixelLights<T: OutputPin, U: OutputPin, V: OutputPin> {
pub out: T,
pub high_out: U,
pub red_led: V
pub red_led: V,
pub debug_light: bool
}
impl<T: OutputPin, U: OutputPin, V: OutputPin> NeopixelLights<T, U, V>
@ -88,6 +90,16 @@ where
self.write(byte & 0x02 != 0);
self.write(byte & 0x01 != 0);
}
/// Blink light, probably to indicate a loop is still running
pub fn heartbeat(&mut self) {
if self.debug_light {
self.red_led.set_low().unwrap();
} else {
self.red_led.set_high().unwrap();
}
self.debug_light = !self.debug_light;
}
}
impl<T: OutputPin, U: OutputPin, V: OutputPin> Lights for NeopixelLights<T, U, V>