1use std::thread;
2use std::time::Duration;
3use vigem_rust::Client;
4use vigem_rust::controller::ds4::Ds4ReportEx;
5
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7 let client = Client::connect()?;
10 println!("Connected to ViGEm bus");
11
12 let ds4 = client.new_ds4_target().plugin()?;
14 println!("Plugged in virtual DualShock 4 controller");
15
16 ds4.wait_for_ready()?;
18 println!("Controller is ready. You can test it at https://hardwaretester.com/gamepad");
19
20 let notifications = ds4.register_notification()?;
21 thread::spawn(move || {
22 println!("Notification Thread Started. Waiting for feedback from the host...");
23 while let Ok(Ok(notification)) = notifications.recv() {
24 println!("Notification Thread Received feedback:");
25 println!(
26 " - Rumble: Large Motor = {}, Small Motor = {}",
27 notification.large_motor, notification.small_motor
28 );
29 println!(
30 " - Lightbar Color: R={}, G={}, B={}",
31 notification.lightbar.red, notification.lightbar.green, notification.lightbar.blue
32 );
33 }
34 });
35
36 let mut report_ex = Ds4ReportEx::default();
38
39 let mut packet_counter: u8 = 0;
41 let mut touch_x: i32 = 0;
42 let mut direction: i32 = 12;
43
44 loop {
45 if touch_x <= 0 {
47 direction = 12;
48 }
49 if touch_x >= 1919 {
50 direction = -12;
51 }
52 touch_x += direction;
53
54 report_ex.touch_packets_n = 1;
55
56 let touch = &mut report_ex.current_touch;
58
59 touch.packet_counter = packet_counter;
61 packet_counter = packet_counter.wrapping_add(1);
62
63 touch.set_touch_1(true, 1, touch_x as u16, 471); touch.set_touch_2(false, 0, 0, 0); ds4.update_ex(&report_ex)?;
68
69 thread::sleep(Duration::from_millis(16));
70 }
71}