main: split out display init code to a trait
This commit is contained in:
parent
f264964ebb
commit
a0d42d2274
33
src/main.rs
33
src/main.rs
@ -19,7 +19,8 @@ mod embedded_graphics_lib;
|
||||
use crate::time::Periodically;
|
||||
use crate::geometry::{Coordinates, VirtualCoordinates};
|
||||
use crate::embedded_graphics_lib::EmbeddedDisplay;
|
||||
use crate::render::{Surfaces, Surface, SimpleSurface};
|
||||
use crate::render::{Surfaces, Surface, SimpleSurface, Display};
|
||||
use crate::task::Task;
|
||||
|
||||
struct IdleTask<T: Surface> {
|
||||
frame: u8,
|
||||
@ -84,16 +85,12 @@ impl LedPixelShape for PonderjarMatrix {
|
||||
|
||||
type PonderjarTarget<'a> = Ws2812DrawTarget<'a, PonderjarMatrix>;
|
||||
|
||||
fn main() {
|
||||
// It is necessary to call this function once. Otherwise some patches to the runtime
|
||||
// implemented by esp-idf-sys might not link properly. See https://github.com/esp-rs/esp-idf-template/issues/71
|
||||
esp_idf_svc::sys::link_patches();
|
||||
|
||||
// Bind the log crate to the ESP Logging facilities
|
||||
esp_idf_svc::log::EspLogger::initialize_default();
|
||||
|
||||
log::info!("Hello, world!");
|
||||
trait DisplayInit {
|
||||
fn new_display<S: Surface>() -> impl Display<S> + Task;
|
||||
}
|
||||
|
||||
impl<Shape: LedPixelShape> DisplayInit for Ws2812DrawTarget<'_, Shape> {
|
||||
fn new_display<S: Surface>() -> impl Display<S> + Task {
|
||||
let peripherals = Peripherals::take().unwrap();
|
||||
let led_pin = peripherals.pins.gpio14;
|
||||
let channel = peripherals.rmt.channel0;
|
||||
@ -102,9 +99,21 @@ fn main() {
|
||||
const POWER_MA : u32 = 500;
|
||||
const MAX_POWER_MW : u32 = POWER_VOLTS * POWER_MA;
|
||||
|
||||
let target = Self::new(channel, led_pin).unwrap();
|
||||
return EmbeddedDisplay::<Self, S>::new(target, MAX_POWER_MW);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// It is necessary to call this function once. Otherwise some patches to the runtime
|
||||
// implemented by esp-idf-sys might not link properly. See https://github.com/esp-rs/esp-idf-template/issues/71
|
||||
esp_idf_svc::sys::link_patches();
|
||||
|
||||
// Bind the log crate to the ESP Logging facilities
|
||||
esp_idf_svc::log::EspLogger::initialize_default();
|
||||
|
||||
log::info!("Setting up display");
|
||||
let target = PonderjarTarget::new(channel, led_pin).unwrap();
|
||||
let mut display = EmbeddedDisplay::<PonderjarTarget, SimpleSurface>::new(target, MAX_POWER_MW);
|
||||
let mut display = PonderjarTarget::new_display::<SimpleSurface>();
|
||||
|
||||
log::info!("Creating runner");
|
||||
let mut runner = task::Scheduler::new(vec![
|
||||
|
Loading…
Reference in New Issue
Block a user