forked from beerpsi/chuniio-yubideck
more separation
This commit is contained in:
parent
ebfb4bc624
commit
1ddf98ea91
30
src/lib.rs
30
src/lib.rs
@ -24,18 +24,19 @@ use std::{
|
|||||||
fmt::Display,
|
fmt::Display,
|
||||||
sync::{
|
sync::{
|
||||||
atomic::{AtomicBool, Ordering},
|
atomic::{AtomicBool, Ordering},
|
||||||
Arc, OnceLock,
|
Arc,
|
||||||
},
|
},
|
||||||
thread,
|
|
||||||
time::Duration,
|
|
||||||
};
|
};
|
||||||
#[cfg(any(all(feature = "chusan", target_arch = "x86"), not(feature = "chusan")))]
|
#[cfg(any(all(feature = "chusan", target_arch = "x86"), not(feature = "chusan")))]
|
||||||
use std::{sync::Mutex, thread::JoinHandle};
|
use std::{
|
||||||
|
sync::{Mutex, OnceLock},
|
||||||
|
thread::{self, JoinHandle},
|
||||||
|
time::Duration,
|
||||||
|
};
|
||||||
|
|
||||||
use ::log::{error, info};
|
use ::log::error;
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use rusb::{DeviceHandle, GlobalContext};
|
|
||||||
use shared_memory::{Shmem, ShmemConf, ShmemError};
|
use shared_memory::{Shmem, ShmemConf, ShmemError};
|
||||||
#[cfg(any(
|
#[cfg(any(
|
||||||
all(feature = "chusan", target_arch = "x86_64"),
|
all(feature = "chusan", target_arch = "x86_64"),
|
||||||
@ -52,14 +53,21 @@ use winapi::{
|
|||||||
winnt::{DLL_PROCESS_ATTACH, HRESULT},
|
winnt::{DLL_PROCESS_ATTACH, HRESULT},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
#[cfg(any(all(feature = "chusan", target_arch = "x86"), not(feature = "chusan")))]
|
||||||
|
use {
|
||||||
|
::log::info,
|
||||||
|
rusb::{DeviceHandle, GlobalContext},
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{configuration::Configuration, log::init_logger};
|
use crate::{configuration::Configuration, log::init_logger};
|
||||||
|
|
||||||
|
static mut INPUT_SHMEM: Option<Arc<Shmem>> = None;
|
||||||
|
|
||||||
#[cfg(any(all(feature = "chusan", target_arch = "x86"), not(feature = "chusan")))]
|
#[cfg(any(all(feature = "chusan", target_arch = "x86"), not(feature = "chusan")))]
|
||||||
type SliderCallbackFn = unsafe extern "C" fn(data: *const u8);
|
type SliderCallbackFn = unsafe extern "C" fn(data: *const u8);
|
||||||
|
|
||||||
|
#[cfg(any(all(feature = "chusan", target_arch = "x86"), not(feature = "chusan")))]
|
||||||
static DEVICE: OnceLock<DeviceHandle<GlobalContext>> = OnceLock::new();
|
static DEVICE: OnceLock<DeviceHandle<GlobalContext>> = OnceLock::new();
|
||||||
static mut INPUT_SHMEM: Option<Arc<Shmem>> = None;
|
|
||||||
|
|
||||||
#[cfg(any(all(feature = "chusan", target_arch = "x86"), not(feature = "chusan")))]
|
#[cfg(any(all(feature = "chusan", target_arch = "x86"), not(feature = "chusan")))]
|
||||||
static mut SLIDER_THREAD: OnceLock<JoinHandle<()>> = OnceLock::new();
|
static mut SLIDER_THREAD: OnceLock<JoinHandle<()>> = OnceLock::new();
|
||||||
@ -136,7 +144,8 @@ pub extern "C" fn chuni_io_get_api_version() -> u16 {
|
|||||||
not(feature = "chusan")
|
not(feature = "chusan")
|
||||||
))]
|
))]
|
||||||
pub extern "C" fn chuni_io_jvs_init() -> HRESULT {
|
pub extern "C" fn chuni_io_jvs_init() -> HRESULT {
|
||||||
if cfg!(not(feature = "chusan")) {
|
#[cfg(not(feature = "chusan"))]
|
||||||
|
{
|
||||||
if let Err(e) = yubideck_init() {
|
if let Err(e) = yubideck_init() {
|
||||||
error!("Could not initialize YubiDeck: {e:#?}");
|
error!("Could not initialize YubiDeck: {e:#?}");
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
@ -232,7 +241,8 @@ pub unsafe extern "C" fn chuni_io_slider_init() -> HRESULT {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg!(not(feature = "chusan")) {
|
#[cfg(not(feature = "chusan"))]
|
||||||
|
{
|
||||||
// Already initialized in chuni_io_jvs_init()
|
// Already initialized in chuni_io_jvs_init()
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
@ -443,6 +453,7 @@ where
|
|||||||
.map_err(|e| anyhow!("Failed to create/open shared memory {os_id}: {e:#}"))
|
.map_err(|e| anyhow!("Failed to create/open shared memory {os_id}: {e:#}"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(any(all(feature = "chusan", target_arch = "x86"), not(feature = "chusan")))]
|
||||||
fn yubideck_init() -> Result<()> {
|
fn yubideck_init() -> Result<()> {
|
||||||
let Some(mut device) = rusb::open_device_with_vid_pid(0x1973, 0x2001) else {
|
let Some(mut device) = rusb::open_device_with_vid_pid(0x1973, 0x2001) else {
|
||||||
return Err(anyhow!("YubiDeck not found."));
|
return Err(anyhow!("YubiDeck not found."));
|
||||||
@ -459,6 +470,7 @@ fn yubideck_init() -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(any(all(feature = "chusan", target_arch = "x86"), not(feature = "chusan")))]
|
||||||
fn input_thread_proc() {
|
fn input_thread_proc() {
|
||||||
info!("Input thread started");
|
info!("Input thread started");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user