show auto status on gui
This commit is contained in:
parent
311427b0a5
commit
1e1a82830b
3 changed files with 35 additions and 21 deletions
|
@ -17,18 +17,22 @@ pub struct AutoInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AutoInterface {
|
impl AutoInterface {
|
||||||
pub fn new(data: watch::Receiver<TelemetryPacket>, config: StorageManager, enable_permission: Arc<AtomicBool>) -> (Self, watch::Receiver<ControlPacket>) {
|
/// new
|
||||||
|
///
|
||||||
|
/// returns command channel from auto, enable status
|
||||||
|
pub fn new(data: watch::Receiver<TelemetryPacket>, config: StorageManager, enable_permission: Arc<AtomicBool>) -> (Self, watch::Receiver<ControlPacket>, Arc<AtomicBool>) {
|
||||||
let (commands, receiver) = watch::channel(ControlPacket::Fire);
|
let (commands, receiver) = watch::channel(ControlPacket::Fire);
|
||||||
|
|
||||||
|
let enabled = Arc::new(AtomicBool::new(false));
|
||||||
let interface = Self {
|
let interface = Self {
|
||||||
command_sender: commands,
|
command_sender: commands,
|
||||||
data_receiver: data,
|
data_receiver: data,
|
||||||
config,
|
config,
|
||||||
enabled: Arc::new(AtomicBool::new(false)),
|
enabled: enabled.clone(),
|
||||||
enable_permission,
|
enable_permission,
|
||||||
};
|
};
|
||||||
|
|
||||||
(interface, receiver)
|
(interface, receiver, enabled)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn subscribe(&self) -> watch::Receiver<ControlPacket> {
|
pub fn subscribe(&self) -> watch::Receiver<ControlPacket> {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::{cell::OnceCell, collections::HashMap, path::PathBuf, sync::{atomic::Ordering, Arc}, time::Duration};
|
use std::{cell::OnceCell, collections::HashMap, path::PathBuf, sync::{atomic::{AtomicBool, Ordering}, Arc}, time::Duration};
|
||||||
|
|
||||||
use common::{ControlPacket, TelemetryPacket};
|
use common::{ControlPacket, TelemetryPacket};
|
||||||
use eframe::{egui::{self, containers, Align2, Checkbox, Context, IconData, Id, ImageSource, Label, Ui}, Storage};
|
use eframe::{egui::{self, containers, Align2, Checkbox, Context, IconData, Id, ImageSource, Label, Ui}, Storage};
|
||||||
|
@ -10,7 +10,7 @@ use crate::{auto::Configurable, storage::StorageManager, POWER_THRESHOLD};
|
||||||
|
|
||||||
pub const GUI: OnceCell<Context> = OnceCell::new();
|
pub const GUI: OnceCell<Context> = OnceCell::new();
|
||||||
|
|
||||||
pub fn gui(data: Receiver<GUIData>, toasts: mpsc::Receiver<Toast>, executor: Runtime, autoconf: watch::Receiver<&'static [Configurable]>, storage: StorageManager) -> eframe::Result {
|
pub fn gui(data: Receiver<GUIData>, toasts: mpsc::Receiver<Toast>, executor: Runtime, autoconf: watch::Receiver<&'static [Configurable]>, storage: StorageManager, auto_allowed: Arc<AtomicBool>, auto_enabled: Arc<AtomicBool>) -> eframe::Result {
|
||||||
let icon = egui::include_image!("../assets/lizard.png");
|
let icon = egui::include_image!("../assets/lizard.png");
|
||||||
|
|
||||||
let icon = image::load_from_memory_with_format(include_bytes!("../assets/lizard.png"), ImageFormat::Png).unwrap();
|
let icon = image::load_from_memory_with_format(include_bytes!("../assets/lizard.png"), ImageFormat::Png).unwrap();
|
||||||
|
@ -35,7 +35,7 @@ pub fn gui(data: Receiver<GUIData>, toasts: mpsc::Receiver<Toast>, executor: Run
|
||||||
// This gives us image support:
|
// This gives us image support:
|
||||||
egui_extras::install_image_loaders(&cc.egui_ctx);
|
egui_extras::install_image_loaders(&cc.egui_ctx);
|
||||||
|
|
||||||
Ok(Box::new(GUI::with_receivers(data, toasts, executor, storage, autoconf)))
|
Ok(Box::new(GUI::with_receivers(data, toasts, executor, storage, autoconf, auto_allowed, auto_enabled)))
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -63,10 +63,12 @@ struct GUI {
|
||||||
selected_auto: usize,
|
selected_auto: usize,
|
||||||
autoconf: watch::Receiver<&'static [Configurable]>,
|
autoconf: watch::Receiver<&'static [Configurable]>,
|
||||||
storage: StorageManager,
|
storage: StorageManager,
|
||||||
|
auto_allowed: Arc<AtomicBool>,
|
||||||
|
auto_enabled: Arc<AtomicBool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GUI {
|
impl GUI {
|
||||||
fn with_receivers(data: Receiver<GUIData>, toasts: mpsc::Receiver<Toast>, executor: Runtime, storage: StorageManager, autoconf: watch::Receiver<&'static [Configurable]>) -> Self {
|
fn with_receivers(data: Receiver<GUIData>, toasts: mpsc::Receiver<Toast>, executor: Runtime, storage: StorageManager, autoconf: watch::Receiver<&'static [Configurable]>, auto_allowed: Arc<AtomicBool>, auto_enabled: Arc<AtomicBool>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
data,
|
data,
|
||||||
toasts,
|
toasts,
|
||||||
|
@ -74,6 +76,8 @@ impl GUI {
|
||||||
selected_auto: 0,
|
selected_auto: 0,
|
||||||
autoconf,
|
autoconf,
|
||||||
storage,
|
storage,
|
||||||
|
auto_allowed,
|
||||||
|
auto_enabled,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,6 +119,9 @@ impl eframe::App for GUI {
|
||||||
if let Some(ref command) = self.data.borrow().last_command {
|
if let Some(ref command) = self.data.borrow().last_command {
|
||||||
ui.label(format!("sending {command:?}"));
|
ui.label(format!("sending {command:?}"));
|
||||||
}
|
}
|
||||||
|
ui.label(format!("auto authorized: {}", if self.auto_allowed.load(Ordering::Acquire) {"✅"} else {"❌"}));
|
||||||
|
ui.label(format!("auto running: {}", if self.auto_enabled.load(Ordering::Acquire) {"✅ zoom vroom"} else {"❌"}));
|
||||||
|
|
||||||
if let Some(ref telem) = self.data.borrow().telemetry {
|
if let Some(ref telem) = self.data.borrow().telemetry {
|
||||||
ui.label(format!("Left tof: {}", if let Some(tof) = telem.sensors.tof_l {format!("✅ {tof}mm")} else {"❌".into()}));
|
ui.label(format!("Left tof: {}", if let Some(tof) = telem.sensors.tof_l {format!("✅ {tof}mm")} else {"❌".into()}));
|
||||||
ui.label(format!("Right tof: {}", if let Some(tof) = telem.sensors.tof_r {format!("✅ {tof}mm")} else {"❌".into()}));
|
ui.label(format!("Right tof: {}", if let Some(tof) = telem.sensors.tof_r {format!("✅ {tof}mm")} else {"❌".into()}));
|
||||||
|
|
|
@ -22,7 +22,7 @@ fn main() -> Result<()> {
|
||||||
let auto_allowed = Arc::new(AtomicBool::new(false));
|
let auto_allowed = Arc::new(AtomicBool::new(false));
|
||||||
|
|
||||||
let (auto_telem_sender, auto_telem) = watch::channel(TelemetryPacket::default());
|
let (auto_telem_sender, auto_telem) = watch::channel(TelemetryPacket::default());
|
||||||
let (interface, auto_command) = AutoInterface::new(auto_telem.clone(), storage.clone(), auto_allowed.clone());
|
let (interface, auto_command, auto_enabled) = AutoInterface::new(auto_telem.clone(), storage.clone(), auto_allowed.clone());
|
||||||
|
|
||||||
println!("name: {}", auto.name());
|
println!("name: {}", auto.name());
|
||||||
|
|
||||||
|
@ -99,6 +99,7 @@ fn main() -> Result<()> {
|
||||||
|
|
||||||
|
|
||||||
let spawner = executor.handle().clone();
|
let spawner = executor.handle().clone();
|
||||||
|
let auto_allowed_ = auto_allowed.clone();
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
spawner.block_on(async {
|
spawner.block_on(async {
|
||||||
let log_toasts = toast_sender.clone();
|
let log_toasts = toast_sender.clone();
|
||||||
|
@ -109,7 +110,7 @@ fn main() -> Result<()> {
|
||||||
});
|
});
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
if let Err(e) = connect(toast_sender.clone(), notes.resubscribe(), data_sender.clone(), logging_sender.clone(), auto_telem_sender.clone(), auto_allowed.clone(), interface.clone()).await {
|
if let Err(e) = connect(toast_sender.clone(), notes.resubscribe(), data_sender.clone(), logging_sender.clone(), auto_telem_sender.clone(), auto_allowed_.clone(), interface.clone()).await {
|
||||||
if let Err(_) = toast_sender.send(Toast::new().text(format!("{e:?}")).kind(ToastKind::Error)).await {
|
if let Err(_) = toast_sender.send(Toast::new().text(format!("{e:?}")).kind(ToastKind::Error)).await {
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
|
@ -121,7 +122,7 @@ fn main() -> Result<()> {
|
||||||
|
|
||||||
println!("launching gui");
|
println!("launching gui");
|
||||||
let (_conf_sender, conf) = watch::channel(CONFIGS);
|
let (_conf_sender, conf) = watch::channel(CONFIGS);
|
||||||
gui(gui_data, toasts, executor, conf, storage.clone()).unwrap();
|
gui(gui_data, toasts, executor, conf, storage.clone(), auto_allowed, auto_enabled).unwrap();
|
||||||
|
|
||||||
drop(stream);
|
drop(stream);
|
||||||
|
|
||||||
|
@ -177,6 +178,7 @@ async fn controller(mut notes: broadcast::Receiver<Detection>, controller: Owned
|
||||||
|
|
||||||
//auto = Some(spawn(seek))
|
//auto = Some(spawn(seek))
|
||||||
|
|
||||||
|
let mut auto_data = interface.subscribe();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let mut control = ControlPacket::Stop;
|
let mut control = ControlPacket::Stop;
|
||||||
|
@ -190,12 +192,16 @@ async fn controller(mut notes: broadcast::Receiver<Detection>, controller: Owned
|
||||||
let (note,vol) = note.context("channel closed")?;
|
let (note,vol) = note.context("channel closed")?;
|
||||||
if let Some(note) = note {
|
if let Some(note) = note {
|
||||||
dbg!(note);
|
dbg!(note);
|
||||||
if let ControlFlow::Break(_) = sax_control(&mut control, vol, note) {
|
if let ControlFlow::Break(_) = sax_control(&mut control, vol, note, enable.clone()) {
|
||||||
if let ControlFlow::Break(_) = recorder_control(&mut control, vol, note) {
|
if let ControlFlow::Break(_) = recorder_control(&mut control, vol, note, enable.clone()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if enable.load(Ordering::Acquire) && interface.enabled() {
|
||||||
|
control = auto_data.borrow_and_update().clone();
|
||||||
|
}
|
||||||
|
|
||||||
send_packet(&mut controller, control.clone()).await?;
|
send_packet(&mut controller, control.clone()).await?;
|
||||||
let _ = logging_sender.send(CombatData::Control(control.clone())).await;
|
let _ = logging_sender.send(CombatData::Control(control.clone())).await;
|
||||||
gui.send_modify(|gui| gui.last_command = Some(control));
|
gui.send_modify(|gui| gui.last_command = Some(control));
|
||||||
|
@ -210,7 +216,7 @@ async fn controller(mut notes: broadcast::Receiver<Detection>, controller: Owned
|
||||||
/// Weapon enabled
|
/// Weapon enabled
|
||||||
const ARMED: bool = true;
|
const ARMED: bool = true;
|
||||||
|
|
||||||
fn sax_control(control: &mut ControlPacket, vol: f32, frequency: f32) -> ControlFlow<()> {
|
fn sax_control(control: &mut ControlPacket, vol: f32, frequency: f32, enable: Arc<AtomicBool>) -> ControlFlow<()> {
|
||||||
if frequency < 150. {
|
if frequency < 150. {
|
||||||
println!("too low");
|
println!("too low");
|
||||||
return ControlFlow::Break(());
|
return ControlFlow::Break(());
|
||||||
|
@ -263,7 +269,7 @@ fn sax_control(control: &mut ControlPacket, vol: f32, frequency: f32) -> Control
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn recorder_control(control: &mut ControlPacket, vol: f32, frequency: f32) -> ControlFlow<()> {
|
fn recorder_control(control: &mut ControlPacket, vol: f32, frequency: f32, enable: Arc<AtomicBool>) -> ControlFlow<()> {
|
||||||
if frequency < 300. {
|
if frequency < 300. {
|
||||||
println!("too low");
|
println!("too low");
|
||||||
return ControlFlow::Break(());
|
return ControlFlow::Break(());
|
||||||
|
@ -303,15 +309,12 @@ fn recorder_control(control: &mut ControlPacket, vol: f32, frequency: f32) -> Co
|
||||||
*control = ControlPacket::Stop;
|
*control = ControlPacket::Stop;
|
||||||
}
|
}
|
||||||
Pitch { letter: NoteLetter::F, accidental: 0} => {
|
Pitch { letter: NoteLetter::F, accidental: 0} => {
|
||||||
println!("stop");
|
println!("auto en");
|
||||||
*control = ControlPacket::Stop;
|
enable.store(true, Ordering::Release);
|
||||||
}
|
}
|
||||||
Pitch { letter: NoteLetter::E, accidental: 0} => {
|
Pitch { letter: NoteLetter::E, accidental: 0} => {
|
||||||
println!("stop");
|
println!("auto disable");
|
||||||
*control = ControlPacket::Stop;
|
enable.store(false, Ordering::Release);
|
||||||
//if let result::Result::Ok(command) = auto_rx.try_recv() {
|
|
||||||
// control = command;
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
pitch => {
|
pitch => {
|
||||||
if vol > 3000. {
|
if vol > 3000. {
|
||||||
|
|
Loading…
Reference in a new issue