MCPcopy Create free account
hub / github.com/emberian/evdev / main

Function main

examples/force_feedback.rs:7–52  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5mod _pick_device;
6
7fn main() -> std::io::Result<()> {
8 let mut d = _pick_device::pick_device();
9 println!("{d}");
10 println!("It's time to rumble!");
11
12 let effect_data = FFEffectData {
13 direction: 0,
14 trigger: FFTrigger::default(),
15 replay: FFReplay {
16 length: 1000,
17 delay: 0,
18 },
19 kind: FFEffectKind::Rumble {
20 strong_magnitude: 0x0000,
21 weak_magnitude: 0xffff,
22 },
23 };
24
25 let mut effect = d.upload_ff_effect(effect_data)?;
26
27 std::thread::spawn(move || {
28 loop {
29 // monitor the response from the device
30 const STOPPED: i32 = FFStatusCode::FF_STATUS_STOPPED.0 as i32;
31 const STARTED: i32 = FFStatusCode::FF_STATUS_PLAYING.0 as i32;
32 for ev in d.fetch_events().unwrap() {
33 match ev.destructure() {
34 EventSummary::ForceFeedback(_, FFEffectCode(id), STARTED) => {
35 println!("Device Started effect id {}", id);
36 }
37 EventSummary::ForceFeedback(_, FFEffectCode(id), STOPPED) => {
38 println!("Device Stopped effect id {}", id);
39 }
40 _ => (),
41 }
42 }
43 }
44 });
45
46 effect.play(1)?;
47 std::thread::sleep(std::time::Duration::from_secs(1));
48 effect.stop()?;
49 std::thread::sleep(std::time::Duration::from_secs(1));
50
51 Ok(())
52}

Callers

nothing calls this directly

Calls 6

pick_deviceFunction · 0.85
playMethod · 0.80
stopMethod · 0.80
upload_ff_effectMethod · 0.45
fetch_eventsMethod · 0.45
destructureMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…