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 uuid::Uuid;
9
10use buttplug_core::errors::ButtplugDeviceError;
11use buttplug_server_device_config::Endpoint;
12
13use crate::device::{
14 hardware::{HardwareCommand, HardwareWriteCmd},
15 protocol::{ProtocolHandler, generic_protocol_setup},
16};
17use std::sync::atomic::{AtomicU8, Ordering};
18
19generic_protocol_setup!(TryFunBlackHole, "tryfun-blackhole");
20
21#[derive(Default)]
22pub struct TryFunBlackHole {
23 packet_id: AtomicU8,
24}
25
26impl ProtocolHandler for TryFunBlackHole {
27 fn handle_output_oscillate_cmd(
28 &self,
29 _feature_index: u32,
30 feature_id: Uuid,
31 speed: u32,
32 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> {
33 let mut sum: u8 = 0xff;
34 let mut data = vec![
35 self.packet_id.fetch_add(1, Ordering::Relaxed),
36 0x02,
37 0x00,
38 0x03,
39 0x0c,
40 speed as u8,
41 ];
42 let mut count = 1;
43 for item in data.iter().skip(1) {
44 sum -= item;
45 count += 1;
46 }
47 sum += count;
48 data.push(sum);
49
50 Ok(vec![
51 HardwareWriteCmd::new(&[feature_id], Endpoint::Tx, data, false).into(),
52 ])
53 }
54
55 fn handle_output_vibrate_cmd(
56 &self,
57 _feature_index: u32,
58 feature_id: Uuid,
59 speed: u32,
60 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> {
61 let mut sum: u8 = 0xff;
62 let mut data = vec![
63 self.packet_id.fetch_add(1, Ordering::Relaxed),
64 0x02,
65 0x00,
66 0x03,
67 0x09,
68 speed as u8,
69 ];
70 let mut count = 1;
71 for item in data.iter().skip(1) {
72 sum -= item;
73 count += 1;
74 }
75 sum += count;
76 data.push(sum);
77
78 Ok(vec![
79 HardwareWriteCmd::new(&[feature_id], Endpoint::Tx, data, false).into(),
80 ])
81 }
82}