add all crates: domain, protocol, application, client, adapters, ESP32 firmware

Server: domain (entities, value objects, ports), protocol (postcard wire types),
application (config service, data projection), adapters (config-memory, tcp-server),
bootstrap (composition root with fake data).

Client: client-domain (layout engine, render tree, HAL ports),
client-application (message handling, repaint commands),
adapters (tcp-client, display-terminal), client-desktop (end-to-end working).

ESP32: client-esp32 firmware with ILI9341 display over SPI, WiFi networking.
Display test verified on hardware — landscape orientation, text rendering works.

60 workspace tests, all passing.
This commit is contained in:
2026-06-18 21:43:59 +02:00
parent 6ad76b98a2
commit 557cceb498
83 changed files with 5844 additions and 1 deletions

View File

@@ -0,0 +1,124 @@
use client_domain::{BoundingBox, DisplayPort};
use embedded_graphics::{
mono_font::{ascii::FONT_6X10, ascii::FONT_10X20, MonoTextStyle},
pixelcolor::Rgb565,
prelude::*,
primitives::{PrimitiveStyle, Rectangle},
text::Text,
};
use embedded_text::{TextBox, style::TextBoxStyleBuilder};
#[derive(Debug)]
pub enum DisplayError {
Draw(String),
}
impl std::fmt::Display for DisplayError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
DisplayError::Draw(e) => write!(f, "draw: {e}"),
}
}
}
pub struct Esp32DisplayAdapter {
inner: Box<dyn ErasedDisplay>,
}
trait ErasedDisplay {
fn clear_region(&mut self, bounds: BoundingBox) -> Result<(), DisplayError>;
fn draw_text(&mut self, text: &str, x: u16, y: u16, bounds: BoundingBox) -> Result<(), DisplayError>;
fn draw_icon(&mut self, icon: &str, x: u16, y: u16) -> Result<(), DisplayError>;
fn fill_background(&mut self, bounds: BoundingBox) -> Result<(), DisplayError>;
fn flush(&mut self) -> Result<(), DisplayError>;
}
impl<D> ErasedDisplay for D
where
D: DrawTarget<Color = Rgb565>,
D::Error: std::fmt::Debug,
{
fn clear_region(&mut self, bounds: BoundingBox) -> Result<(), DisplayError> {
Rectangle::new(
Point::new(bounds.x as i32, bounds.y as i32),
Size::new(bounds.width as u32, bounds.height as u32),
)
.into_styled(PrimitiveStyle::with_fill(Rgb565::BLACK))
.draw(self)
.map_err(|e| DisplayError::Draw(format!("{e:?}")))?;
Ok(())
}
fn draw_text(&mut self, text: &str, _x: u16, _y: u16, bounds: BoundingBox) -> Result<(), DisplayError> {
let style = MonoTextStyle::new(&FONT_6X10, Rgb565::WHITE);
let textbox_style = TextBoxStyleBuilder::new().build();
let rect = Rectangle::new(
Point::new(bounds.x as i32, bounds.y as i32),
Size::new(bounds.width as u32, bounds.height as u32),
);
TextBox::with_textbox_style(text, rect, style, textbox_style)
.draw(self)
.map_err(|e| DisplayError::Draw(format!("{e:?}")))?;
Ok(())
}
fn draw_icon(&mut self, icon: &str, x: u16, y: u16) -> Result<(), DisplayError> {
let style = MonoTextStyle::new(&FONT_10X20, Rgb565::WHITE);
let icon_char = match icon {
"sunny" | "clear" => "*",
"cloud_rain" | "rain" => "~",
"cloud" | "cloudy" => "=",
"dollar" | "money" => "$",
"music" | "note" => "#",
_ => "?",
};
Text::new(icon_char, Point::new(x as i32, y as i32 + 20), style)
.draw(self)
.map_err(|e| DisplayError::Draw(format!("{e:?}")))?;
Ok(())
}
fn fill_background(&mut self, bounds: BoundingBox) -> Result<(), DisplayError> {
self.clear_region(bounds)
}
fn flush(&mut self) -> Result<(), DisplayError> {
Ok(())
}
}
impl Esp32DisplayAdapter {
pub fn new<D>(display: D) -> Self
where
D: DrawTarget<Color = Rgb565> + 'static,
D::Error: std::fmt::Debug,
{
Self {
inner: Box::new(display),
}
}
}
impl DisplayPort for Esp32DisplayAdapter {
type Error = DisplayError;
fn clear_region(&mut self, bounds: BoundingBox) -> Result<(), Self::Error> {
self.inner.clear_region(bounds)
}
fn draw_text(&mut self, text: &str, x: u16, y: u16, bounds: BoundingBox) -> Result<(), Self::Error> {
self.inner.draw_text(text, x, y, bounds)
}
fn draw_icon(&mut self, icon: &str, x: u16, y: u16) -> Result<(), Self::Error> {
self.inner.draw_icon(icon, x, y)
}
fn fill_background(&mut self, bounds: BoundingBox) -> Result<(), Self::Error> {
self.inner.fill_background(bounds)
}
fn flush(&mut self) -> Result<(), Self::Error> {
self.inner.flush()
}
}