Skip to content

Commit de77b63

Browse files
committed
wip windows lamp array API
Signed-off-by: Daniel Schaefer <[email protected]>
1 parent 1f110c6 commit de77b63

File tree

5 files changed

+168
-6
lines changed

5 files changed

+168
-6
lines changed

Cargo.lock

Lines changed: 113 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,14 @@ clap = { version = "4.5", features = ["derive"] }
1414
# See: https://github.com/ruabmbua/hidapi-rs/pull/158
1515
hidapi = { version = "=2.6.1" }
1616

17+
[dependencies.windows]
18+
version = "0.61.3"
19+
features = [
20+
"Devices",
21+
"Devices_Enumeration",
22+
"Devices_Lights",
23+
"Devices_Lights_Effects",
24+
]
25+
1726
[build-dependencies]
1827
static_vcruntime = "2.0"

rust-toolchain.toml

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/lamparray.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
use windows::Win32::Devices::DeviceAndDriverInstallation::{
2+
CM_Get_DevNode_Status, SetupDiChangeState, SetupDiEnumDeviceInfo, SetupDiGetClassDevsW,
3+
SetupDiGetDevicePropertyW, SetupDiSetClassInstallParamsW, CM_PROB_DISABLED, CR_SUCCESS,
4+
DICS_DISABLE, DICS_ENABLE, DICS_FLAG_GLOBAL, DIF_PROPERTYCHANGE, DIGCF_ALLCLASSES, HDEVINFO,
5+
SP_CLASSINSTALL_HEADER, SP_DEVINFO_DATA, SP_PROPCHANGE_PARAMS,
6+
};
7+
use windows::Win32::Devices::Properties::{DEVPKEY_Device_HardwareIds, DEVPROPTYPE};
8+
use windows::{
9+
core::*, Devices::Enumeration::*, Foundation::*, Win32::Foundation::*,
10+
Devices::Lights::*,
11+
Win32::System::Threading::*,
12+
};
13+
14+
// TODO:
15+
// - [ ] Remove unsafe
16+
// - [ ] Remove unnecessary imports
17+
// - [ ] Print lamp array information
18+
// - [ ] Print info about each lamp in the array
19+
pub unsafe fn enumerate_lamparray() -> Result<()> {
20+
let selector = LampArray::GetDeviceSelector();
21+
let watcher = DeviceInformation::CreateWatcher(selector)?;
22+
23+
watcher.Added(&TypedEventHandler::<DeviceWatcher, DeviceInformation>::new(
24+
|_, info| {
25+
let info = info.as_ref().expect("info");
26+
let name = info.Name()?;
27+
28+
if name.to_string().contains("Intel") {
29+
println!("Id: {}, Name: {}", info.Id()?, info.Name()?);
30+
}
31+
Ok(())
32+
},
33+
))?;
34+
35+
watcher.EnumerationCompleted(&TypedEventHandler::new(move |_, _| {
36+
println!("done!");
37+
SetEvent(handle.0);
38+
Ok(())
39+
}))?;
40+
41+
watcher.Start()?;
42+
WaitForSingleObject(handle.0, INFINITE);
43+
44+
Ok(())
45+
}

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pub mod factory;
2+
pub mod lamparray;
23
pub mod raw_hid;
34
pub mod via;
45

0 commit comments

Comments
 (0)