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 uuid::{Uuid, uuid};
9
10use crate::device::{
11 hardware::{HardwareCommand, HardwareWriteCmd},
12 protocol::{ProtocolHandler, generic_protocol_setup},
13};
14use buttplug_core::errors::ButtplugDeviceError;
15use buttplug_server_device_config::Endpoint;
16
17const LIBO_VIBES_PROTOCOL_UUID: Uuid = uuid!("72a3d029-cf33-4fff-beec-1c45b85cc8ae");
18generic_protocol_setup!(LiboVibes, "libo-vibes");
19
20#[derive(Default)]
21pub struct LiboVibes {}
22
23impl ProtocolHandler for LiboVibes {
24 fn handle_output_vibrate_cmd(
25 &self,
26 feature_index: u32,
27 _feature_id: Uuid,
28 speed: u32,
29 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> {
30 let mut msg_vec = vec![];
31 if feature_index == 0 {
32 msg_vec.push(
33 HardwareWriteCmd::new(
34 &[LIBO_VIBES_PROTOCOL_UUID],
35 Endpoint::Tx,
36 vec![speed as u8],
37 false,
38 )
39 .into(),
40 );
41 // If this is a single vibe device, we need to send stop to TxMode too
42 if speed as u8 == 0 {
43 msg_vec.push(
44 HardwareWriteCmd::new(
45 &[LIBO_VIBES_PROTOCOL_UUID],
46 Endpoint::TxMode,
47 vec![0u8],
48 false,
49 )
50 .into(),
51 );
52 }
53 } else if feature_index == 1 {
54 msg_vec.push(
55 HardwareWriteCmd::new(
56 &[LIBO_VIBES_PROTOCOL_UUID],
57 Endpoint::TxMode,
58 vec![speed as u8],
59 false,
60 )
61 .into(),
62 );
63 }
64 Ok(msg_vec)
65 }
66}