use super::{ButtplugDeviceResultFuture, ButtplugProtocol, ButtplugProtocolCommandHandler};
use crate::{
core::messages::{self, ButtplugDeviceCommandMessageUnion, MessageAttributesMap},
device::{
protocol::{generic_command_manager::GenericCommandManager, ButtplugProtocolProperties},
DeviceImpl,
DeviceWriteCmd,
Endpoint,
},
};
use std::sync::Arc;
#[derive(ButtplugProtocolProperties)]
pub struct Svakom {
name: String,
message_attributes: MessageAttributesMap,
stop_commands: Vec<ButtplugDeviceCommandMessageUnion>,
}
impl ButtplugProtocol for Svakom {
fn new_protocol(
name: &str,
message_attributes: MessageAttributesMap,
) -> Box<dyn ButtplugProtocol> {
let manager = GenericCommandManager::new(&message_attributes);
Box::new(Self {
name: name.to_owned(),
message_attributes,
stop_commands: manager.get_stop_commands(),
})
}
}
impl ButtplugProtocolCommandHandler for Svakom {
fn handle_vibrate_cmd(
&self,
device: Arc<Box<dyn DeviceImpl>>,
msg: messages::VibrateCmd,
) -> ButtplugDeviceResultFuture {
let speed = (msg.speeds[0].speed * 19.0) as u8;
let multiplier: u8 = if speed == 0x00 { 0x00 } else { 0x01 };
let msg = DeviceWriteCmd::new(
Endpoint::Tx,
[0x55, 0x04, 0x03, 0x00, multiplier, speed].to_vec(),
false,
);
let fut = device.write_value(msg);
Box::pin(async {
fut.await?;
Ok(messages::Ok::default().into())
})
}
}