@@ -52,12 +52,12 @@ use regulators::Regulators;
52
52
use setup_mode:: SetupMode ;
53
53
use system:: System ;
54
54
use temperatures:: Temperatures ;
55
- use ui:: { message, setup_display, Display , Ui , UiResources } ;
55
+ use ui:: { message, setup_display, Display , ScreenShooter , Ui , UiResources } ;
56
56
use usb_hub:: UsbHub ;
57
57
use watchdog:: Watchdog ;
58
58
use watched_tasks:: WatchedTasksBuilder ;
59
59
60
- async fn init ( ) -> Result < ( Ui , HttpServer , WatchedTasksBuilder ) > {
60
+ async fn init ( screenshooter : ScreenShooter ) -> Result < ( Ui , WatchedTasksBuilder ) > {
61
61
// The tacd spawns a couple of async tasks that should run as long as
62
62
// the tacd runs and if any one fails the tacd should stop.
63
63
// These tasks are spawned via the watched task builder.
@@ -157,26 +157,21 @@ async fn init() -> Result<(Ui, HttpServer, WatchedTasksBuilder)> {
157
157
// and expose the topics via HTTP and MQTT-over-websocket.
158
158
bb. build ( & mut wtb, & mut http_server. server ) ?;
159
159
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
+
160
166
// If a watchdog was requested by systemd we can now start feeding it
161
167
if let Some ( watchdog) = watchdog {
162
168
watchdog. keep_fed ( & mut wtb) ?;
163
169
}
164
170
165
- Ok ( ( ui, http_server , wtb) )
171
+ Ok ( ( ui, wtb) )
166
172
}
167
173
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 < ( ) > {
180
175
// Start drawing the UI
181
176
ui. run ( & mut wtb, display) ?;
182
177
@@ -191,9 +186,10 @@ async fn main() -> Result<()> {
191
186
192
187
// Show a splash screen very early on
193
188
let display = setup_display ( ) ;
189
+ let screenshooter = display. screenshooter ( ) ;
194
190
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 ,
197
193
Err ( e) => {
198
194
// Display a detailed error message on stderr (and thus in the journal) ...
199
195
error ! ( "Failed to initialize tacd: {e}" ) ;
0 commit comments