Skip to content

Commit b9c70f4

Browse files
committed
fix: Actually pay attention to message ids for readings
DO NOT HARDCODE THEM TO 1. :(
1 parent 25456c1 commit b9c70f4

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

crates/buttplug_server/src/device/server_device.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ use buttplug_core::{
4848
errors::{ButtplugDeviceError, ButtplugError},
4949
message::{
5050
self,
51+
ButtplugMessage,
5152
ButtplugServerMessageV4,
5253
DeviceFeature,
5354
DeviceMessageInfoV4,
@@ -535,9 +536,17 @@ impl ServerDevice {
535536
&self,
536537
command_message: ButtplugDeviceCommandMessageUnionV4,
537538
) -> ButtplugServerResultFuture {
538-
match command_message {
539+
match &command_message {
539540
// Input messages
540-
ButtplugDeviceCommandMessageUnionV4::InputCmd(msg) => self.handle_input_cmd(msg),
541+
ButtplugDeviceCommandMessageUnionV4::InputCmd(msg) => {
542+
let fut = self.handle_input_cmd(msg);
543+
let msg_id = msg.id();
544+
async move {
545+
let mut msg = fut.await?;
546+
msg.set_id(msg_id);
547+
Ok(msg)
548+
}.boxed()
549+
},
541550
// Actuator messages
542551
ButtplugDeviceCommandMessageUnionV4::OutputCmd(msg) => self.handle_outputcmd_v4(&msg),
543552
ButtplugDeviceCommandMessageUnionV4::OutputVecCmd(msg) => {
@@ -610,7 +619,7 @@ impl ServerDevice {
610619

611620
fn handle_input_cmd(
612621
&self,
613-
message: CheckedInputCmdV4,
622+
message: &CheckedInputCmdV4,
614623
) -> BoxFuture<'static, Result<ButtplugServerMessageV4, ButtplugError>> {
615624
match message.input_command() {
616625
InputCommandType::Read => self.handle_input_read_cmd(

crates/buttplug_server/src/message/v2/battery_level_cmd.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ impl TryFromDeviceAttributes<BatteryLevelCmdV2> for CheckedInputCmdV4 {
8080
.0;
8181

8282
Ok(CheckedInputCmdV4::new(
83+
msg.id(),
8384
msg.device_index(),
8485
*feature_index,
8586
InputType::Battery,

crates/buttplug_server/src/message/v3/sensor_read_cmd.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ impl TryFromDeviceAttributes<SensorReadCmdV3> for CheckedInputCmdV4 {
8383
.find(|(_, p)| p.input().as_ref().is_some_and(|x| x.battery().is_some()))
8484
{
8585
Ok(CheckedInputCmdV4::new(
86+
msg.id(),
8687
msg.device_index(),
8788
*feature_index,
8889
InputType::Battery,

crates/buttplug_server/src/message/v4/checked_input_cmd.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,15 @@ pub struct CheckedInputCmdV4 {
3636

3737
impl CheckedInputCmdV4 {
3838
pub fn new(
39+
id: u32,
3940
device_index: u32,
4041
feature_index: u32,
4142
input_type: InputType,
4243
input_command: InputCommandType,
4344
feature_id: Uuid,
4445
) -> Self {
4546
Self {
46-
id: 1,
47+
id,
4748
device_index,
4849
feature_index,
4950
input_type,
@@ -69,6 +70,7 @@ impl TryFromDeviceAttributes<InputCmdV4> for CheckedInputCmdV4 {
6970
if let Some(sensor_map) = feature.input() {
7071
if sensor_map.contains(msg.input_type()) {
7172
Ok(CheckedInputCmdV4::new(
73+
msg.id(),
7274
msg.device_index(),
7375
msg.feature_index(),
7476
msg.input_type(),

0 commit comments

Comments
 (0)