Skip to content

Commit

Permalink
fix: Correcting vibe handling for Sam Neo Gen2
Browse files Browse the repository at this point in the history
  • Loading branch information
blackspherefollower authored and qdot committed Oct 20, 2023
1 parent 4a3ab9a commit 404c538
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
3 changes: 2 additions & 1 deletion buttplug/buttplug-device-config/buttplug-device-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3822,7 +3822,8 @@
"services": {
"0000ae00-0000-1000-8000-00805f9b34fb": {
"tx": "0000ae01-0000-1000-8000-00805f9b34fb",
"rx": "0000ae02-0000-1000-8000-00805f9b34fb"
"rx": "0000ae02-0000-1000-8000-00805f9b34fb",
"txmode": "0000ae10-0000-1000-8000-00805f9b34fb"
}
}
},
Expand Down
1 change: 1 addition & 0 deletions buttplug/buttplug-device-config/buttplug-device-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1936,6 +1936,7 @@ protocols:
0000ae00-0000-1000-8000-00805f9b34fb:
tx: 0000ae01-0000-1000-8000-00805f9b34fb
rx: 0000ae02-0000-1000-8000-00805f9b34fb
txmode: 0000ae10-0000-1000-8000-00805f9b34fb
defaults:
name: Svakom Sam Neo
messages:
Expand Down
37 changes: 32 additions & 5 deletions buttplug/src/server/device/protocol/svakom_sam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Licensed under the BSD 3-Clause license. See LICENSE file in the project root
// for full license information.

use crate::server::device::hardware::HardwareSubscribeCmd;
use crate::server::device::hardware::{HardwareReadCmd, HardwareSubscribeCmd};
use crate::{
core::{
errors::ButtplugDeviceError,
Expand Down Expand Up @@ -41,12 +41,22 @@ impl ProtocolInitializer for SvakomSamInitializer {
hardware
.subscribe(&HardwareSubscribeCmd::new(Endpoint::Rx))
.await?;
Ok(Arc::new(SvakomSam::default()))
let gen2 = hardware
.read_value(&HardwareReadCmd::new(Endpoint::TxMode, 16, 500))
.await
.is_ok();
Ok(Arc::new(SvakomSam::new(gen2)))
}
}

#[derive(Default)]
pub struct SvakomSam {}
pub struct SvakomSam {
gen2: bool,
}
impl SvakomSam {
pub fn new(gen2: bool) -> Self {
Self { gen2 }
}
}

impl ProtocolHandler for SvakomSam {
fn keepalive_strategy(&self) -> super::ProtocolKeepaliveStrategy {
Expand All @@ -60,7 +70,24 @@ impl ProtocolHandler for SvakomSam {
let mut msg_vec = vec![];
if let Some((_, speed)) = cmds[0] {
msg_vec.push(
HardwareWriteCmd::new(Endpoint::Tx, [18, 1, 3, 0, 5, speed as u8].to_vec(), false).into(),
HardwareWriteCmd::new(
Endpoint::Tx,
if self.gen2 {
[
18,
1,
3,
0,
if speed == 0 { 0x00 } else { 0x04 },
speed as u8,
]
.to_vec()
} else {
[18, 1, 3, 0, 5, speed as u8].to_vec()
},
false,
)
.into(),
);
}
if cmds.len() > 1 {
Expand Down

0 comments on commit 404c538

Please sign in to comment.