1
0
mirror of https://github.com/4yn/slidershim.git synced 2024-09-24 03:08:23 +02:00

restructure

This commit is contained in:
4yn 2022-02-12 23:23:22 +08:00
parent 4f4d951610
commit 4dbeb432ec
33 changed files with 1819 additions and 172 deletions

1
src-slider_io/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target/

1630
src-slider_io/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -12,3 +12,4 @@ use_try_shorthand = false
use_field_init_shorthand = false use_field_init_shorthand = false
force_explicit_abi = true force_explicit_abi = true
imports_granularity = "Crate" imports_granularity = "Crate"
wrap_comments = true

View File

@ -3,116 +3,23 @@ use image::Luma;
use log::{info, warn}; use log::{info, warn};
use qrcode::QrCode; use qrcode::QrCode;
use serde_json::Value; use serde_json::Value;
use std::{convert::TryFrom, fs, path::PathBuf}; use std::{convert::TryFrom, error::Error, fs, path::PathBuf};
use crate::slider_io::utils::list_ips; use crate::{
device::config::{DeviceMode, HardwareSpec},
lighting::config::{LedMode, ReactiveLayout},
output::config::{GamepadLayout, KeyboardLayout, OutputMode, PollingRate},
};
#[derive(Debug, Clone)] pub fn list_ips() -> Result<Vec<String>, Box<dyn Error>> {
pub enum HardwareSpec { let mut ips = vec![];
TasollerOne, for adapter in ipconfig::get_adapters()? {
TasollerTwo, for ip_address in adapter.ip_addresses() {
Yuancon, ips.push(format!("{}", ip_address));
}
#[derive(Debug, Clone)]
pub enum DeviceMode {
None,
Hardware {
spec: HardwareSpec,
},
Brokenithm {
ground_only: bool,
led_enabled: bool,
},
}
#[derive(Debug, Clone, Copy)]
pub enum PollingRate {
Sixty,
Hundred,
TwoHundredFifty,
FiveHundred,
Thousand,
}
#[derive(Debug, Clone, Copy)]
pub enum KeyboardLayout {
Tasoller,
Yuancon,
Deemo,
Voltex,
Neardayo,
}
#[derive(Debug, Clone, Copy)]
pub enum GamepadLayout {
Voltex,
Neardayo,
}
impl PollingRate {
pub fn from_str(s: &str) -> Option<Self> {
match s {
"60" => Some(PollingRate::Sixty),
"100" => Some(PollingRate::Hundred),
"250" => Some(PollingRate::TwoHundredFifty),
"500" => Some(PollingRate::FiveHundred),
"1000" => Some(PollingRate::Thousand),
_ => None,
} }
} }
pub fn to_t_u64(&self) -> u64 { Ok(ips)
match self {
PollingRate::Sixty => 16666,
PollingRate::Hundred => 10000,
PollingRate::TwoHundredFifty => 4000,
PollingRate::FiveHundred => 2000,
PollingRate::Thousand => 1000,
}
}
}
#[derive(Debug, Clone)]
pub enum OutputMode {
None,
Keyboard {
layout: KeyboardLayout,
polling: PollingRate,
sensitivity: u8,
},
Gamepad {
layout: GamepadLayout,
polling: PollingRate,
sensitivity: u8,
},
Websocket {
url: String,
polling: PollingRate,
},
}
#[derive(Debug, Clone, Copy)]
pub enum ReactiveLayout {
Even { splits: usize },
Voltex,
}
#[derive(Debug, Clone)]
pub enum LedMode {
None,
Reactive {
layout: ReactiveLayout,
sensitivity: u8,
},
Attract,
Test,
Websocket {
url: String,
},
Serial {
port: String,
},
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]

View File

@ -2,15 +2,16 @@ use atomic_float::AtomicF64;
use log::info; use log::info;
use std::sync::{atomic::Ordering, Arc}; use std::sync::{atomic::Ordering, Arc};
use crate::slider_io::{ use crate::{
brokenithm::BrokenithmJob, config::Config,
config::{Config, DeviceMode, LedMode, OutputMode},
controller_state::FullState, controller_state::FullState,
device::HidDeviceJob, device::{brokenithm::BrokenithmJob, config::DeviceMode, device::HidDeviceJob},
led::LedJob, lighting::{config::LedMode, led::LedJob},
output::OutputJob, output::{config::OutputMode, output::OutputJob},
utils::LoopTimer, shared::{
worker::{AsyncHaltableWorker, AsyncWorker, ThreadWorker}, utils::LoopTimer,
worker::{AsyncHaltableWorker, AsyncWorker, ThreadWorker},
},
}; };
#[allow(dead_code)] #[allow(dead_code)]

View File

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 5.7 KiB

View File

Before

Width:  |  Height:  |  Size: 4.9 KiB

After

Width:  |  Height:  |  Size: 4.9 KiB

View File

@ -18,7 +18,7 @@ use tokio::{
use tokio_tungstenite::WebSocketStream; use tokio_tungstenite::WebSocketStream;
use tungstenite::{handshake, Message}; use tungstenite::{handshake, Message};
use crate::slider_io::{controller_state::FullState, worker::AsyncHaltableJob}; use crate::{controller_state::FullState, shared::worker::AsyncHaltableJob};
// https://levelup.gitconnected.com/handling-websocket-and-http-on-the-same-port-with-rust-f65b770722c9 // https://levelup.gitconnected.com/handling-websocket-and-http-on-the-same-port-with-rust-f65b770722c9

View File

@ -0,0 +1,18 @@
#[derive(Debug, Clone)]
pub enum HardwareSpec {
TasollerOne,
TasollerTwo,
Yuancon,
}
#[derive(Debug, Clone)]
pub enum DeviceMode {
None,
Hardware {
spec: HardwareSpec,
},
Brokenithm {
ground_only: bool,
led_enabled: bool,
},
}

View File

@ -7,13 +7,16 @@ use std::{
time::Duration, time::Duration,
}; };
use crate::slider_io::{ use crate::{
config::HardwareSpec,
controller_state::{ControllerState, FullState, LedState}, controller_state::{ControllerState, FullState, LedState},
utils::{Buffer, ShimError}, shared::{
worker::ThreadJob, utils::{Buffer, ShimError},
worker::ThreadJob,
},
}; };
use super::config::HardwareSpec;
type HidReadCallback = fn(&Buffer, &mut ControllerState) -> (); type HidReadCallback = fn(&Buffer, &mut ControllerState) -> ();
type HidLedCallback = fn(&mut Buffer, &LedState) -> (); type HidLedCallback = fn(&mut Buffer, &LedState) -> ();

View File

@ -0,0 +1,6 @@
pub mod config;
mod acio;
pub mod brokenithm;
pub mod device;

View File

@ -1,12 +1,20 @@
#![cfg_attr( #![cfg_attr(
all(not(debug_assertions), target_os = "windows"), all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows" windows_subsystem = "windows"
)] )]
#![feature(div_duration)] #![feature(div_duration)]
#![feature(more_qualified_paths)] #![feature(more_qualified_paths)]
mod slider_io; mod config;
mod controller_state;
mod shared;
pub use slider_io::list_ips; mod device;
pub use slider_io::Config; mod lighting;
pub use slider_io::Manager; mod output;
mod context;
mod manager;
pub use config::{list_ips, Config};
pub use manager::Manager;

View File

@ -0,0 +1,22 @@
#[derive(Debug, Clone, Copy)]
pub enum ReactiveLayout {
Even { splits: usize },
Voltex,
}
#[derive(Debug, Clone)]
pub enum LedMode {
None,
Reactive {
layout: ReactiveLayout,
sensitivity: u8,
},
Attract,
Test,
Websocket {
url: String,
},
Serial {
port: String,
},
}

View File

@ -8,14 +8,13 @@ use std::{
}; };
use tokio::time::{interval, Interval}; use tokio::time::{interval, Interval};
use crate::slider_io::{ use crate::{
config::{LedMode, ReactiveLayout},
controller_state::{FullState, LedState}, controller_state::{FullState, LedState},
utils::Buffer, shared::{utils::Buffer, voltex::VoltexState, worker::AsyncJob},
voltex::VoltexState,
worker::AsyncJob,
}; };
use super::config::{LedMode, ReactiveLayout};
pub struct LedJob { pub struct LedJob {
state: FullState, state: FullState,
mode: LedMode, mode: LedMode,

View File

@ -0,0 +1,3 @@
pub mod config;
pub mod led;

View File

@ -9,9 +9,7 @@ use tokio::{
sync::{mpsc, oneshot}, sync::{mpsc, oneshot},
}; };
use crate::slider_io::{config::Config, context::Context}; use crate::{config::Config, context::Context, controller_state::FullState};
use super::controller_state::FullState;
pub struct Manager { pub struct Manager {
state: Arc<Mutex<Option<FullState>>>, state: Arc<Mutex<Option<FullState>>>,

View File

@ -0,0 +1,65 @@
#[derive(Debug, Clone, Copy)]
pub enum PollingRate {
Sixty,
Hundred,
TwoHundredFifty,
FiveHundred,
Thousand,
}
#[derive(Debug, Clone, Copy)]
pub enum KeyboardLayout {
Tasoller,
Yuancon,
Deemo,
Voltex,
Neardayo,
}
#[derive(Debug, Clone, Copy)]
pub enum GamepadLayout {
Voltex,
Neardayo,
}
#[derive(Debug, Clone)]
pub enum OutputMode {
None,
Keyboard {
layout: KeyboardLayout,
polling: PollingRate,
sensitivity: u8,
},
Gamepad {
layout: GamepadLayout,
polling: PollingRate,
sensitivity: u8,
},
Websocket {
url: String,
polling: PollingRate,
},
}
impl PollingRate {
pub fn from_str(s: &str) -> Option<Self> {
match s {
"60" => Some(PollingRate::Sixty),
"100" => Some(PollingRate::Hundred),
"250" => Some(PollingRate::TwoHundredFifty),
"500" => Some(PollingRate::FiveHundred),
"1000" => Some(PollingRate::Thousand),
_ => None,
}
}
pub fn to_t_u64(&self) -> u64 {
match self {
PollingRate::Sixty => 16666,
PollingRate::Hundred => 10000,
PollingRate::TwoHundredFifty => 4000,
PollingRate::FiveHundred => 2000,
PollingRate::Thousand => 1000,
}
}
}

View File

@ -2,7 +2,9 @@ use log::error;
use std::error::Error; use std::error::Error;
use vigem_client::{Client, TargetId, XButtons, XGamepad, Xbox360Wired}; use vigem_client::{Client, TargetId, XButtons, XGamepad, Xbox360Wired};
use crate::slider_io::{config::GamepadLayout, output::OutputHandler, voltex::VoltexState}; use crate::shared::voltex::VoltexState;
use super::{config::GamepadLayout, output::OutputHandler};
struct LastWind { struct LastWind {
left: bool, left: bool,

View File

@ -4,7 +4,10 @@ use winapi::{
um::winuser::{SendInput, INPUT, INPUT_KEYBOARD, KEYBDINPUT, KEYEVENTF_KEYUP}, um::winuser::{SendInput, INPUT, INPUT_KEYBOARD, KEYBDINPUT, KEYEVENTF_KEYUP},
}; };
use crate::slider_io::{config::KeyboardLayout, output::OutputHandler}; use super::{
config::KeyboardLayout,
output::OutputHandler
};
#[rustfmt::skip] #[rustfmt::skip]
const TASOLLER_KB_MAP: [usize; 41] = [ const TASOLLER_KB_MAP: [usize; 41] = [

View File

@ -0,0 +1,6 @@
pub mod config;
mod gamepad;
mod keyboard;
pub mod output;

View File

@ -3,10 +3,14 @@ use log::error;
use std::time::Duration; use std::time::Duration;
use tokio::time::{interval, Interval}; use tokio::time::{interval, Interval};
use crate::slider_io::{ // use crate::slider_io::{
config::OutputMode, controller_state::FullState, gamepad::GamepadOutput, // config::OutputMode, controller_state::FullState, gamepad::GamepadOutput,
keyboard::KeyboardOutput, worker::AsyncJob, // keyboard::KeyboardOutput, worker::AsyncJob,
}; // };
use crate::{controller_state::FullState, shared::worker::AsyncJob};
use super::{config::OutputMode, gamepad::GamepadOutput, keyboard::KeyboardOutput};
pub trait OutputHandler: Send { pub trait OutputHandler: Send {
fn tick(&mut self, flat_controller_state: &Vec<bool>) -> bool; fn tick(&mut self, flat_controller_state: &Vec<bool>) -> bool;

View File

@ -0,0 +1,3 @@
pub mod utils;
pub mod voltex;
pub mod worker;

View File

@ -40,17 +40,6 @@ impl Error for ShimError {
} }
} }
pub fn list_ips() -> Result<Vec<String>, Box<dyn Error>> {
let mut ips = vec![];
for adapter in ipconfig::get_adapters()? {
for ip_address in adapter.ip_addresses() {
ips.push(format!("{}", ip_address));
}
}
Ok(ips)
}
pub struct LoopTimer { pub struct LoopTimer {
cap: usize, cap: usize,
cur: usize, cur: usize,

View File

@ -11,7 +11,7 @@ use std::{
use tokio::{sync::oneshot, task}; use tokio::{sync::oneshot, task};
use crate::slider_io::utils::LoopTimer; use super::utils::LoopTimer;
pub trait ThreadJob: Send { pub trait ThreadJob: Send {
fn setup(&mut self) -> bool; fn setup(&mut self) -> bool;

View File

@ -1,22 +0,0 @@
mod config;
mod utils;
mod worker;
mod controller_state;
mod voltex;
mod acio;
mod brokenithm;
mod gamepad;
mod keyboard;
mod device;
mod led;
mod output;
mod context;
mod manager;
pub use config::Config;
pub use manager::Manager;
pub use utils::list_ips;