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 state = DisplayState::default();
let mut orchestrator = Orchestrator::<Screen, Screen>::new();
let mut orchestrator = Orchestrator::<Screen>::new();
let rx = receiver();
// Register pages
// Enum-based registration
orchestrator.register_page(Screen::Menu, Screen::Menu);
orchestrator.register_page(Screen::Imu, Screen::Imu);
orchestrator.register_page(Screen::Chat, Screen::Chat);
orchestrator.register(Screen::Menu);
orchestrator.register(Screen::Imu);
orchestrator.register(Screen::Chat);
orchestrator.bind(Key::tab(), ComponentAction::Next);
orchestrator.bind(Key::enter(), ComponentAction::Select);
let _ = orchestrator.navigate_to("menu".into());
let _ = orchestrator.navigate_to(Screen::Menu);
info!("Display ready");
@@ -60,27 +60,27 @@ pub async fn display_task(i2c: I2cDevice) {
match cmd {
DisplayCommand::PushKey(key) => {
if key == Key::tab() {
orchestrator.focus_manager_mut().wrap_next();
orchestrator.focus_manager_mut().next();
} else if key == Key::enter() {
if let Ok(events) = orchestrator.process_frame(key) {
for event in events {
match event {
ScreenEvent::GoToImu => {
let _ = orchestrator.navigate_to("imu".into());
let _ = orchestrator.navigate_to(Screen::Imu);
}
ScreenEvent::GoToChat => {
let _ = orchestrator.navigate_to("chat".into());
let _ = orchestrator.navigate_to(Screen::Chat);
}
ScreenEvent::NavigatePrev => {
if let Some(cur) = orchestrator.current() {
let prev = cur.prev();
let _ = orchestrator.navigate_to(prev.to_str().into());
let _ = orchestrator.navigate_to(prev);
}
}
ScreenEvent::NavigateNext => {
if let Some(cur) = orchestrator.current() {
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;
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum Screen {
Menu,
Imu,
Chat,
}
impl pages_tui::page::PageId for Screen {}
/// Focus targets - different per screen
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum PageFocus {

View File

@@ -5,19 +5,17 @@ use esp_hal::{
i2c::master::{Config, I2c},
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;
#[embassy_executor::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 i2c = I2c::new(peripherals.I2C0, Config::default())