buttplug/server/device/protocol/
magic_motion_v1.rs

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::{
9  core::{errors::ButtplugDeviceError, message::Endpoint},
10  server::device::{
11    hardware::{HardwareCommand, HardwareWriteCmd},
12    protocol::{generic_protocol_setup, ProtocolHandler},
13  },
14};
15
16generic_protocol_setup!(MagicMotionV1, "magic-motion-1");
17
18#[derive(Default)]
19pub struct MagicMotionV1 {}
20
21impl ProtocolHandler for MagicMotionV1 {
22  fn keepalive_strategy(&self) -> super::ProtocolKeepaliveStrategy {
23    super::ProtocolKeepaliveStrategy::RepeatLastPacketStrategy
24  }
25
26  fn handle_scalar_vibrate_cmd(
27    &self,
28    _index: u32,
29    scalar: u32,
30  ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> {
31    Ok(vec![HardwareWriteCmd::new(
32      Endpoint::Tx,
33      vec![
34        0x0b,
35        0xff,
36        0x04,
37        0x0a,
38        0x32,
39        0x32,
40        0x00,
41        0x04,
42        0x08,
43        scalar as u8,
44        0x64,
45        0x00,
46      ],
47      false,
48    )
49    .into()])
50  }
51
52  fn handle_scalar_oscillate_cmd(
53    &self,
54    _index: u32,
55    scalar: u32,
56  ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> {
57    Ok(vec![HardwareWriteCmd::new(
58      Endpoint::Tx,
59      vec![
60        0x0b,
61        0xff,
62        0x04,
63        0x0a,
64        0x32,
65        0x32,
66        0x00,
67        0x04,
68        0x08,
69        scalar as u8,
70        0x64,
71        0x00,
72      ],
73      false,
74    )
75    .into()])
76  }
77}