Buttplug sex toy control library
at master 54 lines 1.6 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 buttplug_core::errors::ButtplugDeviceError; 9use buttplug_server_device_config::Endpoint; 10use uuid::Uuid; 11 12use crate::device::{ 13 hardware::{HardwareCommand, HardwareWriteCmd}, 14 protocol::{ProtocolHandler, generic_protocol_setup}, 15}; 16 17generic_protocol_setup!(SvakomSuitcase, "svakom-suitcase"); 18 19#[derive(Default)] 20pub struct SvakomSuitcase {} 21 22impl ProtocolHandler for SvakomSuitcase { 23 // I am like 90% sure this is wrong since this device has two vibrators, but the original 24 // implementation made no sense in terms of knowing which command addressed which index. Putting 25 // in a best effort here and we'll see if anyone complains. 26 fn handle_output_vibrate_cmd( 27 &self, 28 _feature_index: u32, 29 feature_id: Uuid, 30 speed: u32, 31 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 32 let scalar = speed; 33 let mut speed = (scalar % 10) as u8; 34 let mut intensity = if scalar == 0 { 35 0u8 36 } else { 37 (scalar as f32 / 10.0).floor() as u8 + 1 38 }; 39 if speed == 0 && intensity != 0 { 40 // 10 -> 2,0 -> 1,A 41 speed = 10; 42 intensity -= 1; 43 } 44 Ok(vec![ 45 HardwareWriteCmd::new( 46 &[feature_id], 47 Endpoint::Tx, 48 [0x55, 0x03, 0x00, 0x00, intensity, speed].to_vec(), 49 false, 50 ) 51 .into(), 52 ]) 53 } 54}