Buttplug sex toy control library
1// Buttplug Rust Source Code File - See https://buttplug.io for more info.
2//
3// Copyright 2016-2025 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!(KiirooSpot, "kiiroo-spot");
22
23#[derive(Default)]
24pub struct KiirooSpot {}
25
26impl ProtocolHandler for KiirooSpot {
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![0x00, 0xff, 0x00, 0x00, 0x00, speed as u8],
38 false,
39 )
40 .into(),
41 ])
42 }
43
44 fn handle_battery_level_cmd(
45 &self,
46 device_index: u32,
47 device: Arc<Hardware>,
48 feature_index: u32,
49 feature_id: Uuid,
50 ) -> BoxFuture<'_, Result<InputReadingV4, ButtplugDeviceError>> {
51 debug!("Trying to get battery reading.");
52 let msg = HardwareReadCmd::new(feature_id, Endpoint::RxBLEBattery, 20, 0);
53 let fut = device.read_value(&msg);
54 async move {
55 let hw_msg = fut.await?;
56 let data = hw_msg.data();
57 let battery_reading = message::InputReadingV4::new(
58 device_index,
59 feature_index,
60 InputTypeData::Battery(InputData::new(data[0])),
61 );
62 debug!("Got battery reading: {}", data[0]);
63 Ok(battery_reading)
64 }
65 .boxed()
66 }
67}