Skip to content

Commit

Permalink
feat: Adding support for Vorze UFO TW
Browse files Browse the repository at this point in the history
  • Loading branch information
blackspherefollower authored and qdot committed Sep 24, 2022
1 parent 9dbb185 commit 6bc82f0
Show file tree
Hide file tree
Showing 6 changed files with 183 additions and 223 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 @@ -2627,6 +2627,7 @@
"Bach smart",
"CycSA",
"UFOSA",
"UFO-TW",
"VorzePiston",
"ROCKET"
],
Expand Down Expand Up @@ -2711,6 +2712,30 @@
"VorzeA10CycloneCmd": {}
}
},
{
"identifier": [
"UFO-TW"
],
"name": "Vorze UFO TW",
"messages": {
"RotateCmd": [
{
"StepRange": [
0,
99
],
"ActuatorType": "Rotate"
},
{
"StepRange": [
0,
99
],
"ActuatorType": "Rotate"
}
]
}
},
{
"identifier": [
"VorzePiston"
Expand Down
10 changes: 10 additions & 0 deletions buttplug/buttplug-device-config/buttplug-device-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1419,6 +1419,7 @@ protocols:
- Bach smart
- CycSA
- UFOSA
- UFO-TW
- VorzePiston
- ROCKET
services:
Expand Down Expand Up @@ -1458,6 +1459,15 @@ protocols:
- StepRange: [0, 99]
ActuatorType: Rotate
VorzeA10CycloneCmd: {}
- identifier:
- UFO-TW
name: Vorze UFO TW
messages:
RotateCmd:
- StepRange: [0, 99]
ActuatorType: Rotate
- StepRange: [0, 99]
ActuatorType: Rotate
- identifier:
- VorzePiston
name: Vorze Piston
Expand Down
256 changes: 33 additions & 223 deletions buttplug/src/server/device/protocol/vorze_sa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl ProtocolInitializer for VorzeSAInitializer {
let hwname = hardware.name().to_ascii_lowercase();
let device_type = if hwname.contains("cyclone") {
VorzeDevice::Cyclone
} else if hwname.contains("ufo tw") {
} else if hwname.contains("ufo-tw") {
VorzeDevice::UfoTw
} else if hwname.contains("ufo") {
VorzeDevice::Ufo
Expand Down Expand Up @@ -142,16 +142,39 @@ impl ProtocolHandler for VorzeSA {
&self,
cmds: &Vec<Option<(u32, bool)>>,
) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> {
if let Some((speed, clockwise)) = cmds[0] {
let data: u8 = (clockwise as u8) << 7 | (speed as u8);
Ok(vec![HardwareWriteCmd::new(
Endpoint::Tx,
vec![self.device_type as u8, VorzeActions::Rotate as u8, data],
true,
)
.into()])
if cmds.len() == 1 {
if let Some((speed, clockwise)) = cmds[0] {
let data: u8 = (clockwise as u8) << 7 | (speed as u8);
Ok(vec![HardwareWriteCmd::new(
Endpoint::Tx,
vec![self.device_type as u8, VorzeActions::Rotate as u8, data],
true,
)
.into()])
} else {
Ok(vec![])
}
} else {
Ok(vec![])
let mut data_left = 0u8;
let mut data_right = 0u8;
let mut changed = false;
if let Some((speed, clockwise)) = cmds[0] {
data_left = (clockwise as u8) << 7 | (speed as u8);
changed = true;
}
if let Some((speed, clockwise)) = cmds[1] {
data_right = (clockwise as u8) << 7 | (speed as u8);
changed = true;
}
if changed {
Ok(vec![HardwareWriteCmd::new(
Endpoint::Tx,
vec![self.device_type as u8, data_left, data_right],
true)
.into()])
} else {
Ok(vec![])
}
}
}

Expand Down Expand Up @@ -186,216 +209,3 @@ impl ProtocolHandler for VorzeSA {
self.handle_rotate_cmd(&vec![Some((msg.speed(), msg.clockwise()))])
}
}

/*
#[cfg(all(test, feature = "server"))]
mod test {
use crate::{
core::messages::{
Endpoint,
LinearCmd,
RotateCmd,
RotationSubcommand,
StopDeviceCmd,
VectorSubcommand,
VibrateCmd,
VibrateSubcommand,
},
server::device::{
hardware::{HardwareCommand, HardwareWriteCmd},
hardware::communication::test::{
check_test_recv_empty,
check_test_recv_value,
new_bluetoothle_test_device,
},
},
util::async_manager,
};
#[test]
pub fn test_vorze_sa_vibration_protocol_bach() {
async_manager::block_on(async move {
let (device, test_device) = new_bluetoothle_test_device("Bach smart")
.await
.expect("Test, assuming infallible");
let command_receiver = test_device
.endpoint_receiver(&Endpoint::Tx)
.expect("Test, assuming infallible");
device
.parse_message(VibrateCmd::new(0, vec![VibrateSubcommand::new(0, 0.5)]).into())
.await
.expect("Test, assuming infallible");
check_test_recv_value(
&command_receiver,
HardwareCommand::Write(HardwareWriteCmd::new(
Endpoint::Tx,
vec![0x06, 0x03, 50],
true,
)),
);
assert!(check_test_recv_empty(&command_receiver));
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![0x06, 0x03, 0x0],
true,
)),
);
assert!(check_test_recv_empty(&command_receiver));
});
}
#[test]
pub fn test_vorze_sa_vibration_protocol_rocket() {
async_manager::block_on(async move {
let (device, test_device) = new_bluetoothle_test_device("ROCKET")
.await
.expect("Test, assuming infallible");
let command_receiver = test_device
.endpoint_receiver(&Endpoint::Tx)
.expect("Test, assuming infallible");
device
.parse_message(VibrateCmd::new(0, vec![VibrateSubcommand::new(0, 0.5)]).into())
.await
.expect("Test, assuming infallible");
check_test_recv_value(
&command_receiver,
HardwareCommand::Write(HardwareWriteCmd::new(
Endpoint::Tx,
vec![0x07, 0x03, 50],
true,
)),
);
assert!(check_test_recv_empty(&command_receiver));
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![0x07, 0x03, 0x0],
true,
)),
);
assert!(check_test_recv_empty(&command_receiver));
});
}
#[test]
pub fn test_vorze_sa_rotation_protocol() {
async_manager::block_on(async move {
let (device, test_device) = new_bluetoothle_test_device("CycSA")
.await
.expect("Test, assuming infallible");
let command_receiver = test_device
.endpoint_receiver(&Endpoint::Tx)
.expect("Test, assuming infallible");
device
.parse_message(RotateCmd::new(0, vec![RotationSubcommand::new(0, 0.5, false)]).into())
.await
.expect("Test, assuming infallible");
check_test_recv_value(
&command_receiver,
HardwareCommand::Write(HardwareWriteCmd::new(
Endpoint::Tx,
vec![0x01, 0x01, 50],
true,
)),
);
assert!(check_test_recv_empty(&command_receiver));
device
.parse_message(RotateCmd::new(0, vec![RotationSubcommand::new(0, 0.5, true)]).into())
.await
.expect("Test, assuming infallible");
check_test_recv_value(
&command_receiver,
HardwareCommand::Write(HardwareWriteCmd::new(
Endpoint::Tx,
vec![0x01, 0x01, 178],
true,
)),
);
assert!(check_test_recv_empty(&command_receiver));
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![0x01, 0x01, 0x0],
true,
)),
);
assert!(check_test_recv_empty(&command_receiver));
});
}
#[test]
pub fn test_vorze_sa_linear_protocol() {
async_manager::block_on(async move {
let (device, test_device) = new_bluetoothle_test_device("VorzePiston")
.await
.expect("Test, assuming infallible");
let command_receiver = test_device
.endpoint_receiver(&Endpoint::Tx)
.expect("Test, assuming infallible");
device
.parse_message(LinearCmd::new(0, vec![VectorSubcommand::new(0, 150, 0.95)]).into())
.await
.expect("Test, assuming infallible");
check_test_recv_value(
&command_receiver,
HardwareCommand::Write(HardwareWriteCmd::new(Endpoint::Tx, vec![0x03, 190, 92], true)),
);
assert!(check_test_recv_empty(&command_receiver));
device
.parse_message(LinearCmd::new(0, vec![VectorSubcommand::new(0, 150, 0.95)]).into())
.await
.expect("Test, assuming infallible");
check_test_recv_value(
&command_receiver,
HardwareCommand::Write(HardwareWriteCmd::new(
Endpoint::Tx,
vec![0x03, 190, 100],
true,
)),
);
assert!(check_test_recv_empty(&command_receiver));
device
.parse_message(LinearCmd::new(0, vec![VectorSubcommand::new(0, 50, 0.5)]).into())
.await
.expect("Test, assuming infallible");
check_test_recv_value(
&command_receiver,
HardwareCommand::Write(HardwareWriteCmd::new(
Endpoint::Tx,
vec![0x03, 100, 100],
true,
)),
);
assert!(check_test_recv_empty(&command_receiver));
device
.parse_message(StopDeviceCmd::new(0).into())
.await
.expect("Test, assuming infallible");
assert!(check_test_recv_empty(&command_receiver));
});
}
}
*/
8 changes: 8 additions & 0 deletions buttplug/tests/test_device_protocols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ async fn load_test_case(test_file: &str) -> 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_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) {
//tracing_subscriber::fmt::init();
async_manager::block_on(async {
Expand All @@ -60,6 +62,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_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) {
//tracing_subscriber::fmt::init();
async_manager::block_on(async {
Expand All @@ -80,6 +84,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_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) {
async_manager::block_on(async {
util::device_test::client::client_v2::run_embedded_test_case(&load_test_case(test_file).await)
Expand All @@ -99,6 +105,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_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) {
async_manager::block_on(async {
util::device_test::client::client_v2::run_json_test_case(&load_test_case(test_file).await)
Expand Down
Loading

0 comments on commit 6bc82f0

Please sign in to comment.