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 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 LIBO_SHARK_PROTOCOL_UUID: Uuid = uuid!("c0044425-b59c-4037-a702-0438afcaad3e"); 20generic_protocol_setup!(LiboShark, "libo-shark"); 21 22#[derive(Default)] 23pub struct LiboShark { 24 values: [AtomicU8; 2], 25} 26 27impl ProtocolHandler for LiboShark { 28 fn handle_output_vibrate_cmd( 29 &self, 30 feature_index: u32, 31 _feature_id: Uuid, 32 speed: u32, 33 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 34 self.values[feature_index as usize].store(speed as u8, Ordering::Relaxed); 35 let data = self.values[0].load(Ordering::Relaxed) << 4 | self.values[1].load(Ordering::Relaxed); 36 Ok(vec![ 37 HardwareWriteCmd::new(&[LIBO_SHARK_PROTOCOL_UUID], Endpoint::Tx, vec![data], false).into(), 38 ]) 39 } 40}