()
| 21 | |
| 22 | #[tokio::main] |
| 23 | async fn main() -> anyhow::Result<()> { |
| 24 | let connector = ButtplugRemoteClientConnector::< |
| 25 | ButtplugWebsocketClientTransport, |
| 26 | ButtplugClientJSONSerializer, |
| 27 | >::new(ButtplugWebsocketClientTransport::new_insecure_connector( |
| 28 | "ws://127.0.0.1:12345", |
| 29 | )); |
| 30 | |
| 31 | let client = ButtplugClient::new("Example Client"); |
| 32 | client.connect(connector).await?; |
| 33 | |
| 34 | println!("Connected!"); |
| 35 | |
| 36 | // You usually shouldn't run Start/Stop scanning back-to-back like |
| 37 | // this, but with TestDevice we know our device will be found when we |
| 38 | // call StartScanning, so we can get away with it. |
| 39 | client.start_scanning().await?; |
| 40 | client.stop_scanning().await?; |
| 41 | println!("Client currently knows about these devices:"); |
| 42 | let mut device_index: i32 = -1; |
| 43 | for (i, device) in client.devices() { |
| 44 | device_index = i as i32; |
| 45 | println!("- {}", device.name()); |
| 46 | } |
| 47 | wait_for_input().await; |
| 48 | |
| 49 | for (_, device) in client.devices() { |
| 50 | println!("{} supports these outputs:", device.name()); |
| 51 | for output_type in OutputType::iter() { |
| 52 | for feature in device.device_features().values() { |
| 53 | if feature.feature().contains_output(output_type) { |
| 54 | println!("- {}", output_type); |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | println!("Sending commands"); |
| 61 | |
| 62 | // Now that we know the message types for our connected device, we |
| 63 | // can send a message over! Seeing as we want to stick with the |
| 64 | // modern generic messages, we'll go with VibrateCmd. |
| 65 | // |
| 66 | // There's a couple of ways to send this message. |
| 67 | let devices = client.devices(); |
| 68 | let test_client_device = devices.get(&(device_index as u32)).unwrap(); |
| 69 | |
| 70 | // We can use the convenience functions on ButtplugClientDevice to |
| 71 | // send the message. This version sets all of the motors on a |
| 72 | // vibrating device to the same speed. |
| 73 | test_client_device |
| 74 | .run_output(&ClientDeviceOutputCommand::Vibrate( |
| 75 | ClientDeviceCommandValue::Percent(0.5f64), |
| 76 | )) |
| 77 | .await?; |
| 78 | |
| 79 | // If we wanted to just set one motor on and the other off, we could |
| 80 | // try this version that uses an array. It'll throw an exception if |
nothing calls this directly
no test coverage detected