Skip to content

Commit

Permalink
fix: Correct the state addressing for ScalarCmd
Browse files Browse the repository at this point in the history
This does not apply to RotateCmd because there isn't a v3->v4 feature index converter yet.

Fixes #668
  • Loading branch information
blackspherefollower authored and qdot committed Nov 20, 2024
1 parent cfd9a65 commit 7a3bf3c
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 12 deletions.
26 changes: 14 additions & 12 deletions buttplug/src/server/device/protocol/actuator_command_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::core::{
ScalarSubcommandV4,
},
};
use ahash::{HashMap, HashMapExt};
use getset::Getters;
use std::{
collections::HashSet,
Expand Down Expand Up @@ -205,16 +206,17 @@ impl ActuatorCommandManager {
);
}

let mut final_result: Vec<Option<(ActuatorType, u32)>> = vec![
None;
self
.feature_status
.iter()
.filter(|x| x
.messages()
.contains(&ButtplugActuatorFeatureMessageType::ScalarCmd))
.count()
];
let mut idxs = HashMap::new();
for (i, x) in self.feature_status.iter().enumerate() {
if x
.messages()
.contains(&ButtplugActuatorFeatureMessageType::ScalarCmd)
{
idxs.insert(i, idxs.len());
}
}

let mut final_result: Vec<Option<(ActuatorType, u32)>> = vec![None; idxs.len()];

let mut commands: Vec<(u32, ActuatorType, (f64, bool))> = vec![];
msg
Expand All @@ -228,7 +230,7 @@ impl ActuatorCommandManager {
)?;
result.sort_by(|a, b| a.0.partial_cmp(&b.0).unwrap());
result.iter().for_each(|(index, actuator, value)| {
final_result[*index as usize] = Some((*actuator, value.0))
final_result[idxs[&(*index as usize)]] = Some((*actuator, value.0))
});
Ok(final_result)
}
Expand All @@ -255,7 +257,7 @@ impl ActuatorCommandManager {
.feature_status
.iter()
.filter(|x| x
.messages()
.messages()
.contains(&ButtplugActuatorFeatureMessageType::RotateCmd))
.count()
];
Expand Down
4 changes: 4 additions & 0 deletions buttplug/tests/test_device_protocols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ async fn load_test_case(test_file: &str) -> DeviceTestCase {
#[test_case("test_feelingso.yaml" ; "FeelingSo Protocol")]
#[test_case("test_deepsire.yaml" ; "DeepSire Protocol")]
#[test_case("test_xuanhuan_protocol.yaml" ; "Xuanhuan Protocol")]
#[test_case("test_tcode_linear_and_vibrate.yaml" ; "TCode (Linear + Vibrate)")]
#[tokio::test]
async fn test_device_protocols_embedded_v3(test_file: &str) {
//tracing_subscriber::fmt::init();
Expand Down Expand Up @@ -216,6 +217,7 @@ async fn test_device_protocols_embedded_v3(test_file: &str) {
#[test_case("test_feelingso.yaml" ; "FeelingSo Protocol")]
#[test_case("test_deepsire.yaml" ; "DeepSire Protocol")]
#[test_case("test_xuanhuan_protocol.yaml" ; "Xuanhuan Protocol")]
#[test_case("test_tcode_linear_and_vibrate.yaml" ; "TCode (Linear + Vibrate)")]
#[tokio::test]
async fn test_device_protocols_json_v3(test_file: &str) {
//tracing_subscriber::fmt::init();
Expand Down Expand Up @@ -290,6 +292,7 @@ async fn test_device_protocols_json_v3(test_file: &str) {
#[test_case("test_amorelie_joy_protocol.yaml" ; "Amorelie Joy Protocol")]
#[test_case("test_deepsire.yaml" ; "DeepSire Protocol")]
#[test_case("test_xuanhuan_protocol.yaml" ; "Xuanhuan Protocol")]
#[test_case("test_tcode_linear_and_vibrate.yaml" ; "TCode (Linear + Vibrate)")]
#[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 @@ -363,6 +366,7 @@ async fn test_device_protocols_embedded_v2(test_file: &str) {
#[test_case("test_amorelie_joy_protocol.yaml" ; "Amorelie Joy Protocol")]
#[test_case("test_deepsire.yaml" ; "DeepSire Protocol")]
#[test_case("test_xuanhuan_protocol.yaml" ; "Xuanhuan Protocol")]
#[test_case("test_tcode_linear_and_vibrate.yaml" ; "TCode (Linear + Vibrate)")]
#[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,61 @@
{
"version": {
"major": 3,
"minor": 999
},
"user-configs": {
"protocols": {
"tcode-v03": {
"communication": [{
"btle": {
"names": [
"tcode-v03"
],
"services": {
"0000eea0-0000-1000-8000-00805f9b34fb": {
"tx": "0000ee01-0000-1000-8000-00805f9b34fb"
}
}
}
}
],
"configurations": []
}
},
"devices": [
{
"identifier": {
"protocol": "tcode-v03",
"identifier": "tcode-v03",
"address": "COM7"
},
"config": {
"name": "TCode v0.3 (Single Linear Axis + Single Vibe)",
"features": [{
"description": "",
"feature-type": "Position",
"actuator": {
"step-range": [0, 100],
"step-limit": [0, 100],
"messages": ["LinearCmd"]
}
}, {
"description": "",
"feature-type": "Vibrate",
"actuator": {
"step-range": [0, 99],
"step-limit": [0, 99],
"messages": ["ScalarCmd"]
}
}
],
"user-config": {
"allow": false,
"deny": false,
"index": 0
}
}
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
user_device_config_file: "tcode_linear_and_vibrate_user_config.json"
devices:
- identifier:
name: "tcode-v03"
address: "COM7"
expected_name: "TCode v0.3 (Single Linear Axis + Single Vibe)"
device_commands:
- !Messages
device_index: 0
messages:
- !Linear
- Index: 0
Position: 0.51
Duration: 200
- !Commands
device_index: 0
commands:
- !Write
endpoint: tx
data: [76, 48, 53, 48, 73, 50, 48, 48, 10]
write_with_response: false
- !Messages
device_index: 0
messages:
- !Vibrate
- Index: 0
Speed: 1
- !Commands
device_index: 0
commands:
- !Write
endpoint: tx
data: [86, 48, 57, 57, 10]
write_with_response: false
- !Messages
device_index: 0
messages:
- !Stop
- !Commands
device_index: 0
commands:
- !Write
endpoint: tx
data: [86, 48, 48, 48, 10]
write_with_response: false

0 comments on commit 7a3bf3c

Please sign in to comment.