@@ -52,12 +52,12 @@ use regulators::Regulators;
5252use setup_mode:: SetupMode ;
5353use system:: System ;
5454use temperatures:: Temperatures ;
55- use ui:: { message, setup_display, Display , Ui , UiResources } ;
55+ use ui:: { message, setup_display, Display , ScreenShooter , Ui , UiResources } ;
5656use usb_hub:: UsbHub ;
5757use watchdog:: Watchdog ;
5858use watched_tasks:: WatchedTasksBuilder ;
5959
60- async fn init ( ) -> Result < ( Ui , HttpServer , WatchedTasksBuilder ) > {
60+ async fn init ( screenshooter : ScreenShooter ) -> Result < ( Ui , WatchedTasksBuilder ) > {
6161 // The tacd spawns a couple of async tasks that should run as long as
6262 // the tacd runs and if any one fails the tacd should stop.
6363 // These tasks are spawned via the watched task builder.
@@ -157,26 +157,21 @@ async fn init() -> Result<(Ui, HttpServer, WatchedTasksBuilder)> {
157157 // and expose the topics via HTTP and MQTT-over-websocket.
158158 bb. build ( & mut wtb, & mut http_server. server ) ?;
159159
160+ // Expose the display as a .png on the web server
161+ ui:: serve_display ( & mut http_server. server , screenshooter) ;
162+
163+ // Start serving files and the API
164+ http_server. serve ( & mut wtb) ?;
165+
160166 // If a watchdog was requested by systemd we can now start feeding it
161167 if let Some ( watchdog) = watchdog {
162168 watchdog. keep_fed ( & mut wtb) ?;
163169 }
164170
165- Ok ( ( ui, http_server , wtb) )
171+ Ok ( ( ui, wtb) )
166172}
167173
168- async fn run (
169- ui : Ui ,
170- mut http_server : HttpServer ,
171- display : Display ,
172- mut wtb : WatchedTasksBuilder ,
173- ) -> Result < ( ) > {
174- // Expose the display as a .png on the web server
175- ui:: serve_display ( & mut http_server. server , display. screenshooter ( ) ) ;
176-
177- // Start serving files and the API
178- http_server. serve ( & mut wtb) ?;
179-
174+ async fn run ( ui : Ui , display : Display , mut wtb : WatchedTasksBuilder ) -> Result < ( ) > {
180175 // Start drawing the UI
181176 ui. run ( & mut wtb, display) ?;
182177
@@ -191,9 +186,10 @@ async fn main() -> Result<()> {
191186
192187 // Show a splash screen very early on
193188 let display = setup_display ( ) ;
189+ let screenshooter = display. screenshooter ( ) ;
194190
195- match init ( ) . await {
196- Ok ( ( ui, http_server , wtb) ) => run ( ui, http_server , display, wtb) . await ,
191+ match init ( screenshooter ) . await {
192+ Ok ( ( ui, wtb) ) => run ( ui, display, wtb) . await ,
197193 Err ( e) => {
198194 // Display a detailed error message on stderr (and thus in the journal) ...
199195 error ! ( "Failed to initialize tacd: {e}" ) ;
0 commit comments