|
| 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 | +} |
0 commit comments