Skip to content

Commit 6e14265

Browse files
committed
センサーのstatusを表示
1 parent b793232 commit 6e14265

File tree

1 file changed

+113
-4
lines changed

1 file changed

+113
-4
lines changed

src/main.rs

Lines changed: 113 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ use eframe::egui::{self, FontData, FontDefinitions, FontFamily, IconData};
99
use log::info;
1010
use serialport::available_ports;
1111
use ui::{
12-
AppUI,
1312
altitude::AltitudeUI,
1413
// flight_menu::FlightMenu,
1514
gps::Gps,
1615
imu::IMUUI,
1716
pitot::PitotUI,
1817
servo::ServoUI,
1918
tachometer::TachUI,
20-
vane::VaneUI
19+
vane::VaneUI,
20+
AppUI,
2121
};
2222

2323
use crate::parse::Parser;
@@ -35,7 +35,7 @@ fn main() -> Result<(), eframe::Error> {
3535
eframe::run_native(
3636
"Meister App",
3737
options,
38-
Box::new(|cc|{
38+
Box::new(|cc| {
3939
egui_extras::install_image_loaders(&cc.egui_ctx);
4040
Box::<MeisterApp>::default()
4141
}),
@@ -74,6 +74,7 @@ impl Default for MeisterApp {
7474
servo: ServoUI::new(),
7575
tach: TachUI::new(),
7676
vane: VaneUI::new(),
77+
7778
// menu: FlightMenu::new(),
7879
}
7980
}
@@ -102,7 +103,7 @@ impl eframe::App for MeisterApp {
102103
self.parser.parse();
103104
egui::CentralPanel::default().show(ctx, |ui| {
104105
ctx.request_repaint_after(std::time::Duration::from_millis(25));
105-
106+
106107
// self.menu.update(&mut self.parser, ctx);
107108

108109
match self.parser.get_port() {
@@ -125,6 +126,114 @@ impl eframe::App for MeisterApp {
125126
self.tach.update(&mut self.parser, ctx);
126127
self.vane.update(&mut self.parser, ctx);
127128

129+
// 生存確認
130+
let t = chrono::Utc::now().timestamp_millis();
131+
132+
if let Some((_, timestamp)) = self.parser.get_servo_data().last() {
133+
if t < (*timestamp + 1000) {
134+
ui.colored_label(egui::Color32::GREEN , "0x10:Servo");
135+
} else {
136+
ui.colored_label(egui::Color32::RED, "0x10:Servo");
137+
}
138+
}
139+
ui.horizontal(|ui| {
140+
if let Some((_, timestamp)) = self.parser.get_tach_data(0).last() {
141+
if t < *timestamp + 1000 {
142+
ui.colored_label(egui::Color32::GREEN , "0x20:Thrust");
143+
} else {
144+
ui.colored_label(egui::Color32::RED, "0x20:Thrust");
145+
}
146+
}
147+
if let Some((_, timestamp)) = self.parser.get_tach_data(1).last() {
148+
if t < *timestamp + 1000 {
149+
ui.colored_label(egui::Color32::GREEN , "0x21:Tachometer");
150+
} else {
151+
ui.colored_label(egui::Color32::RED, "0x21:Tachometer");
152+
}
153+
}
154+
});
155+
if let Some((pitot, timestamp)) = self.parser.get_pitot_data().last() {
156+
if t < *timestamp + 1000 {
157+
ui.colored_label(egui::Color32::GREEN , format!("0x{:02x}:Pitot", pitot.id));
158+
} else {
159+
ui.colored_label(egui::Color32::RED, format!("0x{:02x}:Pitot", pitot.id));
160+
}
161+
}
162+
163+
ui.horizontal(|ui| {
164+
if let Some((_, timestamp)) = self.parser.get_imu(0).last() {
165+
if t < (*timestamp + 1000) {
166+
ui.colored_label(egui::Color32::GREEN , "0x40:IMU(B)");
167+
} else {
168+
ui.colored_label(egui::Color32::RED, "0x40:IMU(B)");
169+
}
170+
}
171+
if let Some((_, timestamp)) = self.parser.get_imu(1).last() {
172+
if t < *timestamp + 1000 {
173+
ui.colored_label(egui::Color32::GREEN , "0x41:IMU(L)");
174+
} else {
175+
ui.colored_label(egui::Color32::RED, "0x41:IMU(L)");
176+
}
177+
}
178+
if let Some((_, timestamp)) = self.parser.get_imu(2).last() {
179+
if t < *timestamp + 1000 {
180+
ui.colored_label(egui::Color32::GREEN , "0x42:IMU(R)");
181+
} else {
182+
ui.colored_label(egui::Color32::RED, "0x42:IMU(R)");
183+
}
184+
}
185+
if let Some((_, timestamp)) = self.parser.get_imu(3).last() {
186+
if t < *timestamp + 1000 {
187+
ui.colored_label(egui::Color32::GREEN , "0x43:IMU(A)");
188+
} else {
189+
ui.colored_label(egui::Color32::RED, "0x43:IMU(A)");
190+
}
191+
}
192+
});
193+
194+
if let Some((alt, timestamp)) = self.parser.get_ultra_sonic_data().last() {
195+
if t < *timestamp + 1000 {
196+
ui.colored_label(egui::Color32::GREEN , format!("0x{:02x}:UltraSonic", alt.id));
197+
} else {
198+
ui.colored_label(
199+
egui::Color32::RED,
200+
format!("0x{:02x}:UltraSonic", alt.id),
201+
);
202+
}
203+
}
204+
205+
if let Some((gps, timestamp)) = self.parser.get_gps_data().last() {
206+
if t < *timestamp + 3000 {
207+
ui.colored_label(egui::Color32::GREEN , format!("0x{:02x}:GPS", gps.id));
208+
} else {
209+
ui.colored_label(egui::Color32::RED, format!("0x{:02x}:GPS", gps.id));
210+
}
211+
}
212+
213+
if let Some((vane, timestamp)) = self.parser.get_vane_data().last() {
214+
if t < *timestamp + 1000 {
215+
ui.colored_label(egui::Color32::GREEN , format!("0x{:02x}:Vane", vane.id));
216+
} else {
217+
ui.colored_label(egui::Color32::RED, format!("0x{:02x}:Vane", vane.id));
218+
}
219+
}
220+
221+
ui.horizontal(|ui| {
222+
if let Some((_, timestamp)) = self.parser.get_barometer_data(0).last() {
223+
if t < *timestamp + 1000 {
224+
ui.colored_label(egui::Color32::GREEN , "0x90:Barometer (On-board)");
225+
} else {
226+
ui.colored_label(egui::Color32::RED, "0x90:Barometer (On-board)");
227+
}
228+
}
229+
if let Some((_, timestamp)) = self.parser.get_barometer_data(1).last() {
230+
if t < *timestamp + 1000 {
231+
ui.colored_label(egui::Color32::GREEN , "0x91:Barometer (ground)");
232+
} else {
233+
ui.colored_label(egui::Color32::GREEN , "0x91:Barometer (ground)");
234+
}
235+
}
236+
});
128237
}
129238
None => {
130239
ui.horizontal(|ui| match available_ports() {

0 commit comments

Comments
 (0)