Buttplug sex toy control library
at master 73 lines 2.0 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; 14use std::sync::Arc; 15use std::sync::atomic::{AtomicU8, Ordering}; 16 17generic_protocol_setup!(SvakomIker, "svakom-iker"); 18 19#[derive(Default)] 20pub struct SvakomIker { 21 last_speeds: Arc<[AtomicU8; 2]>, 22} 23 24impl ProtocolHandler for SvakomIker { 25 fn keepalive_strategy(&self) -> ProtocolKeepaliveStrategy { 26 ProtocolKeepaliveStrategy::HardwareRequiredRepeatLastPacketStrategy 27 } 28 29 fn handle_output_vibrate_cmd( 30 &self, 31 feature_index: u32, 32 feature_id: uuid::Uuid, 33 speed: u32, 34 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 35 self.last_speeds[feature_index as usize].store(speed as u8, Ordering::Relaxed); 36 let vibe0 = self.last_speeds[0].load(Ordering::Relaxed); 37 let vibe1 = self.last_speeds[1].load(Ordering::Relaxed); 38 if vibe0 == 0 && vibe1 == 0 { 39 Ok(vec![ 40 HardwareWriteCmd::new( 41 &[feature_id], 42 Endpoint::Tx, 43 [0x55, 0x07, 0x00, 0x00, 0x00, 0x00].to_vec(), 44 false, 45 ) 46 .into(), 47 ]) 48 } else { 49 let mut msgs = vec![]; 50 msgs.push( 51 HardwareWriteCmd::new( 52 &[feature_id], 53 Endpoint::Tx, 54 [0x55, 0x03, 0x03, 0x00, 0x01, { vibe0 }].to_vec(), 55 false, 56 ) 57 .into(), 58 ); 59 if vibe1 > 0 { 60 msgs.push( 61 HardwareWriteCmd::new( 62 &[feature_id], 63 Endpoint::Tx, 64 [0x55, 0x07, 0x00, 0x00, { vibe1 }, 0x00].to_vec(), 65 false, 66 ) 67 .into(), 68 ); 69 } 70 Ok(msgs) 71 } 72 } 73}