better ui with 3 lines now

This commit is contained in:
Priec
2026-01-18 17:09:42 +01:00
parent c5fef061f4
commit a910015856
5 changed files with 175 additions and 175 deletions

View File

@@ -25,17 +25,13 @@ pub async fn display_task(i2c: I2cDevice) {
if let Err(e) = display.init() {
error!("Display init failed: {:?}", e);
loop {
Timer::after(Duration::from_secs(60)).await;
}
loop { Timer::after(Duration::from_secs(60)).await; }
}
let config = EmbeddedBackendConfig {
flush_callback: Box::new(
|d: &mut Ssd1306<_, _, BufferedGraphicsMode<DisplaySize128x32>>| {
let _ = d.flush();
},
),
flush_callback: Box::new(|d: &mut Ssd1306<_, _, BufferedGraphicsMode<DisplaySize128x32>>| {
let _ = d.flush();
}),
..Default::default()
};
@@ -46,47 +42,43 @@ pub async fn display_task(i2c: I2cDevice) {
let mut orchestrator = Orchestrator::<Screen>::new();
let rx = receiver();
// Register all pages
// Register pages
orchestrator.register_page("menu".into(), Screen::Menu);
orchestrator.register_page("imu".into(), Screen::Imu);
orchestrator.register_page("mqtt".into(), Screen::Mqtt);
orchestrator.register_page("status".into(), Screen::Status);
orchestrator.register_page("chat".into(), Screen::Chat);
// Key bindings:
// - Tab (Next button): cycle focus between Prev/Next buttons
// - Enter (Select button): trigger the focused button's action
orchestrator.bind(Key::tab(), ComponentAction::Next);
orchestrator.bind(Key::enter(), ComponentAction::Select);
// Navigate to initial page
let _ = orchestrator.navigate_to("imu".into());
let _ = orchestrator.navigate_to("menu".into());
info!("Display ready");
loop {
while let Ok(cmd) = rx.try_receive() {
match cmd {
DisplayCommand::PushKey(key) => {
if key == Key::tab() {
// Cycle focus between buttons
orchestrator.focus_manager_mut().wrap_next();
info!("Focus changed to: {:?}", orchestrator.focus_manager().current());
} else if key == Key::enter() {
// Process Select - this triggers Component::handle()
let events = orchestrator.process_frame(key);
// Handle navigation events
if let Ok(events) = events {
if let Ok(events) = orchestrator.process_frame(key) {
for event in events {
match event {
ScreenEvent::GoToImu => {
let _ = orchestrator.navigate_to("imu".into());
}
ScreenEvent::GoToChat => {
let _ = orchestrator.navigate_to("chat".into());
}
ScreenEvent::NavigatePrev => {
if let Some(current) = orchestrator.current_id() {
let prev = prev_page_id(current.as_str());
info!("Navigating to prev: {}", prev);
if let Some(cur) = orchestrator.current_id() {
let prev = prev_page_id(cur.as_str());
let _ = orchestrator.navigate_to(prev.into());
}
}
ScreenEvent::NavigateNext => {
if let Some(current) = orchestrator.current_id() {
let next = next_page_id(current.as_str());
info!("Navigating to next: {}", next);
if let Some(cur) = orchestrator.current_id() {
let next = next_page_id(cur.as_str());
let _ = orchestrator.navigate_to(next.into());
}
}
@@ -99,10 +91,8 @@ pub async fn display_task(i2c: I2cDevice) {
}
}
// Render current state
if let Some(current_screen) = orchestrator.current() {
let focused = orchestrator.focus_manager().current();
render_frame(&mut terminal, current_screen, focused, &state);
if let Some(screen) = orchestrator.current() {
render_frame(&mut terminal, screen, orchestrator.focus_manager().current(), &state);
}
Timer::after(Duration::from_millis(REFRESH_INTERVAL_MS)).await;