Update PR to bring it more in line with VirtualDevice::emit
This commit is contained in:
parent
16810308e4
commit
ab0f260115
3 changed files with 25 additions and 29 deletions
|
@ -8,23 +8,23 @@ fn main() {
|
||||||
println!("Blinking the Keyboard LEDS...");
|
println!("Blinking the Keyboard LEDS...");
|
||||||
for i in 0..5 {
|
for i in 0..5 {
|
||||||
let on = i % 2 != 0;
|
let on = i % 2 != 0;
|
||||||
d.send_event(&InputEvent::new(
|
d.send_events(&[
|
||||||
EventType::LED,
|
InputEvent::new(
|
||||||
LedType::LED_CAPSL.0,
|
EventType::LED,
|
||||||
if on { i32::MAX } else { 0 },
|
LedType::LED_CAPSL.0,
|
||||||
))
|
if on { i32::MAX } else { 0 },
|
||||||
.unwrap();
|
),
|
||||||
d.send_event(&InputEvent::new(
|
InputEvent::new(
|
||||||
EventType::LED,
|
EventType::LED,
|
||||||
LedType::LED_NUML.0,
|
LedType::LED_NUML.0,
|
||||||
if on { i32::MAX } else { 0 },
|
if on { i32::MAX } else { 0 },
|
||||||
))
|
),
|
||||||
.unwrap();
|
InputEvent::new(
|
||||||
d.send_event(&InputEvent::new(
|
EventType::LED,
|
||||||
EventType::LED,
|
LedType::LED_SCROLLL.0,
|
||||||
LedType::LED_SCROLLL.0,
|
if on { i32::MAX } else { 0 },
|
||||||
if on { i32::MAX } else { 0 },
|
),
|
||||||
))
|
])
|
||||||
.unwrap();
|
.unwrap();
|
||||||
std::thread::sleep(std::time::Duration::from_secs(1));
|
std::thread::sleep(std::time::Duration::from_secs(1));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use std::fs::{File, OpenOptions};
|
use std::fs::{File, OpenOptions};
|
||||||
|
use std::io::Write;
|
||||||
use std::mem::MaybeUninit;
|
use std::mem::MaybeUninit;
|
||||||
use std::os::unix::io::{AsRawFd, RawFd};
|
use std::os::unix::io::{AsRawFd, RawFd};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
@ -616,15 +617,10 @@ impl RawDevice {
|
||||||
/// Events that are typically sent to devices are
|
/// Events that are typically sent to devices are
|
||||||
/// [EventType::LED] (turn device LEDs on and off),
|
/// [EventType::LED] (turn device LEDs on and off),
|
||||||
/// [EventType::SOUND] (play a sound on the device)
|
/// [EventType::SOUND] (play a sound on the device)
|
||||||
/// and [EventType::FORCEFEEDBACK] (play force feedback events on the device, i.e. rumble).
|
/// and [EventType::FORCEFEEDBACK] (play force feedback effects on the device, i.e. rumble).
|
||||||
pub fn send_event(&mut self, event: &InputEvent) -> io::Result<()> {
|
pub fn send_events(&mut self, events: &[InputEvent]) -> io::Result<()> {
|
||||||
let raw_event = event.as_ref();
|
let bytes = unsafe { crate::cast_to_bytes(events) };
|
||||||
let bytes_written = unsafe {
|
self.file.write_all(bytes)
|
||||||
let buf = crate::cast_to_bytes(raw_event);
|
|
||||||
nix::unistd::write(self.as_raw_fd(), buf)?
|
|
||||||
};
|
|
||||||
debug_assert_eq!(bytes_written, mem::size_of_val(raw_event));
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -348,9 +348,9 @@ impl Device {
|
||||||
/// Events that are typically sent to devices are
|
/// Events that are typically sent to devices are
|
||||||
/// [EventType::LED] (turn device LEDs on and off),
|
/// [EventType::LED] (turn device LEDs on and off),
|
||||||
/// [EventType::SOUND] (play a sound on the device)
|
/// [EventType::SOUND] (play a sound on the device)
|
||||||
/// and [EventType::FORCEFEEDBACK] (play force feedback events on the device, i.e. rumble).
|
/// and [EventType::FORCEFEEDBACK] (play force feedback effects on the device, i.e. rumble).
|
||||||
pub fn send_event(&mut self, event: &InputEvent) -> io::Result<()> {
|
pub fn send_events(&mut self, events: &[InputEvent]) -> io::Result<()> {
|
||||||
self.raw.send_event(event)
|
self.raw.send_events(events)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue