Buttplug sex toy control library
at master 76 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 crate::device::{ 9 hardware::{HardwareCommand, HardwareWriteCmd}, 10 protocol::{ProtocolHandler, ProtocolKeepaliveStrategy, generic_protocol_setup}, 11}; 12use buttplug_core::errors::ButtplugDeviceError; 13use buttplug_server_device_config::Endpoint; 14 15generic_protocol_setup!(SvakomSam2, "svakom-sam2"); 16 17#[derive(Default)] 18pub struct SvakomSam2 {} 19 20impl ProtocolHandler for SvakomSam2 { 21 fn keepalive_strategy(&self) -> ProtocolKeepaliveStrategy { 22 ProtocolKeepaliveStrategy::HardwareRequiredRepeatLastPacketStrategy 23 } 24 25 fn handle_output_vibrate_cmd( 26 &self, 27 _feature_index: u32, 28 feature_id: uuid::Uuid, 29 speed: u32, 30 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 31 Ok(vec![ 32 HardwareWriteCmd::new( 33 &[feature_id], 34 Endpoint::Tx, 35 [ 36 0x55, 37 0x03, 38 0x00, 39 0x00, 40 if speed == 0 { 0x00 } else { 0x05 }, 41 speed as u8, 42 0x00, 43 ] 44 .to_vec(), 45 true, 46 ) 47 .into(), 48 ]) 49 } 50 51 fn handle_output_constrict_cmd( 52 &self, 53 _feature_index: u32, 54 feature_id: uuid::Uuid, 55 level: u32, 56 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 57 Ok(vec![ 58 HardwareWriteCmd::new( 59 &[feature_id], 60 Endpoint::Tx, 61 [ 62 0x55, 63 0x09, 64 0x00, 65 0x00, 66 if level == 0 { 0x00 } else { 0x01 }, 67 level as u8, 68 0x00, 69 ] 70 .to_vec(), 71 true, 72 ) 73 .into(), 74 ]) 75 } 76}