ported into a generic library
This commit is contained in:
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -5,19 +5,17 @@ use esp_hal::{
|
|||||||
i2c::master::{Config, I2c},
|
i2c::master::{Config, I2c},
|
||||||
peripherals::Peripherals,
|
peripherals::Peripherals,
|
||||||
};
|
};
|
||||||
use ssd1306::mode::BufferedGraphicsMode;
|
|
||||||
use log::info;
|
|
||||||
|
|
||||||
#[embassy_executor::task]
|
|
||||||
pub async fn display_task() {
|
|
||||||
use mousefood::{EmbeddedBackend, EmbeddedBackendConfig};
|
use mousefood::{EmbeddedBackend, EmbeddedBackendConfig};
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
layout::{Constraint, Direction, Layout},
|
layout::{Constraint, Direction, Layout},
|
||||||
widgets::{Block, Borders, Paragraph},
|
widgets::{Block, Borders, Paragraph},
|
||||||
Terminal,
|
Terminal,
|
||||||
};
|
};
|
||||||
use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306};
|
use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306, mode::BufferedGraphicsMode};
|
||||||
|
use log::info;
|
||||||
|
|
||||||
|
#[embassy_executor::task]
|
||||||
|
pub async fn display_task() {
|
||||||
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())
|
||||||
|
|||||||
Reference in New Issue
Block a user