Buttplug sex toy control library
at dev 1.3 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!(LiboElle, "libo-elle"); 18 19#[derive(Default)] 20pub struct LiboElle {} 21 22impl ProtocolHandler for LiboElle { 23 fn handle_output_vibrate_cmd( 24 &self, 25 feature_index: u32, 26 feature_id: Uuid, 27 speed: u32, 28 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 29 Ok(vec![{ 30 let speed = speed as u8; 31 if feature_index == 1 { 32 let mut data = 0u8; 33 if speed > 0 && speed <= 7 { 34 data |= (speed - 1) << 4; 35 data |= 1; // Set the mode too 36 } else if speed > 7 { 37 data |= (speed - 8) << 4; 38 data |= 4; // Set the mode too 39 } 40 HardwareWriteCmd::new(&[feature_id], Endpoint::Tx, vec![data], false).into() 41 } else { 42 HardwareWriteCmd::new(&[feature_id], Endpoint::TxMode, vec![speed], false).into() 43 } 44 }]) 45 } 46}