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;
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;
16generic_protocol_setup!(ActiveJoy, "activejoy");
17
18#[derive(Default)]
19pub struct ActiveJoy {}
20
21impl ProtocolHandler for ActiveJoy {
22 fn handle_output_vibrate_cmd(
23 &self,
24 feature_index: u32,
25 feature_id: Uuid,
26 speed: u32,
27 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> {
28 Ok(vec![
29 HardwareWriteCmd::new(
30 &[feature_id],
31 Endpoint::Tx,
32 [
33 0xb0, // static header
34 0x01, // mode: 1=vibe, 5=shock, 6=thrust, 7=suction, 8=rotation, 16=swing,
35 0x00, // strong mode = 1 (thrust, suction, swing, rotate)
36 feature_index as u8, // 0 unless vibe2
37 if speed == 0 { 0x00 } else { 0x01 },
38 speed as u8,
39 ]
40 .to_vec(),
41 false,
42 )
43 .into(),
44 ])
45 }
46}