disconnect button
This commit is contained in:
parent
a3864c4ef0
commit
7811eaf91c
3 changed files with 19 additions and 3 deletions
|
@ -6,7 +6,7 @@ use image::ImageFormat;
|
||||||
use tokio::{runtime::Runtime, sync::{mpsc, watch::{self, Receiver}}};
|
use tokio::{runtime::Runtime, sync::{mpsc, watch::{self, Receiver}}};
|
||||||
use egui_toast::{Toast, Toasts};
|
use egui_toast::{Toast, Toasts};
|
||||||
|
|
||||||
use crate::{auto::Configurable, auto_impl::CONFIGS, storage::StorageManager, POWER_THRESHOLD};
|
use crate::{auto::Configurable, auto_impl::CONFIGS, storage::StorageManager, POWER_THRESHOLD, RECONNECT};
|
||||||
|
|
||||||
pub const GUI: OnceCell<Context> = OnceCell::new();
|
pub const GUI: OnceCell<Context> = OnceCell::new();
|
||||||
|
|
||||||
|
@ -105,6 +105,12 @@ impl eframe::App for GUI {
|
||||||
egui::CentralPanel::default().show(ctx, |ui| {
|
egui::CentralPanel::default().show(ctx, |ui| {
|
||||||
ui.heading("Cruise Control");
|
ui.heading("Cruise Control");
|
||||||
|
|
||||||
|
if !RECONNECT.load(Ordering::Acquire) {
|
||||||
|
if ui.button("disconnect").clicked() {
|
||||||
|
RECONNECT.store(true, Ordering::Release);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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:?}"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#![feature(iter_collect_into)]
|
#![feature(iter_collect_into)]
|
||||||
|
|
||||||
|
use std::sync::atomic::AtomicBool;
|
||||||
|
|
||||||
use atomic_float::AtomicF32;
|
use atomic_float::AtomicF32;
|
||||||
use gui::DEFAULT_VOLUME_THRESHOLD;
|
use gui::DEFAULT_VOLUME_THRESHOLD;
|
||||||
|
|
||||||
|
@ -11,3 +13,4 @@ pub mod storage;
|
||||||
|
|
||||||
pub const POWER_THRESHOLD: AtomicF32 = AtomicF32::new(DEFAULT_VOLUME_THRESHOLD);
|
pub const POWER_THRESHOLD: AtomicF32 = AtomicF32::new(DEFAULT_VOLUME_THRESHOLD);
|
||||||
|
|
||||||
|
pub static RECONNECT: AtomicBool = AtomicBool::new(false);
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
use std::{fmt::format, ops::ControlFlow, path::Path, result, sync::{atomic::{AtomicBool, Ordering}, Arc}, thread::{self, sleep}, time::Duration};
|
use std::{fmt::format, ops::ControlFlow, path::Path, result, sync::{atomic::{AtomicBool, Ordering}, Arc}, thread::{self, sleep}, time::Duration};
|
||||||
|
|
||||||
use anyhow::{Context, Ok, Result};
|
use anyhow::{anyhow, Context, Ok, Result};
|
||||||
use atomic_float::AtomicF32;
|
use atomic_float::AtomicF32;
|
||||||
use directories::ProjectDirs;
|
use directories::ProjectDirs;
|
||||||
use interface::{auto::{get_confs, Auto, AutoInterface}, auto_impl::{self, CONFIGS}, combatlog::{combat_logger, CombatData}, storage::StorageManager, POWER_THRESHOLD};
|
use interface::{auto::{get_confs, Auto, AutoInterface}, auto_impl::{self, CONFIGS}, combatlog::{combat_logger, CombatData}, storage::StorageManager, POWER_THRESHOLD, RECONNECT};
|
||||||
use common::{ControlPacket, TelemetryPacket};
|
use common::{ControlPacket, TelemetryPacket};
|
||||||
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
|
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
|
||||||
use egui_toast::{Toast, ToastKind};
|
use egui_toast::{Toast, ToastKind};
|
||||||
|
@ -117,6 +117,7 @@ fn main() -> Result<()> {
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
let _ = data_sender.send(GUIData { telemetry: None, last_command: None });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -237,6 +238,12 @@ async fn controller(mut notes: broadcast::Receiver<Detection>, controller: Owned
|
||||||
gui.send_modify(|gui| gui.last_command = Some(control));
|
gui.send_modify(|gui| gui.last_command = Some(control));
|
||||||
|
|
||||||
GUI.get().map(|c| c.request_repaint());
|
GUI.get().map(|c| c.request_repaint());
|
||||||
|
|
||||||
|
if RECONNECT.load(Ordering::Acquire) {
|
||||||
|
RECONNECT.store(false, Ordering::Release);
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue