add diva slider only layout without buttons

pull/13/head
4yn 2022-04-03 11:30:34 +08:00
parent f0ed581b3d
commit 1d9e52b92f
5 changed files with 44 additions and 6 deletions

View File

@ -27,6 +27,12 @@ pub enum GamepadLayout {
Neardayo, Neardayo,
} }
#[derive(Debug, Clone, Copy)]
pub enum HoriLayout {
Full,
SliderOnly,
}
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum OutputMode { pub enum OutputMode {
None, None,
@ -41,6 +47,7 @@ pub enum OutputMode {
sensitivity: u8, sensitivity: u8,
}, },
Hori { Hori {
layout: HoriLayout,
polling: PollingRate, polling: PollingRate,
sensitivity: u8, sensitivity: u8,
}, },
@ -128,6 +135,12 @@ impl OutputMode {
sensitivity: u8::try_from(v["keyboardSensitivity"].as_i64()?).ok()?, sensitivity: u8::try_from(v["keyboardSensitivity"].as_i64()?).ok()?,
}, },
"gamepad-hori" => OutputMode::Hori { "gamepad-hori" => OutputMode::Hori {
layout: HoriLayout::Full,
polling: PollingRate::from_str(v["outputPolling"].as_str()?)?,
sensitivity: u8::try_from(v["keyboardSensitivity"].as_i64()?).ok()?,
},
"gamepad-hori-wide" => OutputMode::Hori {
layout: HoriLayout::SliderOnly,
polling: PollingRate::from_str(v["outputPolling"].as_str()?)?, polling: PollingRate::from_str(v["outputPolling"].as_str()?)?,
sensitivity: u8::try_from(v["keyboardSensitivity"].as_i64()?).ok()?, sensitivity: u8::try_from(v["keyboardSensitivity"].as_i64()?).ok()?,
}, },

View File

@ -4,20 +4,27 @@ use vigem_client::{Client, DS4Report, DualShock4Wired, TargetId};
use crate::shared::hori::HoriState; use crate::shared::hori::HoriState;
use super::output::OutputHandler; use super::{config::HoriLayout, output::OutputHandler};
pub struct HoriOutput { pub struct HoriOutput {
target: DualShock4Wired<Client>, target: DualShock4Wired<Client>,
slider_only: bool,
gamepad: DS4Report, gamepad: DS4Report,
} }
impl HoriOutput { impl HoriOutput {
pub fn new() -> Option<Self> { pub fn new(layout: HoriLayout) -> Option<Self> {
let target = Self::get_target(); let target = Self::get_target();
let slider_only = match layout {
HoriLayout::Full => false,
HoriLayout::SliderOnly => true,
};
match target { match target {
Ok(target) => Some(Self { Ok(target) => Some(Self {
target, target,
slider_only,
gamepad: DS4Report::default(), gamepad: DS4Report::default(),
}), }),
Err(e) => { Err(e) => {
@ -50,7 +57,10 @@ impl HoriOutput {
impl OutputHandler for HoriOutput { impl OutputHandler for HoriOutput {
fn tick(&mut self, flat_input: &Vec<bool>) -> bool { fn tick(&mut self, flat_input: &Vec<bool>) -> bool {
let hori_state = HoriState::from_flat(flat_input); let hori_state = match self.slider_only {
false => HoriState::from_flat(flat_input),
true => HoriState::from_flat_to_wide(flat_input)
};
let buttons: u16 = hori_state let buttons: u16 = hori_state
.bt .bt

View File

@ -67,11 +67,12 @@ impl AsyncJob for OutputJob {
} }
} }
OutputMode::Hori { OutputMode::Hori {
layout,
polling, polling,
sensitivity, sensitivity,
} => { } => {
self.sensitivity = sensitivity; self.sensitivity = sensitivity;
let handler = HoriOutput::new(); let handler = HoriOutput::new(layout.clone());
self.timer = interval(Duration::from_micros(polling.to_t_u64())); self.timer = interval(Duration::from_micros(polling.to_t_u64()));
match handler { match handler {

View File

@ -24,4 +24,17 @@ impl HoriState {
hori_state hori_state
} }
pub fn from_flat_to_wide(flat_input: &Vec<bool>) -> Self {
let mut hori_state = Self {
slider: [false; 16],
bt: [false; 4],
};
for (idx, i) in flat_input[0..32].iter().enumerate() {
hori_state.slider[idx / 2] |= *i;
}
hori_state
}
} }

View File

@ -304,8 +304,9 @@
<option value="gamepad-neardayo" <option value="gamepad-neardayo"
>XBOX 360 Gamepad, Neardayo Layout</option >XBOX 360 Gamepad, Neardayo Layout</option
> >
<option value="gamepad-hori" <option value="gamepad-hori">DS4, HORI DIVA FT ASC Layout</option>
>DS4, HORI DIVA Future Tone ASC Layout</option <option value="gamepad-hori-wide"
>DS4, HORI DIVA FT ASC Slider Only Layout</option
> >
<!-- <option value="websocket">Websocket</option> --> <!-- <option value="websocket">Websocket</option> -->
</select> </select>