1
0
mirror of https://github.com/4yn/slidershim.git synced 2024-11-27 23:10:49 +01: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
force_explicit_abi = true
imports_granularity = "Crate"
wrap_comments = true

View File

@ -3,116 +3,23 @@ use image::Luma;
use log::{info, warn};
use qrcode::QrCode;
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 enum HardwareSpec {
TasollerOne,
TasollerTwo,
Yuancon,
}
#[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 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));
}
}
pub fn to_t_u64(&self) -> u64 {
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,
},
Ok(ips)
}
#[derive(Debug, Clone)]

View File

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

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,
};
use crate::slider_io::{
config::HardwareSpec,
use crate::{
controller_state::{ControllerState, FullState, LedState},
utils::{Buffer, ShimError},
worker::ThreadJob,
shared::{
utils::{Buffer, ShimError},
worker::ThreadJob,
},
};
use super::config::HardwareSpec;
type HidReadCallback = fn(&Buffer, &mut ControllerState) -> ();
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(
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
)]
#![feature(div_duration)]
#![feature(more_qualified_paths)]
mod slider_io;
mod config;
mod controller_state;
mod shared;
pub use slider_io::list_ips;
pub use slider_io::Config;
pub use slider_io::Manager;
mod device;
mod lighting;
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 crate::slider_io::{
config::{LedMode, ReactiveLayout},
use crate::{
controller_state::{FullState, LedState},
utils::Buffer,
voltex::VoltexState,
worker::AsyncJob,
shared::{utils::Buffer, voltex::VoltexState, worker::AsyncJob},
};
use super::config::{LedMode, ReactiveLayout};
pub struct LedJob {
state: FullState,
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},
};
use crate::slider_io::{config::Config, context::Context};
use super::controller_state::FullState;
use crate::{config::Config, context::Context, controller_state::FullState};
pub struct Manager {
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 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 {
left: bool,

View File

@ -4,7 +4,10 @@ use winapi::{
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]
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 tokio::time::{interval, Interval};
use crate::slider_io::{
config::OutputMode, controller_state::FullState, gamepad::GamepadOutput,
keyboard::KeyboardOutput, worker::AsyncJob,
};
// use crate::slider_io::{
// config::OutputMode, controller_state::FullState, gamepad::GamepadOutput,
// keyboard::KeyboardOutput, worker::AsyncJob,
// };
use crate::{controller_state::FullState, shared::worker::AsyncJob};
use super::{config::OutputMode, gamepad::GamepadOutput, keyboard::KeyboardOutput};
pub trait OutputHandler: Send {
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 {
cap: usize,
cur: usize,

View File

@ -11,7 +11,7 @@ use std::{
use tokio::{sync::oneshot, task};
use crate::slider_io::utils::LoopTimer;
use super::utils::LoopTimer;
pub trait ThreadJob: Send {
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;