Skip to content

Commit

Permalink
feat: Adding support for Mizz Zee V2 models
Browse files Browse the repository at this point in the history
Thanks to @Spazzwanjunk at their friend for doing the hard work on this one:
buttplugio/stpihkal#136 (comment)
  • Loading branch information
blackspherefollower committed Jun 10, 2022
1 parent fc8029e commit 284e99e
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 0 deletions.
25 changes: 25 additions & 0 deletions buttplug/buttplug-device-config/buttplug-device-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3330,6 +3330,31 @@
}
}
},
"mizzzee-v2": {
"btle": {
"names": [
"XHT"
],
"services": {
"0000eea0-0000-1000-8000-00805f9b34fb": {
"tx": "0000ee01-0000-1000-8000-00805f9b34fb"
}
}
},
"defaults": {
"name": {
"en-us": "Mizz Zee Device"
},
"messages": {
"VibrateCmd": {
"FeatureCount": 1,
"StepCount": [
68
]
}
}
}
},
"htk_bm": {
"btle": {
"names": [
Expand Down
15 changes: 15 additions & 0 deletions buttplug/buttplug-device-config/buttplug-device-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2202,6 +2202,21 @@ protocols:
FeatureCount: 1
StepCount:
- 68
mizzzee-v2:
btle:
names:
- XHT
services:
0000eea0-0000-1000-8000-00805f9b34fb:
tx: 0000ee01-0000-1000-8000-00805f9b34fb
defaults:
name:
en-us: Mizz Zee Device
messages:
VibrateCmd:
FeatureCount: 1
StepCount:
- 68
htk_bm:
btle:
names:
Expand Down
94 changes: 94 additions & 0 deletions buttplug/src/device/protocol/mizzzee_v2.rs
Original file line number Diff line number Diff line change
@@ -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<DeviceImpl>,
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,
)),
);
});
}
}
2 changes: 2 additions & 0 deletions buttplug/src/device/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,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;
Expand Down Expand Up @@ -139,6 +140,7 @@ pub fn get_default_protocol_map() -> DashMap<String, TryCreateProtocolFunc> {
add_to_protocol_map::<maxpro::Maxpro>(&map, "maxpro");
add_to_protocol_map::<meese::Meese>(&map, "meese");
add_to_protocol_map::<mizzzee::MizzZee>(&map, "mizzzee");
add_to_protocol_map::<mizzzee_v2::MizzZeeV2>(&map, "mizzzee-v2");
add_to_protocol_map::<motorbunny::Motorbunny>(&map, "motorbunny");
add_to_protocol_map::<mysteryvibe::MysteryVibe>(&map, "mysteryvibe");
add_to_protocol_map::<nobra::Nobra>(&map, "nobra");
Expand Down

0 comments on commit 284e99e

Please sign in to comment.