Skip to content

Commit

Permalink
feat: Support Satisfyer devices with more than 2 vibes
Browse files Browse the repository at this point in the history
We've been sending packets of 8 bytes to all Satisfyer devices
so far, but it turns out that we should be sending 4 bytes per
feature. Right now the features are vibrators, oscilators or
single direction rotators (all map to VibrateCmd).

This change uses the feature count to initialise the length of
the data packet array, and dynamically loads the values into the
array before sending.
  • Loading branch information
blackspherefollower committed May 6, 2022
1 parent 3f3e1fe commit 90a898f
Showing 1 changed file with 14 additions and 24 deletions.
38 changes: 14 additions & 24 deletions buttplug/src/device/protocol/satisfyer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::{
};
use std::{sync::Arc, time::Duration};
use tokio::sync::Mutex;
use crate::core::messages::ButtplugDeviceMessageType::VibrateCmd;

#[derive(ButtplugProtocolProperties)]
pub struct Satisfyer {
Expand Down Expand Up @@ -94,7 +95,13 @@ impl ButtplugProtocol for Satisfyer {
)?;
// Now that we've initialized and constructed the device, start the update cycle to make sure
// we don't drop the connection.
let last_command = Arc::new(Mutex::new(vec![0u8; 8]));
let mut size: usize = 8;
if let Some(vattr) = attrs.get(&VibrateCmd) {
if let Some(count) = vattr.feature_count {
size = 4 * count as usize;
}
}
let last_command = Arc::new(Mutex::new(vec![0u8; size]));
let device = Self::new(&name, attrs, last_command.clone());
async_manager::spawn(async move {
send_satisfyer_updates(device_impl, last_command).await;
Expand All @@ -116,29 +123,12 @@ impl ButtplugProtocolCommandHandler for Satisfyer {
Box::pin(async move {
let result = manager.lock().await.update_vibration(&message, true)?;
if let Some(cmds) = result {
let data = if cmds.len() == 1 {
vec![
cmds[0].unwrap_or(0) as u8,
cmds[0].unwrap_or(0) as u8,
cmds[0].unwrap_or(0) as u8,
cmds[0].unwrap_or(0) as u8,
0x00,
0x00,
0x00,
0x00,
]
} else {
vec![
cmds[1].unwrap_or(0) as u8,
cmds[1].unwrap_or(0) as u8,
cmds[1].unwrap_or(0) as u8,
cmds[1].unwrap_or(0) as u8,
cmds[0].unwrap_or(0) as u8,
cmds[0].unwrap_or(0) as u8,
cmds[0].unwrap_or(0) as u8,
cmds[0].unwrap_or(0) as u8,
]
};
let mut data = vec![0u8; (cmds.len() * 4) as usize];
for (i, cmd) in cmds.iter().enumerate() {
for j in 0..4 {
data[(i * 4) + j] = cmd.unwrap_or(0) as u8
}
}
*last_command.lock().await = data.clone();
device
.write_value(DeviceWriteCmd::new(Endpoint::Tx, data, false))
Expand Down

0 comments on commit 90a898f

Please sign in to comment.