Skip to content

Commit fefa42f

Browse files
blackspherefollowerqdot
authored andcommitted
fix: Correct the handling of the Solace's oscillation range
1 parent 62b5d08 commit fefa42f

File tree

6 files changed

+195
-33
lines changed

6 files changed

+195
-33
lines changed

crates/buttplug_server/src/device/protocol_impl/lovense/lovense_multi_actuator.rs

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,26 @@ impl LovenseMultiActuator {
3131
}
3232
}
3333

34-
fn form_packet(&self) -> Vec<u8> {
35-
format!(
36-
"Mply:{};",
37-
self
38-
.vibrator_values
39-
.iter()
40-
.map(|v| v.load(Ordering::Relaxed).to_string())
41-
.collect::<Vec<String>>()
42-
.join(":")
43-
)
44-
.as_bytes()
45-
.to_vec()
34+
fn form_packet(&self) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> {
35+
Ok(vec![
36+
HardwareWriteCmd::new(
37+
&[LOVENSE_MPLY_PROTOCOL_UUID],
38+
Endpoint::Tx,
39+
format!(
40+
"Mply:{};",
41+
self
42+
.vibrator_values
43+
.iter()
44+
.map(|v| v.load(Ordering::Relaxed).to_string())
45+
.collect::<Vec<String>>()
46+
.join(":")
47+
)
48+
.as_bytes()
49+
.to_vec(),
50+
false,
51+
)
52+
.into(),
53+
])
4654
}
4755
}
4856

@@ -58,15 +66,7 @@ impl ProtocolHandler for LovenseMultiActuator {
5866
speed: u32,
5967
) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> {
6068
self.vibrator_values[feature_index as usize].store(speed, Ordering::Relaxed);
61-
Ok(vec![
62-
HardwareWriteCmd::new(
63-
&[LOVENSE_MPLY_PROTOCOL_UUID],
64-
Endpoint::Tx,
65-
self.form_packet(),
66-
false,
67-
)
68-
.into(),
69-
])
69+
self.form_packet()
7070
}
7171

7272
fn handle_output_rotate_cmd(
@@ -76,15 +76,7 @@ impl ProtocolHandler for LovenseMultiActuator {
7676
speed: i32,
7777
) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> {
7878
self.vibrator_values[feature_index as usize].store(speed.abs() as u32, Ordering::Relaxed);
79-
Ok(vec![
80-
HardwareWriteCmd::new(
81-
&[LOVENSE_MPLY_PROTOCOL_UUID],
82-
Endpoint::Tx,
83-
self.form_packet(),
84-
false,
85-
)
86-
.into(),
87-
])
79+
self.form_packet()
8880
}
8981

9082
fn handle_battery_level_cmd(

crates/buttplug_server/src/device/protocol_impl/lovense/lovense_stroker.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,25 @@ impl ProtocolHandler for LovenseStroker {
6868
) -> BoxFuture<'static, Result<InputReadingV4, ButtplugDeviceError>> {
6969
super::handle_battery_level_cmd(device_index, device, feature_index, feature_id)
7070
}
71+
72+
fn handle_output_oscillate_cmd(
73+
&self,
74+
_feature_index: u32,
75+
feature_id: Uuid,
76+
speed: u32,
77+
) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> {
78+
Ok(vec![
79+
HardwareWriteCmd::new(
80+
&[feature_id],
81+
Endpoint::Tx,
82+
format!("Mply:{}:{};", speed, if speed == 0 { 0 } else { 20 })
83+
.as_bytes()
84+
.to_vec(),
85+
false,
86+
)
87+
.into(),
88+
])
89+
}
7190
}
7291

7392
async fn update_linear_movement(device: Arc<Hardware>, linear_info: Arc<(AtomicU32, AtomicU32)>) {

crates/buttplug_server/src/device/protocol_impl/lovense/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,7 @@ impl ProtocolInitializer for LovenseInitializer {
231231

232232
// This might need better tuning if other complex Lovenses are released
233233
// Currently this only applies to the Flexer/Lapis/Solace
234-
let use_mply =
235-
(vibrator_count == 2 && output_count > 2) || vibrator_count > 2 || device_type == "H";
234+
let use_mply = (vibrator_count == 2 && output_count > 2) || vibrator_count > 2;
236235

237236
// New Lovense devices seem to be moving to the simplified LVS:<bytearray>; command format.
238237
// I'm not sure if there's a good way to detect this.
@@ -245,7 +244,7 @@ impl ProtocolInitializer for LovenseInitializer {
245244
if use_mply { "" } else { "not " }
246245
);
247246

248-
if device_type == "BA" {
247+
if device_type == "BA" || device_type == "H" {
249248
Ok(Arc::new(LovenseStroker::new(hardware)))
250249
} else if output_count == 1 {
251250
Ok(Arc::new(LovenseSingleActuator::default()))

crates/buttplug_tests/tests/test_device_protocols.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ async fn load_test_case(test_file: &str) -> DeviceTestCase {
7272
#[test_case("test_lovense_ridge_user_config.yaml" ; "Lovense Protocol - Lovense Ridge (User Config)")]
7373
#[test_case("test_lovense_ridge.yaml" ; "Lovense Protocol - Lovense Ridge (Oscillate)")]
7474
#[test_case("test_lovense_single_vibrator.yaml" ; "Lovense Protocol - Single Vibrator Device")]
75+
#[test_case("test_lovense_solace.yaml" ; "Lovense Protocol - Lovense Solace")]
76+
#[test_case("test_lovense_spinel.yaml" ; "Lovense Protocol - Lovense Spinel")]
7577
#[test_case("test_luvmazer_protocol.yaml" ; "Luvmazer Protocol")]
7678
#[test_case("test_magic_motion_1_magic_cell.yaml" ; "MagicMotion Protocol 1 - Magic Cell")]
7779
////#[test_case("test_magic_motion_2_eidolon.yaml" ; "MagicMotion Protocol 2 - Eidolon")]
@@ -195,6 +197,8 @@ async fn test_device_protocols_embedded_v4(test_file: &str) {
195197
#[test_case("test_lovense_ridge_user_config.yaml" ; "Lovense Protocol - Lovense Ridge (User Config)")]
196198
#[test_case("test_lovense_ridge.yaml" ; "Lovense Protocol - Lovense Ridge (Oscillate)")]
197199
#[test_case("test_lovense_single_vibrator.yaml" ; "Lovense Protocol - Single Vibrator Device")]
200+
#[test_case("test_lovense_solace.yaml" ; "Lovense Protocol - Lovense Solace")]
201+
#[test_case("test_lovense_spinel.yaml" ; "Lovense Protocol - Lovense Spinel")]
198202
#[test_case("test_luvmazer_protocol.yaml" ; "Luvmazer Protocol")]
199203
#[test_case("test_magic_motion_1_magic_cell.yaml" ; "MagicMotion Protocol 1 - Magic Cell")]
200204
////#[test_case("test_magic_motion_2_eidolon.yaml" ; "MagicMotion Protocol 2 - Eidolon")]
@@ -317,6 +321,8 @@ async fn test_device_protocols_json_v4(test_file: &str) {
317321
#[test_case("test_lovense_ridge_user_config.yaml" ; "Lovense Protocol - Lovense Ridge (User Config)")]
318322
#[test_case("test_lovense_ridge.yaml" ; "Lovense Protocol - Lovense Ridge (Oscillate)")]
319323
#[test_case("test_lovense_single_vibrator.yaml" ; "Lovense Protocol - Single Vibrator Device")]
324+
#[test_case("test_lovense_solace.yaml" ; "Lovense Protocol - Lovense Solace")]
325+
#[test_case("test_lovense_spinel.yaml" ; "Lovense Protocol - Lovense Spinel")]
320326
#[test_case("test_luvmazer_protocol.yaml" ; "Luvmazer Protocol")]
321327
#[test_case("test_magic_motion_1_magic_cell.yaml" ; "MagicMotion Protocol 1 - Magic Cell")]
322328
////#[test_case("test_magic_motion_2_eidolon.yaml" ; "MagicMotion Protocol 2 - Eidolon")]
@@ -440,6 +446,8 @@ async fn test_device_protocols_embedded_v3(test_file: &str) {
440446
#[test_case("test_lovense_ridge_user_config.yaml" ; "Lovense Protocol - Lovense Ridge (User Config)")]
441447
#[test_case("test_lovense_ridge.yaml" ; "Lovense Protocol - Lovense Ridge (Oscillate)")]
442448
#[test_case("test_lovense_single_vibrator.yaml" ; "Lovense Protocol - Single Vibrator Device")]
449+
#[test_case("test_lovense_solace.yaml" ; "Lovense Protocol - Lovense Solace")]
450+
#[test_case("test_lovense_spinel.yaml" ; "Lovense Protocol - Lovense Spinel")]
443451
#[test_case("test_luvmazer_protocol.yaml" ; "Luvmazer Protocol")]
444452
#[test_case("test_magic_motion_1_magic_cell.yaml" ; "MagicMotion Protocol 1 - Magic Cell")]
445453
////#[test_case("test_magic_motion_2_eidolon.yaml" ; "MagicMotion Protocol 2 - Eidolon")]
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
devices:
2+
- identifier:
3+
name: "LVS-DoesntMatter"
4+
expected_name: "Lovense Solace"
5+
device_init:
6+
# Initialization
7+
- !Commands
8+
device_index: 0
9+
commands:
10+
- !Subscribe
11+
endpoint: rx
12+
- !Write
13+
endpoint: tx
14+
# "DeviceType;"
15+
data: [68, 101, 118, 105, 99, 101, 84, 121, 112, 101, 59]
16+
write_with_response: false
17+
- !Events
18+
device_index: 0
19+
events:
20+
- !Notifications
21+
- endpoint: rx
22+
# "H:253:0082059AD3BD;"
23+
data: [72, 58, 50, 53, 50, 58, 48, 48, 56, 50, 48, 53, 57, 65, 68, 51, 66, 68, 59]
24+
device_commands:
25+
- !Messages
26+
device_index: 0
27+
messages:
28+
- !Scalar
29+
- Index: 0
30+
Scalar: 0.5
31+
ActuatorType: Oscillate
32+
- !Commands
33+
device_index: 0
34+
commands:
35+
- !Write
36+
endpoint: tx
37+
# "Mply:10:20;"
38+
data: [77, 112, 108, 121, 58, 49, 48, 58, 50, 48, 59]
39+
write_with_response: false
40+
- !Messages
41+
device_index: 0
42+
messages:
43+
- !Scalar
44+
- Index: 0
45+
Scalar: 0.75
46+
ActuatorType: Oscillate
47+
- !Commands
48+
device_index: 0
49+
commands:
50+
- !Write
51+
endpoint: tx
52+
# "Mply:15:20;"
53+
data: [77, 112, 108, 121, 58, 49, 53, 58, 50, 48, 59]
54+
write_with_response: false
55+
- !Messages
56+
device_index: 0
57+
messages:
58+
- !Stop
59+
- !Commands
60+
device_index: 0
61+
commands:
62+
- !Write
63+
endpoint: tx
64+
# "Mply:0:0;"
65+
data: [77, 112, 108, 121, 58, 48, 58, 48, 59]
66+
write_with_response: false
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
devices:
2+
- identifier:
3+
name: "LVS-DoesntMatter"
4+
expected_name: "Lovense Spinel"
5+
device_init:
6+
# Initialization
7+
- !Commands
8+
device_index: 0
9+
commands:
10+
- !Subscribe
11+
endpoint: rx
12+
- !Write
13+
endpoint: tx
14+
# "DeviceType;"
15+
data: [68, 101, 118, 105, 99, 101, 84, 121, 112, 101, 59]
16+
write_with_response: false
17+
- !Events
18+
device_index: 0
19+
events:
20+
- !Notifications
21+
- endpoint: rx
22+
# "WD:253:0082059AD3BD;"
23+
data: [87, 68, 58, 50, 53, 50, 58, 48, 48, 56, 50, 48, 53, 57, 65, 68, 51, 66, 68, 59]
24+
device_commands:
25+
- !Messages
26+
device_index: 0
27+
messages:
28+
- !Scalar
29+
- Index: 0
30+
Scalar: 0.5
31+
ActuatorType: Vibrate
32+
- Index: 1
33+
Scalar: 0.5
34+
ActuatorType: Oscillate
35+
- !Commands
36+
device_index: 0
37+
commands:
38+
- !Write
39+
endpoint: tx
40+
# "Vibrate1:10;"
41+
data: [86, 105, 98, 114, 97, 116, 101, 49, 58, 49, 48, 59]
42+
write_with_response: false
43+
- !Write
44+
endpoint: tx
45+
# "Vibrate2:10;"
46+
data: [86, 105, 98, 114, 97, 116, 101, 50, 58, 49, 48, 59]
47+
write_with_response: false
48+
- !Messages
49+
device_index: 0
50+
messages:
51+
- !Vibrate
52+
- Index: 0
53+
Speed: 0.75
54+
- !Commands
55+
device_index: 0
56+
commands:
57+
- !Write
58+
endpoint: tx
59+
# "Vibrate1:15;"
60+
data: [86, 105, 98, 114, 97, 116, 101, 49, 58, 49, 53, 59]
61+
write_with_response: false
62+
- !Messages
63+
device_index: 0
64+
messages:
65+
- !Stop
66+
- !Commands
67+
device_index: 0
68+
commands:
69+
- !Write
70+
endpoint: tx
71+
# "Vibrate1:0;"
72+
data: [86, 105, 98, 114, 97, 116, 101, 49, 58, 48, 59]
73+
write_with_response: false
74+
- !Write
75+
endpoint: tx
76+
# "Vibrate2:0;"
77+
data: [86, 105, 98, 114, 97, 116, 101, 50, 58, 48, 59]
78+
write_with_response: false

0 commit comments

Comments
 (0)