address compiler warnings
This commit is contained in:
parent
923b5a1a96
commit
8ecbd05253
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/target
|
||||
/dist
|
16
build-all.sh
Normal file
16
build-all.sh
Normal file
@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
|
||||
mkdir -p dist/chusan
|
||||
mkdir -p dist/chuni
|
||||
|
||||
for backend in tasoller_v1 tasoller_v2 yubideck_v3
|
||||
do
|
||||
cargo build --target i686-pc-windows-msvc --release --features chusan,$backend
|
||||
cargo build --target x86_64-pc-windows-msvc --release --features chusan,$backend
|
||||
|
||||
cp target/i686-pc-windows-msvc/release/chuniio_rs.dll dist/chusan/chuniio_${backend}_chusan.dll
|
||||
cp target/x86_64-pc-windows-msvc/release/chuniio_rs.dll dist/chusan/chuniio_${backend}_amdaemon.dll
|
||||
|
||||
cargo build --target i686-pc-windows-msvc --release --features $backend
|
||||
cp target/i686-pc-windows-msvc/release/chuniio_rs.dll dist/chuni/chuniio_${backend}.dll
|
||||
done
|
@ -1,2 +0,0 @@
|
||||
[toolchain]
|
||||
channel = "nightly"
|
3
rustfmt.toml
Normal file
3
rustfmt.toml
Normal file
@ -0,0 +1,3 @@
|
||||
imports_granularity = "Crate"
|
||||
reorder_imports = true
|
||||
group_imports = "StdExternalCrate"
|
@ -1,4 +1,6 @@
|
||||
#[cfg(any(chuni, chusanapp))]
|
||||
use anyhow::Result;
|
||||
#[cfg(any(chuni, chusanapp))]
|
||||
use rusb::{DeviceHandle, UsbContext};
|
||||
|
||||
use super::ReadType;
|
||||
|
@ -29,11 +29,14 @@
|
||||
//! - Bytes 3..96: Slider LED (GRB order, right -> left)
|
||||
//! - Bytes 96..240: Nothing.
|
||||
|
||||
#[cfg(any(chuni, chusanapp))]
|
||||
use anyhow::Result;
|
||||
#[cfg(any(chuni, chusanapp))]
|
||||
use rusb::{DeviceHandle, UsbContext};
|
||||
|
||||
use crate::TIMEOUT;
|
||||
use super::ReadType;
|
||||
#[cfg(any(chuni, chusanapp))]
|
||||
use crate::TIMEOUT;
|
||||
|
||||
pub const DEVICE_VID: u16 = 0x1CCF;
|
||||
pub const DEVICE_PID: u16 = 0x2333;
|
||||
@ -111,11 +114,7 @@ pub fn set_slider_leds<T: UsbContext>(
|
||||
output[1] = 0x4C;
|
||||
output[2] = 0;
|
||||
|
||||
for (buf_chunk, state_chunk) in output[3..96]
|
||||
.chunks_mut(3)
|
||||
.take(31)
|
||||
.zip(rgb.chunks(3))
|
||||
{
|
||||
for (buf_chunk, state_chunk) in output[3..96].chunks_mut(3).take(31).zip(rgb.chunks(3)) {
|
||||
buf_chunk[0] = state_chunk[1];
|
||||
buf_chunk[1] = state_chunk[0];
|
||||
buf_chunk[2] = state_chunk[2];
|
||||
|
@ -21,11 +21,14 @@
|
||||
//! - Bytes 3..96: Slider LED (GRB order, right -> left)
|
||||
//! - Bytes 96..240: Nothing.
|
||||
|
||||
#[cfg(any(chuni, chusanapp))]
|
||||
use anyhow::Result;
|
||||
#[cfg(any(chuni, chusanapp))]
|
||||
use rusb::{DeviceHandle, UsbContext};
|
||||
|
||||
use crate::TIMEOUT;
|
||||
use super::ReadType;
|
||||
#[cfg(any(chuni, chusanapp))]
|
||||
use crate::TIMEOUT;
|
||||
|
||||
pub const DEVICE_VID: u16 = 0x1CCF;
|
||||
pub const DEVICE_PID: u16 = 0x2333;
|
||||
@ -73,11 +76,7 @@ pub fn set_slider_leds<T: UsbContext>(
|
||||
output[1] = 0x4C;
|
||||
output[2] = 0;
|
||||
|
||||
for (buf_chunk, state_chunk) in output[3..96]
|
||||
.chunks_mut(3)
|
||||
.take(31)
|
||||
.zip(rgb.chunks(3))
|
||||
{
|
||||
for (buf_chunk, state_chunk) in output[3..96].chunks_mut(3).take(31).zip(rgb.chunks(3)) {
|
||||
buf_chunk[0] = state_chunk[1];
|
||||
buf_chunk[1] = state_chunk[0];
|
||||
buf_chunk[2] = state_chunk[2];
|
||||
@ -97,7 +96,7 @@ pub fn set_led_colors<T: UsbContext>(
|
||||
rgb: &[u8],
|
||||
) -> Result<()> {
|
||||
if board != 0 && board != 1 {
|
||||
return Ok(())
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
output[0] = 0x42;
|
||||
|
@ -29,11 +29,14 @@
|
||||
//! - Bytes 40..43: Card reader LED (RGB)
|
||||
//! - Bytes 43..61: Padding
|
||||
|
||||
#[cfg(any(chuni, chusanapp))]
|
||||
use anyhow::Result;
|
||||
#[cfg(any(chuni, chusanapp))]
|
||||
use rusb::{DeviceHandle, UsbContext};
|
||||
|
||||
use crate::TIMEOUT;
|
||||
use super::ReadType;
|
||||
#[cfg(any(chuni, chusanapp))]
|
||||
use crate::TIMEOUT;
|
||||
|
||||
pub const DEVICE_VID: u16 = 0x1973;
|
||||
pub const DEVICE_PID: u16 = 0x2001;
|
||||
@ -72,10 +75,7 @@ pub fn set_slider_leds<T: UsbContext>(
|
||||
output[0] = 0;
|
||||
output[61] = 1;
|
||||
|
||||
for (buf_chunk, state_chunk) in output[1..61]
|
||||
.chunks_mut(3)
|
||||
.zip(rgb.chunks(3).take(20))
|
||||
{
|
||||
for (buf_chunk, state_chunk) in output[1..61].chunks_mut(3).zip(rgb.chunks(3).take(20)) {
|
||||
buf_chunk[0] = state_chunk[0];
|
||||
buf_chunk[1] = state_chunk[1];
|
||||
buf_chunk[2] = state_chunk[2];
|
||||
@ -104,7 +104,7 @@ pub fn set_led_colors<T: UsbContext>(
|
||||
rgb: &[u8],
|
||||
) -> Result<()> {
|
||||
if board != 0 && board != 1 {
|
||||
return Ok(())
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
output[61] = 1;
|
||||
@ -120,7 +120,7 @@ pub fn set_led_colors<T: UsbContext>(
|
||||
output[99] = rgb[181];
|
||||
output[100] = rgb[182];
|
||||
}
|
||||
_ => unreachable!()
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
||||
device.write_interrupt(0x02, &output[61..], TIMEOUT)?;
|
||||
|
27
src/lib.rs
27
src/lib.rs
@ -5,19 +5,17 @@ pub mod backends;
|
||||
mod configuration;
|
||||
mod log;
|
||||
|
||||
use ::log::{error, info};
|
||||
use rusb::{DeviceHandle, GlobalContext};
|
||||
use std::{
|
||||
ffi::c_void,
|
||||
fmt::Display,
|
||||
rc::Rc,
|
||||
sync::{
|
||||
atomic::{AtomicBool, Ordering},
|
||||
OnceLock, RwLock,
|
||||
},
|
||||
thread::{self, JoinHandle},
|
||||
sync::atomic::{AtomicBool, Ordering},
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use ::log::error;
|
||||
use anyhow::{anyhow, Result};
|
||||
use shared_memory::{Shmem, ShmemConf, ShmemError};
|
||||
use winapi::{
|
||||
shared::{
|
||||
minwindef::{BOOL, DWORD, HINSTANCE, LPVOID, TRUE},
|
||||
@ -26,10 +24,6 @@ use winapi::{
|
||||
um::winnt::{DLL_PROCESS_ATTACH, HRESULT},
|
||||
};
|
||||
|
||||
use anyhow::{anyhow, Result};
|
||||
use shared_memory::{Shmem, ShmemConf, ShmemError};
|
||||
|
||||
use crate::backends::ReadType;
|
||||
use crate::log::init_logger;
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
@ -48,6 +42,14 @@ cfg_if::cfg_if! {
|
||||
if #[cfg(any(chuni, chusanapp))] {
|
||||
type SliderCallbackFn = unsafe extern "C" fn(data: *const u8);
|
||||
|
||||
use std::{sync::{RwLock, OnceLock}, thread::{self, JoinHandle}};
|
||||
|
||||
use ::log::info;
|
||||
use rusb::{DeviceHandle, GlobalContext};
|
||||
|
||||
use crate::backends::ReadType;
|
||||
|
||||
static DEVICE: OnceLock<DeviceHandle<GlobalContext>> = OnceLock::new();
|
||||
static mut SLIDER_THREAD: OnceLock<JoinHandle<()>> = OnceLock::new();
|
||||
static SLIDER_ACTIVE: AtomicBool = AtomicBool::new(false);
|
||||
static SLIDER_OUTPUT: RwLock<[u8; con_impl::OUTPUT_MEMORY_SIZE]> = RwLock::new([0u8; con_impl::OUTPUT_MEMORY_SIZE]);
|
||||
@ -102,7 +104,6 @@ cfg_if::cfg_if! {
|
||||
}
|
||||
|
||||
pub static TIMEOUT: Duration = Duration::from_millis(20);
|
||||
static DEVICE: OnceLock<DeviceHandle<GlobalContext>> = OnceLock::new();
|
||||
static mut INPUT_SHMEM: Option<Rc<Shmem>> = None;
|
||||
|
||||
#[no_mangle]
|
||||
@ -319,6 +320,7 @@ pub unsafe extern "C" fn chuni_io_led_set_colors(board: u8, rgb: *const u8) {
|
||||
#[cfg(amdaemon)]
|
||||
pub extern "C" fn chuni_io_led_set_colors(_rgb: *const u8) {}
|
||||
|
||||
#[cfg(any(chuni, chusanapp))]
|
||||
fn device_init() -> Result<()> {
|
||||
let Some(mut device) =
|
||||
rusb::open_device_with_vid_pid(con_impl::DEVICE_VID, con_impl::DEVICE_PID)
|
||||
@ -337,6 +339,7 @@ fn device_init() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(any(chuni, chusanapp))]
|
||||
fn input_thread_proc() {
|
||||
info!("Input thread started");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user