more separation

This commit is contained in:
beerpsi 2023-12-24 04:05:51 +07:00
parent ebfb4bc624
commit 1ddf98ea91

View File

@ -24,18 +24,19 @@ use std::{
fmt::Display,
sync::{
atomic::{AtomicBool, Ordering},
Arc, OnceLock,
Arc,
},
thread,
time::Duration,
};
#[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 lazy_static::lazy_static;
use rusb::{DeviceHandle, GlobalContext};
use shared_memory::{Shmem, ShmemConf, ShmemError};
#[cfg(any(
all(feature = "chusan", target_arch = "x86_64"),
@ -52,14 +53,21 @@ use winapi::{
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};
static mut INPUT_SHMEM: Option<Arc<Shmem>> = None;
#[cfg(any(all(feature = "chusan", target_arch = "x86"), not(feature = "chusan")))]
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 mut INPUT_SHMEM: Option<Arc<Shmem>> = None;
#[cfg(any(all(feature = "chusan", target_arch = "x86"), not(feature = "chusan")))]
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")
))]
pub extern "C" fn chuni_io_jvs_init() -> HRESULT {
if cfg!(not(feature = "chusan")) {
#[cfg(not(feature = "chusan"))]
{
if let Err(e) = yubideck_init() {
error!("Could not initialize YubiDeck: {e:#?}");
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()
return S_OK;
}
@ -443,6 +453,7 @@ where
.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<()> {
let Some(mut device) = rusb::open_device_with_vid_pid(0x1973, 0x2001) else {
return Err(anyhow!("YubiDeck not found."));
@ -459,6 +470,7 @@ fn yubideck_init() -> Result<()> {
Ok(())
}
#[cfg(any(all(feature = "chusan", target_arch = "x86"), not(feature = "chusan")))]
fn input_thread_proc() {
info!("Input thread started");