1
Fork 0

disconnect button

This commit is contained in:
Andy Killorin 2025-03-30 01:06:29 -04:00
parent a3864c4ef0
commit 7811eaf91c
Signed by: ank
GPG key ID: 23F9463ECB67FE8C
3 changed files with 19 additions and 3 deletions

View file

@ -6,7 +6,7 @@ use image::ImageFormat;
use tokio::{runtime::Runtime, sync::{mpsc, watch::{self, Receiver}}};
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();
@ -105,6 +105,12 @@ impl eframe::App for GUI {
egui::CentralPanel::default().show(ctx, |ui| {
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 {
ui.label(format!("sending {command:?}"));
}

View file

@ -1,5 +1,7 @@
#![feature(iter_collect_into)]
use std::sync::atomic::AtomicBool;
use atomic_float::AtomicF32;
use gui::DEFAULT_VOLUME_THRESHOLD;
@ -11,3 +13,4 @@ pub mod storage;
pub const POWER_THRESHOLD: AtomicF32 = AtomicF32::new(DEFAULT_VOLUME_THRESHOLD);
pub static RECONNECT: AtomicBool = AtomicBool::new(false);

View file

@ -1,9 +1,9 @@
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 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 cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
use egui_toast::{Toast, ToastKind};
@ -117,6 +117,7 @@ fn main() -> Result<()> {
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.get().map(|c| c.request_repaint());
if RECONNECT.load(Ordering::Acquire) {
RECONNECT.store(false, Ordering::Release);
return Ok(());
}
}
}