Buttplug sex toy control library
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, 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 NOBRA_PROTOCOL_UUID: Uuid = uuid!("166e7d2b-b9ed-4769-aaaf-66127e4e14eb"); 29generic_protocol_initializer_setup!(Nobra, "nobra"); 30 31#[derive(Default)] 32pub struct NobraInitializer {} 33 34#[async_trait] 35impl ProtocolInitializer for NobraInitializer { 36 async fn initialize( 37 &mut self, 38 hardware: Arc<Hardware>, 39 _: &ServerDeviceDefinition, 40 ) -> Result<Arc<dyn ProtocolHandler>, ButtplugDeviceError> { 41 hardware 42 .write_value(&HardwareWriteCmd::new( 43 &[NOBRA_PROTOCOL_UUID], 44 Endpoint::Tx, 45 vec![0x70], 46 false, 47 )) 48 .await?; 49 Ok(Arc::new(Nobra::default())) 50 } 51} 52 53#[derive(Default)] 54pub struct Nobra {} 55 56impl ProtocolHandler for Nobra { 57 fn handle_output_vibrate_cmd( 58 &self, 59 _feature_index: u32, 60 feature_id: Uuid, 61 speed: u32, 62 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 63 let output_speed = if speed == 0 { 0x70 } else { 0x60 + speed }; 64 Ok(vec![ 65 HardwareWriteCmd::new(&[feature_id], Endpoint::Tx, vec![output_speed as u8], false).into(), 66 ]) 67 } 68}