Buttplug sex toy control library
at master 59 lines 1.8 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 super::mysteryvibe::MysteryVibe; 9use crate::device::{ 10 hardware::{Hardware, HardwareWriteCmd}, 11 protocol::{ 12 ProtocolHandler, 13 ProtocolIdentifier, 14 ProtocolInitializer, 15 generic_protocol_initializer_setup, 16 }, 17}; 18use async_trait::async_trait; 19use buttplug_core::errors::ButtplugDeviceError; 20use buttplug_server_device_config::Endpoint; 21use buttplug_server_device_config::{ 22 ProtocolCommunicationSpecifier, 23 ServerDeviceDefinition, 24 UserDeviceIdentifier, 25}; 26use std::sync::Arc; 27use uuid::{Uuid, uuid}; 28 29generic_protocol_initializer_setup!(MysteryVibeV2, "mysteryvibe-v2"); 30 31const MYSTERYVIBE_V2_PROTOCOL_UUID: Uuid = uuid!("215a2c34-11fa-419a-84d2-60ac6acbc9f8"); 32 33#[derive(Default)] 34pub struct MysteryVibeV2Initializer {} 35 36#[async_trait] 37impl ProtocolInitializer for MysteryVibeV2Initializer { 38 async fn initialize( 39 &mut self, 40 hardware: Arc<Hardware>, 41 def: &ServerDeviceDefinition, 42 ) -> Result<Arc<dyn ProtocolHandler>, ButtplugDeviceError> { 43 // The only thing that's different about MysteryVibeV2 from v1 is the initialization packet. 44 // Just send that then return the older protocol version. 45 let msg = HardwareWriteCmd::new( 46 &[MYSTERYVIBE_V2_PROTOCOL_UUID], 47 Endpoint::TxMode, 48 vec![0x03u8, 0x02u8, 0x40u8], 49 true, 50 ); 51 hardware.write_value(&msg).await?; 52 let vibrator_count = def 53 .features() 54 .iter() 55 .filter(|x| x.output().is_some()) 56 .count(); 57 Ok(Arc::new(MysteryVibe::new(vibrator_count as u8))) 58 } 59}