task: rewrite event handling as a step towards event-based subscriptions

This commit is contained in:
2024-12-14 14:53:24 +01:00
parent f9a8b32d3e
commit a0d524b825
8 changed files with 319 additions and 158 deletions

View File

@@ -9,8 +9,11 @@ mod animations;
mod mappings;
mod buffers;
mod events;
mod scenes;
use events::Event;
use rgb::Rgb;
use scenes::Sequencer;
use crate::events::EventBus;
use crate::platform::{DefaultBoard, Board};
@@ -40,7 +43,11 @@ fn main() {
log::info!("🌌 Creating animations");
let mut animations = FixedSizeScheduler::new([
Box::new(animations::IdleTask::new(&mut surfaces)),
Box::new(animations::TestPattern::new(surfaces.new_surface(&Rectangle::everything()).unwrap())),
Box::new(animations::TestPattern::new(surfaces.new_surface(Rectangle::everything()).unwrap())),
]);
let mut inputs = FixedSizeScheduler::new([
Box::new(Sequencer::new()),
]);
let mut renderer = FixedSizeScheduler::new([Box::new(Renderer::new(output, surfaces))]);
@@ -48,14 +55,36 @@ fn main() {
log::info!("🚌 Starting event bus");
let mut bus = EventBus::new();
log::info!("Ready to rock and roll");
bus.push(Event::new_property_change("colors.primary", Rgb::new(255, 128, 128)));
bus.push(Event::new_property_change("system.board.chip_id", DefaultBoard::chip_id()));
bus.push(Event::new_property_change("system.network.online", false));
log::info!("Priming events...");
let initial_tasks = [
"Renderer",
"renderbug::scenes::Sequencer",
"renderbug::buffers::BufferedSurfacePool",
"renderbug::platform::esp32::WifiTask",
"renderbug::platform::esp32::MqttTask",
"renderbug::platform::esp32::CircadianRhythm"
];
for task_name in initial_tasks {
bus.push(Event::new_start_thing(task_name));
log::info!("+ {}", task_name);
}
bus.push(Event::new_ready_to_rock());
log::info!("🚀 Launching...");
loop {
let next_event = bus.next();
match next_event {
events::Event::Tick => (),
_ => log::info!("Event: {:?}", next_event)
Event::ReadyToRock => {
log::info!("🚀 Ready to rock and roll");
}
_ => log::info!("⚡ Event: {:?}", next_event)
}
inputs.tick(&next_event, &mut bus);
animations.tick(&next_event, &mut bus);
system.tick(&next_event, &mut bus);
renderer.tick(&next_event, &mut bus);