-
Notifications
You must be signed in to change notification settings - Fork 31
Open
Description
I have a device with a tristate button.
I can get the new events is it possible to get the current value?
let d = Device::new_from_path("/dev/input/event1").unwrap();
loop {
let ev = d.next_event(ReadFlag::NORMAL).map(|val| val.1);
match ev {
Ok(ev) => {
if let Some(ev_type) = ev.event_type() {
if ev_type == EventType::EV_ABS {
let state = ev.value;
Using a loop without sleeping after each iteration is quite hard on the battery.
This C function can return the current state:
#include <stdio.h>
#include <linux/input.h>
#include <fcntl.h>
int read_state() {
int fd;
int abs[6] = {0};
if ((fd = open("/dev/input/event1", O_RDONLY)) < 0) {
perror("evtest");
return -1;
}
ioctl(fd, EVIOCGABS(34), abs);
return abs[0];
}
Metadata
Metadata
Assignees
Labels
No labels