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 uuid::Uuid;
9
10use crate::device::{
11 hardware::{HardwareCommand, HardwareWriteCmd},
12 protocol::{ProtocolHandler, generic_protocol_setup},
13};
14use buttplug_core::errors::ButtplugDeviceError;
15use buttplug_server_device_config::Endpoint;
16
17generic_protocol_setup!(Cupido, "cupido");
18
19#[derive(Default)]
20pub struct Cupido {}
21
22impl ProtocolHandler for Cupido {
23 fn handle_output_vibrate_cmd(
24 &self,
25 _feature_index: u32,
26 feature_id: Uuid,
27 speed: u32,
28 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> {
29 Ok(vec![
30 HardwareWriteCmd::new(
31 &[feature_id],
32 Endpoint::Tx,
33 vec![0xb0, 0x03, 0, 0, 0, speed as u8, 0xaa],
34 false,
35 )
36 .into(),
37 ])
38 }
39
40 /* -- expensive if we're not caching the battery
41 fn handle_battery_level_cmd(
42 &self,
43 device: Arc<Hardware>,
44 message: SensorReadCmd,
45 ) -> BoxFuture<Result<ButtplugServerMessage, ButtplugDeviceError>> {
46 let mut device_notification_receiver = device.event_stream();
47 async move {
48 device
49 .subscribe(&HardwareSubscribeCmd::new(Endpoint::Rx))
50 .await?;
51 while let Ok(event) = device_notification_receiver.recv().await {
52 return match event {
53 HardwareEvent::Notification(_, endpoint, data) => {
54 if endpoint != Endpoint::Rx {
55 continue;
56 }
57 if data.len() == 6 && data[0..5] != vec![0xb0, 0, 0, 0, 1] {
58 continue;
59 }
60 let battery_reading = SensorReading::new(
61 message.device_index(),
62 *message.sensor_index(),
63 *message.input_type(),
64 vec![data[5] as i32],
65 );
66 Ok(battery_reading.into())
67 }
68 HardwareEvent::Disconnected(_) => Err(ButtplugDeviceError::ProtocolSpecificError(
69 "Cupido".to_owned(),
70 "Cupido Device disconnected while getting Battery info.".to_owned(),
71 )),
72 };
73 }
74 Err(ButtplugDeviceError::ProtocolSpecificError(
75 "Cupido".to_owned(),
76 "Cupido Device disconnected while getting Battery info.".to_owned(),
77 ))
78 }
79 .boxed()
80 }*/
81}