1
0
mirror of https://github.com/4yn/slidershim.git synced 2025-01-21 12:23:39 +01:00

add disable air strings option

This commit is contained in:
4yn 2022-03-16 20:05:04 +08:00
parent bcff45da56
commit ff6e971f62
5 changed files with 51 additions and 25 deletions

View File

@ -30,12 +30,14 @@ impl Config {
Self::from_str(
r#"{
"deviceMode": "none",
"devicePolling": "100",
"outputMode": "none",
"ledMode": "none",
"disableAirStrings": false,
"divaSerialPort": "COM1",
"divaBrightness": 63,
"keyboardSensitivity": 20,
"outputWebsocketUrl": "localhost:3000",
"outputPolling": "100",
"outputWebsocketUrl": "localhost:3000",
"ledSensitivity": 20,
"ledWebsocketUrl": "localhost:3001",
"ledSerialPort": "COM5"
@ -55,12 +57,13 @@ impl Config {
}
pub fn load() -> Self {
Self::load_saved()
.or_else(|| {
warn!("Config loading from file failed, using default");
Some(Self::default())
})
.unwrap()
let t = Self::load_saved();
warn!("{:?}", t);
t.or_else(|| {
warn!("Config loading from file failed, using default");
Some(Self::default())
})
.unwrap()
}
pub fn save(&self) -> Option<()> {

View File

@ -50,13 +50,13 @@ impl Context {
BrokenithmJob::new(&state, ground_only, lights_enabled),
)),
),
DeviceMode::Hardware { spec } => (
DeviceMode::Hardware { spec, disable_air } => (
{
let timer = LoopTimer::new();
timers.push(("d", timer.fork()));
Some(ThreadWorker::new(
"device",
HidJob::from_config(&state, spec),
HidJob::from_config(&state, spec, disable_air),
timer,
))
},

View File

@ -12,6 +12,7 @@ pub enum DeviceMode {
None,
Hardware {
spec: HardwareSpec,
disable_air: bool,
},
Brokenithm {
ground_only: bool,
@ -29,31 +30,26 @@ impl DeviceMode {
"none" => DeviceMode::None,
"tasoller-one" => DeviceMode::Hardware {
spec: HardwareSpec::TasollerOne,
disable_air: v["disableAirStrings"].as_bool()?,
},
"tasoller-two" => DeviceMode::Hardware {
spec: HardwareSpec::TasollerTwo,
disable_air: v["disableAirStrings"].as_bool()?,
},
"yuancon" => DeviceMode::Hardware {
spec: HardwareSpec::Yuancon,
disable_air: v["disableAirStrings"].as_bool()?,
},
"diva" => DeviceMode::DivaSlider {
port: v["divaSerialPort"].as_str()?.to_string(),
brightness: u8::try_from(v["divaBrightness"].as_i64()?).ok()?,
},
"brokenithm" => DeviceMode::Brokenithm {
ground_only: false,
ground_only: v["disableAirStrings"].as_bool()?,
lights_enabled: false,
},
"brokenithm-led" => DeviceMode::Brokenithm {
ground_only: false,
lights_enabled: true,
},
"brokenithm-ground" => DeviceMode::Brokenithm {
ground_only: true,
lights_enabled: false,
},
"brokenithm-ground-led" => DeviceMode::Brokenithm {
ground_only: true,
ground_only: v["disableAirStrings"].as_bool()?,
lights_enabled: true,
},
_ => return None,

View File

@ -32,6 +32,7 @@ pub struct HidJob {
pid: u16,
read_endpoint: u8,
led_endpoint: u8,
disable_air: bool,
read_callback: HidReadCallback,
read_buf: Buffer,
@ -51,6 +52,7 @@ impl HidJob {
pid: u16,
read_endpoint: u8,
led_endpoint: u8,
disable_air: bool,
read_callback: HidReadCallback,
led_type: WriteType,
led_callback: HidLedCallback,
@ -61,6 +63,7 @@ impl HidJob {
pid,
read_endpoint,
led_endpoint,
disable_air,
read_callback,
read_buf: Buffer::new(),
last_read_buf: Buffer::new(),
@ -71,7 +74,7 @@ impl HidJob {
}
}
pub fn from_config(state: &SliderState, spec: &HardwareSpec) -> Self {
pub fn from_config(state: &SliderState, spec: &HardwareSpec, disable_air: &bool) -> Self {
match spec {
HardwareSpec::TasollerOne => Self::new(
state.clone(),
@ -79,6 +82,7 @@ impl HidJob {
0x2333,
0x84,
0x03,
*disable_air,
|buf, input| {
if buf.len != 11 {
return;
@ -121,6 +125,7 @@ impl HidJob {
0x2333,
0x84,
0x03,
*disable_air,
|buf, input| {
if buf.len != 36 {
return;
@ -157,6 +162,7 @@ impl HidJob {
0x2001,
0x81,
0x02,
*disable_air,
|buf, input| {
if buf.len != 34 {
return;
@ -246,6 +252,10 @@ impl ThreadJob for HidJob {
work = true;
let mut input_handle = self.state.input.lock();
(self.read_callback)(&self.read_buf, input_handle.deref_mut());
if self.disable_air {
input_handle.air.fill(0);
}
swap(&mut self.read_buf, &mut self.last_read_buf);
}
}

View File

@ -10,6 +10,7 @@
let outputMode = "none";
let ledMode = "none";
let disableAirStrings = false;
let divaSerialPort = "COM1";
let divaBrightness = 63;
let keyboardSensitivity = 20;
@ -58,6 +59,7 @@
outputMode = payload.outputMode || "none";
ledMode = payload.ledMode || "none";
disableAirStrings = payload.disableAirStrings || false;
divaSerialPort = payload.divaSerialPort || "COM1";
divaBrightness = payload.divaBrightness || 63;
keyboardSensitivity = payload.keyboardSensitivity || 20;
@ -101,12 +103,14 @@
async function setConfig() {
console.log("Updating config");
console.log(disableAirStrings);
await emit(
"setConfig",
JSON.stringify({
deviceMode,
outputMode,
ledMode,
disableAirStrings,
divaSerialPort,
divaBrightness,
keyboardSensitivity,
@ -170,13 +174,26 @@
<option value="diva">Slider over Serial</option>
<option value="brokenithm">Brokenithm</option>
<option value="brokenithm-led">Brokenithm + Led</option>
<option value="brokenithm-ground">Brokenithm, Ground only</option>
<option value="brokenithm-ground-led"
>Brokenithm + Led, Ground only</option
>
</select>
</div>
</div>
{#if deviceMode.slice(0, 8) === "tasoller" || deviceMode.slice(0, 7) === "yuancon" || deviceMode.slice(0, 10) === "brokenithm"}
<div class="row">
<div class="label" />
<div class="input">
<span>
<input
type="checkbox"
id="disable-air"
style="width: unset;"
bind:checked={disableAirStrings}
on:change={markDirty}
/>
<label for="disable-air">Disable Air Strings</label>
</span>
</div>
</div>
{/if}
{#if deviceMode.slice(0, 10) === "brokenithm"}
<div class="row">
<div class="label" />