Skip to content

Commit

Permalink
tacd: inline run() into main()
Browse files Browse the repository at this point in the history
Many small functions is a nice thing in general, but a three line function
that is only used once seems a bit over the top.

Signed-off-by: Leonard Göhrs <[email protected]>
  • Loading branch information
hnez committed Nov 9, 2023
1 parent c7c4f6b commit ea5cc2b
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ use regulators::Regulators;
use setup_mode::SetupMode;
use system::System;
use temperatures::Temperatures;
use ui::{message, setup_display, Display, ScreenShooter, Ui, UiResources};
use ui::{message, setup_display, ScreenShooter, Ui, UiResources};
use usb_hub::UsbHub;
use watchdog::Watchdog;
use watched_tasks::WatchedTasksBuilder;
Expand Down Expand Up @@ -171,25 +171,25 @@ async fn init(screenshooter: ScreenShooter) -> Result<(Ui, WatchedTasksBuilder)>
Ok((ui, wtb))
}

async fn run(ui: Ui, display: Display, mut wtb: WatchedTasksBuilder) -> Result<()> {
// Start drawing the UI
ui.run(&mut wtb, display)?;

info!("Setup complete. Handling requests");

wtb.watch().await
}

#[async_std::main]
async fn main() -> Result<()> {
env_logger::init();

// Show a splash screen very early on
let display = setup_display();

// This allows us to expose screenshoots of the LCD screen via HTTP
let screenshooter = display.screenshooter();

match init(screenshooter).await {
Ok((ui, wtb)) => run(ui, display, wtb).await,
Ok((ui, mut wtb)) => {
// Start drawing the UI
ui.run(&mut wtb, display)?;

info!("Setup complete. Handling requests");

wtb.watch().await
}
Err(e) => {
// Display a detailed error message on stderr (and thus in the journal) ...
error!("Failed to initialize tacd: {e}");
Expand Down

0 comments on commit ea5cc2b

Please sign in to comment.