Skip to content

Demonstrate how to expose multiple batteries - DO NOT MERGE #39

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

Closed
wants to merge 7 commits into from

Conversation

forderud
Copy link
Contributor

@forderud forderud commented Jan 12, 2025

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_DISABLED in C:\Users\<username>\AppData\Local\Arduino15\packages\arduino\hardware\avr\<version>\cores\arduino\USBDesc.h to 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_DISABLED is defined to enable 6 batteries. UPS.ino has also been modified to expose slightly different charge levels for each battery to make the example more interesting:
image
image

Windows 2000 screenshot

HID battery support actually goes back to Windows 2000, which was released 25 years ago.
image

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.

forderud and others added 4 commits January 19, 2025 11:09
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.
@forderud forderud force-pushed the multi-battery-wip branch 4 times, most recently from 01f2e83 to 5367a8d Compare January 19, 2025 15:03
@forderud
Copy link
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.
…els in each battery. Also, change bCapacityMode from 2(%) to 1(mWh) so that Windows reports each battery charge level correctly.
@forderud forderud closed this Apr 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant