From 404c538cf67b9695d772d95f97aea65484c9b874 Mon Sep 17 00:00:00 2001 From: blackspherefollower Date: Fri, 20 Oct 2023 14:33:42 +0100 Subject: [PATCH] fix: Correcting vibe handling for Sam Neo Gen2 --- .../buttplug-device-config.json | 3 +- .../buttplug-device-config.yml | 1 + .../src/server/device/protocol/svakom_sam.rs | 37 ++++++++++++++++--- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/buttplug/buttplug-device-config/buttplug-device-config.json b/buttplug/buttplug-device-config/buttplug-device-config.json index d767b84ff..ae8eb979c 100644 --- a/buttplug/buttplug-device-config/buttplug-device-config.json +++ b/buttplug/buttplug-device-config/buttplug-device-config.json @@ -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" } } }, diff --git a/buttplug/buttplug-device-config/buttplug-device-config.yml b/buttplug/buttplug-device-config/buttplug-device-config.yml index 14cc9684d..876a32940 100644 --- a/buttplug/buttplug-device-config/buttplug-device-config.yml +++ b/buttplug/buttplug-device-config/buttplug-device-config.yml @@ -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: diff --git a/buttplug/src/server/device/protocol/svakom_sam.rs b/buttplug/src/server/device/protocol/svakom_sam.rs index 2f6c44aed..726ea1d2c 100644 --- a/buttplug/src/server/device/protocol/svakom_sam.rs +++ b/buttplug/src/server/device/protocol/svakom_sam.rs @@ -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, @@ -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 { @@ -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 {