Buttplug sex toy control library
at dev 2.0 kB view raw
1// Buttplug Rust Source Code File - See https://buttplug.io for more info. 2// 3// Copyright 2016-2025 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 std::sync::atomic::{AtomicU8, Ordering}; 9 10use uuid::{Uuid, uuid}; 11 12use crate::device::{ 13 hardware::{HardwareCommand, HardwareWriteCmd}, 14 protocol::{ProtocolHandler, generic_protocol_setup}, 15}; 16use buttplug_core::errors::ButtplugDeviceError; 17use buttplug_server_device_config::Endpoint; 18 19const BANANASOME_PROTOCOL_UUID: Uuid = uuid!("a0a2e5f8-3692-4f6b-8add-043513ed86f6"); 20generic_protocol_setup!(Bananasome, "bananasome"); 21 22pub struct Bananasome { 23 current_commands: [AtomicU8; 3], 24} 25 26impl Default for Bananasome { 27 fn default() -> Self { 28 Self { 29 current_commands: [AtomicU8::new(0), AtomicU8::new(0), AtomicU8::new(0)], 30 } 31 } 32} 33 34impl Bananasome { 35 fn hardware_command(&self, feature_index: u32, speed: u32) -> Vec<HardwareCommand> { 36 self.current_commands[feature_index as usize].store(speed as u8, Ordering::Relaxed); 37 vec![ 38 HardwareWriteCmd::new( 39 &[BANANASOME_PROTOCOL_UUID], 40 Endpoint::Tx, 41 vec![ 42 0xa0, 43 0x03, 44 self.current_commands[0].load(Ordering::Relaxed), 45 self.current_commands[1].load(Ordering::Relaxed), 46 self.current_commands[2].load(Ordering::Relaxed), 47 ], 48 false, 49 ) 50 .into(), 51 ] 52 } 53} 54 55impl ProtocolHandler for Bananasome { 56 fn handle_output_oscillate_cmd( 57 &self, 58 feature_index: u32, 59 _feature_id: Uuid, 60 speed: u32, 61 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 62 Ok(self.hardware_command(feature_index, speed)) 63 } 64 65 fn handle_output_vibrate_cmd( 66 &self, 67 feature_index: u32, 68 _feature_id: Uuid, 69 speed: u32, 70 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 71 Ok(self.hardware_command(feature_index, speed)) 72 } 73}