From 8cec8aba243545ac39989beedaf3d90cc98acf08 Mon Sep 17 00:00:00 2001 From: blackspherefollower Date: Fri, 10 Jun 2022 07:18:22 -0700 Subject: [PATCH] feat: Adding support for Mizz Zee V2 models Thanks to @Spazzwanjunk at their friend for doing the hard work on this one: https://github.com/buttplugio/stpihkal/issues/136#issuecomment-1151179571 --- .../buttplug-device-config.json | 23 +++++ .../buttplug-device-config.yml | 13 +++ buttplug/src/device/protocol/mizzzee_v2.rs | 94 +++++++++++++++++++ .../src/server/device/protocol/mizzzee.rs | 51 ---------- .../src/server/device/protocol/mizzzee_v2.rs | 43 +++++++++ buttplug/src/server/device/protocol/mod.rs | 5 + .../test_mizzzee_protocol.yaml | 38 ++++++++ .../test_mizzzee_v2_protocol.yaml | 38 ++++++++ 8 files changed, 254 insertions(+), 51 deletions(-) create mode 100644 buttplug/src/device/protocol/mizzzee_v2.rs create mode 100644 buttplug/src/server/device/protocol/mizzzee_v2.rs create mode 100644 buttplug/tests/device_test_case/test_mizzzee_protocol.yaml create mode 100644 buttplug/tests/device_test_case/test_mizzzee_v2_protocol.yaml diff --git a/buttplug/buttplug-device-config/buttplug-device-config.json b/buttplug/buttplug-device-config/buttplug-device-config.json index b82a0adf0..20152cfb7 100644 --- a/buttplug/buttplug-device-config/buttplug-device-config.json +++ b/buttplug/buttplug-device-config/buttplug-device-config.json @@ -3215,6 +3215,29 @@ } } }, + "mizzzee-v2": { + "btle": { + "names": [ + "XHT" + ], + "services": { + "0000eea0-0000-1000-8000-00805f9b34fb": { + "tx": "0000ee01-0000-1000-8000-00805f9b34fb" + } + } + }, + "defaults": { + "name": "Mizz Zee Device", + "messages": { + "ScalarCmd": [ + { + "StepCount": 68, + "ActuatorType": "Vibrate" + } + ] + } + } + }, "htk_bm": { "btle": { "names": [ diff --git a/buttplug/buttplug-device-config/buttplug-device-config.yml b/buttplug/buttplug-device-config/buttplug-device-config.yml index 5f43cfffa..8290e20cc 100644 --- a/buttplug/buttplug-device-config/buttplug-device-config.yml +++ b/buttplug/buttplug-device-config/buttplug-device-config.yml @@ -1984,6 +1984,19 @@ protocols: ScalarCmd: - StepCount: 68 ActuatorType: Vibrate + mizzzee-v2: + btle: + names: + - XHT + services: + 0000eea0-0000-1000-8000-00805f9b34fb: + tx: 0000ee01-0000-1000-8000-00805f9b34fb + defaults: + name: Mizz Zee Device + messages: + ScalarCmd: + - StepCount: 68 + ActuatorType: Vibrate htk_bm: btle: names: diff --git a/buttplug/src/device/protocol/mizzzee_v2.rs b/buttplug/src/device/protocol/mizzzee_v2.rs new file mode 100644 index 000000000..d1a57023b --- /dev/null +++ b/buttplug/src/device/protocol/mizzzee_v2.rs @@ -0,0 +1,94 @@ +use super::{ButtplugDeviceResultFuture, ButtplugProtocol, ButtplugProtocolCommandHandler}; +use crate::{ + core::messages::{self, ButtplugDeviceCommandMessageUnion, DeviceMessageAttributesMap}, + device::{ + protocol::{generic_command_manager::GenericCommandManager, ButtplugProtocolProperties}, + DeviceImpl, + DeviceWriteCmd, + Endpoint, + }, +}; +use std::sync::Arc; + +super::default_protocol_declaration!(MizzZeeV2); + +impl ButtplugProtocolCommandHandler for MizzZeeV2 { + fn handle_vibrate_cmd( + &self, + device: Arc, + message: messages::VibrateCmd, + ) -> ButtplugDeviceResultFuture { + let manager = self.manager.clone(); + Box::pin(async move { + let result = manager.lock().await.update_vibration(&message, false)?; + if let Some(cmds) = result { + if let Some(speed) = cmds[0] { + device + .write_value(DeviceWriteCmd::new( + Endpoint::Tx, + vec![ + 0x69, + 0x96, + 0x04, + 0x02, + speed as u8, + 0x2c, + speed as u8, + ], + false, + )) + .await?; + } + } + + Ok(messages::Ok::default().into()) + }) + } +} + +#[cfg(all(test, feature = "server"))] +mod test { + use crate::{ + core::messages::{StopDeviceCmd, VibrateCmd, VibrateSubcommand}, + device::{DeviceImplCommand, DeviceWriteCmd, Endpoint}, + server::comm_managers::test::{check_test_recv_value, new_bluetoothle_test_device}, + util::async_manager, + }; + + #[test] + pub fn test_mizz_zee_v2_protocol() { + async_manager::block_on(async move { + let (device, test_device) = new_bluetoothle_test_device("XHT") + .await + .expect("Test, assuming infallible"); + device + .parse_message(VibrateCmd::new(0, vec![VibrateSubcommand::new(0, 0.5)]).into()) + .await + .expect("Test, assuming infallible"); + let command_receiver = test_device + .get_endpoint_receiver(&Endpoint::Tx) + .expect("Test, assuming infallible"); + check_test_recv_value( + &command_receiver, + DeviceImplCommand::Write(DeviceWriteCmd::new( + Endpoint::Tx, + vec![0x69, 0x96, 0x04, 0x02, 34, 0x2c, 34 ], + false, + )), + ); + // Test to make sure we handle packet IDs across protocol clones correctly. + device + .parse_message(StopDeviceCmd::new(0).into()) + .await + .expect("Test, assuming infallible"); + check_test_recv_value( + &command_receiver, + DeviceImplCommand::Write(DeviceWriteCmd::new( + Endpoint::Tx, + vec![0x69, 0x96, 0x04, 0x02, 0x00, 0x2c, 0x00], + false, + )), + ); + }); + } +} diff --git a/buttplug/src/server/device/protocol/mizzzee.rs b/buttplug/src/server/device/protocol/mizzzee.rs index 5ef99225e..c78bbb616 100644 --- a/buttplug/src/server/device/protocol/mizzzee.rs +++ b/buttplug/src/server/device/protocol/mizzzee.rs @@ -39,54 +39,3 @@ impl ProtocolHandler for MizzZee { .into()]) } } -/* - -#[cfg(all(test, feature = "server"))] -mod test { - use crate::{ - core::messages::{Endpoint, StopDeviceCmd, VibrateCmd, VibrateSubcommand}, - server::device::{ - hardware::communication::test::{check_test_recv_value, new_bluetoothle_test_device}, - hardware::{HardwareCommand, HardwareWriteCmd}, - }, - util::async_manager, - }; - - #[test] - pub fn test_mizz_zee_protocol() { - async_manager::block_on(async move { - let (device, test_device) = new_bluetoothle_test_device("NFY008") - .await - .expect("Test, assuming infallible"); - device - .parse_message(VibrateCmd::new(0, vec![VibrateSubcommand::new(0, 0.5)]).into()) - .await - .expect("Test, assuming infallible"); - let command_receiver = test_device - .endpoint_receiver(&Endpoint::Tx) - .expect("Test, assuming infallible"); - check_test_recv_value( - &command_receiver, - HardwareCommand::Write(HardwareWriteCmd::new( - Endpoint::Tx, - vec![0x69, 0x96, 0x03, 0x01, 0x01, 34], - false, - )), - ); - // Test to make sure we handle packet IDs across protocol clones correctly. - device - .parse_message(StopDeviceCmd::new(0).into()) - .await - .expect("Test, assuming infallible"); - check_test_recv_value( - &command_receiver, - HardwareCommand::Write(HardwareWriteCmd::new( - Endpoint::Tx, - vec![0x69, 0x96, 0x03, 0x01, 0x00, 0x00], - false, - )), - ); - }); - } -} - */ diff --git a/buttplug/src/server/device/protocol/mizzzee_v2.rs b/buttplug/src/server/device/protocol/mizzzee_v2.rs new file mode 100644 index 000000000..4cf9b92d3 --- /dev/null +++ b/buttplug/src/server/device/protocol/mizzzee_v2.rs @@ -0,0 +1,43 @@ +// Buttplug Rust Source Code File - See https://buttplug.io for more info. +// +// Copyright 2016-2022 Nonpolynomial Labs LLC. All rights reserved. +// +// Licensed under the BSD 3-Clause license. See LICENSE file in the project root +// for full license information. + +use crate::{ + core::{errors::ButtplugDeviceError, messages::Endpoint}, + server::device::{ + hardware::{HardwareCommand, HardwareWriteCmd}, + protocol::{generic_protocol_setup, ProtocolHandler}, + }, +}; + +generic_protocol_setup!(MizzZeeV2, "mizzzee-v2"); + +#[derive(Default)] +pub struct MizzZeeV2 {} + +impl ProtocolHandler for MizzZeeV2 { + fn handle_scalar_vibrate_cmd( + &self, + _index: u32, + scalar: u32, + ) -> Result, ButtplugDeviceError> { + Ok(vec![HardwareWriteCmd::new( + Endpoint::Tx, + vec![ + 0x69, + 0x96, + 0x04, + 0x02, + scalar as u8, + 0x2c, + scalar as u8, + ], + false, + ) + .into()]) + } +} + diff --git a/buttplug/src/server/device/protocol/mod.rs b/buttplug/src/server/device/protocol/mod.rs index 547bae0c6..459b6a5e5 100644 --- a/buttplug/src/server/device/protocol/mod.rs +++ b/buttplug/src/server/device/protocol/mod.rs @@ -44,6 +44,7 @@ pub mod mannuo; pub mod maxpro; pub mod meese; pub mod mizzzee; +pub mod mizzzee_v2; pub mod motorbunny; pub mod nobra; pub mod patoo; @@ -229,6 +230,10 @@ pub fn get_default_protocol_map() -> HashMap