add disable air strings option

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

View File

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

View File

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

View File

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

View File

@ -10,6 +10,7 @@
let outputMode = "none"; let outputMode = "none";
let ledMode = "none"; let ledMode = "none";
let disableAirStrings = false;
let divaSerialPort = "COM1"; let divaSerialPort = "COM1";
let divaBrightness = 63; let divaBrightness = 63;
let keyboardSensitivity = 20; let keyboardSensitivity = 20;
@ -58,6 +59,7 @@
outputMode = payload.outputMode || "none"; outputMode = payload.outputMode || "none";
ledMode = payload.ledMode || "none"; ledMode = payload.ledMode || "none";
disableAirStrings = payload.disableAirStrings || false;
divaSerialPort = payload.divaSerialPort || "COM1"; divaSerialPort = payload.divaSerialPort || "COM1";
divaBrightness = payload.divaBrightness || 63; divaBrightness = payload.divaBrightness || 63;
keyboardSensitivity = payload.keyboardSensitivity || 20; keyboardSensitivity = payload.keyboardSensitivity || 20;
@ -101,12 +103,14 @@
async function setConfig() { async function setConfig() {
console.log("Updating config"); console.log("Updating config");
console.log(disableAirStrings);
await emit( await emit(
"setConfig", "setConfig",
JSON.stringify({ JSON.stringify({
deviceMode, deviceMode,
outputMode, outputMode,
ledMode, ledMode,
disableAirStrings,
divaSerialPort, divaSerialPort,
divaBrightness, divaBrightness,
keyboardSensitivity, keyboardSensitivity,
@ -170,13 +174,26 @@
<option value="diva">Slider over Serial</option> <option value="diva">Slider over Serial</option>
<option value="brokenithm">Brokenithm</option> <option value="brokenithm">Brokenithm</option>
<option value="brokenithm-led">Brokenithm + Led</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> </select>
</div> </div>
</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"} {#if deviceMode.slice(0, 10) === "brokenithm"}
<div class="row"> <div class="row">
<div class="label" /> <div class="label" />