-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Conversation
I need uW/uA switch, I'm way too used to uA rather than to uW. |
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. |
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. |
60c5304
to
157de11
Compare
@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 😄 |
|
||
// Lithium ion self discharge | ||
const lithiumDischarge = | ||
((parseInt(batterymAh) * 1000 * lithiumIonMonthlyDischargePercent) / |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 😅).
df28e38
to
099092d
Compare
There was a problem hiding this 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.
const palette = [ | ||
"#bbdefb", | ||
"#90caf9", | ||
"#64b5f6", | ||
"#42a5f5", | ||
"#2196f3", | ||
"#1e88e5", | ||
"#1976d2", | ||
]; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
? { | ||
powerSupply: { | ||
type: psuType, | ||
outputVoltage: outputV, |
There was a problem hiding this comment.
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."} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above.
099092d
to
263d46c
Compare
Does this mean we can stick to this name? Your other suggestions just feel too long IMO. Thoughts?
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.
This is a fair point. It should be pretty easy to extend this to handle that.
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).
It does! Try it out. |
4e647cf
to
7eeead0
Compare
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. |
7eeead0
to
0c5527b
Compare
There was a problem hiding this 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.
docs/src/pages/power-profiler.js
Outdated
powerSupply: { | ||
type: psuType, | ||
outputVoltage: outputV, | ||
quiescent, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Units would be nice.
docs/src/pages/power-profiler.js
Outdated
<div className="profilerInput"> | ||
<label> | ||
Bonded Bluetooth Profiles{" "} | ||
<span tooltip="The average amount of host devices connected at once"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<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> |
There was a problem hiding this comment.
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.
9419384
to
ef00e7f
Compare
ef00e7f
to
943329f
Compare
@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. |
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...) |
@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. |
There was a problem hiding this 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 !
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: