Repository navigation
v0.1.14 β USB Power Accuracy & Hierarchical Device Tree
Highlights
This release significantly improves USB power reporting accuracy, fixes a device enumeration bug that caused devices behind USB hubs to disappear, and introduces hierarchical USB device tree rendering.
USB Power Display: β€ instead of β
Problem: USB devices like the built-in Card Reader showed β4.480 W β implying an estimate close to the real value. In reality, this number came from bMaxPower in the USB descriptor, which is the maximum allocated current, not actual consumption. An idle card reader typically uses 50β200 mA, not the full 896 mA it declares.
Fix: Devices using descriptor-based power now display β€ (upper bound) instead of β (approximate). This makes it clear the value is a ceiling, not a guess. When real measured power is available (from PowerOutDetails or SMC), the exact value is shown without any prefix.
SMC PUSB Key for USB Total Power
Added reading of the SMC key PUSB as a new data source for total USB power consumption. The priority chain is now:
PUSBfrom SMC β hardware-measured total (when available)PowerOutDetailsfrom AppleSmartBattery β per-port measured power (MacBooks with battery)- USB descriptor sum β
bMaxPower Γ 5Vfallback withβ€prefix
This mirrors the existing approach for WiFi (wiPm SMC key). On current Mac hardware, PUSB returns 0, but the infrastructure is ready for future models that may report it.
Fixed: USB Port Power Matching
Problem: When multiple USB devices were connected (e.g., iPhone + iPad + AirPods), they could be assigned the wrong port's power data. Both iPhone and iPad were matching the same PowerOutDetails port, showing identical wattage.
Root cause: The port matching extracted (locationID >> 20) & 0xF which collided for devices on different USB controllers.
Fix: Discovered that on Apple Silicon Macs, PowerOutDetails.PortIndex = (locationID >> 24) + 1 β the upper byte of locationID is the 0-indexed USB controller ID, while PortIndex is 1-indexed. The new assign_usb_port_power() function uses multi-pass matching with a "claimed ports" set to prevent duplicates:
- Exact
LocationIDmatch (whenPowerOutDetailsprovides it) controller_id + 1formula match- Remaining unmatched devices paired with remaining unclaimed ports
Also extended PowerOutDetails reading to capture LocationID per port entry via the new UsbPortPower struct.
Fixed: Missing USB Devices Behind Hubs
Problem: Devices connected through a USB hub (e.g., Logitech USB Receiver via a USB-C multiport adapter) were invisible β IOKit found 6 IOUSBHostDevice entries, but macpow only listed 4.
Root cause: The list_usb_devices() function interleaved property reading and find_storage_stats() child-tree walks with the IOKit iterator. The recursive IORegistryEntryCreateIterator inside find_storage_stats could invalidate the outer IOServiceGetMatchingServices iterator, silently dropping remaining entries.
Fix: Two-pass enumeration β first collect all IOIteratorNext handles in a tight loop, then process each one for properties and storage stats. This prevents child-tree walks from interfering with the parent iterator.
Hierarchical USB Device Tree
USB devices are now rendered as a tree reflecting the actual USB topology. Devices behind hubs are visually nested under their parent:
ββ USB (6 devices) 3.626 W
ββ iPad (480Mbps, 2400mA) 1.010 W
ββ iPhone (480Mbps, 2400mA) 10.715 W
ββ USB3.1 Hub (5Gbps) β€0.000 W
ββ USB2.0 Hub (480Mbps) β€0.000 W
β ββ USB Receiver (12Mbps) β€0.000 W
β ββ USB-C Digital AV Multiport Adapter β€0.000 W
ββ ...
Parent-child relationships are computed from locationID topology: each non-zero nibble in the location encodes a port level, so clearing the lowest non-zero nibble yields the parent's locationID. Hubs are collapsible in the TUI β click or press Enter to expand/collapse.
Technical Details
Files Changed
src/types.rsβ AddedUsbPortPowerstruct,usb_power_smc_wfield toMetrics,parent_location_idfield toUsbDevicesrc/peripherals.rsβ Two-pass IOKit enumeration,compute_usb_parents()for hierarchysrc/battery.rsβread_usb_power_out_per_port()now returnsVec<UsbPortPower>withLocationIDsrc/metrics.rsβ Reads SMCPUSBkey alongsidewiPm,PDBR,PDTRsrc/app.rsβPowerPrefixenum (Exact/Estimated/MaxBound),assign_usb_port_power()multi-pass matcher, DFS-based hierarchical USB tree rendering
Full Changelog: v0.1.13...v0.1.14