Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor code making it easier to add new device types #249

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

NeroReflex
Copy link
Contributor

Since LEDs devices do not have a devnode the hard requirement for source devices of having one is to be removed and the presence check must be postponed to type of devices that actually have one and requires it to work properly.

Refactor manager.rs to remove device specialization where no particular benefits are provided by that specialization.

This PR reduces the overall number of running threads, without changing how the application behaves.

Pending is an infinite loop, this means that if run() terminates the program will be stuck in an endless (unresponsive) loop: remove the usage of pending and replace it with a join on run so that if the program exits due to an error systemd can restart it; this also avoids using an unnecessary task.

Also avoid losing reference to the spawned Ctrl+C task.
…:devnode being populated

For a future implementation of leds it is important checks of devnode being populated are pushed where devnode is acually used: do that while also splitting up a gigantic method that both leaked a reference to a spaned task and was very hard to work with.
…ctually requires it

In order to implement LED(s) handling and potentially other device types that
don't have a node in /dev early checks for devnode() being valid must be dropped.
src/input/manager.rs Outdated Show resolved Hide resolved
src/input/manager.rs Outdated Show resolved Hide resolved
@NeroReflex NeroReflex force-pushed the main_refactor branch 8 times, most recently from 81ba6f6 to 91d58d9 Compare January 3, 2025 19:50
Copy link
Contributor

@pastaq pastaq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor nits and a couple questions. Overall I like the changes, good work. Especially the simplified functions, that has been on my TODO list for a while.

src/input/manager.rs Show resolved Hide resolved
src/input/manager.rs Show resolved Hide resolved
src/input/manager.rs Show resolved Hide resolved
src/input/manager.rs Show resolved Hide resolved
src/input/manager.rs Show resolved Hide resolved
src/input/manager.rs Outdated Show resolved Hide resolved
src/input/manager.rs Show resolved Hide resolved
src/main.rs Show resolved Hide resolved
@NeroReflex NeroReflex force-pushed the main_refactor branch 2 times, most recently from 08a0005 to 2927a34 Compare January 4, 2025 13:56
src/input/manager.rs Outdated Show resolved Hide resolved
@NeroReflex NeroReflex force-pushed the main_refactor branch 2 times, most recently from d035686 to e5a9f36 Compare January 5, 2025 14:27
src/input/manager.rs Outdated Show resolved Hide resolved
src/input/manager.rs Outdated Show resolved Hide resolved
… the manager component

This makes it easier in the future to add new device types suc as led devices.
@NeroReflex NeroReflex requested a review from ShadowApex January 8, 2025 02:20
Copy link
Contributor

@pastaq pastaq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When ManageAllDevices is set to true, Manager fails to create a CompositeDevice for an external controller. We get a false positive for a virtual controller when it should detect as a bluetooth device.

Tested on Xbox Elite Series 2 Controller.

[2025-01-09T00:46:30Z DEBUG inputplumber::input::manager] Xbox Wireless Controller (event21) is virtual, skipping consideration for /devices/virtual/misc/uhid/0005:045E:0B22.002C/input/input125/event21

"Unable to create UdevDevice from {base_path}/{name} to check initialization"
);
attempt += 1;
tokio::time::sleep(Duration::from_millis(10)).await;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this was 10ms before, but my Elite 2 controller doesn't initialize fully before the 800ms have passed. It seems to connect fine if this is 50ms.

if let Err(e) = result {
log::error!("Unable to send command: {:?}", e);
}
tokio::time::sleep(Duration::from_millis(10)).await;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

50ms here as well.


// Check if the virtual device is using the bluetooth bus
// TODO: Can we get properties from UdevDevice::get_attribute_from_tree?
let id_bus = device_info.properties.get("ID_BUS");

log::debug!("Bus ID for {dev_node}: {id_bus:?}");
log::debug!("Bus ID for {dev_path}: {id_bus:?}");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

devnode is required for virtual device checks, devpath will not match the bus ID .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a debug, am I missing something here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look at the two lines above. The device_info grabbed for devnode is not the same as devpath. devpath wont return the same udev device instance, so the info will be different.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants