From 9e43e6a943d0855b792d9d4f8ad89c7340febfb4 Mon Sep 17 00:00:00 2001 From: Andy Killorin <37423245+Speedy6451@users.noreply.github.com> Date: Sun, 9 Mar 2025 20:08:54 -0400 Subject: [PATCH] load config from real file --- auto/src/lib.rs | 5 +++-- interface/src/auto.rs | 25 ++++++++++++++++++++++--- interface/src/gui.rs | 1 - interface/src/main.rs | 5 ++++- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/auto/src/lib.rs b/auto/src/lib.rs index 08a8d52..13e47ef 100644 --- a/auto/src/lib.rs +++ b/auto/src/lib.rs @@ -5,13 +5,14 @@ use interface::auto::{AutoInterface, Configurable}; #[unsafe(no_mangle)] -pub fn entry(interface: AutoInterface) -> Pin + Send>> { +pub fn entry(interface: AutoInterface) -> Pin>> { Box::pin(auto(interface)) } #[unsafe(no_mangle)] pub static NAME: &'static str = "scanseek v1"; + const AUTO_GAP: Configurable = Configurable::new("auto minimum gap").range(0. .. 300.).default(140.) .description("distance (mm) distance measurements must instantaneously drop to indicate a detection. This should line up with the size of the smallest robot you compete against"); const AUTO_SELF_OCCLUSION: Configurable = Configurable::new("auto self occlusion").range(0. .. 200.).default(143.) @@ -23,7 +24,7 @@ pub static CONFIGS: &[Configurable] = &[ AUTO_SELF_OCCLUSION, ]; -async fn auto (interface: AutoInterface) { +async fn auto (mut interface: AutoInterface) { let mut tof_l = Stats::new(); let mut tof_r = Stats::new(); loop { diff --git a/interface/src/auto.rs b/interface/src/auto.rs index b43a217..dd81603 100644 --- a/interface/src/auto.rs +++ b/interface/src/auto.rs @@ -3,6 +3,7 @@ use std::{collections::VecDeque, ops::{Deref, Div, Index, Range, Sub}, sync::Arc use common::{CamState, ControlPacket, SensorData, TelemetryPacket}; use anyhow::{Context, Ok, Result}; use eframe::Storage; +use libloading::{Library, Symbol}; use tokio::sync::{self, broadcast, mpsc, watch}; pub struct AutoConfig { @@ -11,14 +12,14 @@ pub struct AutoConfig { } #[derive(Clone)] -pub struct AutoInterface<'s> { +pub struct AutoInterface { command_sender: Option>, data_receiver: watch::Receiver, - config: &'s dyn Storage, + config: &'static dyn Storage, enabled: bool, } -impl<'s> AutoInterface<'s> { +impl AutoInterface { /// change active command, fails if not in control pub async fn run_command(&self, command: ControlPacket) -> Result<()> { self.command_sender.as_ref().context("no sender")?.send(command).await?; @@ -100,3 +101,21 @@ pub trait Auto { fn default_configs() -> [Configurable]; fn name() -> &'static str; } + + +pub fn get_confs() -> Result<()> { + let lib = unsafe {Library::new("../auto/target/release/libauto.so")?}; + + let configurations: Symbol<&&[Configurable]> = unsafe {lib.get(b"CONFIGS").unwrap()}; + + for config in configurations.iter() { + println!("co {}", config.name); + println!("co {:?}", config.description); + } + + let name: Symbol<&&'static str> = unsafe {lib.get(b"NAME").unwrap()}; + println!("na {:?}", *name); + + Ok(()) +} + diff --git a/interface/src/gui.rs b/interface/src/gui.rs index a06ce2a..3b09761 100644 --- a/interface/src/gui.rs +++ b/interface/src/gui.rs @@ -93,7 +93,6 @@ const AUTO_GAP: Configurable = Configurable::new("auto minimum gap").range(0. .. const AUTO_SELF_OCCLUSION: Configurable = Configurable::new("auto self occlusion").range(0. .. 200.).default(143.) .description("distance (mm) below which measurements are considered noise in the scan phase"); -#[unsafe(no_mangle)] pub static CONFIGS: &[Configurable] = &[ AUTO_GAP, AUTO_SELF_OCCLUSION, diff --git a/interface/src/main.rs b/interface/src/main.rs index 238af37..e99953f 100644 --- a/interface/src/main.rs +++ b/interface/src/main.rs @@ -2,7 +2,7 @@ use std::{fmt::format, ops::ControlFlow, result, sync::{atomic::Ordering, Arc}, use anyhow::{Context, Ok, Result}; use atomic_float::AtomicF32; -use interface::{combatlog::{combat_logger, CombatData}, POWER_THRESHOLD}; +use interface::{auto::get_confs, combatlog::{combat_logger, CombatData}, POWER_THRESHOLD}; use common::{ControlPacket, TelemetryPacket}; use cpal::traits::{DeviceTrait, HostTrait, StreamTrait}; use egui_toast::{Toast, ToastKind}; @@ -13,6 +13,9 @@ use tokio::{io::{AsyncReadExt, AsyncWriteExt, BufWriter, WriteHalf}, net::{tcp:: fn main() -> Result<()> { + get_confs().unwrap(); + panic!("got too far"); + let (logging_sender, combatlog) = mpsc::channel(64); // assumes pulseaudio system with f32 samples and 2204 sample packets