Skip to content

Commit

Permalink
feat: Adding support for the Lovense Solace
Browse files Browse the repository at this point in the history
The depth is locked to max:20
  • Loading branch information
blackspherefollower authored and qdot committed Nov 16, 2023
1 parent 0018d68 commit 1babf7a
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 19 deletions.
22 changes: 22 additions & 0 deletions buttplug/buttplug-device-config/buttplug-device-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@
"53440001-0023-4bd4-bbd5-a6920e4c5653": {
"tx": "53440002-0023-4bd4-bbd5-a6920e4c5653",
"rx": "53440003-0023-4bd4-bbd5-a6920e4c5653"
},
"48300001-0023-4bd4-bbd5-a6920e4c5653": {
"tx": "48300002-0023-4bd4-bbd5-a6920e4c5653",
"rx": "48300003-0023-4bd4-bbd5-a6920e4c5653"
}
}
},
Expand Down Expand Up @@ -563,6 +567,24 @@
"SD"
],
"name": "Lovense Vulse"
},
{
"identifier": [
"H"
],
"name": "Lovense Solace",
"messages": {
"ScalarCmd": [
{
"StepRange": [
0,
20
],
"ActuatorType": "Oscillate",
"FeatureDescriptor": "Stroker Oscillation Speed"
}
]
}
}
]
},
Expand Down
13 changes: 12 additions & 1 deletion buttplug/buttplug-device-config/buttplug-device-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
# user in the user device config file.
version:
major: 2
minor: 21
minor: 22
protocols:
lovense:
# Lovense is special. Special in oh so many ways.
Expand Down Expand Up @@ -202,6 +202,9 @@ protocols:
53440001-0023-4bd4-bbd5-a6920e4c5653: # Vulse
tx: 53440002-0023-4bd4-bbd5-a6920e4c5653
rx: 53440003-0023-4bd4-bbd5-a6920e4c5653
48300001-0023-4bd4-bbd5-a6920e4c5653: # Solace
tx: 48300002-0023-4bd4-bbd5-a6920e4c5653
rx: 48300003-0023-4bd4-bbd5-a6920e4c5653
defaults:
name: Lovense Device
messages:
Expand Down Expand Up @@ -380,6 +383,14 @@ protocols:
- identifier:
- SD
name: Lovense Vulse
- identifier:
- H
name: Lovense Solace
messages:
ScalarCmd:
- StepRange: [0, 20]
ActuatorType: Oscillate
FeatureDescriptor: Stroker Oscillation Speed
lovense-connect-service:
lovense-connect-service:
exists: true
Expand Down
50 changes: 32 additions & 18 deletions buttplug/src/server/device/protocol/lovense.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ impl ProtocolIdentifier for LovenseIdentifier {
if let Ok(HardwareEvent::Notification(_, _, n)) = event {
let type_response = std::str::from_utf8(&n).map_err(|_| ButtplugDeviceError::ProtocolSpecificError("lovense".to_owned(), "Lovense device init got back non-UTF8 string.".to_owned()))?.to_owned();
info!("Lovense Device Type Response: {}", type_response);
return Ok((ServerDeviceIdentifier::new(hardware.address(), "lovense", &ProtocolAttributesType::Identifier(lovense_model_resolver(type_response))), Box::new(LovenseInitializer::default())));
let ident = lovense_model_resolver(type_response);
return Ok((ServerDeviceIdentifier::new(hardware.address(), "lovense", &ProtocolAttributesType::Identifier(ident.clone())), Box::new(LovenseInitializer::new(ident))));
} else {
return Err(
ButtplugDeviceError::ProtocolSpecificError(
Expand All @@ -116,18 +117,24 @@ impl ProtocolIdentifier for LovenseIdentifier {
let re = Regex::new(r"LVS-([A-Z]+)\d+").expect("Static regex shouldn't fail");
if let Some(caps) = re.captures(hardware.name()) {
info!("Lovense Device identified by BLE name");
return Ok((ServerDeviceIdentifier::new(hardware.address(), "lovense", &ProtocolAttributesType::Identifier(caps[1].to_string())), Box::new(LovenseInitializer::default())));
return Ok((ServerDeviceIdentifier::new(hardware.address(), "lovense", &ProtocolAttributesType::Identifier(caps[1].to_string())), Box::new(LovenseInitializer::new(caps[1].to_string()))));
};
return Ok((ServerDeviceIdentifier::new(hardware.address(), "lovense", &ProtocolAttributesType::Default), Box::new(LovenseInitializer::default())));
return Ok((ServerDeviceIdentifier::new(hardware.address(), "lovense", &ProtocolAttributesType::Default), Box::new(LovenseInitializer::new("".to_string()))));
}
}
}
}
}
}
pub struct LovenseInitializer {
device_type: String,
}

#[derive(Default)]
pub struct LovenseInitializer {}
impl LovenseInitializer {
pub fn new(device_type: String) -> Self {
Self { device_type }
}
}

#[async_trait]
impl ProtocolInitializer for LovenseInitializer {
Expand All @@ -137,6 +144,7 @@ impl ProtocolInitializer for LovenseInitializer {
attributes: &ProtocolDeviceAttributes,
) -> Result<Arc<dyn ProtocolHandler>, ButtplugDeviceError> {
let mut protocol = Lovense::default();
protocol.device_type = self.device_type.clone();

if let Some(scalars) = attributes.message_attributes.scalar_cmd() {
protocol.vibrator_count = scalars
Expand All @@ -146,8 +154,11 @@ impl ProtocolInitializer for LovenseInitializer {
.count();

// This might need better tuning if other complex Lovenses are released
// Currently this only applies to the Flexer
if (protocol.vibrator_count == 2 && scalars.len() > 2) || protocol.vibrator_count > 2 {
// Currently this only applies to the Flexer/Lapis/Solace
if (protocol.vibrator_count == 2 && scalars.len() > 2)
|| protocol.vibrator_count > 2
|| protocol.device_type == "H"
{
protocol.use_mply = true;
}
}
Expand All @@ -161,6 +172,7 @@ pub struct Lovense {
rotation_direction: Arc<AtomicBool>,
vibrator_count: usize,
use_mply: bool,
device_type: String,
}

impl ProtocolHandler for Lovense {
Expand All @@ -178,20 +190,22 @@ impl ProtocolHandler for Lovense {
cmds: &[Option<(ActuatorType, u32)>],
) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> {
if self.use_mply {
let lovense_cmd = format!(
"Mply:{};",
cmds
.iter()
.map(|x| if let Some(val) = x {
let mut speeds = cmds
.iter()
.map(|x| {
if let Some(val) = x {
val.1.to_string()
} else {
"-1".to_string()
})
.collect::<Vec<_>>()
.join(":")
)
.as_bytes()
.to_vec();
}
})
.collect::<Vec<_>>();

if speeds.len() == 1 && self.device_type == "H" {
speeds.push("20".to_string()); // Max range
}

let lovense_cmd = format!("Mply:{};", speeds.join(":")).as_bytes().to_vec();

return Ok(vec![HardwareWriteCmd::new(
Endpoint::Tx,
Expand Down

0 comments on commit 1babf7a

Please sign in to comment.