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

feat(docs): Add power profiler #312

Merged
merged 1 commit into from
Mar 11, 2021

Conversation

Nicell
Copy link
Member

@Nicell Nicell commented Oct 30, 2020

This adds a battery life estimator to the docs website. This is currently working quite well I'd say, but I'd like to get some feedback before I go into the details of cleaning up the code. Try it here: https://deploy-preview-312--zmk.netlify.app/power-profiler

Todo:

  • Document how the calculations are done and some of the methodology
  • Document how to add new boards or features
  • Add MIT license headers (as opposed to the rest of the docs)

@Nicell Nicell added documentation Improvements or additions to documentation enhancement New feature or request labels Oct 30, 2020
@innovaker innovaker self-requested a review November 17, 2020 21:05
@joric
Copy link

joric commented Nov 18, 2020

I need uW/uA switch, I'm way too used to uA rather than to uW.

@innovaker
Copy link
Contributor

It's looking good @Nicell!

Technical reviews aside, my primary concern with a "ZMK-branded" power profiler will be its accuracy. What margin of error are we talking here? What data is it based on? Can the estimated margins of error be represented visually?

Even with the disclaimer, having large margins of error will unfortunately lead to bad mouthing about ZMK.

@Nicell
Copy link
Member Author

Nicell commented Nov 22, 2020

Technical reviews aside, my primary concern with a "ZMK-branded" power profiler will be its accuracy. What margin of error are we talking here? What data is it based on? Can the estimated margins of error be represented visually?

Even with the disclaimer, having large margins of error will unfortunately lead to bad mouthing about ZMK.
@innovaker

Margin of error of the calculation should be quite small when thinking about it. Most error will come from how accurate the data is that the user inputs. Maybe we can quantify that? Especially the battery mAh.

@Nicell Nicell force-pushed the docs/power-profiler branch 3 times, most recently from 60c5304 to 157de11 Compare January 9, 2021 22:08
@Nicell Nicell marked this pull request as ready for review January 9, 2021 23:51
@Nicell Nicell requested a review from joelspadin January 9, 2021 23:51
@Nicell
Copy link
Member Author

Nicell commented Jan 9, 2021

@innovaker @joelspadin I've finished up this PR finally and would appreciate some feedback on it! For some reason netlify is failing to deploy it (says there's no changes??), so you'll have to test it locally. Thanks 😄

docs/src/components/power-estimate.js Show resolved Hide resolved
docs/src/components/power-estimate.js Outdated Show resolved Hide resolved

// Lithium ion self discharge
const lithiumDischarge =
((parseInt(batterymAh) * 1000 * lithiumIonMonthlyDischargePercent) /
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: could pull this calculation (and others below) out into a separate function to simplify the component.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that the model/calculations should probably be split into simple functions independent from React. Cohesive functions may also improve the readability/comprehensibility.

Copy link
Member Author

@Nicell Nicell Feb 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've redone how these are all calculated so that the variables are much more direct and found the only real calculation I can pull out is the conversion from microamps to milliwatt usage, which feels superfluous. Hopefully what I've updated to is much more readable (should only need to know ohms law and metric conversion now 😅).

docs/src/components/power-estimate.js Outdated Show resolved Hide resolved
docs/src/data/power.js Outdated Show resolved Hide resolved
docs/src/pages/power-profiler.js Outdated Show resolved Hide resolved
@Nicell Nicell force-pushed the docs/power-profiler branch 5 times, most recently from df28e38 to 099092d Compare January 13, 2021 01:59
Copy link
Contributor

@innovaker innovaker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! There's some really neat ideas in here and you've clearly put a lot of effort into it!

Below are notes that came to mind as I read through the code. I appreciate it's still early days for this feature though.

  • "Power profiler" implies it takes readings from your keyboard (to "profile" your power use), much as I believe the Nordic Power Profiler does? Suggestions:
    a) Battery Life Calculator
    b) Power Usage Estimator/Guesstimator
    c) Juice Projector/Predictor 😃
    or some combination/variation of the above words.
    EDIT: having now used Nordic's Online Power Profiler - I now appreciate where you got the name from.

  • Headers/licenses please!

  • Are you intending to maintain this going forward? I suspect ZMK is going to evolve somewhat this year which will probably invalidate the assumptions and data. We can't expect firmware contributors to keep it in sync.

  • It's safe to assume that the concept of "split" will be generalized to more than two nodes later this year. It's probably worth keeping that in the back of your mind for design choices.

  • Even with the big fat disclaimer, I still have concerns about introducing this feature without implementing a clear feedback loop for data from actual keyboards to verify and improve the model. But I won't stand in the way of it going live.

  • Does the page adapt to mobile devices well? I'd imagine this particular page will be accessed from phones a lot.

docs/docusaurus.config.js Outdated Show resolved Hide resolved
docs/src/pages/power-profiler.js Outdated Show resolved Hide resolved
docs/src/data/power.js Show resolved Hide resolved
Comment on lines +17 to +37
const palette = [
"#bbdefb",
"#90caf9",
"#64b5f6",
"#42a5f5",
"#2196f3",
"#1e88e5",
"#1976d2",
];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these be in the styling as classes?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to how they're used, I feel they're better this way. Using them as classes would be pretty cumbersome

docs/src/components/power-estimate.js Outdated Show resolved Hide resolved
? {
powerSupply: {
type: psuType,
outputVoltage: outputV,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on other the naming conventions, presumably this is in volts rather than milli-volts or micro-volts?

<div className="container">
<h1 className="hero__title">ZMK Power Profiler</h1>
<p className="hero__subtitle">
{"Estimate your keyboard's power usage and battery life on ZMK."}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.

docs/src/pages/power-profiler.js Show resolved Hide resolved
docs/src/pages/power-profiler.js Outdated Show resolved Hide resolved
docs/src/pages/power-profiler.js Outdated Show resolved Hide resolved
@Nicell
Copy link
Member Author

Nicell commented Jan 30, 2021

  • "Power profiler" implies it takes readings from your keyboard (to "profile" your power use), much as I believe the Nordic Power Profiler does? Suggestions:
    EDIT: having now used Nordic's Online Power Profiler - I now appreciate where you got the name from.

Does this mean we can stick to this name? Your other suggestions just feel too long IMO. Thoughts?

  • Are you intending to maintain this going forward? I suspect ZMK is going to evolve somewhat this year which will probably invalidate the assumptions and data. We can't expect firmware contributors to keep it in sync.

Yes, I'll definitely plan to keep this maintained. Ideally I'll be updating the numbers on a schedule by retesting all of the values.

  • It's safe to assume that the concept of "split" will be generalized to more than two nodes later this year. It's probably worth keeping that in the back of your mind for design choices.

This is a fair point. It should be pretty easy to extend this to handle that.

  • Even with the big fat disclaimer, I still have concerns about introducing this feature without implementing a clear feedback loop for data from actual keyboards to verify and improve the model. But I won't stand in the way of it going live.

I'm not sure if there's much more we can do. If it means anything, of the people I've asked, their battery life has fallen within the range besides a few exceptions (whom I think had some other power stuff going on they weren't accounting for. LEDs, OLEDs, etc).

  • Does the page adapt to mobile devices well? I'd imagine this particular page will be accessed from phones a lot.

It does! Try it out.

@Nicell Nicell force-pushed the docs/power-profiler branch 4 times, most recently from 4e647cf to 7eeead0 Compare February 4, 2021 19:43
@Nicell
Copy link
Member Author

Nicell commented Feb 4, 2021

I've addressed nearly everything from the reviews. I should note that the headers I've added are under the MIT license rather than the rest of the docs that has a creative commons license. I chose this, as I feel this work should be under MIT since it's not really directly documentation. If anyone has some opposition, I'm open to persuasion to use the other license instead.

Copy link
Collaborator

@joelspadin joelspadin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are still a few places in here with massive functions that could be split into smaller components, but this seems like a good start to me.

powerSupply: {
type: psuType,
outputVoltage: outputV,
quiescent,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Units would be nice.

<div className="profilerInput">
<label>
Bonded Bluetooth Profiles{" "}
<span tooltip="The average amount of host devices connected at once">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<span tooltip="The average amount of host devices connected at once">
<span tooltip="The average number of host devices connected at once">

Subjective, but this feels like more natural wording to me.

</div>
<div className="col col--4">
<div className="profilerInput">
<label>Split Keyboard</label>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems a little odd that you are allowed to control this for standalone boards that are either always or never splits, but that can be improved later.

@Nicell Nicell force-pushed the docs/power-profiler branch 2 times, most recently from 9419384 to ef00e7f Compare February 16, 2021 20:33
@Nicell
Copy link
Member Author

Nicell commented Mar 1, 2021

@innovaker @petejohanson, this PR is holding me up on a few projects. Any chance this could get a review soon? I have a feeling we could iterate on this forever, so hopefully we can focus on most iterations happening in future PRs.

@markstos
Copy link

markstos commented Mar 2, 2021

Cool project. As a USB keyboard user, I'm curious about the power draw of QMK vs ZMK. I noticed there are USB power meters that could be added in-line between the laptop and the keyboard to measure the power usage over say, 24 hours:

https://www.amazon.com/Klein-Tools-ET920-Capacity-Resistance/dp/B07FMHHS43/

If someone had a keyboard with hot-swap sockets with both QMK and ZMK-programmed chips, it would be possible to check power draw for idling and "typical use" with otherwise identical PCBs and switches. I'm curious if ZMKs low-power features translate to USB as well. (I suppose I should open a new thread for this...)

@Nicell
Copy link
Member Author

Nicell commented Mar 6, 2021

@markstos This power profiler is mostly targeted to handle power readings for batteries, but the results should be pretty close to what you'd get off USB. Of course, USB power pull isn't nearly as important as battery pull when wireless. Sure ZMK may idle at only 20uA higher than quiescent, but even 10mA will barely make a difference when connected over USB. A lot of this also comes down to the MCU of choice. The same hardware setup on QMK and ZMK probably won't have very different power usage.

Copy link
Contributor

@petejohanson petejohanson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a totally acceptable starting point for this. It's definitely used by folks already, and the numbers have been reported to be "on target", which combined w/ the disclaimer, is enough for me. Thanks @Nicell !

@petejohanson petejohanson merged commit 4ef11ac into zmkfirmware:main Mar 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request hacktoberfest-accepted
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants