Buttplug sex toy control library
1// Buttplug Rust Source Code File - See https://buttplug.io for more info.
2//
3// Copyright 2016-2025 Nonpolynomial Labs LLC. All rights reserved.
4//
5// Licensed under the BSD 3-Clause license. See LICENSE file in the project root
6// for full license information.
7
8use crate::device::{
9 hardware::{HardwareCommand, HardwareWriteCmd},
10 protocol::{ProtocolHandler, ProtocolKeepaliveStrategy, generic_protocol_setup},
11};
12use buttplug_core::errors::ButtplugDeviceError;
13use buttplug_server_device_config::Endpoint;
14use std::time::Duration;
15use uuid::Uuid;
16
17generic_protocol_setup!(SexverseV3, "sexverse-v3");
18
19const SEXVERSE_COMMAND_DELAY_MS: u64 = 100;
20
21#[derive(Default)]
22pub struct SexverseV3 {}
23
24impl SexverseV3 {
25 fn form_command(
26 &self,
27 feature_index: u32,
28 feature_id: Uuid,
29 speed: u32,
30 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> {
31 Ok(vec![
32 HardwareWriteCmd::new(
33 &[feature_id],
34 Endpoint::Tx,
35 vec![0xa1, 0x04, speed as u8, feature_index as u8 + 1],
36 true,
37 )
38 .into(),
39 ])
40 }
41}
42
43impl ProtocolHandler for SexverseV3 {
44 fn keepalive_strategy(&self) -> ProtocolKeepaliveStrategy {
45 ProtocolKeepaliveStrategy::RepeatLastPacketStrategyWithTiming(Duration::from_millis(
46 SEXVERSE_COMMAND_DELAY_MS,
47 ))
48 }
49
50 fn handle_output_vibrate_cmd(
51 &self,
52 feature_index: u32,
53 feature_id: uuid::Uuid,
54 speed: u32,
55 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> {
56 self.form_command(feature_index, feature_id, speed)
57 }
58
59 fn handle_output_rotate_cmd(
60 &self,
61 feature_index: u32,
62 feature_id: uuid::Uuid,
63 speed: i32,
64 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> {
65 self.form_command(feature_index, feature_id, speed as u32)
66 }
67}