Buttplug sex toy control library
at dev 86 lines 2.0 kB view raw
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 buttplug_core::{ 9 errors::ButtplugMessageError, 10 message::{ 11 ButtplugDeviceMessage, 12 ButtplugMessage, 13 ButtplugMessageFinalizer, 14 ButtplugMessageValidator, 15 }, 16}; 17pub use getset::{CopyGetters, Getters}; 18use serde::{Deserialize, Serialize}; 19 20#[derive(Debug, PartialEq, Clone, CopyGetters, Serialize, Deserialize)] 21#[getset(get_copy = "pub")] 22pub struct RotationSubcommandV1 { 23 #[serde(rename = "Index")] 24 index: u32, 25 #[serde(rename = "Speed")] 26 speed: f64, 27 #[serde(rename = "Clockwise")] 28 clockwise: bool, 29} 30 31impl RotationSubcommandV1 { 32 pub fn new(index: u32, speed: f64, clockwise: bool) -> Self { 33 Self { 34 index, 35 speed, 36 clockwise, 37 } 38 } 39} 40 41#[derive( 42 Debug, 43 ButtplugDeviceMessage, 44 ButtplugMessageFinalizer, 45 PartialEq, 46 Clone, 47 Getters, 48 Serialize, 49 Deserialize, 50)] 51pub struct RotateCmdV1 { 52 #[serde(rename = "Id")] 53 id: u32, 54 #[serde(rename = "DeviceIndex")] 55 device_index: u32, 56 #[getset(get = "pub")] 57 #[serde(rename = "Rotations")] 58 #[getset(get = "pub")] 59 rotations: Vec<RotationSubcommandV1>, 60} 61 62impl RotateCmdV1 { 63 pub fn new(device_index: u32, rotations: Vec<RotationSubcommandV1>) -> Self { 64 Self { 65 id: 1, 66 device_index, 67 rotations, 68 } 69 } 70} 71 72impl ButtplugMessageValidator for RotateCmdV1 { 73 fn is_valid(&self) -> Result<(), ButtplugMessageError> { 74 self.is_not_system_id(self.id)?; 75 for rotation in &self.rotations { 76 self.is_in_command_range( 77 rotation.speed, 78 format!( 79 "Speed {} for RotateCmd index {} is invalid. Speed should be a value between 0.0 and 1.0", 80 rotation.speed, rotation.index 81 ), 82 )?; 83 } 84 Ok(()) 85 } 86}