Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 9 additions & 25 deletions crates/buttplug_client/src/device/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,8 @@ impl ButtplugClientDevice {
fn filter_device_outputs(&self, actuator_type: OutputType) -> Vec<ClientDeviceFeature> {
self
.device_features
.iter()
.filter(|x| {
if let Some(output) = x.1.feature().output() {
output.contains(actuator_type)
} else {
false
}
})
.map(|(_, x)| x)
.values()
.filter(|x| x.feature().contains_output(actuator_type))
.cloned()
.collect()
}
Expand Down Expand Up @@ -204,13 +197,10 @@ impl ButtplugClientDevice {
}

pub fn input_available(&self, input_type: InputType) -> bool {
self.device_features.iter().any(|x| {
x.1
.feature()
.input()
.as_ref()
.is_some_and(|x| x.contains(input_type))
})
self
.device_features
.values()
.any(|x| x.feature().contains_input(input_type))
}

fn input_feature(
Expand All @@ -219,14 +209,8 @@ impl ButtplugClientDevice {
) -> Result<&ClientDeviceFeature, ButtplugClientError> {
let inputs: Vec<_> = self
.device_features
.iter()
.filter(|x| {
x.1
.feature()
.input()
.as_ref()
.is_some_and(|x| x.contains(input_type))
})
.values()
.filter(|x| x.feature().contains_input(input_type))
.collect();
let input_count = inputs.len();
if input_count > 1 {
Expand All @@ -238,7 +222,7 @@ impl ButtplugClientDevice {
ButtplugDeviceError::DeviceNoInputError(input_type).into(),
))
} else {
Ok(inputs[0].1)
Ok(inputs[0])
}
}

Expand Down
58 changes: 15 additions & 43 deletions crates/buttplug_client/src/device/feature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl ClientDeviceFeature {
ClientDeviceCommandValue::Percent(f) => self.convert_float_value(feature_output, *f)?,
ClientDeviceCommandValue::Steps(i) => *i,
};
if feature_output.step_limit().contains(&value) {
if feature_output.step_limit().contains(value) {
Ok(value)
} else {
Err(ButtplugClientError::ButtplugOutputCommandConversionError(
Expand Down Expand Up @@ -118,23 +118,12 @@ impl ClientDeviceFeature {
) -> Result<OutputCmdV4, ButtplugClientError> {
let output_type: OutputType = client_cmd.into();
// First off, make sure we support this output.
let output = self
.feature
.output()
.as_ref()
.ok_or(ButtplugClientError::ButtplugOutputCommandConversionError(
format!(
"Device feature does not support output type {}",
output_type
),
))?
.get(output_type)
.ok_or(ButtplugClientError::ButtplugOutputCommandConversionError(
format!(
"Device feature does not support output type {}",
output_type
),
))?;
let output = self.feature.get_output_limits(output_type).ok_or(
ButtplugClientError::ButtplugOutputCommandConversionError(format!(
"Device feature does not support output type {}",
output_type
)),
)?;

let output_cmd = match client_cmd {
ClientDeviceOutputCommand::Vibrate(v) => {
Expand Down Expand Up @@ -186,9 +175,8 @@ impl ClientDeviceFeature {
}

pub fn run_input_subscribe(&self, sensor_type: InputType) -> ButtplugClientResultFuture {
if let Some(sensor_map) = self.feature.input()
&& let Some(sensor) = sensor_map.get(sensor_type)
&& sensor.command().contains(&InputCommandType::Subscribe)
if let Some(sensor) = self.feature.get_input(sensor_type)
&& sensor.command().contains(InputCommandType::Subscribe)
{
let msg = InputCmdV4::new(
self.device_index,
Expand All @@ -206,9 +194,8 @@ impl ClientDeviceFeature {
}

pub fn run_input_unsubscribe(&self, sensor_type: InputType) -> ButtplugClientResultFuture {
if let Some(sensor_map) = self.feature.input()
&& let Some(sensor) = sensor_map.get(sensor_type)
&& sensor.command().contains(&InputCommandType::Subscribe)
if let Some(sensor) = self.feature.get_input(sensor_type)
&& sensor.command().contains(InputCommandType::Subscribe)
{
let msg = InputCmdV4::new(
self.device_index,
Expand All @@ -229,9 +216,8 @@ impl ClientDeviceFeature {
&self,
sensor_type: InputType,
) -> ButtplugClientResultFuture<InputTypeReading> {
if let Some(sensor_map) = self.feature.input()
&& let Some(sensor) = sensor_map.get(sensor_type)
&& sensor.command().contains(&InputCommandType::Read)
if let Some(sensor) = self.feature.get_input(sensor_type)
&& sensor.command().contains(InputCommandType::Read)
{
let msg = InputCmdV4::new(
self.device_index,
Expand Down Expand Up @@ -271,14 +257,7 @@ impl ClientDeviceFeature {
}

pub fn battery(&self) -> ButtplugClientResultFuture<u32> {
if self
.feature()
.input()
.as_ref()
.ok_or(false)
.unwrap()
.contains(InputType::Battery)
{
if self.feature().contains_input(InputType::Battery) {
let send_fut = self.run_input_read(InputType::Battery);
Box::pin(async move {
let data = send_fut.await?;
Expand All @@ -298,14 +277,7 @@ impl ClientDeviceFeature {
}

pub fn rssi(&self) -> ButtplugClientResultFuture<i8> {
if self
.feature()
.input()
.as_ref()
.ok_or(false)
.unwrap()
.contains(InputType::Rssi)
{
if self.feature().contains_input(InputType::Rssi) {
let send_fut = self.run_input_read(InputType::Rssi);
Box::pin(async move {
let data = send_fut.await?;
Expand Down
3 changes: 2 additions & 1 deletion crates/buttplug_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,5 @@ enum_dispatch = "0.3"
tracing = "0.1.44"
wasm-bindgen-futures = { version = "0.4.64", optional = true }
wasmtimer = { version = "0.4.3", optional = true }

smallvec = { version = "1.15.1", features = ["serde", "const_generics"] }
enumflags2 = "0.7.12"
Loading