Skip to content

Commit f4b0660

Browse files
blackspherefollowerqdot
authored andcommitted
chore: Simplify the JoyHub implementation by using explicit feature indexes
1 parent a29f567 commit f4b0660

File tree

18 files changed

+1932
-2495
lines changed

18 files changed

+1932
-2495
lines changed

crates/buttplug_server/src/device/protocol_impl/joyhub/joyhub.rs renamed to crates/buttplug_server/src/device/protocol_impl/joyhub.rs

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ generic_protocol_setup!(JoyHub, "joyhub");
2222

2323
#[derive(Default)]
2424
pub struct JoyHub {
25-
last_cmds: [AtomicU8; 3],
25+
last_cmds: [AtomicU8; 4],
2626
}
2727

2828
impl JoyHub {
@@ -40,9 +40,9 @@ impl JoyHub {
4040
0xa0,
4141
0x03,
4242
self.last_cmds[0].load(Ordering::Relaxed),
43-
self.last_cmds[2].load(Ordering::Relaxed),
4443
self.last_cmds[1].load(Ordering::Relaxed),
45-
0x00,
44+
self.last_cmds[2].load(Ordering::Relaxed),
45+
self.last_cmds[3].load(Ordering::Relaxed),
4646
0xaa,
4747
],
4848
false,
@@ -68,7 +68,7 @@ impl ProtocolHandler for JoyHub {
6868
_feature_id: Uuid,
6969
speed: i32,
7070
) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> {
71-
self.form_hardware_command(feature_index, speed as u32)
71+
self.form_hardware_command(feature_index, speed.abs() as u32)
7272
}
7373

7474
fn handle_output_oscillate_cmd(
@@ -82,25 +82,37 @@ impl ProtocolHandler for JoyHub {
8282

8383
fn handle_output_constrict_cmd(
8484
&self,
85-
_feature_index: u32,
85+
feature_index: u32,
8686
feature_id: Uuid,
8787
level: u32,
8888
) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> {
89-
Ok(vec![
90-
HardwareWriteCmd::new(
91-
&[feature_id],
92-
Endpoint::Tx,
93-
vec![
94-
0xa0,
95-
0x07,
96-
if level == 0 { 0x00 } else { 0x01 },
97-
0x00,
98-
level as u8,
99-
0xff,
100-
],
101-
false,
102-
)
103-
.into(),
104-
])
89+
if feature_index == 4 {
90+
Ok(vec![
91+
HardwareWriteCmd::new(
92+
&[feature_id],
93+
Endpoint::Tx,
94+
vec![
95+
0xa0,
96+
0x07,
97+
if level == 0 { 0x00 } else { 0x01 },
98+
0x00,
99+
level as u8,
100+
0xff,
101+
],
102+
false,
103+
)
104+
.into(),
105+
])
106+
} else {
107+
Ok(vec![
108+
HardwareWriteCmd::new(
109+
&[feature_id],
110+
Endpoint::Tx,
111+
vec![0xa0, 0x0d, 0x00, 0x00, level as u8, 0xff],
112+
false,
113+
)
114+
.into(),
115+
])
116+
}
105117
}
106118
}

crates/buttplug_server/src/device/protocol_impl/joyhub/joyhub_v2.rs

Lines changed: 0 additions & 99 deletions
This file was deleted.

crates/buttplug_server/src/device/protocol_impl/joyhub/joyhub_v3.rs

Lines changed: 0 additions & 39 deletions
This file was deleted.

crates/buttplug_server/src/device/protocol_impl/joyhub/joyhub_v4.rs

Lines changed: 0 additions & 105 deletions
This file was deleted.

0 commit comments

Comments
 (0)