Buttplug sex toy control library
1// Buttplug Rust Source Code File - See https://buttplug.io for more info.
2//
3// Copyright 2016-2024 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 buttplug_core::errors::ButtplugDeviceError;
9use buttplug_server_device_config::Endpoint;
10use uuid::Uuid;
11
12use crate::device::{
13 hardware::{HardwareCommand, HardwareWriteCmd},
14 protocol::{ProtocolHandler, generic_protocol_setup},
15};
16
17generic_protocol_setup!(SvakomDT250A, "svakom-dt250a");
18
19#[derive(Default)]
20pub struct SvakomDT250A {}
21
22impl SvakomDT250A {
23 // Note: This protocol used to have a mode byte that was set in cases where multiple commands were
24 // sent at the same time. This has been removed in the v10 line, but may cause issues. If we get
25 // bug reports on that, we may need to revisit this implementation.
26
27 fn form_hardware_command(
28 &self,
29 mode: u8,
30 feature_id: Uuid,
31 speed: u32,
32 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> {
33 Ok(vec![
34 HardwareWriteCmd::new(
35 &[feature_id],
36 Endpoint::Tx,
37 [
38 0x55,
39 mode,
40 0x00,
41 0x00,
42 if speed == 0 { 0x00 } else { 0x01 },
43 speed as u8,
44 ]
45 .to_vec(),
46 false,
47 )
48 .into(),
49 ])
50 }
51}
52
53impl ProtocolHandler for SvakomDT250A {
54 fn handle_output_vibrate_cmd(
55 &self,
56 _feature_index: u32,
57 feature_id: uuid::Uuid,
58 speed: u32,
59 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> {
60 self.form_hardware_command(0x03, feature_id, speed)
61 }
62
63 fn handle_output_constrict_cmd(
64 &self,
65 _feature_index: u32,
66 feature_id: uuid::Uuid,
67 level: u32,
68 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> {
69 self.form_hardware_command(0x08, feature_id, level)
70 }
71}