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 crate::device::{
9 hardware::{Hardware, HardwareCommand, HardwareReadCmd, HardwareWriteCmd},
10 protocol::{ProtocolHandler, generic_protocol_setup},
11};
12use buttplug_core::{
13 errors::ButtplugDeviceError,
14 message::{self, InputData, InputReadingV4, InputTypeData},
15};
16use buttplug_server_device_config::Endpoint;
17use futures::{FutureExt, future::BoxFuture};
18use std::{default::Default, sync::Arc};
19use uuid::Uuid;
20
21generic_protocol_setup!(KiirooProWand, "kiiroo-prowand");
22
23#[derive(Default)]
24pub struct KiirooProWand {}
25
26impl ProtocolHandler for KiirooProWand {
27 fn handle_output_vibrate_cmd(
28 &self,
29 _feature_index: u32,
30 feature_id: Uuid,
31 speed: u32,
32 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> {
33 Ok(vec![
34 HardwareWriteCmd::new(
35 &[feature_id],
36 Endpoint::Tx,
37 vec![
38 0x00,
39 0x00,
40 0x64,
41 if speed == 0 { 0x00 } else { 0xff },
42 speed as u8,
43 speed as u8,
44 ],
45 false,
46 )
47 .into(),
48 ])
49 }
50
51 fn handle_battery_level_cmd(
52 &self,
53 device_index: u32,
54 device: Arc<Hardware>,
55 feature_index: u32,
56 feature_id: Uuid,
57 ) -> BoxFuture<'_, Result<InputReadingV4, ButtplugDeviceError>> {
58 debug!("Trying to get battery reading.");
59 let msg = HardwareReadCmd::new(feature_id, Endpoint::RxBLEBattery, 20, 0);
60 let fut = device.read_value(&msg);
61 async move {
62 let hw_msg = fut.await?;
63 let data = hw_msg.data();
64 let battery_reading = message::InputReadingV4::new(
65 device_index,
66 feature_index,
67 InputTypeData::Battery(InputData::new(data[0])),
68 );
69 debug!("Got battery reading: {}", data[0]);
70 Ok(battery_reading)
71 }
72 .boxed()
73 }
74}