Skip to content

Commit

Permalink
fix: Correct motorbunny rotation feature
Browse files Browse the repository at this point in the history
  • Loading branch information
blackspherefollower authored and qdot committed Mar 2, 2024
1 parent ca26dff commit ab54ec7
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 6 deletions.
6 changes: 3 additions & 3 deletions buttplug/buttplug-device-config/buttplug-device-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7272,7 +7272,7 @@
}
},
"defaults": {
"name": "Meeese Device",
"name": "Meese Device",
"messages": {
"ScalarCmd": [
{
Expand All @@ -7297,13 +7297,13 @@
"identifier": [
"Meese-V389"
],
"name": "Meeese Tera"
"name": "Meese Tera"
},
{
"identifier": [
"Meese-cd"
],
"name": "Meeese Modo",
"name": "Meese Modo",
"messages": {
"ScalarCmd": [
{
Expand Down
6 changes: 3 additions & 3 deletions buttplug/buttplug-device-config/buttplug-device-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3572,7 +3572,7 @@ protocols:
0000ffe0-0000-1000-8000-00805f9b34fb:
tx: 0000ffe1-0000-1000-8000-00805f9b34fb
defaults:
name: Meeese Device
name: Meese Device
messages:
ScalarCmd:
- StepRange: [0, 10]
Expand All @@ -3582,10 +3582,10 @@ protocols:
configurations:
- identifier:
- Meese-V389
name: Meeese Tera
name: Meese Tera
- identifier:
- Meese-cd
name: Meeese Modo
name: Meese Modo
messages:
ScalarCmd:
- StepRange: [0, 10]
Expand Down
25 changes: 25 additions & 0 deletions buttplug/src/server/device/protocol/motorbunny.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,29 @@ impl ProtocolHandler for Motorbunny {
)
.into()])
}

fn handle_rotate_cmd(
&self,
commands: &[Option<(u32, bool)>],
) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> {
let rotate = commands[0].unwrap_or((0, false));
let mut command_vec: Vec<u8>;
if rotate.0 == 0 {
command_vec = vec![0xa0, 0x00, 0x00, 0x00, 0x00, 0xec];
} else {
command_vec = vec![0xfa];
let mut rotate_command = vec![if rotate.1 { 0x2a } else { 0x29 }, rotate.0 as u8].repeat(7);
let crc = rotate_command
.iter()
.fold(0u8, |a, b| a.overflowing_add(*b).0);
command_vec.append(&mut rotate_command);
command_vec.append(&mut vec![crc, 0xec]);
}
Ok(vec![HardwareWriteCmd::new(
Endpoint::Tx,
command_vec,
false,
)
.into()])
}
}
4 changes: 4 additions & 0 deletions buttplug/tests/test_device_protocols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ async fn load_test_case(test_file: &str) -> DeviceTestCase {
#[test_case("test_joyhub_protocol.yaml" ; "JoyHub Protocol")]
#[test_case("test_itoys_protocol.yaml" ; "iToys Protocol")]
#[test_case("test_leten_protocol.yaml" ; "Leten Protocol")]
#[test_case("test_motorbunny_protocol.yaml" ; "Motorbunny Protocol")]
#[tokio::test]
async fn test_device_protocols_embedded_v3(test_file: &str) {
//tracing_subscriber::fmt::init();
Expand Down Expand Up @@ -185,6 +186,7 @@ async fn test_device_protocols_embedded_v3(test_file: &str) {
#[test_case("test_joyhub_protocol.yaml" ; "JoyHub Protocol")]
#[test_case("test_itoys_protocol.yaml" ; "iToys Protocol")]
#[test_case("test_leten_protocol.yaml" ; "Leten Protocol")]
#[test_case("test_motorbunny_protocol.yaml" ; "Motorbunny Protocol")]
#[tokio::test]
async fn test_device_protocols_json_v3(test_file: &str) {
//tracing_subscriber::fmt::init();
Expand Down Expand Up @@ -250,6 +252,7 @@ async fn test_device_protocols_json_v3(test_file: &str) {
#[test_case("test_foreo_protocol.yaml" ; "Foreo Protocol")]
#[test_case("test_itoys_protocol.yaml" ; "iToys Protocol")]
#[test_case("test_leten_protocol.yaml" ; "Leten Protocol")]
#[test_case("test_motorbunny_protocol.yaml" ; "Motorbunny Protocol")]
#[tokio::test]
async fn test_device_protocols_embedded_v2(test_file: &str) {
util::device_test::client::client_v2::run_embedded_test_case(&load_test_case(test_file).await)
Expand Down Expand Up @@ -314,6 +317,7 @@ async fn test_device_protocols_embedded_v2(test_file: &str) {
#[test_case("test_foreo_protocol.yaml" ; "Foreo Protocol")]
#[test_case("test_itoys_protocol.yaml" ; "iToys Protocol")]
#[test_case("test_leten_protocol.yaml" ; "Leten Protocol")]
#[test_case("test_motorbunny_protocol.yaml" ; "Motorbunny Protocol")]
#[tokio::test]
async fn test_device_protocols_json_v2(test_file: &str) {
util::device_test::client::client_v2::run_json_test_case(&load_test_case(test_file).await).await;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
devices:
- identifier:
name: "MB Controller"
expected_name: "Motorbunny Classic"
device_commands:
- !Messages
device_index: 0
messages:
- !Vibrate
- Index: 0
Speed: 0.5
- !Commands
device_index: 0
commands:
- !Write
endpoint: tx
data: [0xff, 0x80, 0x14, 0x80, 0x14, 0x80, 0x14, 0x80, 0x14, 0x80, 0x14, 0x80, 0x14, 0x80, 0x14, 0x0c, 0xec]
write_with_response: false
- !Messages
device_index: 0
messages:
- !Vibrate
- Index: 0
Speed: 0.75
- !Commands
device_index: 0
commands:
- !Write
endpoint: tx
data: [0xff, 0xC0, 0x14, 0xC0, 0x14, 0xC0, 0x14, 0xC0, 0x14, 0xC0, 0x14, 0xC0, 0x14, 0xC0, 0x14, 0xcc, 0xec]
write_with_response: false
- !Messages
device_index: 0
messages:
- !Rotate
- Index: 0
Speed: 0.5
Clockwise: true
- !Commands
device_index: 0
commands:
- !Write
endpoint: tx
data: [0xfa, 0x2a, 0x80, 0x2a, 0x80, 0x2a, 0x80, 0x2a, 0x80, 0x2a, 0x80, 0x2a, 0x80, 0x2a, 0x80, 0xa6, 0xec]
write_with_response: false
- !Messages
device_index: 0
messages:
- !Rotate
- Index: 0
Speed: 0.75
Clockwise: false
- !Commands
device_index: 0
commands:
- !Write
endpoint: tx
data: [0xfa, 0x29, 0xC0, 0x29, 0xC0, 0x29, 0xC0, 0x29, 0xC0, 0x29, 0xC0, 0x29, 0xC0, 0x29, 0xC0, 0x5F, 0xec]
write_with_response: false
- !Messages
device_index: 0
messages:
- !Stop
- !Commands
device_index: 0
commands:
- !Write
endpoint: tx
data: [ 0xf0, 0x00, 0x00, 0x00, 0x00, 0xec ]
write_with_response: false
- !Write
endpoint: tx
data: [ 0xa0, 0x00, 0x00, 0x00, 0x00, 0xec ]
write_with_response: false

0 comments on commit ab54ec7

Please sign in to comment.