Buttplug sex toy control library
1// Buttplug Rust Source Code File - See https://buttplug.io for more info.
2//
3// Copyright 2016-2023 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!(SvakomBarnard, "svakom-barnard");
16
17#[derive(Default)]
18pub struct SvakomBarnard {}
19
20impl ProtocolHandler for SvakomBarnard {
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 speed as u8,
41 if speed == 0 { 0x00 } else { 0x01 },
42 ]
43 .to_vec(),
44 false,
45 )
46 .into(),
47 ])
48 }
49
50 fn handle_output_oscillate_cmd(
51 &self,
52 _feature_index: u32,
53 feature_id: uuid::Uuid,
54 speed: u32,
55 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> {
56 Ok(vec![
57 HardwareWriteCmd::new(
58 &[feature_id],
59 Endpoint::Tx,
60 [
61 0x55,
62 0x08,
63 0x00,
64 0x00,
65 speed as u8,
66 if speed == 0 { 0x00 } else { 0xff },
67 ]
68 .to_vec(),
69 false,
70 )
71 .into(),
72 ])
73 }
74}