ported into a generic library

This commit is contained in:
Priec
2026-01-19 15:53:19 +01:00
parent 9910bf9402
commit 2774e83d99
3 changed files with 17 additions and 28 deletions

View File

@@ -39,19 +39,19 @@ pub async fn display_task(i2c: I2cDevice) {
let mut terminal = Terminal::new(backend).expect("terminal init failed"); let mut terminal = Terminal::new(backend).expect("terminal init failed");
let mut state = DisplayState::default(); let mut state = DisplayState::default();
let mut orchestrator = Orchestrator::<Screen, Screen>::new(); let mut orchestrator = Orchestrator::<Screen>::new();
let rx = receiver(); let rx = receiver();
// Register pages // Register pages
// Enum-based registration // Enum-based registration
orchestrator.register_page(Screen::Menu, Screen::Menu); orchestrator.register(Screen::Menu);
orchestrator.register_page(Screen::Imu, Screen::Imu); orchestrator.register(Screen::Imu);
orchestrator.register_page(Screen::Chat, Screen::Chat); orchestrator.register(Screen::Chat);
orchestrator.bind(Key::tab(), ComponentAction::Next); orchestrator.bind(Key::tab(), ComponentAction::Next);
orchestrator.bind(Key::enter(), ComponentAction::Select); orchestrator.bind(Key::enter(), ComponentAction::Select);
let _ = orchestrator.navigate_to("menu".into()); let _ = orchestrator.navigate_to(Screen::Menu);
info!("Display ready"); info!("Display ready");
@@ -60,27 +60,27 @@ pub async fn display_task(i2c: I2cDevice) {
match cmd { match cmd {
DisplayCommand::PushKey(key) => { DisplayCommand::PushKey(key) => {
if key == Key::tab() { if key == Key::tab() {
orchestrator.focus_manager_mut().wrap_next(); orchestrator.focus_manager_mut().next();
} else if key == Key::enter() { } else if key == Key::enter() {
if let Ok(events) = orchestrator.process_frame(key) { if let Ok(events) = orchestrator.process_frame(key) {
for event in events { for event in events {
match event { match event {
ScreenEvent::GoToImu => { ScreenEvent::GoToImu => {
let _ = orchestrator.navigate_to("imu".into()); let _ = orchestrator.navigate_to(Screen::Imu);
} }
ScreenEvent::GoToChat => { ScreenEvent::GoToChat => {
let _ = orchestrator.navigate_to("chat".into()); let _ = orchestrator.navigate_to(Screen::Chat);
} }
ScreenEvent::NavigatePrev => { ScreenEvent::NavigatePrev => {
if let Some(cur) = orchestrator.current() { if let Some(cur) = orchestrator.current() {
let prev = cur.prev(); let prev = cur.prev();
let _ = orchestrator.navigate_to(prev.to_str().into()); let _ = orchestrator.navigate_to(prev);
} }
} }
ScreenEvent::NavigateNext => { ScreenEvent::NavigateNext => {
if let Some(cur) = orchestrator.current() { if let Some(cur) = orchestrator.current() {
let next = cur.next(); let next = cur.next();
let _ = orchestrator.navigate_to(next.to_str().into()); let _ = orchestrator.navigate_to(next);
} }
} }
} }

View File

@@ -11,15 +11,6 @@ use ratatui::{
}; };
use log::info; use log::info;
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum Screen {
Menu,
Imu,
Chat,
}
impl pages_tui::page::PageId for Screen {}
/// Focus targets - different per screen /// Focus targets - different per screen
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum PageFocus { pub enum PageFocus {

View File

@@ -5,19 +5,17 @@ use esp_hal::{
i2c::master::{Config, I2c}, i2c::master::{Config, I2c},
peripherals::Peripherals, peripherals::Peripherals,
}; };
use ssd1306::mode::BufferedGraphicsMode; use mousefood::{EmbeddedBackend, EmbeddedBackendConfig};
use ratatui::{
layout::{Constraint, Direction, Layout},
widgets::{Block, Borders, Paragraph},
Terminal,
};
use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306, mode::BufferedGraphicsMode};
use log::info; use log::info;
#[embassy_executor::task] #[embassy_executor::task]
pub async fn display_task() { pub async fn display_task() {
use mousefood::{EmbeddedBackend, EmbeddedBackendConfig};
use ratatui::{
layout::{Constraint, Direction, Layout},
widgets::{Block, Borders, Paragraph},
Terminal,
};
use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306};
let peripherals = unsafe { Peripherals::steal() }; let peripherals = unsafe { Peripherals::steal() };
let i2c = I2c::new(peripherals.I2C0, Config::default()) let i2c = I2c::new(peripherals.I2C0, Config::default())