-
-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathossm.rs
More file actions
81 lines (73 loc) · 1.99 KB
/
ossm.rs
File metadata and controls
81 lines (73 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Buttplug Rust Source Code File - See https://buttplug.io for more info.
//
// Copyright 2016-2024 Nonpolynomial Labs LLC. All rights reserved.
//
// Licensed under the BSD 3-Clause license. See LICENSE file in the project root
// for full license information.
use crate::device::{
hardware::{Hardware, HardwareCommand, HardwareWriteCmd},
protocol::{
ProtocolHandler,
ProtocolIdentifier,
ProtocolInitializer,
generic_protocol_initializer_setup
},
};
use buttplug_core::errors::ButtplugDeviceError;
use buttplug_server_device_config::{
Endpoint,
ServerDeviceDefinition,
UserDeviceIdentifier,
ProtocolCommunicationSpecifier,
};
use std::sync::Arc;
use uuid::{Uuid, uuid};
use async_trait::async_trait;
const OSSM_PROTOCOL_UUID: Uuid = uuid!("a817e40d-acda-439d-bebf-420badbabe69");
generic_protocol_initializer_setup!(OSSM, "ossm");
#[derive(Default)]
pub struct OSSMInitializer {}
#[async_trait]
impl ProtocolInitializer for OSSMInitializer {
async fn initialize(
&mut self,
hardware: Arc<Hardware>,
_: &ServerDeviceDefinition,
) -> Result<Arc<dyn ProtocolHandler>, ButtplugDeviceError> {
let msg = HardwareWriteCmd::new(
&[OSSM_PROTOCOL_UUID],
Endpoint::Tx,
format!("go:strokeEngine").into_bytes(),
false,
);
hardware.write_value(&msg).await?;
Ok(Arc::new(OSSM::default()))
}
}
#[derive(Default)]
pub struct OSSM {}
impl ProtocolHandler for OSSM {
fn handle_output_oscillate_cmd(
&self,
feature_index: u32,
feature_id: Uuid,
value: u32,
) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> {
let param = if feature_index == 0 {
"speed"
} else {
return Err(ButtplugDeviceError::DeviceFeatureMismatch(
format!("OSSM command received for unknown feature index: {}", feature_index),
));
};
Ok(vec![
HardwareWriteCmd::new(
&[feature_id],
Endpoint::Tx,
format!("set:{param}:{value}").into_bytes(),
false,
)
.into(),
])
}
}