Skip to content

Commit

Permalink
make power viewing nicer in the UI
Browse files Browse the repository at this point in the history
  • Loading branch information
timoschilling committed Jan 21, 2023
1 parent 068e18c commit 25277ce
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
11 changes: 8 additions & 3 deletions fs_src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -444,9 +444,14 @@ <h1 id="head">Switch</h1>
</label>
</div>
<div class="form-control" id="power_stats_container" style="display: none;">
<label for="power_stats">Power:</label>
<span id="power_stats"></span>
</div>
<div class="form-control">
<label for="power_stats_current">Current:</label>
<span id="power_stats_current"></span>
</div>
<div class="form-control">
<label for="power_stats_total">Total:</label>
<span id="power_stats_total"></span>
</div>
<div>
<div class="form-control">
<label for="name">Name:</label>
Expand Down
12 changes: 9 additions & 3 deletions fs_src/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -1074,12 +1074,18 @@ function updateElement(key, value, info) {
function updatePowerStats(c, cd) {
if (cd.apower === undefined) return;

apower = Math.round(cd.apower * 10) / 10;
console.log(apower)
updateInnerText(el(c, "power_stats"), `${apower}W, ${cd.aenergy}Wh`);
updateInnerText(
el(c, "power_stats_current"), `${formatFloat(cd.apower, 3)} W`);
updateInnerText(
el(c, "power_stats_total"), `${formatFloat(cd.aenergy, 3)} Wh`);
el(c, "power_stats_container").style.display = "block";
}

function formatFloat(number, digits) {
return new Intl.NumberFormat("en-EN", {minimumFractionDigits: digits})
.format(number);
}

function getInfo() {
return new Promise(function(resolve, reject) {
if (pendingGetInfo) {
Expand Down

0 comments on commit 25277ce

Please sign in to comment.