From c9be70fe7e1b532410efdd226dbdf4bcc24ed443 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 | 26 +++++ .../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 ++++++++ buttplug/tests/test_device_protocols.rs | 8 ++ .../test_mizzzee_protocol.yaml | 30 ++++++ .../test_mizzzee_v2_protocol.yaml | 30 ++++++ 11 files changed, 325 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 create mode 100644 buttplug/tests/util/device_test/device_test_case/test_mizzzee_protocol.yaml create mode 100644 buttplug/tests/util/device_test/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 0b9ce0e5e..734af8320 100644 --- a/buttplug/buttplug-device-config/buttplug-device-config.json +++ b/buttplug/buttplug-device-config/buttplug-device-config.json @@ -3767,6 +3767,32 @@ } } }, + "mizzzee-v2": { + "btle": { + "names": [ + "XHT" + ], + "services": { + "0000eea0-0000-1000-8000-00805f9b34fb": { + "tx": "0000ee01-0000-1000-8000-00805f9b34fb" + } + } + }, + "defaults": { + "name": "Mizz Zee Device", + "messages": { + "ScalarCmd": [ + { + "StepRange": [ + 0, + 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 9710170e9..5be6d7061 100644 --- a/buttplug/buttplug-device-config/buttplug-device-config.yml +++ b/buttplug/buttplug-device-config/buttplug-device-config.yml @@ -1999,6 +1999,19 @@ protocols: ScalarCmd: - StepRange: [0, 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: + - StepRange: [0, 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 dffc4fe00..62aac19ed 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..9d96e24e9 --- /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, message::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 f781fa4db..97619c7e7 100644 --- a/buttplug/src/server/device/protocol/mod.rs +++ b/buttplug/src/server/device/protocol/mod.rs @@ -45,6 +45,7 @@ pub mod mannuo; pub mod maxpro; pub mod meese; pub mod mizzzee; +pub mod mizzzee_v2; pub mod motorbunny; pub mod mysteryvibe; pub mod nobra; @@ -225,6 +226,10 @@ pub fn get_default_protocol_map() -> HashMap DeviceTestCase { #[test_case("test_satisfyer_dual_vibrator.yaml" ; "Satisfyer Protocol - Dual Vibrator")] #[test_case("test_mysteryvibe.yaml" ; "Mysteryvibe Protocol")] #[test_case("test_meese_protocol.yaml" ; "Meese Protocol")] +#[test_case("test_mizzzee_protocol.yaml" ; "Mizz Zee Protocol")] +#[test_case("test_mizzzee_v2_protocol.yaml" ; "Mizz Zee v2 Protocol")] #[test_case("test_vorze_ufo.yaml" ; "Vorze Protocol - UFO")] #[test_case("test_vorze_ufo.yaml" ; "Vorze Protocol - UFO TW")] fn test_device_protocols_embedded_v3(test_file: &str) { @@ -62,6 +64,8 @@ fn test_device_protocols_embedded_v3(test_file: &str) { #[test_case("test_satisfyer_dual_vibrator.yaml" ; "Satisfyer Protocol - Dual Vibrator")] #[test_case("test_mysteryvibe.yaml" ; "Mysteryvibe Protocol")] #[test_case("test_meese_protocol.yaml" ; "Meese Protocol")] +#[test_case("test_mizzzee_protocol.yaml" ; "Mizz Zee Protocol")] +#[test_case("test_mizzzee_v2_protocol.yaml" ; "Mizz Zee v2 Protocol")] #[test_case("test_vorze_ufo.yaml" ; "Vorze Protocol - UFO")] #[test_case("test_vorze_ufo.yaml" ; "Vorze Protocol - UFO TW")] fn test_device_protocols_json_v3(test_file: &str) { @@ -84,6 +88,8 @@ fn test_device_protocols_json_v3(test_file: &str) { #[test_case("test_satisfyer_dual_vibrator.yaml" ; "Satisfyer Protocol - Dual Vibrator")] #[test_case("test_mysteryvibe.yaml" ; "Mysteryvibe Protocol")] #[test_case("test_meese_protocol.yaml" ; "Meese Protocol")] +#[test_case("test_mizzzee_protocol.yaml" ; "Mizz Zee Protocol")] +#[test_case("test_mizzzee_v2_protocol.yaml" ; "Mizz Zee v2 Protocol")] #[test_case("test_vorze_ufo.yaml" ; "Vorze Protocol - UFO")] #[test_case("test_vorze_ufo.yaml" ; "Vorze Protocol - UFO TW")] fn test_device_protocols_embedded_v2(test_file: &str) { @@ -105,6 +111,8 @@ fn test_device_protocols_embedded_v2(test_file: &str) { #[test_case("test_satisfyer_dual_vibrator.yaml" ; "Satisfyer Protocol - Dual Vibrator")] #[test_case("test_mysteryvibe.yaml" ; "Mysteryvibe Protocol")] #[test_case("test_meese_protocol.yaml" ; "Meese Protocol")] +#[test_case("test_mizzzee_protocol.yaml" ; "Mizz Zee Protocol")] +#[test_case("test_mizzzee_v2_protocol.yaml" ; "Mizz Zee v2 Protocol")] #[test_case("test_vorze_ufo.yaml" ; "Vorze Protocol - UFO")] #[test_case("test_vorze_ufo.yaml" ; "Vorze Protocol - UFO TW")] fn test_device_protocols_json_v2(test_file: &str) { diff --git a/buttplug/tests/util/device_test/device_test_case/test_mizzzee_protocol.yaml b/buttplug/tests/util/device_test/device_test_case/test_mizzzee_protocol.yaml new file mode 100644 index 000000000..53af6af59 --- /dev/null +++ b/buttplug/tests/util/device_test/device_test_case/test_mizzzee_protocol.yaml @@ -0,0 +1,30 @@ +devices: + - identifier: + name: "NFY008" + expected_name: "Mizz Zee Device" +device_commands: + # Commands + - !Messages + device_index: 0 + messages: + - !Vibrate + - Index: 0 + Speed: 0.5 + - !Commands + device_index: 0 + commands: + - !Write + endpoint: tx + data: [105, 150, 3, 1, 1, 34] + write_with_response: false + - !Messages + device_index: 0 + messages: + - !Stop + - !Commands + device_index: 0 + commands: + - !Write + endpoint: tx + data: [105, 150, 3, 1, 0, 0] + write_with_response: false diff --git a/buttplug/tests/util/device_test/device_test_case/test_mizzzee_v2_protocol.yaml b/buttplug/tests/util/device_test/device_test_case/test_mizzzee_v2_protocol.yaml new file mode 100644 index 000000000..49dc52872 --- /dev/null +++ b/buttplug/tests/util/device_test/device_test_case/test_mizzzee_v2_protocol.yaml @@ -0,0 +1,30 @@ +devices: + - identifier: + name: "XHT" + expected_name: "Mizz Zee Device" +device_commands: + # Commands + - !Messages + device_index: 0 + messages: + - !Vibrate + - Index: 0 + Speed: 0.5 + - !Commands + device_index: 0 + commands: + - !Write + endpoint: tx + data: [105, 150, 4, 2, 34, 44, 34] + write_with_response: false + - !Messages + device_index: 0 + messages: + - !Stop + - !Commands + device_index: 0 + commands: + - !Write + endpoint: tx + data: [105, 150, 4, 2, 0, 44, 0] + write_with_response: false