internal data sources (clock, static text), connection indicator, rendering fixes
DataSourceConfig refactored to enum: External/Clock/StaticText. Clock generates formatted time via chrono, static text emits configured string. ESP32: connection status indicator (green/red dot bottom-right), per-widget clear before redraw, RenderEvent enum for local + server messages. Polling uses DataUpdate instead of ScreenUpdate to avoid wiping widget state. Empty mappings passthrough raw source data for internal sources.
This commit is contained in:
@@ -2,16 +2,21 @@ use std::sync::mpsc;
|
||||
use std::time::{Duration, Instant};
|
||||
use std::collections::HashMap;
|
||||
use client_domain::{
|
||||
BoundingBox, DisplayPort, FontMetrics, RenderEngine, ScrollState, ThemeConfig,
|
||||
BoundingBox, Color, DisplayPort, FontMetrics, RenderEngine, ScrollState, ThemeConfig,
|
||||
};
|
||||
use client_application::{ClientApp, RepaintCommand};
|
||||
use domain::{DisplayHint, Value};
|
||||
use protocol::ServerMessage;
|
||||
use super::RenderEvent;
|
||||
use crate::config::RENDER_POLL_INTERVAL;
|
||||
use crate::adapters::display::Esp32DisplayAdapter;
|
||||
use log::*;
|
||||
|
||||
const SCROLL_TICK: Duration = Duration::from_millis(50);
|
||||
const INDICATOR_DIAMETER: u16 = 8;
|
||||
const INDICATOR_MARGIN: u16 = 4;
|
||||
const COLOR_CONNECTED: Color = Color(0, 200, 0);
|
||||
const COLOR_DISCONNECTED: Color = Color(200, 0, 0);
|
||||
|
||||
struct WidgetCache {
|
||||
hint: DisplayHint,
|
||||
@@ -23,7 +28,7 @@ struct WidgetCache {
|
||||
pub fn run(
|
||||
screen: BoundingBox,
|
||||
mut display: Esp32DisplayAdapter,
|
||||
rx: mpsc::Receiver<ServerMessage>,
|
||||
rx: mpsc::Receiver<RenderEvent>,
|
||||
) {
|
||||
let metrics = FontMetrics {
|
||||
small: (6, 10),
|
||||
@@ -34,13 +39,23 @@ pub fn run(
|
||||
let mut widgets: HashMap<u16, WidgetCache> = HashMap::new();
|
||||
let mut first_update = true;
|
||||
let mut last_tick = Instant::now();
|
||||
let mut connected = false;
|
||||
|
||||
info!("Render loop started");
|
||||
draw_indicator(&mut display, screen, connected);
|
||||
display.flush().unwrap();
|
||||
|
||||
loop {
|
||||
let timeout = RENDER_POLL_INTERVAL.min(SCROLL_TICK);
|
||||
match rx.recv_timeout(timeout) {
|
||||
Ok(msg) => {
|
||||
Ok(RenderEvent::ConnectionStatus(status)) => {
|
||||
if status != connected {
|
||||
connected = status;
|
||||
draw_indicator(&mut display, screen, connected);
|
||||
display.flush().unwrap();
|
||||
}
|
||||
}
|
||||
Ok(RenderEvent::Server(msg)) => {
|
||||
let is_screen_update = matches!(msg, ServerMessage::ScreenUpdate { .. });
|
||||
let repaints = app.handle_message(msg);
|
||||
|
||||
@@ -49,19 +64,20 @@ pub fn run(
|
||||
engine.set_theme(app.theme().clone());
|
||||
}
|
||||
|
||||
let bg = engine.theme().background;
|
||||
if !repaints.is_empty() && (first_update || is_screen_update || theme_changed) {
|
||||
let bg = engine.theme().background;
|
||||
display.fill_rect(screen, bg).unwrap();
|
||||
first_update = false;
|
||||
}
|
||||
|
||||
for cmd in &repaints {
|
||||
let cache = update_cache(&engine, cmd);
|
||||
display.fill_rect(cache.bounds, bg).unwrap();
|
||||
draw_widget(&engine, &mut display, &cache);
|
||||
widgets.insert(cmd.widget_id, cache);
|
||||
}
|
||||
|
||||
if !repaints.is_empty() {
|
||||
draw_indicator(&mut display, screen, connected);
|
||||
display.flush().unwrap();
|
||||
}
|
||||
}
|
||||
@@ -86,11 +102,19 @@ pub fn run(
|
||||
}
|
||||
}
|
||||
if needs_flush {
|
||||
draw_indicator(&mut display, screen, connected);
|
||||
display.flush().unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_indicator(display: &mut Esp32DisplayAdapter, screen: BoundingBox, connected: bool) {
|
||||
let color = if connected { COLOR_CONNECTED } else { COLOR_DISCONNECTED };
|
||||
let x = screen.x + screen.width - INDICATOR_DIAMETER - INDICATOR_MARGIN;
|
||||
let y = screen.y + screen.height - INDICATOR_DIAMETER - INDICATOR_MARGIN;
|
||||
display.fill_circle(x, y, INDICATOR_DIAMETER, color).unwrap();
|
||||
}
|
||||
|
||||
fn update_cache(engine: &RenderEngine, cmd: &RepaintCommand) -> WidgetCache {
|
||||
let hint: DisplayHint = cmd.display_hint.clone().into();
|
||||
let data: Vec<(String, Value)> = cmd.state.data
|
||||
|
||||
Reference in New Issue
Block a user