Buttplug sex toy control library
1// Buttplug Rust Source Code File - See https://buttplug.io for more info.
2//
3// Copyright 2016-2023 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 uuid::Uuid;
9
10use crate::device::{
11 hardware::{HardwareCommand, HardwareWriteCmd},
12 protocol::{ProtocolHandler, ProtocolKeepaliveStrategy, generic_protocol_setup},
13};
14use buttplug_core::errors::ButtplugDeviceError;
15use buttplug_server_device_config::Endpoint;
16
17generic_protocol_setup!(SvakomV2, "svakom-v2");
18
19#[derive(Default)]
20pub struct SvakomV2 {}
21
22impl ProtocolHandler for SvakomV2 {
23 fn keepalive_strategy(&self) -> ProtocolKeepaliveStrategy {
24 ProtocolKeepaliveStrategy::HardwareRequiredRepeatLastPacketStrategy
25 }
26
27 fn handle_output_vibrate_cmd(
28 &self,
29 feature_index: u32,
30 feature_id: Uuid,
31 speed: u32,
32 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> {
33 if feature_index == 1 {
34 Ok(vec![
35 HardwareWriteCmd::new(
36 &[feature_id],
37 Endpoint::Tx,
38 [0x55, 0x06, 0x01, 0x00, speed as u8, speed as u8].to_vec(),
39 true,
40 )
41 .into(),
42 ])
43 } else {
44 Ok(vec![
45 HardwareWriteCmd::new(
46 &[feature_id],
47 Endpoint::Tx,
48 [
49 0x55,
50 0x03,
51 0x03,
52 0x00,
53 if speed == 0 { 0x00 } else { 0x01 },
54 speed as u8,
55 ]
56 .to_vec(),
57 true,
58 )
59 .into(),
60 ])
61 }
62 }
63}