-
Notifications
You must be signed in to change notification settings - Fork 21
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
Changes from 6 commits
cd3dbdd
57271e6
53edb30
005be00
48772bd
7135d06
bd6c100
3e21daa
006df63
0fc2c59
b6f0803
27f33ec
54db7ae
368cf3e
45d1cdf
45eb711
79a2bc6
bbee9b3
c65effe
7d9f0cc
0b79670
ac25809
00efbb9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Remote launch", | ||
"type": "lldb", | ||
"request": "launch", | ||
"program": "${workspaceFolder}/target/debug/inputplumber", | ||
"sourceLanguages": ["rust"], | ||
"initCommands": [ | ||
"platform select remote-linux", | ||
"platform connect connect://192.168.1.19:1234", | ||
"settings set target.inherit-env false" | ||
], | ||
"env": { | ||
"PATH": "/usr/bin:/usr/local/sbin:/usr/local/bin:/var/lib/flatpak/exports/bin:/usr/lib/rustup/bin" | ||
} | ||
}, | ||
{ | ||
"type": "lldb", | ||
"request": "launch", | ||
"name": "Debug unit tests in library 'inputplumber'", | ||
"cargo": { | ||
"args": [ | ||
"test", | ||
"--no-run", | ||
"--lib", | ||
"--package=inputplumber" | ||
], | ||
"filter": { | ||
"name": "inputplumber", | ||
"kind": "lib" | ||
} | ||
}, | ||
"args": [], | ||
"cwd": "${workspaceFolder}" | ||
}, | ||
{ | ||
"type": "lldb", | ||
"request": "launch", | ||
"name": "Debug executable 'inputplumber'", | ||
"cargo": { | ||
"args": [ | ||
"build", | ||
"--bin=inputplumber", | ||
"--package=inputplumber" | ||
], | ||
"filter": { | ||
"name": "inputplumber", | ||
"kind": "bin" | ||
} | ||
}, | ||
"args": [], | ||
"cwd": "${workspaceFolder}" | ||
}, | ||
{ | ||
"type": "lldb", | ||
"request": "launch", | ||
"name": "Debug unit tests in executable 'inputplumber'", | ||
"cargo": { | ||
"args": [ | ||
"test", | ||
"--no-run", | ||
"--bin=inputplumber", | ||
"--package=inputplumber" | ||
], | ||
"filter": { | ||
"name": "inputplumber", | ||
"kind": "bin" | ||
} | ||
}, | ||
"args": [], | ||
"cwd": "${workspaceFolder}" | ||
} | ||
] | ||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
use std::{ | ||
error::Error, | ||
ffi::CString, | ||
path::Path, | ||
time::{Duration, Instant}, | ||
}; | ||
|
||
|
@@ -51,12 +52,24 @@ pub struct Driver { | |
impl Driver { | ||
pub fn new(udevice: UdevDevice) -> Result<Self, Box<dyn Error + Send + Sync>> { | ||
let path = udevice.devnode(); | ||
let cs_path = CString::new(path.clone())?; | ||
if !Path::new(path.as_str()).exists() { | ||
return Err(format!( | ||
"Device '{}' does not have a devnode: a valid OrangePi NEO Controller has one", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The phrasing of this is a little strange. "Failed to find device node for {}, aborting initialization." Or something closer to that effect would be better. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I want the message to include the fact it's coming from an opi device... Can you give me a phrase that includes that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Failed to find device node for {}, aborting initialization as OrangePi NEO Controller." |
||
udevice.name() | ||
) | ||
.into()); | ||
} | ||
|
||
let cs_path = CString::new(path)?; | ||
let api = hidapi::HidApi::new()?; | ||
let device = api.open_path(&cs_path)?; | ||
let info = device.get_device_info()?; | ||
if info.vendor_id() != VID || info.product_id() != PID { | ||
return Err(format!("Device '{path}' is not a OrangePi NEO Controller").into()); | ||
return Err(format!( | ||
"Device '{}' is not a OrangePi NEO Controller", | ||
udevice.name() | ||
) | ||
.into()); | ||
} | ||
|
||
Ok(Self { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
use std::{error::Error, ffi::OsStr, time::Duration}; | ||
use std::{error::Error, ffi::OsStr, path::Path, time::Duration}; | ||
|
||
use udev::Device; | ||
|
||
|
@@ -19,8 +19,17 @@ impl Driver { | |
let vid = udevice.id_vendor(); | ||
let pid = udevice.id_product(); | ||
if VID != vid || !PIDS.contains(&pid) { | ||
return Err(format!("'{}' is not an ROG Ally controller", udevice.devnode()).into()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. R starts with a vowel sound, "an ROG" is correct here. |
||
return Err(format!("Device {} is not a ROG Ally controller", udevice.name()).into()); | ||
} | ||
|
||
if !Path::new(udevice.devnode().as_str()).exists() { | ||
return Err(format!( | ||
"Device {}, part of a ROG Ally controller does not have a devnode", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use wording to similar to comment in orange pi |
||
udevice.name() | ||
) | ||
.into()); | ||
} | ||
|
||
// TODO: When resuming from sleep, if mcu_powersave is set, the device init takes longer. | ||
// inotify will trigger this driver before the attribute tree is fully built and the driver | ||
// will error and exit, leaving some controls unusable. We should find a way to only | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
use std::{error::Error, ffi::CString}; | ||
use std::{error::Error, ffi::CString, path::Path}; | ||
|
||
use hidapi::HidDevice; | ||
use packed_struct::PackedStruct; | ||
|
@@ -47,17 +47,29 @@ pub struct Driver { | |
|
||
impl Driver { | ||
pub fn new(udevice: UdevDevice) -> Result<Self, Box<dyn Error + Send + Sync>> { | ||
let path = udevice.devnode(); | ||
let driver = udevice.drivers(); | ||
if !driver.contains(&"microsoft".to_string()) { | ||
return Err(format!("Device '{path}' is not using the hid-microsoft driver").into()); | ||
return Err(format!( | ||
"Device '{}' is not using the hid-microsoft driver", | ||
udevice.name() | ||
) | ||
.into()); | ||
} | ||
|
||
if !Path::new(udevice.devnode().as_str()).exists() { | ||
return Err(format!( | ||
"Device {} an xpad controller does not have a devnode", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as previous |
||
udevice.name() | ||
) | ||
.into()); | ||
} | ||
|
||
let syspath = udevice.syspath(); | ||
if !syspath.contains("uhid") { | ||
return Err(format!("Device '{path}' is not a uhid virtual device").into()); | ||
return Err(format!("Device '{}' is not a uhid virtual device", udevice.name()).into()); | ||
} | ||
|
||
let cs_path = CString::new(path.clone())?; | ||
let cs_path = CString::new(udevice.devnode().clone())?; | ||
let api = hidapi::HidApi::new()?; | ||
let device = api.open_path(&cs_path)?; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't commit editor-specific configurations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not editor configuration as in "dev favourite color palette" this is what is needed to remote debug it. The PATH env var is important too as it specify where to find udevadm.