Demonstrate how to expose multiple batteries - DO NOT MERGE#39
Closed
forderud wants to merge 7 commits intoabratchik:masterfrom
Closed
Demonstrate how to expose multiple batteries - DO NOT MERGE#39forderud wants to merge 7 commits intoabratchik:masterfrom
forderud wants to merge 7 commits intoabratchik:masterfrom
Conversation
This was referenced Jan 12, 2025
Preparation to better support multi-battery setups where a global HID singleton no longer makes sense. This also simplifies the HIDPowerDevice_ class by removing wrapper methods that just forwards the call to the underlying HID_ class.
The HIDPowerDevice HID report descriptor only contains INPUT and FEATURE reports, and no OUTPUT reports. It therefore makes little sense to configure a USB input endpoint for INPUT reports. This also makes the implementation more similar to the upstream Arduino code on https://github.com/arduino/ArduinoCore-avr/blob/master/libraries/HID/src/HID.cpp
Adopt coding style from https://github.com/arduino/ArduinoCore-avr/blob/master/libraries/HID/src/HID.cpp that uses "pluggedEndpoint" from the PluggableUSBModule base-class as endpoint number instead of a hardcoded preprocessor define. This allows removal of several defines in the header that are now unused. Benefits: * Closer alignment to the upstream Arduino sources. * Fewer hardcoded values, which will simplify future scaling to support multiple batteries in a USB composite device.
01f2e83 to
5367a8d
Compare
Contributor
Author
|
@abratchik What do you think about merging #36 and #37 to enable multi-battery setups as demonstrated in this draft PR? |
All batteries are configured with the same parameters, so this is by no means a complete example.
5367a8d to
9059996
Compare
…els in each battery. Also, change bCapacityMode from 2(%) to 1(mWh) so that Windows reports each battery charge level correctly.
…ing CDC_DISABLED.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The PR is NOT intended for merging, only to showcase how multiple batteries can be simulated after #36 and #37 are merged.
There seems to be an Arduino HW limit of 7 USB endpoints. This limits the maximum number of simulated batteries to 3 by default, but this can be increased to 6 by defining
CDC_DISABLEDinC:\Users\<username>\AppData\Local\Arduino15\packages\arduino\hardware\avr\<version>\cores\arduino\USBDesc.hto disable the USB serial console endpoints. If doing so, then one needs to use the Arduino's reset button to be able to flash it.Windows 10 screenshots
Screenshots where


CDC_DISABLEDis defined to enable 6 batteries.UPS.inohas also been modified to expose slightly different charge levels for each battery to make the example more interesting:Windows 2000 screenshot
HID battery support actually goes back to Windows 2000, which was released 25 years ago.

The screenshot was obtained by creating a Windows 2000 SP4 VM in VirtualBox and forwarding the Arduino USB device to the VirtualBox VM. A default Windows 2000 installation will then automatically detect the HID battery devices, even without Windows Update connectivity.