refactor the heartbeat led logic into the driver
This commit is contained in:
parent
56115d5132
commit
03bd72808a
3 changed files with 19 additions and 19 deletions
|
@ -10,12 +10,12 @@ use lights::{
|
||||||
Rgb
|
Rgb
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
use lights_hal::{boot, delay, entry, OutputPin};
|
use lights_hal::{boot, delay, entry};
|
||||||
|
|
||||||
#[entry]
|
#[entry]
|
||||||
fn main() -> ! {
|
fn main() -> ! {
|
||||||
let mut lights = boot();
|
let mut lights = boot();
|
||||||
lights.red_led.set_high().unwrap();
|
lights.heartbeat();
|
||||||
|
|
||||||
let pattern =
|
let pattern =
|
||||||
repeat(&Rgb(255,0,255)).take(150)
|
repeat(&Rgb(255,0,255)).take(150)
|
||||||
|
@ -24,15 +24,9 @@ fn main() -> ! {
|
||||||
).cycle();
|
).cycle();
|
||||||
|
|
||||||
let mut buffer = [HardwareRgb(255,255,0); 200];
|
let mut buffer = [HardwareRgb(255,255,0); 200];
|
||||||
let mut light = false;
|
|
||||||
loop {
|
loop {
|
||||||
// blink light to demonstrate loop is still running
|
// blink light to demonstrate loop is still running
|
||||||
if light {
|
lights.heartbeat();
|
||||||
lights.red_led.set_high().unwrap();
|
|
||||||
} else {
|
|
||||||
lights.red_led.set_low().unwrap();
|
|
||||||
}
|
|
||||||
light = !light;
|
|
||||||
|
|
||||||
for (i, pixel) in pattern.clone().take(200).enumerate() {
|
for (i, pixel) in pattern.clone().take(200).enumerate() {
|
||||||
buffer[i] = correct(pixel);
|
buffer[i] = correct(pixel);
|
||||||
|
|
|
@ -10,12 +10,12 @@ use lights::{
|
||||||
Rgb
|
Rgb
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
use lights_hal::{boot, delay, entry, OutputPin};
|
use lights_hal::{boot, delay, entry};
|
||||||
|
|
||||||
#[entry]
|
#[entry]
|
||||||
fn main() -> ! {
|
fn main() -> ! {
|
||||||
let mut lights = boot();
|
let mut lights = boot();
|
||||||
lights.red_led.set_high().unwrap();
|
lights.heartbeat();
|
||||||
|
|
||||||
let mut pattern =
|
let mut pattern =
|
||||||
repeat(&Rgb(255,0,0)).take(5)
|
repeat(&Rgb(255,0,0)).take(5)
|
||||||
|
@ -34,15 +34,9 @@ fn main() -> ! {
|
||||||
).cycle();
|
).cycle();
|
||||||
|
|
||||||
let mut buffer = [HardwareRgb(255,255,0); 200];
|
let mut buffer = [HardwareRgb(255,255,0); 200];
|
||||||
let mut light = false;
|
|
||||||
//delay(48_000_000 * 3);
|
//delay(48_000_000 * 3);
|
||||||
loop {
|
loop {
|
||||||
if light {
|
lights.heartbeat();
|
||||||
lights.red_led.set_high().unwrap();
|
|
||||||
} else {
|
|
||||||
lights.red_led.set_low().unwrap();
|
|
||||||
}
|
|
||||||
light = !light;
|
|
||||||
|
|
||||||
for (i, pixel) in pattern.clone().take(200).enumerate() {
|
for (i, pixel) in pattern.clone().take(200).enumerate() {
|
||||||
buffer[i] = correct(pixel);
|
buffer[i] = correct(pixel);
|
||||||
|
|
|
@ -37,6 +37,7 @@ pub fn boot() -> NeopixelLights<impl OutputPin<Error = ()>, impl OutputPin<Error
|
||||||
out: pins.d7.into_push_pull_output(&mut pins.port),
|
out: pins.d7.into_push_pull_output(&mut pins.port),
|
||||||
high_out: pins.d5.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),
|
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 struct NeopixelLights<T: OutputPin, U: OutputPin, V: OutputPin> {
|
||||||
pub out: T,
|
pub out: T,
|
||||||
pub high_out: U,
|
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>
|
impl<T: OutputPin, U: OutputPin, V: OutputPin> NeopixelLights<T, U, V>
|
||||||
|
@ -88,6 +90,16 @@ where
|
||||||
self.write(byte & 0x02 != 0);
|
self.write(byte & 0x02 != 0);
|
||||||
self.write(byte & 0x01 != 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>
|
impl<T: OutputPin, U: OutputPin, V: OutputPin> Lights for NeopixelLights<T, U, V>
|
||||||
|
|
Loading…
Reference in a new issue