Skip to main content

csi_webclient/ui/
control.rs

1use crate::state::{DeviceAction, DeviceState};
2
3/// Render the control view for one device.
4pub fn render(ui: &mut egui::Ui, device: &mut DeviceState, actions: &mut Vec<DeviceAction>) {
5    ui.add(
6        egui::Label::new(format!("Control — {}", device.id))
7            .wrap(),
8    );
9    ui.add_space(10.0);
10    render_body(ui, device, actions);
11}
12
13fn render_body(ui: &mut egui::Ui, device: &mut DeviceState, actions: &mut Vec<DeviceAction>) {
14    ui.strong("Collection");
15    ui.add_space(4.0);
16
17    ui.horizontal_wrapped(|ui| {
18        ui.label("Duration (seconds, optional)");
19        ui.add(
20            egui::TextEdit::singleline(&mut device.forms.start_duration_seconds)
21                .desired_width(80.0),
22        );
23    });
24    ui.add_space(6.0);
25
26    ui.horizontal_wrapped(|ui| {
27        if ui.button("Start Collection").clicked() {
28            actions.push(DeviceAction::StartCollection {
29                duration_seconds: device.forms.start_duration_seconds.clone(),
30            });
31        }
32        if ui.button("Stop Collection").clicked() {
33            actions.push(DeviceAction::StopCollection);
34        }
35        if ui.button("Show Stats").clicked() {
36            actions.push(DeviceAction::ShowStats);
37        }
38    });
39
40    ui.add_space(10.0);
41    ui.strong("Device");
42    ui.add_space(4.0);
43
44    ui.horizontal_wrapped(|ui| {
45        if ui.button("Reset Device (RTS)").clicked() {
46            actions.push(DeviceAction::ResetDevice);
47        }
48        if ui.button("Fetch Status").clicked() {
49            actions.push(DeviceAction::FetchStatus);
50        }
51        if ui.button("Fetch Info").clicked() {
52            actions.push(DeviceAction::FetchInfo);
53        }
54        if ui.button("Fetch Config").clicked() {
55            actions.push(DeviceAction::FetchConfig);
56        }
57    });
58
59    ui.add_space(10.0);
60    ui.strong("WebSocket");
61    ui.add_space(4.0);
62
63    ui.horizontal_wrapped(|ui| {
64        if !device.ws_connected {
65            if ui.button("Connect WebSocket").clicked() {
66                actions.push(DeviceAction::ConnectWebSocket);
67            }
68        } else if ui.button("Disconnect WebSocket").clicked() {
69            actions.push(DeviceAction::DisconnectWebSocket);
70        }
71        if ui.button("Clear Stream Frames").clicked() {
72            actions.push(DeviceAction::ClearFrames);
73        }
74    });
75
76    ui.add_space(8.0);
77    ui.add(
78        egui::Label::new(
79            "Stop sends the literal 'q' byte (graceful). Reset pulses RTS and re-verifies firmware.",
80        )
81        .wrap(),
82    );
83}