Skip to content

Commit 25456c1

Browse files
committed
chore: Change InputData to InputReading, simplify InputCmd field names
1 parent 47e1bcf commit 25456c1

File tree

15 files changed

+51
-51
lines changed

15 files changed

+51
-51
lines changed

crates/buttplug_client/src/device/feature.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use buttplug_core::{
55
errors::{ButtplugDeviceError, ButtplugError, ButtplugMessageError},
66
message::{
77
ButtplugDeviceMessageNameV4, ButtplugServerMessageV4, DeviceFeature, DeviceFeatureOutputLimits,
8-
InputCmdV4, InputCommandType, InputType, InputTypeData, OutputCmdV4, OutputCommand,
8+
InputCmdV4, InputCommandType, InputType, InputTypeReading, OutputCmdV4, OutputCommand,
99
OutputPositionWithDuration, OutputType, OutputValue,
1010
},
1111
};
@@ -244,7 +244,7 @@ impl ClientDeviceFeature {
244244
)
245245
}
246246

247-
fn read_sensor(&self, sensor_type: InputType) -> ButtplugClientResultFuture<InputTypeData> {
247+
fn read_input(&self, sensor_type: InputType) -> ButtplugClientResultFuture<InputTypeReading> {
248248
if let Some(sensor_map) = self.feature.input()
249249
&& let Some(sensor) = sensor_map.get(sensor_type)
250250
&& sensor.input_commands().contains(&InputCommandType::Read)
@@ -259,8 +259,8 @@ impl ClientDeviceFeature {
259259
let reply = self.event_loop_sender.send_message(msg);
260260
return async move {
261261
if let ButtplugServerMessageV4::InputReading(data) = reply.await? {
262-
if sensor_type == data.data().as_input_type() {
263-
Ok(data.data())
262+
if sensor_type == data.reading().into() {
263+
Ok(data.reading())
264264
} else {
265265
Err(
266266
ButtplugError::ButtplugMessageError(ButtplugMessageError::UnexpectedMessageType(
@@ -295,10 +295,10 @@ impl ClientDeviceFeature {
295295
.unwrap()
296296
.contains(InputType::Battery)
297297
{
298-
let send_fut = self.read_sensor(InputType::Battery);
298+
let send_fut = self.read_input(InputType::Battery);
299299
Box::pin(async move {
300300
let data = send_fut.await?;
301-
let battery_level = if let InputTypeData::Battery(level) = data {
301+
let battery_level = if let InputTypeReading::Battery(level) = data {
302302
level.data()
303303
} else {
304304
0
@@ -322,10 +322,10 @@ impl ClientDeviceFeature {
322322
.unwrap()
323323
.contains(InputType::Rssi)
324324
{
325-
let send_fut = self.read_sensor(InputType::Rssi);
325+
let send_fut = self.read_input(InputType::Rssi);
326326
Box::pin(async move {
327327
let data = send_fut.await?;
328-
let rssi_level = if let InputTypeData::Rssi(level) = data {
328+
let rssi_level = if let InputTypeReading::Rssi(level) = data {
329329
level.data()
330330
} else {
331331
0

crates/buttplug_core/schema/buttplug-schema.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -507,10 +507,10 @@
507507
"FeatureIndex": {
508508
"type": "integer"
509509
},
510-
"InputType": {
510+
"Type": {
511511
"type": "string"
512512
},
513-
"InputCommand": {
513+
"Command": {
514514
"type": "string"
515515
}
516516
},
@@ -519,8 +519,8 @@
519519
"Id",
520520
"DeviceIndex",
521521
"FeatureIndex",
522-
"InputType",
523-
"InputCommand"
522+
"Type",
523+
"Command"
524524
]
525525
},
526526
"InputReading": {
@@ -540,7 +540,7 @@
540540
"type": "object",
541541
"patternProperties": {
542542
"^Battery|Rssi|Pressure|Button": {
543-
"type": "integer"
543+
"type": "object"
544544
}
545545
},
546546
"maxProperties": 1

crates/buttplug_core/src/message/v4/input_cmd.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ pub struct InputCmdV4 {
4747
#[serde(rename = "FeatureIndex")]
4848
feature_index: u32,
4949
#[getset(get_copy = "pub")]
50-
#[serde(rename = "InputType")]
50+
#[serde(rename = "Type")]
5151
input_type: InputType,
5252
#[getset(get_copy = "pub")]
53-
#[serde(rename = "InputCommand")]
53+
#[serde(rename = "Command")]
5454
input_command: InputCommandType,
5555
}
5656

crates/buttplug_core/src/message/v4/input_reading.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ use serde::{Deserialize, Serialize};
1717

1818
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, CopyGetters)]
1919
#[getset(get_copy = "pub")]
20-
pub struct InputData<T>
20+
pub struct InputValue<T>
2121
where
2222
T: Copy + Clone,
2323
{
24-
#[serde(rename = "Data")]
24+
#[serde(rename = "Value")]
2525
data: T,
2626
}
2727

28-
impl<T> InputData<T>
28+
impl<T> InputValue<T>
2929
where
3030
T: Copy + Clone,
3131
{
@@ -35,15 +35,15 @@ where
3535
}
3636

3737
#[derive(Debug, Display, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
38-
pub enum InputTypeData {
39-
Battery(InputData<u8>),
40-
Rssi(InputData<i8>),
41-
Button(InputData<u8>),
42-
Pressure(InputData<u32>),
38+
pub enum InputTypeReading {
39+
Battery(InputValue<u8>),
40+
Rssi(InputValue<i8>),
41+
Button(InputValue<u8>),
42+
Pressure(InputValue<u32>),
4343
}
4444

45-
impl InputTypeData {
46-
pub fn as_input_type(&self) -> InputType {
45+
impl Into<InputType> for InputTypeReading {
46+
fn into(self) -> InputType {
4747
match self {
4848
Self::Battery(_) => InputType::Battery,
4949
Self::Rssi(_) => InputType::Rssi,
@@ -76,18 +76,18 @@ pub struct InputReadingV4 {
7676
#[serde(rename = "FeatureIndex")]
7777
#[getset[get_copy="pub"]]
7878
feature_index: u32,
79-
#[serde(rename = "Data")]
79+
#[serde(rename = "Reading")]
8080
#[getset[get_copy="pub"]]
81-
data: InputTypeData,
81+
reading: InputTypeReading,
8282
}
8383

8484
impl InputReadingV4 {
85-
pub fn new(device_index: u32, feature_index: u32, data: InputTypeData) -> Self {
85+
pub fn new(device_index: u32, feature_index: u32, data: InputTypeReading) -> Self {
8686
Self {
8787
id: 0,
8888
device_index,
8989
feature_index,
90-
data,
90+
reading: data,
9191
}
9292
}
9393
}

crates/buttplug_core/src/message/v4/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub use {
1818
device_list::DeviceListV4,
1919
device_message_info::DeviceMessageInfoV4,
2020
input_cmd::{InputCmdV4, InputCommandType},
21-
input_reading::{InputData, InputReadingV4, InputTypeData},
21+
input_reading::{InputValue, InputReadingV4, InputTypeReading},
2222
output_cmd::{OutputCmdV4, OutputCommand, OutputPositionWithDuration, OutputValue},
2323
request_server_info::RequestServerInfoV4,
2424
server_info::ServerInfoV4,

crates/buttplug_server/src/device/protocol.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
1010
use buttplug_core::{
1111
errors::ButtplugDeviceError,
12-
message::{InputData, InputReadingV4, InputType, OutputCommand},
12+
message::{InputValue, InputReadingV4, InputType, OutputCommand},
1313
};
1414
use buttplug_server_device_config::{
1515
Endpoint,
@@ -432,7 +432,7 @@ pub trait ProtocolHandler: Sync + Send {
432432
let battery_reading = InputReadingV4::new(
433433
device_index,
434434
feature_index,
435-
buttplug_core::message::InputTypeData::Battery(InputData::new(battery_level as u8)),
435+
buttplug_core::message::InputTypeReading::Battery(InputValue::new(battery_level as u8)),
436436
);
437437
debug!("Got battery reading: {}", battery_level);
438438
Ok(battery_reading)

crates/buttplug_server/src/device/protocol_impl/galaku.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use futures_util::future::BoxFuture;
1414
use futures_util::{FutureExt, future};
1515

1616
use buttplug_core::errors::ButtplugDeviceError;
17-
use buttplug_core::message::{InputData, InputReadingV4, InputType, InputTypeData};
17+
use buttplug_core::message::{InputValue, InputReadingV4, InputType, InputTypeReading};
1818
use buttplug_server_device_config::Endpoint;
1919

2020
use buttplug_server_device_config::{
@@ -330,7 +330,7 @@ impl ProtocolHandler for Galaku {
330330
let battery_reading = InputReadingV4::new(
331331
device_index,
332332
feature_index,
333-
InputTypeData::Battery(InputData::new(data[0])),
333+
InputTypeReading::Battery(InputValue::new(data[0])),
334334
);
335335
Ok(battery_reading)
336336
}

crates/buttplug_server/src/device/protocol_impl/kgoal_boost.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::{
1414
};
1515
use buttplug_core::{
1616
errors::ButtplugDeviceError,
17-
message::{InputData, InputReadingV4, InputType},
17+
message::{InputValue, InputReadingV4, InputType},
1818
util::{async_manager, stream::convert_broadcast_receiver_to_stream},
1919
};
2020
use buttplug_server_device_config::Endpoint;
@@ -105,7 +105,7 @@ impl ProtocolHandler for KGoalBoost {
105105
InputReadingV4::new(
106106
device_index,
107107
feature_index,
108-
buttplug_core::message::InputTypeData::Pressure(InputData::new(normalized)),
108+
buttplug_core::message::InputTypeReading::Pressure(InputValue::new(normalized)),
109109
)
110110
.into(),
111111
)
@@ -120,7 +120,7 @@ impl ProtocolHandler for KGoalBoost {
120120
InputReadingV4::new(
121121
device_index,
122122
feature_index,
123-
buttplug_core::message::InputTypeData::Pressure(InputData::new(unnormalized)),
123+
buttplug_core::message::InputTypeReading::Pressure(InputValue::new(unnormalized)),
124124
)
125125
.into(),
126126
)

crates/buttplug_server/src/device/protocol_impl/kiiroo_powershot.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::device::{
1111
};
1212
use buttplug_core::{
1313
errors::ButtplugDeviceError,
14-
message::{self, InputData, InputReadingV4, InputTypeData},
14+
message::{self, InputValue, InputReadingV4, InputTypeReading},
1515
};
1616
use buttplug_server_device_config::Endpoint;
1717
use futures::{FutureExt, future::BoxFuture};
@@ -79,7 +79,7 @@ impl ProtocolHandler for KiirooPowerShot {
7979
let battery_reading = message::InputReadingV4::new(
8080
device_index,
8181
feature_index,
82-
InputTypeData::Battery(InputData::new(data[0])),
82+
InputTypeReading::Battery(InputValue::new(data[0])),
8383
);
8484
debug!("Got battery reading: {}", data[0]);
8585
Ok(battery_reading)

crates/buttplug_server/src/device/protocol_impl/kiiroo_prowand.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::device::{
1111
};
1212
use buttplug_core::{
1313
errors::ButtplugDeviceError,
14-
message::{self, InputData, InputReadingV4, InputTypeData},
14+
message::{self, InputValue, InputReadingV4, InputTypeReading},
1515
};
1616
use buttplug_server_device_config::Endpoint;
1717
use futures::{FutureExt, future::BoxFuture};
@@ -64,7 +64,7 @@ impl ProtocolHandler for KiirooProWand {
6464
let battery_reading = message::InputReadingV4::new(
6565
device_index,
6666
feature_index,
67-
InputTypeData::Battery(InputData::new(data[0])),
67+
InputTypeReading::Battery(InputValue::new(data[0])),
6868
);
6969
debug!("Got battery reading: {}", data[0]);
7070
Ok(battery_reading)

0 commit comments

Comments
 (0)