Buttplug sex toy control library
at master 2.0 kB view raw
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; 16 17generic_protocol_setup!(TCodeV03, "tcode-v03"); 18 19#[derive(Default)] 20pub struct TCodeV03 {} 21 22impl ProtocolHandler for TCodeV03 { 23 fn handle_output_position_cmd( 24 &self, 25 _feature_index: u32, 26 feature_id: Uuid, 27 position: u32, 28 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 29 let mut msg_vec = vec![]; 30 31 let command = format!("L0{position:03}\nR0{position:03}\n"); 32 msg_vec.push( 33 HardwareWriteCmd::new( 34 &[feature_id], 35 Endpoint::Tx, 36 command.as_bytes().to_vec(), 37 false, 38 ) 39 .into(), 40 ); 41 42 Ok(msg_vec) 43 } 44 45 fn handle_position_with_duration_cmd( 46 &self, 47 feature_index: u32, 48 feature_id: Uuid, 49 position: u32, 50 duration: u32, 51 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 52 let mut msg_vec = vec![]; 53 54 let command = format!("L{feature_index}{position:02}I{duration}\n"); 55 msg_vec.push( 56 HardwareWriteCmd::new( 57 &[feature_id], 58 Endpoint::Tx, 59 command.as_bytes().to_vec(), 60 false, 61 ) 62 .into(), 63 ); 64 65 Ok(msg_vec) 66 } 67 68 fn handle_output_vibrate_cmd( 69 &self, 70 feature_index: u32, 71 feature_id: Uuid, 72 speed: u32, 73 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 74 Ok(vec![ 75 HardwareWriteCmd::new( 76 &[feature_id], 77 Endpoint::Tx, 78 format!("V{feature_index}{speed:02}\n").as_bytes().to_vec(), 79 false, 80 ) 81 .into(), 82 ]) 83 } 84}