Browse Source

feat(docs): add backlight to power profiler

xmkb
Alessandro Bortolin 3 years ago committed by Pete Johanson
parent
commit
f8bf8bffd5
  1. 34
      docs/src/components/power-estimate.js
  2. 12
      docs/src/data/power.js
  3. 101
      docs/src/pages/power-profiler.js
  4. 1
      schema/hardware-metadata.schema.json

34
docs/src/components/power-estimate.js

@ -6,7 +6,12 @@
import React from "react"; import React from "react";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import { displayPower, underglowPower, zmkBase } from "../data/power"; import {
displayPower,
underglowPower,
backlightPower,
zmkBase,
} from "../data/power";
import "../css/power-estimate.css"; import "../css/power-estimate.css";
// Average monthly discharge percent // Average monthly discharge percent
@ -82,6 +87,7 @@ function PowerEstimate({
batteryMilliAh, batteryMilliAh,
usage, usage,
underglow, underglow,
backlight,
display, display,
}) { }) {
if (!board || !board.powerSupply.type || !batteryMilliAh) { if (!board || !board.powerSupply.type || !batteryMilliAh) {
@ -180,6 +186,31 @@ function PowerEstimate({
}); });
} }
if (backlight.backlightEnabled) {
let backlightMicroA =
((board.powerSupply.outputVoltage - backlight.backlightVoltage) /
backlight.backlightResistance) *
1000000 *
backlight.backlightBrightness *
backlight.backlightQuantity;
if (
backlight.backlightBrightness > 0 &&
backlight.backlightBrightness < 1
) {
backlightMicroA += backlightPower.pwmPower;
}
const backlightMicroW = backlightMicroA * voltageEquivalent;
const backlightUsage = backlightMicroW * (1 - usage.percentAsleep);
totalUsage += backlightUsage;
powerUsage.push({
title: "Backlight",
usage: backlightUsage,
});
}
if (display.displayEnabled && display.displayType) { if (display.displayEnabled && display.displayType) {
const { activePercent, active, sleep } = displayPower[display.displayType]; const { activePercent, active, sleep } = displayPower[display.displayType];
@ -260,6 +291,7 @@ PowerEstimate.propTypes = {
batteryMilliAh: PropTypes.number, batteryMilliAh: PropTypes.number,
usage: PropTypes.Object, usage: PropTypes.Object,
underglow: PropTypes.Object, underglow: PropTypes.Object,
backlight: PropTypes.Object,
display: PropTypes.Object, display: PropTypes.Object,
}; };

12
docs/src/data/power.js

@ -71,6 +71,18 @@ export const underglowPower = {
ledOff: 460, // Quiescent current of a WS2812B ledOff: 460, // Quiescent current of a WS2812B
}; };
export const backlightLEDs = {
White: 3.2,
Blue: 3.0,
Green: 2.2,
Yellow: 2.1,
Red: 1.8,
};
export const backlightPower = {
pwmPower: 510, // Estimated power consumption of PWM module
};
export const displayPower = { export const displayPower = {
// Based on GoodDisplay's 1.02in epaper // Based on GoodDisplay's 1.02in epaper
EPAPER: { EPAPER: {

101
docs/src/pages/power-profiler.js

@ -11,7 +11,7 @@ import styles from "./styles.module.css";
import PowerEstimate from "../components/power-estimate"; import PowerEstimate from "../components/power-estimate";
import CustomBoardForm from "../components/custom-board-form"; import CustomBoardForm from "../components/custom-board-form";
import { useInput } from "../utils/hooks"; import { useInput } from "../utils/hooks";
import { zmkBoards } from "../data/power"; import { zmkBoards, backlightLEDs } from "../data/power";
import "../css/power-profiler.css"; import "../css/power-profiler.css";
const Disclaimer = `This profiler makes many assumptions about typing const Disclaimer = `This profiler makes many assumptions about typing
@ -41,6 +41,17 @@ function PowerProfiler() {
const { value: glowQuantity, bind: bindGlowQuantity } = useInput(10); const { value: glowQuantity, bind: bindGlowQuantity } = useInput(10);
const { value: glowBrightness, bind: bindGlowBrightness } = useInput(1); const { value: glowBrightness, bind: bindGlowBrightness } = useInput(1);
const { value: backlightEnabled, bind: bindBacklightEnabled } =
useInput(false);
const { value: backlightQuantity, bind: bindBacklightQuantity } =
useInput(60);
const { value: backlightColor, bind: bindBacklightColor } = useInput("");
const { value: backlightVoltage, bind: bindBacklightVoltage } = useInput(2.2);
const { value: backlightResistance, bind: bindBacklightResistance } =
useInput(100);
const { value: backlightBrightness, bind: bindBacklightBrightness } =
useInput(1);
const { value: displayEnabled, bind: bindDisplayEnabled } = useInput(false); const { value: displayEnabled, bind: bindDisplayEnabled } = useInput(false);
const { value: displayType, bind: bindDisplayType } = useInput(""); const { value: displayType, bind: bindDisplayType } = useInput("");
@ -63,6 +74,11 @@ function PowerProfiler() {
} }
: zmkBoards[board]; : zmkBoards[board];
const currentBacklightVoltage =
backlightColor === "custom"
? backlightVoltage
: backlightLEDs[backlightColor || "White"];
return ( return (
<Layout <Layout
title={`ZMK Power Profiler`} title={`ZMK Power Profiler`}
@ -207,6 +223,68 @@ function PowerProfiler() {
</> </>
)} )}
</div> </div>
<div className="col col--4">
<div className="profilerInput">
<label>Backlight</label>
<input
checked={backlightEnabled}
id="backlight"
{...bindBacklightEnabled}
className="toggleInput"
type="checkbox"
/>
<label htmlFor="backlight" className="toggle">
<div className="toggleThumb" />
</label>
</div>
{backlightEnabled && (
<>
<div className="profilerInput">
<label>LED Quantity</label>
<div className="inputBox">
<input {...bindBacklightQuantity} type="number" />
</div>
</div>
<div className="profilerInput">
<label>LED Forward Voltage</label>
<select {...bindBacklightColor}>
{Object.entries(backlightLEDs).map(([c, v]) => (
<option key={c} value={c}>
{c} ({v.toFixed(1)} V)
</option>
))}
<option value="custom">Custom</option>
</select>
{backlightColor === "custom" && (
<div className="profilerInput">
<div className="inputBox">
<input {...bindBacklightVoltage} type="number" />
<span>V</span>
</div>
</div>
)}
</div>
<div className="profilerInput">
<label>LED Resistance</label>
<div className="inputBox">
<input {...bindBacklightResistance} type="number" />
<span>ohm</span>
</div>
</div>
<div className="profilerInput">
<label>Brightness</label>
<input
{...bindBacklightBrightness}
type="range"
min="0"
step=".01"
max="1"
/>
<span>{Math.round(backlightBrightness * 100)}%</span>
</div>
</>
)}
</div>
<div className="col col--4"> <div className="col col--4">
<div className="profilerInput"> <div className="profilerInput">
<label>Display</label> <label>Display</label>
@ -244,6 +322,13 @@ function PowerProfiler() {
batteryMilliAh={batteryMilliAh} batteryMilliAh={batteryMilliAh}
usage={{ bondedQty, percentAsleep }} usage={{ bondedQty, percentAsleep }}
underglow={{ glowEnabled, glowBrightness, glowQuantity }} underglow={{ glowEnabled, glowBrightness, glowQuantity }}
backlight={{
backlightEnabled,
backlightVoltage: currentBacklightVoltage,
backlightResistance,
backlightBrightness,
backlightQuantity,
}}
display={{ displayEnabled, displayType }} display={{ displayEnabled, displayType }}
/> />
<PowerEstimate <PowerEstimate
@ -252,6 +337,13 @@ function PowerProfiler() {
batteryMilliAh={batteryMilliAh} batteryMilliAh={batteryMilliAh}
usage={{ bondedQty, percentAsleep }} usage={{ bondedQty, percentAsleep }}
underglow={{ glowEnabled, glowBrightness, glowQuantity }} underglow={{ glowEnabled, glowBrightness, glowQuantity }}
backlight={{
backlightEnabled,
backlightVoltage: currentBacklightVoltage,
backlightResistance,
backlightBrightness,
backlightQuantity,
}}
display={{ displayEnabled, displayType }} display={{ displayEnabled, displayType }}
/> />
</> </>
@ -262,6 +354,13 @@ function PowerProfiler() {
batteryMilliAh={batteryMilliAh} batteryMilliAh={batteryMilliAh}
usage={{ bondedQty, percentAsleep }} usage={{ bondedQty, percentAsleep }}
underglow={{ glowEnabled, glowBrightness, glowQuantity }} underglow={{ glowEnabled, glowBrightness, glowQuantity }}
backlight={{
backlightEnabled,
backlightVoltage: currentBacklightVoltage,
backlightResistance,
backlightBrightness,
backlightQuantity,
}}
display={{ displayEnabled, displayType }} display={{ displayEnabled, displayType }}
/> />
)} )}

1
schema/hardware-metadata.schema.json

@ -55,6 +55,7 @@
"display", "display",
"encoder", "encoder",
"underglow", "underglow",
"backlight",
"pointer" "pointer"
] ]
} }

Loading…
Cancel
Save