Buttplug sex toy control library
at dev 2.2 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 crate::device::{ 9 hardware::{Hardware, HardwareCommand, HardwareSubscribeCmd, HardwareWriteCmd}, 10 protocol::{ 11 ProtocolHandler, 12 ProtocolIdentifier, 13 ProtocolInitializer, 14 generic_protocol_initializer_setup, 15 }, 16}; 17use async_trait::async_trait; 18use buttplug_core::errors::ButtplugDeviceError; 19use buttplug_server_device_config::Endpoint; 20use buttplug_server_device_config::{ 21 ProtocolCommunicationSpecifier, 22 ServerDeviceDefinition, 23 UserDeviceIdentifier, 24}; 25use std::sync::Arc; 26use uuid::{Uuid, uuid}; 27 28const LIONESS_PROTOCOL_UUID: Uuid = uuid!("1912c626-f611-4569-9d62-fb40ff8e1474"); 29generic_protocol_initializer_setup!(Lioness, "lioness"); 30 31#[derive(Default)] 32pub struct LionessInitializer {} 33 34#[async_trait] 35impl ProtocolInitializer for LionessInitializer { 36 async fn initialize( 37 &mut self, 38 hardware: Arc<Hardware>, 39 _: &ServerDeviceDefinition, 40 ) -> Result<Arc<dyn ProtocolHandler>, ButtplugDeviceError> { 41 hardware 42 .subscribe(&HardwareSubscribeCmd::new( 43 LIONESS_PROTOCOL_UUID, 44 Endpoint::Rx, 45 )) 46 .await?; 47 48 let res = hardware 49 .write_value(&HardwareWriteCmd::new( 50 &[LIONESS_PROTOCOL_UUID], 51 Endpoint::Tx, 52 vec![0x01, 0xAA, 0xAA, 0xBB, 0xCC, 0x10], 53 true, 54 )) 55 .await; 56 57 if res.is_err() { 58 return Err(ButtplugDeviceError::DeviceCommunicationError( 59 "Lioness may need pairing with OS. Use PIN 6496 or 006496 when pairing.".to_string(), 60 )); 61 } 62 Ok(Arc::new(Lioness::default())) 63 } 64} 65 66#[derive(Default)] 67pub struct Lioness {} 68 69impl ProtocolHandler for Lioness { 70 fn handle_output_vibrate_cmd( 71 &self, 72 _feature_index: u32, 73 feature_id: Uuid, 74 speed: u32, 75 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 76 Ok(vec![ 77 HardwareWriteCmd::new( 78 &[feature_id], 79 Endpoint::Tx, 80 vec![0x02, 0xAA, 0xBB, 0xCC, 0xCC, speed as u8], 81 false, 82 ) 83 .into(), 84 ]) 85 } 86}