prepare Outputs type
This commit is contained in:
+26
-18
@@ -11,10 +11,11 @@ use alloc::boxed::Box;
|
|||||||
use creaturedex::card::decoder::split_nfc_hex;
|
use creaturedex::card::decoder::split_nfc_hex;
|
||||||
use creaturedex::card::model::Card;
|
use creaturedex::card::model::Card;
|
||||||
use creaturedex::display::shared_bus::{DualSecondaryDisplay, init_dual_displays};
|
use creaturedex::display::shared_bus::{DualSecondaryDisplay, init_dual_displays};
|
||||||
use creaturedex::display::tertiary_lcd::{init_tertiary_lcd, write_wrapped};
|
use creaturedex::display::tertiary_lcd::{TertiaryI2cLcd, init_tertiary_lcd, write_wrapped};
|
||||||
use creaturedex::drivers::nfc_pn532::NfcPn532Driver;
|
use creaturedex::drivers::nfc_pn532::NfcPn532Driver;
|
||||||
use creaturedex::navigation::inputs::Inputs;
|
use creaturedex::navigation::inputs::Inputs;
|
||||||
use creaturedex::navigation::navigation::{self, CARD_DATA};
|
use creaturedex::navigation::navigation::{self, CARD_DATA};
|
||||||
|
use creaturedex::navigation::outputs::Outputs;
|
||||||
use creaturedex::network::wifi::setup_wifi;
|
use creaturedex::network::wifi::setup_wifi;
|
||||||
use embassy_executor::Spawner;
|
use embassy_executor::Spawner;
|
||||||
use embassy_time::Instant;
|
use embassy_time::Instant;
|
||||||
@@ -65,7 +66,7 @@ async fn main(spawner: Spawner) {
|
|||||||
let timg0 = TimerGroup::new(peripherals.TIMG0);
|
let timg0 = TimerGroup::new(peripherals.TIMG0);
|
||||||
esp_rtos::start(timg0.timer0, sw_interrupt.software_interrupt0);
|
esp_rtos::start(timg0.timer0, sw_interrupt.software_interrupt0);
|
||||||
|
|
||||||
let (display, oled) = Box::leak(Box::new(init_dual_displays(
|
let (display, mut oled) = init_dual_displays(
|
||||||
peripherals.SPI2,
|
peripherals.SPI2,
|
||||||
peripherals.GPIO36, // sck
|
peripherals.GPIO36, // sck
|
||||||
peripherals.GPIO35, // mosi
|
peripherals.GPIO35, // mosi
|
||||||
@@ -75,18 +76,12 @@ async fn main(spawner: Spawner) {
|
|||||||
peripherals.GPIO10, // primary reset
|
peripherals.GPIO10, // primary reset
|
||||||
peripherals.GPIO47, // secondary reset
|
peripherals.GPIO47, // secondary reset
|
||||||
peripherals.GPIO12, // shared dc
|
peripherals.GPIO12, // shared dc
|
||||||
)));
|
);
|
||||||
|
|
||||||
let _secondary_oled_cs_2 = Output::new(
|
let _secondary_oled_cs_2 =
|
||||||
peripherals.GPIO14,
|
Output::new(peripherals.GPIO14, Level::High, OutputConfig::default());
|
||||||
Level::High,
|
let _secondary_oled_cs_3 =
|
||||||
OutputConfig::default(),
|
Output::new(peripherals.GPIO21, Level::High, OutputConfig::default());
|
||||||
);
|
|
||||||
let _secondary_oled_cs_3 = Output::new(
|
|
||||||
peripherals.GPIO21,
|
|
||||||
Level::High,
|
|
||||||
OutputConfig::default(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let config = I2cConfig::default().with_frequency(esp_hal::time::Rate::from_khz(400));
|
let config = I2cConfig::default().with_frequency(esp_hal::time::Rate::from_khz(400));
|
||||||
let i2c = match I2c::new(peripherals.I2C0, config) {
|
let i2c = match I2c::new(peripherals.I2C0, config) {
|
||||||
@@ -101,10 +96,10 @@ async fn main(spawner: Spawner) {
|
|||||||
let shared_i2c = Box::leak(Box::new(AtomicCell::new(i2c)));
|
let shared_i2c = Box::leak(Box::new(AtomicCell::new(i2c)));
|
||||||
log::info!("Shared I2C bus ready on GPIO17 (SDA) and GPIO18 (SCL)");
|
log::info!("Shared I2C bus ready on GPIO17 (SDA) and GPIO18 (SCL)");
|
||||||
|
|
||||||
let mut lcd = init_tertiary_lcd(AtomicDevice::new(shared_i2c));
|
let mut lcd: TertiaryI2cLcd = init_tertiary_lcd(AtomicDevice::new(shared_i2c));
|
||||||
if let Err(_) = write_wrapped(&mut lcd, "Testing more than 16 chars what happens now?") {
|
if let Err(e) = write_wrapped(&mut lcd, "Testing more than 16 chars what happens now?") {
|
||||||
log::error!(
|
log::error!(
|
||||||
"Tertiary LCD startup text write failed over shared I2C bus; check the shared bus, wiring, and device responses"
|
"Tertiary LCD startup text write failed over shared I2C bus; check the shared bus, wiring, and device responses: {e}"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,14 +122,27 @@ async fn main(spawner: Spawner) {
|
|||||||
ok: Input::new(peripherals.GPIO0, button_config),
|
ok: Input::new(peripherals.GPIO0, button_config),
|
||||||
};
|
};
|
||||||
|
|
||||||
display_shit(oled);
|
display_shit(&mut oled);
|
||||||
|
|
||||||
|
let outputs = Outputs {
|
||||||
|
primary_display: display,
|
||||||
|
secondary_display_1: oled,
|
||||||
|
// secondary_display_2: todo!(),
|
||||||
|
// secondary_display_3: todo!(),
|
||||||
|
tertiary_display: lcd,
|
||||||
|
_led_a: (),
|
||||||
|
};
|
||||||
|
|
||||||
log::info!("Setup complete, entering main loop");
|
log::info!("Setup complete, entering main loop");
|
||||||
spawner.spawn(navigation::run(inputs, display).expect("run task failed"));
|
spawner.spawn(navigation::run(inputs, outputs).expect("run task failed"));
|
||||||
spawner.spawn(nfc_driver_task(nfc_driver).expect("nfc driver task failed"));
|
spawner.spawn(nfc_driver_task(nfc_driver).expect("nfc driver task failed"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[embassy_executor::task]
|
#[embassy_executor::task]
|
||||||
|
#[allow(
|
||||||
|
clippy::large_stack_frames,
|
||||||
|
reason = "ignoring this for now because it still works"
|
||||||
|
)]
|
||||||
async fn nfc_driver_task(
|
async fn nfc_driver_task(
|
||||||
mut nfc_driver: NfcPn532Driver<AtomicDevice<'static, I2c<'static, Blocking>>>,
|
mut nfc_driver: NfcPn532Driver<AtomicDevice<'static, I2c<'static, Blocking>>>,
|
||||||
) {
|
) {
|
||||||
|
|||||||
+6
-6
@@ -48,9 +48,9 @@ impl Display for CardType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub type PrimaryColor = Rgb565;
|
pub type PrimaryColor = Rgb565;
|
||||||
impl Into<PrimaryColor> for CardType {
|
impl From<CardType> for PrimaryColor {
|
||||||
fn into(self) -> PrimaryColor {
|
fn from(val: CardType) -> Self {
|
||||||
match self {
|
match val {
|
||||||
CardType::Default => Rgb888::new(0xD8, 0x68, 0x30).into(),
|
CardType::Default => Rgb888::new(0xD8, 0x68, 0x30).into(),
|
||||||
CardType::Blueprint => Rgb888::new(0x6D, 0x81, 0xFF).into(),
|
CardType::Blueprint => Rgb888::new(0x6D, 0x81, 0xFF).into(),
|
||||||
CardType::CYBER => Rgb888::new(0xFF, 0xFF, 0x04).into(),
|
CardType::CYBER => Rgb888::new(0xFF, 0xFF, 0x04).into(),
|
||||||
@@ -64,9 +64,9 @@ impl Into<PrimaryColor> for CardType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub type Palette = [Rgb565; 16];
|
pub type Palette = [Rgb565; 16];
|
||||||
impl Into<Palette> for CardType {
|
impl From<CardType> for Palette {
|
||||||
fn into(self) -> Palette {
|
fn from(val: CardType) -> Self {
|
||||||
match self {
|
match val {
|
||||||
CardType::Default => [
|
CardType::Default => [
|
||||||
Rgb888::new(31, 23, 35).into(),
|
Rgb888::new(31, 23, 35).into(),
|
||||||
Rgb888::new(60, 47, 82).into(),
|
Rgb888::new(60, 47, 82).into(),
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
use embedded_hal::i2c::I2c;
|
use embedded_hal::i2c::I2c;
|
||||||
|
use embedded_hal_bus::i2c::AtomicDevice;
|
||||||
use esp_hal::delay::Delay;
|
use esp_hal::delay::Delay;
|
||||||
use i2c_character_display::{CharacterDisplayPCF8574T, LcdDisplayType};
|
use i2c_character_display::{CharacterDisplayPCF8574T, LcdDisplayType};
|
||||||
use log::error;
|
use log::error;
|
||||||
|
|
||||||
pub type TertiaryLcd<I2C> = CharacterDisplayPCF8574T<I2C, Delay>;
|
pub type TertiaryLcd<I2C> = CharacterDisplayPCF8574T<I2C, Delay>;
|
||||||
|
pub type TertiaryI2cLcd<'a> = TertiaryLcd<AtomicDevice<'a, esp_hal::i2c::master::I2c<'a, esp_hal::Blocking>>>;
|
||||||
|
|
||||||
pub fn init_tertiary_lcd<I2C>(i2c: I2C) -> TertiaryLcd<I2C>
|
pub fn init_tertiary_lcd<I2C>(i2c: I2C) -> TertiaryLcd<I2C>
|
||||||
where
|
where
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
pub mod inputs;
|
pub mod inputs;
|
||||||
pub mod navigation;
|
pub mod navigation;
|
||||||
pub mod state;
|
pub mod state;
|
||||||
|
pub mod outputs;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use crate::card::model::Card;
|
use crate::card::model::Card;
|
||||||
use crate::display::shared_bus::DualPrimaryDisplay;
|
|
||||||
use crate::navigation::inputs::ButtonAction;
|
use crate::navigation::inputs::ButtonAction;
|
||||||
use crate::navigation::inputs::Inputs;
|
use crate::navigation::inputs::Inputs;
|
||||||
|
use crate::navigation::outputs::Outputs;
|
||||||
use crate::navigation::state::NavigationState;
|
use crate::navigation::state::NavigationState;
|
||||||
use crate::views::view::View;
|
use crate::views::view::View;
|
||||||
|
|
||||||
@@ -33,15 +33,16 @@ pub trait Navigable {
|
|||||||
where
|
where
|
||||||
D: DrawTarget<Color = Rgb565> + Send,
|
D: DrawTarget<Color = Rgb565> + Send,
|
||||||
D::Error: core::fmt::Debug;
|
D::Error: core::fmt::Debug;
|
||||||
|
// fn display<D>(&self, outputs: &mut Outputs) -> impl core::future::Future<Output = ()> + Send;
|
||||||
fn handle_input(&self, input: Action) -> impl core::future::Future<Output = NewState> + Send;
|
fn handle_input(&self, input: Action) -> impl core::future::Future<Output = NewState> + Send;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[embassy_executor::task]
|
#[embassy_executor::task]
|
||||||
pub async fn run(mut inputs: Inputs, display: &'static mut DualPrimaryDisplay<'static>) {
|
pub async fn run(mut inputs: Inputs, mut outputs: Outputs) {
|
||||||
log::info!("starting navigation");
|
log::info!("starting navigation");
|
||||||
|
|
||||||
let mut state = NavigationState::new();
|
let mut state = NavigationState::new();
|
||||||
state.screens.last().unwrap().display(display).await;
|
state.screens.last().unwrap().display(&mut outputs.primary_display).await;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let selection = select(
|
let selection = select(
|
||||||
@@ -87,7 +88,7 @@ pub async fn run(mut inputs: Inputs, display: &'static mut DualPrimaryDisplay<'s
|
|||||||
state.screens.push(new_state.view);
|
state.screens.push(new_state.view);
|
||||||
|
|
||||||
if action != Action::Timer || new_state.redraw {
|
if action != Action::Timer || new_state.redraw {
|
||||||
state.screens.last().unwrap().display(display).await;
|
state.screens.last().unwrap().display(&mut outputs.primary_display).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
Timer::after(Duration::from_millis(DEBOUNCE_DURATION_MILLIS)).await;
|
Timer::after(Duration::from_millis(DEBOUNCE_DURATION_MILLIS)).await;
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
use crate::display::{shared_bus::{DualPrimaryDisplay, DualSecondaryDisplay}, tertiary_lcd::TertiaryI2cLcd};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
pub struct Outputs {
|
||||||
|
pub primary_display: DualPrimaryDisplay<'static>,
|
||||||
|
pub secondary_display_1: DualSecondaryDisplay<'static>,
|
||||||
|
// pub secondary_display_2: DualSecondaryDisplay<'static>,
|
||||||
|
// pub secondary_display_3: DualSecondaryDisplay<'static>,
|
||||||
|
pub tertiary_display: TertiaryI2cLcd<'static>,
|
||||||
|
pub _led_a: (),
|
||||||
|
}
|
||||||
@@ -24,16 +24,16 @@ impl NavigationState {
|
|||||||
match &self.screens.len() {
|
match &self.screens.len() {
|
||||||
0 => {
|
0 => {
|
||||||
log::info!("No screens to go back to");
|
log::info!("No screens to go back to");
|
||||||
return self.screens.last().unwrap();
|
self.screens.last().unwrap()
|
||||||
}
|
}
|
||||||
1 => {
|
1 => {
|
||||||
log::info!("Only one screen on stack, cannot go back");
|
log::info!("Only one screen on stack, cannot go back");
|
||||||
return self.screens.last().unwrap();
|
self.screens.last().unwrap()
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
log::info!("Going back to previous screen");
|
log::info!("Going back to previous screen");
|
||||||
self.screens.pop();
|
self.screens.pop();
|
||||||
return self.screens.last().unwrap();
|
self.screens.last().unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use embedded_graphics::prelude::Point;
|
|||||||
use embedded_graphics::prelude::RgbColor;
|
use embedded_graphics::prelude::RgbColor;
|
||||||
use embedded_graphics::text::Text;
|
use embedded_graphics::text::Text;
|
||||||
|
|
||||||
pub fn show<'a, D>(display: &mut D, name: &str, position: i32, selected: i32)
|
pub fn show<D>(display: &mut D, name: &str, position: i32, selected: i32)
|
||||||
where
|
where
|
||||||
D: DrawTarget<Color = Rgb565>,
|
D: DrawTarget<Color = Rgb565>,
|
||||||
D::Error: core::fmt::Debug,
|
D::Error: core::fmt::Debug,
|
||||||
|
|||||||
Reference in New Issue
Block a user