forked from buttplugio/buttplug
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Adding support for Mizz Zee V2 models
Thanks to @Spazzwanjunk at their friend for doing the hard work on this one: buttplugio/stpihkal#136 (comment)
- Loading branch information
1 parent
fc8029e
commit 284e99e
Showing
4 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
)), | ||
); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters