mirror of https://github.com/4yn/slidershim
General cleanup
parent
5694d39577
commit
05ff89b923
|
@ -2,29 +2,29 @@ extern crate slidershim;
|
|||
|
||||
use std::io;
|
||||
|
||||
use slidershim::slider_io::worker::{Job, Worker};
|
||||
// use slidershim::slider_io::worker::{Job, Worker};
|
||||
|
||||
struct TestJob {
|
||||
data: i64,
|
||||
}
|
||||
// struct TestJob {
|
||||
// data: i64,
|
||||
// }
|
||||
|
||||
impl Job for TestJob {
|
||||
fn setup(&mut self) {
|
||||
self.data = 10;
|
||||
println!("setup {}", self.data);
|
||||
}
|
||||
fn tick(&mut self) {
|
||||
self.data -= 1;
|
||||
println!("tick {}", self.data);
|
||||
}
|
||||
fn teardown(&mut self) {
|
||||
self.data = 11;
|
||||
println!("teardown {}", self.data);
|
||||
}
|
||||
}
|
||||
// impl Job for TestJob {
|
||||
// fn setup(&mut self) {
|
||||
// self.data = 10;
|
||||
// println!("setup {}", self.data);
|
||||
// }
|
||||
// fn tick(&mut self) {
|
||||
// self.data -= 1;
|
||||
// println!("tick {}", self.data);
|
||||
// }
|
||||
// fn teardown(&mut self) {
|
||||
// self.data = 11;
|
||||
// println!("teardown {}", self.data);
|
||||
// }
|
||||
// }
|
||||
|
||||
fn main() {
|
||||
let worker = Worker::new(TestJob { data: 1 });
|
||||
// let worker = Worker::new(TestJob { data: 1 });
|
||||
|
||||
let mut input = String::new();
|
||||
let string = io::stdin().read_line(&mut input).unwrap();
|
||||
|
|
|
@ -56,7 +56,9 @@ fn main() {
|
|||
})
|
||||
.setup(|app| {
|
||||
app.listen_global("setConfig", |event| {
|
||||
println!("Setting config to {}", event.payload().unwrap());
|
||||
let payload = event.payload().unwrap();
|
||||
println!("Setting config to {}", payload);
|
||||
|
||||
});
|
||||
|
||||
let handle = app.handle();
|
||||
|
|
|
@ -39,10 +39,15 @@ pub enum ReactiveLayout {
|
|||
#[derive(Debug, Clone)]
|
||||
pub enum LedMode {
|
||||
None,
|
||||
Reactive { layout: ReactiveLayout },
|
||||
Reactive {
|
||||
layout: ReactiveLayout,
|
||||
sensitivity: u8,
|
||||
},
|
||||
Attract,
|
||||
Test,
|
||||
Websocket { url: String },
|
||||
Websocket {
|
||||
url: String,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
@ -91,12 +96,15 @@ impl Config {
|
|||
"none" => LedMode::None,
|
||||
"reactive-4" => LedMode::Reactive {
|
||||
layout: ReactiveLayout::Four,
|
||||
sensitivity: u8::try_from(v["ledSensitivity"].as_i64().unwrap()).unwrap(),
|
||||
},
|
||||
"reactive-8" => LedMode::Reactive {
|
||||
layout: ReactiveLayout::Eight,
|
||||
sensitivity: u8::try_from(v["ledSensitivity"].as_i64().unwrap()).unwrap(),
|
||||
},
|
||||
"reactive-16" => LedMode::Reactive {
|
||||
layout: ReactiveLayout::Sixteen,
|
||||
sensitivity: u8::try_from(v["ledSensitivity"].as_i64().unwrap()).unwrap(),
|
||||
},
|
||||
"attract" => LedMode::Attract,
|
||||
"test" => LedMode::Test,
|
||||
|
|
|
@ -125,7 +125,7 @@ impl HidDeviceJob {
|
|||
}
|
||||
}
|
||||
|
||||
const timeout: Duration = Duration::from_millis(20);
|
||||
const TIMEOUT: Duration = Duration::from_millis(20);
|
||||
|
||||
impl Job for HidDeviceJob {
|
||||
fn setup(&mut self) {
|
||||
|
@ -138,7 +138,7 @@ impl Job for HidDeviceJob {
|
|||
|
||||
{
|
||||
let res = handle
|
||||
.read_interrupt(self.read_endpoint, &mut self.read_buf.data, timeout)
|
||||
.read_interrupt(self.read_endpoint, &mut self.read_buf.data, TIMEOUT)
|
||||
.unwrap_or(0);
|
||||
self.read_buf.len = res;
|
||||
if self.read_buf.len != 0 {
|
||||
|
@ -153,7 +153,7 @@ impl Job for HidDeviceJob {
|
|||
(self.led_callback)(&mut self.led_buf, led_state_handle.deref_mut());
|
||||
if self.led_buf.len != 0 {
|
||||
let res = handle
|
||||
.write_interrupt(self.led_endpoint, &self.led_buf.data, timeout)
|
||||
.write_interrupt(self.led_endpoint, &self.led_buf.data, TIMEOUT)
|
||||
.unwrap_or(0);
|
||||
if res == self.led_buf.len + 1 {
|
||||
self.led_buf.len = 0;
|
||||
|
|
|
@ -5,10 +5,10 @@ use winapi::{
|
|||
um::winuser::{SendInput, INPUT, INPUT_KEYBOARD, KEYBDINPUT, KEYEVENTF_KEYUP},
|
||||
};
|
||||
|
||||
use crate::slider_io::{config::KeyboardLayout, controller_state::ControllerState};
|
||||
use crate::slider_io::config::KeyboardLayout;
|
||||
|
||||
#[rustfmt::skip]
|
||||
const tasoller_kb_map: [usize; 41] = [
|
||||
const TASOLLER_KB_MAP: [usize; 41] = [
|
||||
0x41 /* A */, 0x31 /* 1 */, 0x5a /* Z */, 0x51 /* Q */, 0x53 /* S */, 0x32 /* 2 */, 0x58 /* X */, 0x57 /* W */,
|
||||
0x44 /* D */, 0x33 /* 3 */, 0x43 /* C */, 0x45 /* E */, 0x46 /* F */, 0x34 /* 4 */, 0x56 /* V */, 0x52 /* R */,
|
||||
0x47 /* G */, 0x35 /* 5 */, 0x42 /* B */, 0x54 /* T */, 0x48 /* H */, 0x36 /* 6 */, 0x4e /* N */, 0x59 /* Y */,
|
||||
|
@ -19,7 +19,7 @@ const tasoller_kb_map: [usize; 41] = [
|
|||
];
|
||||
|
||||
#[rustfmt::skip]
|
||||
const yuancon_kb_map: [usize; 41] = [
|
||||
const YUANCON_KB_MAP: [usize; 41] = [
|
||||
0x36 /* 6 */, 0x35 /* 5 */, 0x34 /* 4 */, 0x33 /* 3 */, 0x32 /* 2 */, 0x31 /* 1 */, 0x5a /* Z */, 0x59 /* Y */,
|
||||
0x58 /* X */, 0x57 /* W */, 0x56 /* V */, 0x55 /* U */, 0x54 /* T */, 0x53 /* S */, 0x52 /* R */, 0x51 /* Q */,
|
||||
0x50 /* P */, 0x4f /* O */, 0x4e /* N */, 0x4d /* M */, 0x4c /* L */, 0x4b /* K */, 0x4a /* J */, 0x49 /* I */,
|
||||
|
@ -29,6 +29,18 @@ const yuancon_kb_map: [usize; 41] = [
|
|||
0x0d, 0x20, 0x1b, // VK_RETURN, VK_SPACE, VK_ESCAPE
|
||||
];
|
||||
|
||||
#[rustfmt::skip]
|
||||
const DEEMO_KB_MAP: [usize; 41] = [
|
||||
0x35, 0x35, 0x35, 0x35, 0x35, 0x35, // S
|
||||
0x4f, 0x4f, 0x4f, 0x4f, // D
|
||||
0x46, 0x46, 0x46, 0x46, 0x46, 0x46, // F
|
||||
0x4a, 0x4a, 0x4a, 0x4a, 0x4a, 0x4a, // J
|
||||
0x4b, 0x4b, 0x4b, 0x4b, // K
|
||||
0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, // L
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, // VK_SPACE
|
||||
0x00, 0x00, 0x00, // Disabled
|
||||
];
|
||||
|
||||
pub struct KeyboardOutput {
|
||||
ground_to_idx: [usize; 41],
|
||||
idx_to_keycode: [u16; 41],
|
||||
|
@ -44,11 +56,9 @@ pub struct KeyboardOutput {
|
|||
impl KeyboardOutput {
|
||||
pub fn new(layout: KeyboardLayout) -> Self {
|
||||
let kb_map = match layout {
|
||||
KeyboardLayout::Tasoller => &tasoller_kb_map,
|
||||
KeyboardLayout::Yuancon => &yuancon_kb_map,
|
||||
KeyboardLayout::Deemo => {
|
||||
panic!("Not yet")
|
||||
}
|
||||
KeyboardLayout::Tasoller => &TASOLLER_KB_MAP,
|
||||
KeyboardLayout::Yuancon => &YUANCON_KB_MAP,
|
||||
KeyboardLayout::Deemo => &DEEMO_KB_MAP,
|
||||
};
|
||||
|
||||
let mut ground_to_idx = [0 as usize; 41];
|
||||
|
@ -116,6 +126,10 @@ impl KeyboardOutput {
|
|||
.zip(self.last_keys.iter_mut())
|
||||
.enumerate()
|
||||
{
|
||||
let wVk = self.idx_to_keycode[i];
|
||||
if wVk == 0 {
|
||||
continue;
|
||||
}
|
||||
match (*n, *l) {
|
||||
(false, true) => {
|
||||
let inner: &mut KEYBDINPUT = unsafe { self.kb_buf[self.n_kb_buf as usize].u.ki_mut() };
|
||||
|
|
|
@ -12,8 +12,6 @@ use crate::slider_io::{
|
|||
worker::Job,
|
||||
};
|
||||
|
||||
type LedCallback = fn(&Vec<bool>, &mut LedState) -> ();
|
||||
|
||||
pub struct LedJob {
|
||||
state: FullState,
|
||||
mode: LedMode,
|
||||
|
@ -25,19 +23,28 @@ pub struct LedJob {
|
|||
|
||||
impl LedJob {
|
||||
pub fn new(state: &FullState, mode: &LedMode) -> Self {
|
||||
let splits = match mode {
|
||||
LedMode::Reactive { layout } => match layout {
|
||||
ReactiveLayout::Four => 4,
|
||||
ReactiveLayout::Eight => 8,
|
||||
ReactiveLayout::Sixteen => 16,
|
||||
},
|
||||
_ => 16,
|
||||
let mut splits = 16;
|
||||
let mut sensitivity = 20;
|
||||
|
||||
match mode {
|
||||
LedMode::Reactive {
|
||||
layout,
|
||||
sensitivity: sensitivity_ref,
|
||||
} => {
|
||||
sensitivity = *sensitivity_ref;
|
||||
splits = match layout {
|
||||
ReactiveLayout::Four => 4,
|
||||
ReactiveLayout::Eight => 8,
|
||||
ReactiveLayout::Sixteen => 16,
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
|
||||
Self {
|
||||
state: state.clone(),
|
||||
mode: mode.clone(),
|
||||
sensitivity: 20,
|
||||
sensitivity,
|
||||
|
||||
splits,
|
||||
buttons_per_split: 32 / splits,
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
pub mod config;
|
||||
pub mod controller_state;
|
||||
pub mod worker;
|
||||
|
||||
pub mod keyboard;
|
||||
mod controller_state;
|
||||
mod worker;
|
||||
|
||||
pub mod device;
|
||||
pub mod led;
|
||||
pub mod output;
|
||||
mod keyboard;
|
||||
|
||||
mod device;
|
||||
mod led;
|
||||
mod output;
|
||||
|
||||
pub mod manager;
|
||||
|
|
|
@ -1,13 +1,7 @@
|
|||
use std::{
|
||||
thread,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
use std::{thread, time::Duration};
|
||||
|
||||
use crate::slider_io::{
|
||||
config::{KeyboardLayout, OutputMode},
|
||||
controller_state::FullState,
|
||||
keyboard::KeyboardOutput,
|
||||
worker::Job,
|
||||
config::OutputMode, controller_state::FullState, keyboard::KeyboardOutput, worker::Job,
|
||||
};
|
||||
|
||||
pub struct KeyboardOutputJob {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
import { onMount } from "svelte";
|
||||
import { emit, listen } from "@tauri-apps/api/event";
|
||||
|
||||
import Preview from "./Preview.svelte"
|
||||
import Preview from "./Preview.svelte";
|
||||
|
||||
let deviceMode = "none";
|
||||
let outputMode = "none";
|
||||
|
@ -10,6 +10,7 @@
|
|||
|
||||
let keyboardSensitivity = 20;
|
||||
let outputWebsocketUrl = "http://localhost:3000";
|
||||
let ledSensitivity = 20;
|
||||
let ledWebsocketUrl = "http://localhost:3001";
|
||||
|
||||
onMount(async () => {
|
||||
|
@ -20,29 +21,34 @@
|
|||
ledMode = payload.ledMode;
|
||||
keyboardSensitivity = payload.keyboardSensitivity;
|
||||
outputWebsocketUrl = payload.outputWebsocketUrl;
|
||||
ledSensitivity = payload.ledSensitivity;
|
||||
ledWebsocketUrl = payload.ledWebsocketUrl;
|
||||
});
|
||||
});
|
||||
|
||||
async function setConfig() {
|
||||
console.log("Updating config");
|
||||
await emit("setConfig", JSON.stringify({
|
||||
deviceMode,
|
||||
outputMode,
|
||||
ledMode,
|
||||
keyboardSensitivity,
|
||||
outputWebsocketUrl,
|
||||
ledWebsocketUrl
|
||||
}));
|
||||
await emit(
|
||||
"setConfig",
|
||||
JSON.stringify({
|
||||
deviceMode,
|
||||
outputMode,
|
||||
ledMode,
|
||||
keyboardSensitivity,
|
||||
outputWebsocketUrl,
|
||||
ledSensitivity,
|
||||
ledWebsocketUrl,
|
||||
})
|
||||
);
|
||||
console.log("Done");
|
||||
}
|
||||
|
||||
async function hide() {
|
||||
await emit("hide", "")
|
||||
await emit("hide", "");
|
||||
}
|
||||
|
||||
async function quit() {
|
||||
await emit("quit", "")
|
||||
await emit("quit", "");
|
||||
}
|
||||
</script>
|
||||
|
||||
|
@ -96,7 +102,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="label"></div>
|
||||
<div class="label" />
|
||||
<div class="input">
|
||||
<input
|
||||
type="range"
|
||||
|
@ -130,6 +136,32 @@
|
|||
</select>
|
||||
</div>
|
||||
</div>
|
||||
{#if ledMode.slice(0, 8) === "reactive"}
|
||||
<div class="row">
|
||||
<div class="label">Sensitivity</div>
|
||||
<div class="input">
|
||||
<input
|
||||
type="number"
|
||||
min="1"
|
||||
max="255"
|
||||
step="1"
|
||||
bind:value={keyboardSensitivity}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="label" />
|
||||
<div class="input">
|
||||
<input
|
||||
type="range"
|
||||
min="1"
|
||||
max="255"
|
||||
step="1"
|
||||
bind:value={keyboardSensitivity}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{#if ledMode === "websocket"}
|
||||
<div class="row">
|
||||
<div class="label">LED URL</div>
|
||||
|
|
Loading…
Reference in New Issue