evdev-rs
evdev-rs copied to clipboard
Enable::enable() for EventCode Type Doesn't Allow for Data Arguments
Some event codes, when enabled, require additional arguments. For example, the EV_ABS EventCodes require an EnableCodeData::AbsInfo to be supplied to describe the range of reports from the peripheral. However, Enable::enable() doesn't accept any extra arguments. Indeed, it passes None for the data:
https://github.com/ndesh26/evdev-rs/blob/8540f66c83d06fc615651eb0e2c14cf602047f45/src/device.rs#L62-L65
As such, despite the docs recommending to use enable(), DeviceWrapper::enable_event_code() must instead be called in order to supply the data:
let absinfo = EnableCodeData::AbsInfo ( AbsInfo {
value: 127,
minimum: 0,
maximum: 255,
resolution: 196,
fuzz: 0,
flat: 0,
});
_ = edev_joy.enable_event_code (&EventCode::EV_ABS (EV_ABS::ABS_X), Some (absinfo))?;
If you look at the description for the Enable trait, it mentions that we need to use enable_event_code if we need to provide extra arguments. We did it the way it is now to have a cleaner API for most use cases. We might need to update the documentation of enable_event_code to indicate this exception. I'll be happy to accept a change which updates the documentation.