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

Implement LED source output device #246

Closed
wants to merge 23 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
cd3dbdd
feat(VSCode IDE): add debug button
NeroReflex Dec 28, 2024
57271e6
improv(manager): reorganize code and reduce dependency of UdevDevice:…
NeroReflex Dec 30, 2024
53edb30
feat(VSCode IDE): specify the language as being rust for remote debug…
NeroReflex Dec 30, 2024
005be00
improv(composite_device): better error reporting
NeroReflex Dec 30, 2024
48772bd
fix(udev::Device): bufix for number being u32 and code cleanup
NeroReflex Dec 30, 2024
7135d06
improv(udev::Device): don't use udevadm to inspect devices
NeroReflex Dec 30, 2024
bd6c100
manager: check for devnode() validity for device types that actually …
NeroReflex Dec 30, 2024
3e21daa
feat(config) implement LED configuration
NeroReflex Dec 30, 2024
006df63
feat(LED): LEDs initial implementation
NeroReflex Dec 31, 2024
0fc2c59
feat(LED): implement leds as a source output device
NeroReflex Dec 31, 2024
b6f0803
fix(manager): avoid cycling twice configurations
NeroReflex Dec 31, 2024
27f33ec
improv(CompositeDevice): make the code more readable
NeroReflex Dec 31, 2024
54db7ae
improv(main) do not lose the reference to the ctrl+C signal watcher
NeroReflex Dec 31, 2024
368cf3e
improv(LED): add configuration for the ASUS ROG Ally device
NeroReflex Dec 31, 2024
45d1cdf
improv(LED): increase code readability
NeroReflex Dec 31, 2024
45eb711
improv(code): cargo fmt
NeroReflex Dec 31, 2024
79a2bc6
fix(MultiColorChassis): solve a warning about an unused field
NeroReflex Dec 31, 2024
bbee9b3
improv(code): increase readability by replacing if let() with match
NeroReflex Dec 31, 2024
c65effe
fix(dbus) make dbus path parth of a CompositeDevice at construction
NeroReflex Dec 31, 2024
7d9f0cc
fix(manager): avoid borrowing syntax from typescript
NeroReflex Dec 31, 2024
0b79670
improv(code): cargo fmt
NeroReflex Dec 31, 2024
ac25809
fix(comments): apply suggestions from the PR feedback
NeroReflex Dec 31, 2024
00efbb9
fix(LED): fix inverted b and r components
NeroReflex Dec 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions src/udev/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ pub struct Device {
/// M: Device name in /sys (i.e. the last component of "P:")
pub name: String,
/// R: Device number in /sys (i.e. the numeric suffix of the last component of "P:")
pub number: u32,
pub number: u64,
/// U: Kernel subsystem
pub subsystem: String,
/// T: Device type within subsystem
Expand All @@ -653,10 +653,21 @@ pub struct Device {
}

impl Device {
/// Returns a path to the sysfs device link, such as
/// "/sys/devices/pci0000:00/0000:00:08.1/0000:09:00.3/usb1/1-3/1-3:1.2/0003:0B05:1ABE.0003/hidraw/hidraw2/device"
fn sysnode_device_link(&self) -> String {
let s = self.path.as_str();
match s.ends_with("/device") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this actually the correct thing to do? In changes below you change from this:

        let path = format!("/sys{}/device/id/vendor", self.path.clone());

to this:

        let path = format!("{}/id/vendor", self.sysnode_device_link());

The path now has device appended to it since it didn't end with it. Only get_parent_device_name() expected this.

I would suggest adding some unit tests. Or drop this change completely since the commit apparently addresses only the `u64 change and not this.

In fact please drop all the changes that aren't u64. You've changed the behaviour unnecessarily

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree, only the bugfix is needed here.

true => String::from(s),
false => format!("{}/device", s)
}
}

/// Returns the parent sysfs device path
pub fn get_parent(&self) -> Option<String> {
let path = format!("/sys{}/device", self.path.clone());
let base_path = format!("/sys{}", self.path.clone());
let path = self.sysnode_device_link();
let s = path.as_str();
let base_path = if s.ends_with("/device") { &s[..s.len()-7] } else { &s };
let device_path = read_link(path.clone()).ok()?.to_string_lossy().to_string();
let relative_path = format!("{base_path}/{device_path}");
let full_path = fs::canonicalize(relative_path).ok()?;
Expand All @@ -666,7 +677,7 @@ impl Device {

/// Returns the name of the parent (e.g. input26)
pub fn get_parent_device_name(&self) -> Option<String> {
let path = format!("/sys{}/device", self.path.clone());
let path = self.sysnode_device_link();
let device_path = read_link(path).ok()?;
let name = device_path.file_name()?;
Some(name.to_string_lossy().to_string())
Expand Down Expand Up @@ -703,15 +714,15 @@ impl Device {
/// Returns the vendor id for the given device. Will only work with event
/// devices.
pub fn get_vendor_id(&self) -> Option<String> {
let path = format!("/sys{}/device/id/vendor", self.path.clone());
let path = format!("{}/id/vendor", self.sysnode_device_link());
let id = fs::read_to_string(path).ok()?;
Some(id.replace('\n', ""))
}

/// Returns the product id for the given device. Will only work with event
/// devices.
pub fn get_product_id(&self) -> Option<String> {
let path = format!("/sys{}/device/id/product", self.path.clone());
let path = format!("{}/id/product", self.sysnode_device_link());
let id = fs::read_to_string(path).ok()?;
Some(id.replace('\n', ""))
}
Expand Down