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; 10 11use crate::device::{ 12 hardware::{HardwareCommand, HardwareWriteCmd}, 13 protocol::{ProtocolHandler, generic_protocol_setup}, 14}; 15 16generic_protocol_setup!(TryFun, "tryfun"); 17 18#[derive(Default)] 19pub struct TryFun {} 20 21impl ProtocolHandler for TryFun { 22 fn handle_output_oscillate_cmd( 23 &self, 24 _feature_index: u32, 25 feature_id: uuid::Uuid, 26 speed: u32, 27 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 28 let mut sum: u8 = 0xff; 29 let mut data = vec![0xAA, 0x02, 0x07, speed as u8]; 30 let mut count = 0; 31 for item in data.iter().skip(1) { 32 sum -= item; 33 count += 1; 34 } 35 sum += count; 36 data.push(sum); 37 38 Ok(vec![ 39 HardwareWriteCmd::new(&[feature_id], Endpoint::Tx, data, true).into(), 40 ]) 41 } 42 43 fn handle_output_rotate_cmd( 44 &self, 45 _feature_index: u32, 46 feature_id: uuid::Uuid, 47 speed: i32, 48 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 49 let mut sum: u8 = 0xff; 50 let mut data = vec![0xAA, 0x02, 0x08, speed as u8]; 51 let mut count = 0; 52 for item in data.iter().skip(1) { 53 sum -= item; 54 count += 1; 55 } 56 sum += count; 57 data.push(sum); 58 59 Ok(vec![ 60 HardwareWriteCmd::new(&[feature_id], Endpoint::Tx, data, true).into(), 61 ]) 62 } 63 64 fn handle_output_vibrate_cmd( 65 &self, 66 _feature_index: u32, 67 feature_id: uuid::Uuid, 68 speed: u32, 69 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 70 Ok(vec![ 71 HardwareWriteCmd::new( 72 &[feature_id], 73 Endpoint::Tx, 74 vec![ 75 0x00, 76 0x02, 77 0x00, 78 0x05, 79 if speed == 0 { 1u8 } else { 2u8 }, 80 if speed == 0 { 2u8 } else { speed as u8 }, 81 0x01, 82 if speed == 0 { 1u8 } else { 0u8 }, 83 0xfd - (speed as u8).max(1), 84 ], 85 true, 86 ) 87 .into(), 88 ]) 89 } 90}