From 52e5adbe733e787f2817d296b5bb7b0613dac818 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 +++++ .../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 +++++++++++ 10 files changed, 231 insertions(+), 51 deletions(-) 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 0b9ce0e5..734af832 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 9710170e..5be6d706 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/server/device/protocol/mizzzee.rs b/buttplug/src/server/device/protocol/mizzzee.rs index dffc4fe0..62aac19e 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 00000000..9d96e24e --- /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 f781fa4d..97619c7e 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 00000000..53af6af5 --- /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 00000000..49dc5287 --- /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