From 52793839a3a6e0a41a3e71ca5f8860ebbb3b7f0f Mon Sep 17 00:00:00 2001 From: Haruka <990628wjy@gmail.com> Date: Sat, 15 Feb 2025 08:17:06 +0800 Subject: [PATCH] Add support for Yiciyuan device --- .../buttplug-device-config-v3.json | 69 +++++++++++++++++++ .../buttplug-device-config-v3.yml | 40 ++++++++++- buttplug/src/server/device/protocol/mod.rs | 2 + .../src/server/device/protocol/yiciyuan.rs | 43 ++++++++++++ buttplug/tests/test_device_protocols.rs | 1 + .../test_yiciyuan_protocol.yaml | 56 +++++++++++++++ 6 files changed, 210 insertions(+), 1 deletion(-) create mode 100644 buttplug/src/server/device/protocol/yiciyuan.rs create mode 100644 buttplug/tests/util/device_test/device_test_case/test_yiciyuan_protocol.yaml diff --git a/buttplug/buttplug-device-config/build-config/buttplug-device-config-v3.json b/buttplug/buttplug-device-config/build-config/buttplug-device-config-v3.json index e6eb3a007..5128ae919 100644 --- a/buttplug/buttplug-device-config/build-config/buttplug-device-config-v3.json +++ b/buttplug/buttplug-device-config/build-config/buttplug-device-config-v3.json @@ -18577,6 +18577,75 @@ } } ] + }, + "yiciyuan": { + "defaults": { + "name": "YiCiYuan Device", + "features": [ + { + "feature-type": "Vibrate", + "actuator": { + "step-range": [ + 0, + 20 + ], + "messages": [ + "ScalarCmd" + ] + } + } + ] + }, + "configurations": [ + { + "identifier": [ + "YS-TD-01" + ], + "name": "YiCiYuan Vibrator 01" + }, + { + "identifier": [ + "YS-TD-02" + ], + "name": "YiCiYuan Vibrator 02" + }, + { + "identifier": [ + "YS-TD-03" + ], + "name": "YiCiYuan Vibrator 03" + }, + { + "identifier": [ + "YCY-FJB-01" + ], + "name": "YiCiYuan Masturbation Cup 01" + }, + { + "identifier": [ + "YCY-FJB-02" + ], + "name": "YiCiYuan Masturbation Cup 02" + } + ], + "communication": [ + { + "btle": { + "names": [ + "YS-TD-01", + "YS-TD-02", + "YS-TD-03", + "YCY-FJB-01", + "YCY-FJB-02" + ], + "services": { + "0000ff40-0000-1000-8000-00805f9b34fb": { + "tx": "0000ff41-0000-1000-8000-00805f9b34fb" + } + } + } + } + ] } } } diff --git a/buttplug/buttplug-device-config/device-config-v3/buttplug-device-config-v3.yml b/buttplug/buttplug-device-config/device-config-v3/buttplug-device-config-v3.yml index 8d8834eba..b9890e154 100644 --- a/buttplug/buttplug-device-config/device-config-v3/buttplug-device-config-v3.yml +++ b/buttplug/buttplug-device-config/device-config-v3/buttplug-device-config-v3.yml @@ -10650,4 +10650,42 @@ protocols: - S6 services: 0000ffb0-0000-1000-8000-00805f9b34fb: - tx: 0000ffb2-0000-1000-8000-00805f9b34fb \ No newline at end of file + tx: 0000ffb2-0000-1000-8000-00805f9b34fb + yiciyuan: + defaults: + name: YiCiYuan Device + features: + - feature-type: Vibrate + actuator: + step-range: + - 0 + - 20 + messages: + - ScalarCmd + configurations: + - identifier: + - YS-TD-01 + name: YiCiYuan Vibrator 01 + - identifier: + - YS-TD-02 + name: YiCiYuan Vibrator 02 + - identifier: + - YS-TD-03 + name: YiCiYuan Vibrator 03 + - identifier: + - YCY-FJB-01 + name: YiCiYuan Masturbation Cup 01 + - identifier: + - YCY-FJB-02 + name: YiCiYuan Masturbation Cup 02 + communication: + - btle: + names: + - YS-TD-01 + - YS-TD-02 + - YS-TD-03 + - YCY-FJB-01 + - YCY-FJB-02 + services: + 0000ff40-0000-1000-8000-00805f9b34fb: + tx: 0000ff41-0000-1000-8000-00805f9b34fb \ No newline at end of file diff --git a/buttplug/src/server/device/protocol/mod.rs b/buttplug/src/server/device/protocol/mod.rs index 0d5af1507..432aa1332 100644 --- a/buttplug/src/server/device/protocol/mod.rs +++ b/buttplug/src/server/device/protocol/mod.rs @@ -140,6 +140,7 @@ pub mod xibao; pub mod xinput; pub mod xiuxiuda; pub mod xuanhuan; +pub mod yiciyuan; pub mod youcups; pub mod youou; pub mod zalo; @@ -651,6 +652,7 @@ pub fn get_default_protocol_map() -> HashMap super::ProtocolKeepaliveStrategy { + super::ProtocolKeepaliveStrategy::RepeatLastPacketStrategy + } + + fn handle_scalar_vibrate_cmd( + &self, + _index: u32, + scalar: u32, + ) -> Result, ButtplugDeviceError> { + let mut cmd = vec![0x35, 0x12, scalar as u8]; + cmd.resize(16, 0); + Ok(vec![HardwareWriteCmd::new( + Endpoint::Tx, + cmd, + false, + ) + .into()]) + } +} diff --git a/buttplug/tests/test_device_protocols.rs b/buttplug/tests/test_device_protocols.rs index 697e68fc2..1b657050a 100644 --- a/buttplug/tests/test_device_protocols.rs +++ b/buttplug/tests/test_device_protocols.rs @@ -409,6 +409,7 @@ async fn test_device_protocols_embedded_v2(test_file: &str) { #[test_case("test_fleshy_thrust_protocol.yaml" ; "Fleshy Thrust Sync Protocol")] #[test_case("test_nexus_revo.yaml" ; "Nexus Revo Protocol")] #[test_case("test_omobo_protocol.yaml" ; "Omobo Protocol")] +#[test_case("test_yiciyuan_protocol.yaml" ; "Yiciyuan 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; diff --git a/buttplug/tests/util/device_test/device_test_case/test_yiciyuan_protocol.yaml b/buttplug/tests/util/device_test/device_test_case/test_yiciyuan_protocol.yaml new file mode 100644 index 000000000..71e1dd91e --- /dev/null +++ b/buttplug/tests/util/device_test/device_test_case/test_yiciyuan_protocol.yaml @@ -0,0 +1,56 @@ +devices: + - identifier: + name: "YCY-FJB-02" + expected_name: "YiCiYuan Masturbation Cup 02" +device_commands: + # Commands + - !Messages + device_index: 0 + messages: + - !Vibrate + - Index: 0 + Speed: 0.5 + - !Commands + device_index: 0 + commands: + - !Write + endpoint: tx + data: [0x35, 0x12, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] + write_with_response: false + - !Messages + device_index: 0 + messages: + - !Vibrate + - Index: 0 + Speed: 0.1 + - !Commands + device_index: 0 + commands: + - !Write + endpoint: tx + data: [0x35, 0x12, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] + write_with_response: false + - !Messages + device_index: 0 + messages: + - !Vibrate + - Index: 0 + Speed: 1.0 + - !Commands + device_index: 0 + commands: + - !Write + endpoint: tx + data: [0x35, 0x12, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] + write_with_response: false + - !Messages + device_index: 0 + messages: + - !Stop + - !Commands + device_index: 0 + commands: + - !Write + endpoint: tx + data: [0x35, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] + write_with_response: false