1
0
mirror of https://github.com/4yn/slidershim.git synced 2024-11-23 21:40:57 +01:00

add slower led update option

This commit is contained in:
4yn 2022-03-16 20:23:50 +08:00
parent ff6e971f62
commit 748a76cf06
4 changed files with 49 additions and 6 deletions

View File

@ -38,6 +38,7 @@ impl Config {
"keyboardSensitivity": 20,
"outputPolling": "100",
"outputWebsocketUrl": "localhost:3000",
"ledFaster": false,
"ledSensitivity": 20,
"ledWebsocketUrl": "localhost:3001",
"ledSerialPort": "COM5"

View File

@ -11,14 +11,19 @@ pub enum ReactiveLayout {
pub enum LightsMode {
None,
Reactive {
faster: bool,
layout: ReactiveLayout,
sensitivity: u8,
},
Attract,
Attract {
faster: bool,
},
Websocket {
faster: bool,
url: String,
},
Serial {
faster: bool,
port: String,
},
}
@ -28,30 +33,39 @@ impl LightsMode {
Some(match v["ledMode"].as_str()? {
"none" => LightsMode::None,
"reactive-4" => LightsMode::Reactive {
faster: v["ledFaster"].as_bool()?,
layout: ReactiveLayout::Even { splits: 4 },
sensitivity: u8::try_from(v["ledSensitivity"].as_i64()?).ok()?,
},
"reactive-8" => LightsMode::Reactive {
faster: v["ledFaster"].as_bool()?,
layout: ReactiveLayout::Even { splits: 8 },
sensitivity: u8::try_from(v["ledSensitivity"].as_i64()?).ok()?,
},
"reactive-16" => LightsMode::Reactive {
faster: v["ledFaster"].as_bool()?,
layout: ReactiveLayout::Even { splits: 16 },
sensitivity: u8::try_from(v["ledSensitivity"].as_i64()?).ok()?,
},
"reactive-rainbow" => LightsMode::Reactive {
faster: v["ledFaster"].as_bool()?,
layout: ReactiveLayout::Rainbow,
sensitivity: u8::try_from(v["ledSensitivity"].as_i64()?).ok()?,
},
"reactive-voltex" => LightsMode::Reactive {
faster: v["ledFaster"].as_bool()?,
layout: ReactiveLayout::Voltex,
sensitivity: u8::try_from(v["ledSensitivity"].as_i64()?).ok()?,
},
"attract" => LightsMode::Attract,
"attract" => LightsMode::Attract {
faster: v["ledFaster"].as_bool()?,
},
"websocket" => LightsMode::Websocket {
faster: v["ledFaster"].as_bool()?,
url: v["ledWebsocketUrl"].as_str()?.to_string(),
},
"serial" => LightsMode::Serial {
faster: v["ledFaster"].as_bool()?,
port: v["ledSerialPort"].as_str()?.to_string(),
},
_ => return None,

View File

@ -30,7 +30,15 @@ impl LightsJob {
mode: mode.clone(),
serial_port: None,
started: Instant::now(),
timer: interval(Duration::from_micros(33333)),
timer: match match mode {
LightsMode::Attract { faster, .. } => *faster,
LightsMode::Websocket { faster, .. } => *faster,
LightsMode::Serial { faster, .. } => *faster,
_ => false,
} {
false => interval(Duration::from_micros(66666)),
true => interval(Duration::from_micros(33333)),
},
}
}
@ -145,7 +153,7 @@ impl LightsJob {
}
}
}
LightsMode::Attract => {
LightsMode::Attract { .. } => {
let theta = self
.started
.elapsed()
@ -187,7 +195,7 @@ impl LightsJob {
impl AsyncJob for LightsJob {
async fn setup(&mut self) -> bool {
match &self.mode {
LightsMode::Serial { port } => {
LightsMode::Serial { port, .. } => {
info!(
"Serial port for led opening at {} {:?}",
port.as_str(),

View File

@ -16,6 +16,7 @@
let keyboardSensitivity = 20;
let outputPolling = "100";
let outputWebsocketUrl = "http://localhost:3000";
let ledFaster = false;
let ledSensitivity = 20;
let ledWebsocketUrl = "http://localhost:3001";
let ledSerialPort = "COM5";
@ -66,6 +67,7 @@
outputPolling = payload.outputPolling || "100";
outputWebsocketUrl =
payload.outputWebsocketUrl || "http://localhost:3000/";
ledFaster = payload.ledFaster || false;
ledSensitivity = payload.ledSensitivity || 20;
ledWebsocketUrl = payload.ledWebsocketUrl || "http://localhost:3001";
ledSerialPort = payload.ledSerialPort || "COM5";
@ -116,6 +118,7 @@
keyboardSensitivity,
outputPolling,
outputWebsocketUrl,
ledFaster,
ledSensitivity,
ledWebsocketUrl,
ledSerialPort,
@ -298,7 +301,7 @@
</div>
</div>
{/if}
{#if outputMode.slice(0, 2) === "kb" && deviceMode.slice(0, 10) !== "brokenithm"}
{#if (outputMode.slice(0, 2) === "kb" || outputMode.slice(0, 7) === "gamepad") && deviceMode.slice(0, 10) !== "brokenithm"}
<div class="row">
<div class="label" title="Larger means harder to trigger">
Sensitivity
@ -357,6 +360,23 @@
</select>
</div>
</div>
{#if ledMode !== "none"}
<div class="row">
<div class="label" />
<div class="input">
<span>
<input
type="checkbox"
id="led-faster"
style="width: unset;"
bind:checked={ledFaster}
on:change={markDirty}
/>
<label for="led-faster">Update LED data faster</label>
</span>
</div>
</div>
{/if}
{#if ledMode.slice(0, 8) === "reactive" && deviceMode.slice(0, 10) !== "brokenithm"}
<div class="row">
<div class="label" title="Larger means harder to trigger">