Skip to content
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

[Electron] Power management #1412

merged 9 commits into from Nov 6, 2017


Copy link

commented Oct 23, 2017

submission notes
**Important:** Please sanitize/remove any confidential info like usernames, passwords, org names, product names/ids, access tokens, client ids/secrets, or anything else you don't wish to share.

Please Read and Sign the Contributor License Agreement ([Info here](

You may also delete this submission notes header if you'd like. Thank you for contributing!


This PR:

  • Adds DIAG_ID_SYSTEM_POWER_SOURCE diagnostics data source:
      • Default value
      • The device is being powered by VIN pin or a non-compliant USB-charger
      • The device is being powered by a USB Host
      • The device is being powered by a compliant USB-charger
      • The device is being powered by an USB-OTG device (e.g. phone, tablet etc)
      • The device is being powered from battery (battery state diagnostic should indicate BATTERY_STATE_DISCHARGING)
  • Introduces a number of changes to Electron's power management (TODO: write documentation explaining new behavior and peculiarities)
  • Adds new battery state BATTERY_STATE_DISCONNECTED
  • Adds two new system events that replicate battery state and power source diagnostic data sources:
    • battery_state
    • power_source
  • Modifies battery state of charge diagnostic to report logical value based on termination voltage (upper bound) and fixed (physical 20% of charge) lower bound (see

Steps to Test


Example App




  • User is totes amazing for contributing!
  • Contributor has signed CLA (Info here)
  • Problem and Solution clearly stated
  • Run unit/integration/application tests on device
  • Added documentation
  • Added to after merging (add links to docs and issues)
avtolstoy added 9 commits Oct 23, 2017
PMIC changes:
- Implements getInputCurrentLimit()
- Adds getChargeVoltageValue() returning voltage
- Adds getRechargeThreshold()/setRechargeThreshold()
Implements FuelGauge::getNormalizedSoC() returning normalized state of
charge value based on termination voltage (upper bound) and 20% of
physcial charge (lower bound).
battery_state_t and power_source_t changes:
- Adds DISCONNECTED state to battery_state_t
- Adds power_source_t definition
- Adds particle::SimpleEnumDiagnosticData<particle::power::power_source_t> diagnostic source
Moved power management implementation into PowerManager class
- Fixes DISCONNECTED battery state detection
- Adds DIAG_ID_SYSTEM_POWER_SOURCE diagnostic source implementation
system_power_management_update() no longer needs to be called from Sp…
…ark_Idle_Events or listening mode event loop

@avtolstoy avtolstoy requested a review from technobly Oct 31, 2017

Copy link

left a comment

There is a lot going on here :) Most everything looks good to me, but I fear that staring at it will not be enough to know how well everything works. This one screams for some on-device tests to be added. I would love to see some of the conversion functions validated via unit tests as well, like getNormalizedSoC() and getChargeVoltageValue(). Also a comment about what the default setRechargeThreshold() is be welcome. We'll also need Documentation straight away for this as it's a fairly big change. We also switched from power.disableDPDM(); to power.enableDPDM(); and I would like to know how this has been tested and what effects it will have on USB power sources and also USB power banks / USB wall adapters.

@m-mcgowan m-mcgowan added this to the 0.8.0 milestone Nov 6, 2017

@m-mcgowan m-mcgowan merged commit e36f33b into feature/diagnostics-merge Nov 6, 2017

0 of 2 checks passed

continuous-integration/travis-ci/pr The Travis CI build failed
continuous-integration/travis-ci/push The Travis CI build failed
@m-mcgowan m-mcgowan referenced this pull request Nov 6, 2017
3 of 6 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
3 participants
You can’t perform that action at this time.