Skip to content

Commit

Permalink
Support Fetching and Displaying the Driver Interface
Browse files Browse the repository at this point in the history
  • Loading branch information
FrostyCoolSlug committed Mar 28, 2024
1 parent 37746fb commit 55d30b8
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 10 deletions.
14 changes: 11 additions & 3 deletions daemon/src/primary_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use crate::platform::{get_ui_app_path, has_autostart, set_autostart};
use crate::{FileManager, PatchEvent, SettingsHandle, Shutdown, SYSTEM_LOCALE, VERSION};
use anyhow::{anyhow, Result};
use goxlr_ipc::{
Activation, DaemonCommand, DaemonConfig, DaemonStatus, Files, GoXLRCommand, HardwareStatus,
HttpSettings, Locale, PathTypes, Paths, SampleFile, UsbProductInformation,
Activation, DaemonCommand, DaemonConfig, DaemonStatus, DriverDetails, Files, GoXLRCommand,
HardwareStatus, HttpSettings, Locale, PathTypes, Paths, SampleFile, UsbProductInformation,
};
use goxlr_types::DeviceType;
use goxlr_usb::device::base::GoXLRDevice;
use goxlr_usb::device::{find_devices, from_device};
use goxlr_usb::device::{find_devices, from_device, get_version};
use goxlr_usb::{PID_GOXLR_FULL, PID_GOXLR_MINI};
use json_patch::diff;
use log::{debug, error, info, warn};
Expand Down Expand Up @@ -76,6 +76,10 @@ pub async fn spawn_usb_handler(
let update_sleep = sleep(update_duration);
tokio::pin!(update_sleep);

// Get the Driver Type and Details..
let (interface, version) = get_version();
let driver_interface = DriverDetails { interface, version };

// Create the Primary Device List, and 'Ignore' list..
let mut devices: HashMap<String, Device> = HashMap::new();
let mut ignore_list = HashMap::new();
Expand All @@ -85,6 +89,7 @@ pub async fn spawn_usb_handler(
&devices,
&settings,
&http_settings,
&driver_interface,
files.clone(),
&mut app_check,
)
Expand Down Expand Up @@ -339,6 +344,7 @@ pub async fn spawn_usb_handler(
&devices,
&settings,
&http_settings,
&driver_interface,
files.clone(),
&mut app_check,
)
Expand All @@ -365,6 +371,7 @@ async fn get_daemon_status(
devices: &HashMap<String, Device<'_>>,
settings: &SettingsHandle,
http_settings: &HttpSettings,
driver_details: &DriverDetails,
files: Files,
app_check: &mut AppPathCheck,
) -> DaemonStatus {
Expand All @@ -384,6 +391,7 @@ async fn get_daemon_status(
config: DaemonConfig {
http_settings: http_settings.clone(),
daemon_version: String::from(VERSION),
driver_interface: driver_details.clone(),
locale: Locale {
user_locale: settings.get_selected_locale().await,
system_locale: SYSTEM_LOCALE.clone(),
Expand Down
20 changes: 14 additions & 6 deletions ipc/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ use enum_map::EnumMap;
use goxlr_types::MuteState::Unmuted;
use goxlr_types::{
AnimationMode, Button, ButtonColourOffStyle, ChannelName, CompressorAttackTime,
CompressorRatio, CompressorReleaseTime, DeviceType, DisplayMode, EchoStyle, EffectBankPresets,
EncoderColourTargets, EqFrequencies, FaderDisplayStyle, FaderName, FirmwareVersions, GateTimes,
GenderStyle, HardTuneSource, HardTuneStyle, InputDevice, MegaphoneStyle, MicrophoneType,
MiniEqFrequencies, Mix, MuteFunction, MuteState, OutputDevice, PitchStyle, ReverbStyle,
RobotStyle, SampleBank, SampleButtons, SamplePlayOrder, SamplePlaybackMode,
SamplerColourTargets, SimpleColourTargets, SubMixChannelName, WaterfallDirection,
CompressorRatio, CompressorReleaseTime, DeviceType, DisplayMode, DriverInterface, EchoStyle,
EffectBankPresets, EncoderColourTargets, EqFrequencies, FaderDisplayStyle, FaderName,
FirmwareVersions, GateTimes, GenderStyle, HardTuneSource, HardTuneStyle, InputDevice,
MegaphoneStyle, MicrophoneType, MiniEqFrequencies, Mix, MuteFunction, MuteState, OutputDevice,
PitchStyle, ReverbStyle, RobotStyle, SampleBank, SampleButtons, SamplePlayOrder,
SamplePlaybackMode, SamplerColourTargets, SimpleColourTargets, SubMixChannelName,
VersionNumber, WaterfallDirection,
};
use serde::{Deserialize, Serialize};
use std::collections::{BTreeMap, HashMap};
Expand All @@ -26,6 +27,7 @@ pub struct DaemonStatus {
pub struct DaemonConfig {
pub http_settings: HttpSettings,
pub daemon_version: String,
pub driver_interface: DriverDetails,
pub locale: Locale,
pub activation: Activation,
pub autostart_enabled: bool,
Expand All @@ -36,6 +38,12 @@ pub struct DaemonConfig {
pub open_ui_on_launch: bool,
}

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct DriverDetails {
pub interface: DriverInterface,
pub version: VersionNumber,
}

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct Locale {
pub user_locale: Option<String>,
Expand Down
11 changes: 10 additions & 1 deletion types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub struct FirmwareVersions {
pub dice: VersionNumber,
}

#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Clone, Default, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct VersionNumber(pub u32, pub u32, pub Option<u32>, pub Option<u32>);

Expand Down Expand Up @@ -783,3 +783,12 @@ pub enum DeviceType {
Full,
Mini,
}

#[derive(Default, Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "clap", derive(ValueEnum))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum DriverInterface {
#[default]
TUSB,
LIBUSB,
}
14 changes: 14 additions & 0 deletions usb/src/device/libusb/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::device::base::{
use crate::{PID_GOXLR_FULL, PID_GOXLR_MINI, VID_GOXLR};
use anyhow::{anyhow, bail, Error, Result};
use byteorder::{ByteOrder, LittleEndian};
use goxlr_types::{DriverInterface, VersionNumber};
use log::{debug, error, info, warn};
use rusb::Error::Pipe;
use rusb::{
Expand Down Expand Up @@ -458,3 +459,16 @@ pub fn find_devices() -> Vec<GoXLRDevice> {

found_devices
}

pub fn get_interface_version() -> (DriverInterface, VersionNumber) {
let version = rusb::version();
(
DriverInterface::LIBUSB,
VersionNumber(
version.major() as u32,
version.minor() as u32,
Some(version.micro() as u32),
None,
),
)
}
10 changes: 10 additions & 0 deletions usb/src/device/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::device::base::AttachGoXLR;
use crate::device::base::FullGoXLRDevice;
use crate::device::base::GoXLRDevice;
use crate::device::libusb::device::get_interface_version;
use anyhow::Result;
use goxlr_types::{DriverInterface, VersionNumber};
use tokio::sync::mpsc::Sender;

pub mod base;
Expand All @@ -12,6 +14,10 @@ cfg_if::cfg_if! {
mod tusb;
use crate::device::tusb::device;

pub fn get_version() -> (DriverInterface, VersionNumber) {
get_interface_version()
}

pub fn find_devices() -> Vec<GoXLRDevice> {
device::find_devices()
}
Expand All @@ -29,6 +35,10 @@ cfg_if::cfg_if! {
mod libusb;
use crate::device::libusb::device;

pub fn get_version() -> (DriverInterface, VersionNumber) {
get_interface_version()
}

pub fn find_devices() -> Vec<GoXLRDevice> {
device::find_devices()
}
Expand Down
6 changes: 6 additions & 0 deletions usb/src/device/tusb/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::device::tusb::tusbaudio::{
};
use anyhow::{bail, Result};
use byteorder::{ByteOrder, LittleEndian};
use goxlr_types::{DriverInterface, VersionNumber};
use log::{debug, error, warn};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Mutex};
Expand Down Expand Up @@ -366,3 +367,8 @@ impl FullGoXLRDevice for TUSBAudioGoXLR {}
pub fn find_devices() -> Vec<GoXLRDevice> {
get_devices()
}

pub fn get_interface_version() -> (DriverInterface, VersionNumber) {
let version = rusb::version();
(DriverInterface::TUSB, get_version_number())
}
46 changes: 46 additions & 0 deletions usb/src/device/tusb/tusbaudio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::device::base::GoXLRDevice;
use crate::{PID_GOXLR_FULL, PID_GOXLR_MINI, VID_GOXLR};
use anyhow::{anyhow, bail, Result};
use byteorder::{ByteOrder, LittleEndian};
use goxlr_types::VersionNumber;
use lazy_static::lazy_static;
use libloading::{Library, Symbol};
use log::{debug, error, info, warn};
Expand All @@ -24,6 +25,7 @@ use winreg::RegKey;

// Define the Types of the various methods..
type EnumerateDevices = unsafe extern "C" fn() -> u32;
type GetDriverInfo = unsafe extern "C" fn(*mut DriverInfo) -> u32;
type GetAPIVersion = unsafe extern "C" fn() -> ApiVersion;
type CheckAPIVersion = unsafe extern "C" fn(u32, u32) -> bool;
type GetDeviceCount = unsafe extern "C" fn() -> u32;
Expand Down Expand Up @@ -69,6 +71,9 @@ fn locate_library() -> String {

#[allow(dead_code)]
pub struct TUSBAudio<'lib> {
// DriverInfo
driver_info: DriverInfo,

// Need to enumerate..
initial_enumeration: Arc<Mutex<bool>>,
pnp_thread_running: Arc<Mutex<bool>>,
Expand All @@ -78,6 +83,9 @@ pub struct TUSBAudio<'lib> {
get_api_version: Symbol<'lib, GetAPIVersion>,
check_api_version: Symbol<'lib, CheckAPIVersion>,

// Driver Version
get_driver_info: Symbol<'lib, GetDriverInfo>,

// Enumeration / Opening..
enumerate_devices: Symbol<'lib, EnumerateDevices>,
open_device_by_index: Symbol<'lib, OpenDeviceByIndex>,
Expand Down Expand Up @@ -106,6 +114,8 @@ impl TUSBAudio<'_> {
let get_api_version: Symbol<_> = unsafe { LIBRARY.get(b"TUSBAUDIO_GetApiVersion")? };
let check_api_version = unsafe { LIBRARY.get(b"TUSBAUDIO_CheckApiVersion")? };

let get_driver_info = unsafe { LIBRARY.get(b"TUSBAUDIO_GetDriverInfo")? };

let enumerate_devices = unsafe { LIBRARY.get(b"TUSBAUDIO_EnumerateDevices")? };
let open_device_by_index = unsafe { LIBRARY.get(b"TUSBAUDIO_OpenDeviceByIndex")? };

Expand All @@ -126,13 +136,26 @@ impl TUSBAudio<'_> {
let status_code_string = unsafe { LIBRARY.get(b"TUSBAUDIO_StatusCodeStringA")? };
let close_device = unsafe { LIBRARY.get(b"TUSBAUDIO_CloseDevice")? };

debug!("Performing initial Enumeration..");
unsafe { (enumerate_devices)() };

debug!("Fetching Versioning Information..");
let mut driver_info = DriverInfo::default();
let driver_info_ptr: *mut DriverInfo = &mut driver_info;
let result = unsafe { (get_driver_info)(driver_info_ptr) };
if result != 0 {
warn!("Unable to Obtain Driver Info: {}", result);
}

let tusb_audio = Self {
driver_info,
initial_enumeration: Arc::new(Mutex::new(false)),
pnp_thread_running: Arc::new(Mutex::new(false)),
discovered_devices: Arc::new(Mutex::new(Vec::new())),

get_api_version,
check_api_version,
get_driver_info,
enumerate_devices,
open_device_by_index,
get_device_count,
Expand Down Expand Up @@ -172,6 +195,15 @@ impl TUSBAudio<'_> {
Ok(tusb_audio)
}

pub fn get_driver_version(&self) -> VersionNumber {
VersionNumber(
self.driver_info.driver_major,
self.driver_info.driver_minor,
self.driver_info.driver_patch,
None,
)
}

fn get_error(&self, error: u32) -> String {
let res = unsafe { (self.status_code_string)(error) };
let text = unsafe { CStr::from_ptr(res) };
Expand Down Expand Up @@ -682,6 +714,16 @@ struct ApiVersion {
minor: u16,
}

#[repr(C)]
struct DriverInfo {
api_major: u32,
api_minor: u32,
driver_major: u32,
driver_minor: u32,
driver_patch: u32,
flags: u32,
}

#[repr(C)]
#[derive(Debug)]
pub struct Properties {
Expand Down Expand Up @@ -746,6 +788,10 @@ pub fn get_devices() -> Vec<GoXLRDevice> {
list
}

pub fn get_version() -> VersionNumber {
let info = TUSB_INTERFACE.get_driver_version();
}

pub struct EventChannelReceiver {
pub(crate) data_read: Receiver<bool>,
}
Expand Down

0 comments on commit 55d30b8

Please sign in to comment.