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:
69
crates/domain/src/entities/data_source.rs
Normal file
69
crates/domain/src/entities/data_source.rs
Normal file
@@ -0,0 +1,69 @@
|
||||
use std::time::Duration;
|
||||
|
||||
pub type DataSourceId = u16;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum DataSourceType {
|
||||
Weather,
|
||||
Media,
|
||||
Xtb,
|
||||
Rss,
|
||||
HttpJson,
|
||||
Webhook,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DataSourceConfig {
|
||||
pub url: Option<String>,
|
||||
pub headers: Vec<(String, String)>,
|
||||
pub api_key: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DataSource {
|
||||
pub id: DataSourceId,
|
||||
pub name: String,
|
||||
pub source_type: DataSourceType,
|
||||
pub poll_interval: Duration,
|
||||
pub config: DataSourceConfig,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum DataSourceValidationError {
|
||||
UrlRequired,
|
||||
PollIntervalNotAllowed,
|
||||
PollIntervalRequired,
|
||||
}
|
||||
|
||||
impl DataSource {
|
||||
pub fn validate(&self) -> Vec<DataSourceValidationError> {
|
||||
let mut errors = Vec::new();
|
||||
|
||||
let is_webhook = self.source_type == DataSourceType::Webhook;
|
||||
|
||||
if is_webhook {
|
||||
if !self.poll_interval.is_zero() {
|
||||
errors.push(DataSourceValidationError::PollIntervalNotAllowed);
|
||||
}
|
||||
} else {
|
||||
if self.poll_interval.is_zero() {
|
||||
errors.push(DataSourceValidationError::PollIntervalRequired);
|
||||
}
|
||||
if self.requires_url() && self.config.url.is_none() {
|
||||
errors.push(DataSourceValidationError::UrlRequired);
|
||||
}
|
||||
}
|
||||
|
||||
errors
|
||||
}
|
||||
|
||||
fn requires_url(&self) -> bool {
|
||||
matches!(
|
||||
self.source_type,
|
||||
DataSourceType::Weather
|
||||
| DataSourceType::Media
|
||||
| DataSourceType::Rss
|
||||
| DataSourceType::HttpJson
|
||||
)
|
||||
}
|
||||
}
|
||||
10
crates/domain/src/entities/layout_preset.rs
Normal file
10
crates/domain/src/entities/layout_preset.rs
Normal file
@@ -0,0 +1,10 @@
|
||||
use crate::value_objects::Layout;
|
||||
|
||||
pub type LayoutPresetId = u16;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct LayoutPreset {
|
||||
pub id: LayoutPresetId,
|
||||
pub name: String,
|
||||
pub layout: Layout,
|
||||
}
|
||||
7
crates/domain/src/entities/mod.rs
Normal file
7
crates/domain/src/entities/mod.rs
Normal file
@@ -0,0 +1,7 @@
|
||||
mod widget_config;
|
||||
mod data_source;
|
||||
mod layout_preset;
|
||||
|
||||
pub use widget_config::{WidgetConfig, WidgetId};
|
||||
pub use data_source::{DataSource, DataSourceId, DataSourceType, DataSourceConfig, DataSourceValidationError};
|
||||
pub use layout_preset::{LayoutPreset, LayoutPresetId};
|
||||
70
crates/domain/src/entities/widget_config.rs
Normal file
70
crates/domain/src/entities/widget_config.rs
Normal file
@@ -0,0 +1,70 @@
|
||||
use std::collections::BTreeMap;
|
||||
use crate::value_objects::{DisplayHint, KeyMapping, Value, WidgetState};
|
||||
|
||||
pub type WidgetId = u16;
|
||||
pub type DataSourceId = u16;
|
||||
|
||||
const DEFAULT_MAX_DATA_SIZE: u16 = 2048;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct WidgetConfig {
|
||||
pub id: WidgetId,
|
||||
pub name: String,
|
||||
pub display_hint: DisplayHint,
|
||||
pub data_source_id: DataSourceId,
|
||||
pub mappings: Vec<KeyMapping>,
|
||||
pub max_data_size: u16,
|
||||
}
|
||||
|
||||
impl WidgetConfig {
|
||||
pub fn new(
|
||||
id: WidgetId,
|
||||
name: String,
|
||||
display_hint: DisplayHint,
|
||||
data_source_id: DataSourceId,
|
||||
mappings: Vec<KeyMapping>,
|
||||
) -> Self {
|
||||
Self {
|
||||
id,
|
||||
name,
|
||||
display_hint,
|
||||
data_source_id,
|
||||
mappings,
|
||||
max_data_size: DEFAULT_MAX_DATA_SIZE,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn extract(&self, raw: &Value) -> WidgetState {
|
||||
let budget = self.max_data_size as usize;
|
||||
let mut used = 0usize;
|
||||
let mut data = BTreeMap::new();
|
||||
|
||||
for mapping in &self.mappings {
|
||||
if let Some((key, value)) = mapping.extract(raw) {
|
||||
let key_cost = key.len();
|
||||
let remaining = budget.saturating_sub(used + key_cost);
|
||||
let value = Self::truncate_value(value, remaining);
|
||||
used += key_cost + value.estimated_size();
|
||||
data.insert(key, value);
|
||||
if used >= budget {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
WidgetState { data, error: None }
|
||||
}
|
||||
|
||||
fn truncate_value(value: Value, max_bytes: usize) -> Value {
|
||||
match value {
|
||||
Value::String(s) if s.len() > max_bytes => {
|
||||
let truncated: String = s.char_indices()
|
||||
.take_while(|(i, _)| *i < max_bytes)
|
||||
.map(|(_, c)| c)
|
||||
.collect();
|
||||
Value::String(truncated)
|
||||
}
|
||||
other => other,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user