meshtastic/src/utils/calculateADC.ts

24 lines
819 B
TypeScript
Raw Normal View History

export default function calculateADC() {
2024-01-05 17:04:40 -08:00
//const variables
const batMillivoltsFull = 4.2;
const batMillivoltsEmpty = 3.27;
const batFullPercent = 1;
//variable
const batteryChargePercent =
2024-02-08 13:23:54 -08:00
Number.parseFloat(
2024-01-05 17:04:40 -08:00
(<HTMLInputElement>document.getElementById("batteryChargePercent")).value,
) / 100;
2024-02-08 13:23:54 -08:00
const operativeAdcMultiplier = Number.parseFloat(
2024-01-05 17:04:40 -08:00
(<HTMLInputElement>document.getElementById("operativeAdcMultiplier")).value,
);
const result =
(operativeAdcMultiplier *
((batFullPercent - 1) * batMillivoltsEmpty -
batFullPercent * batMillivoltsFull)) /
((batteryChargePercent - 1) * batMillivoltsEmpty -
batteryChargePercent * batMillivoltsFull);
(<HTMLInputElement>(
document.getElementById("newOperativeAdcMultiplier")
)).value = result.toFixed(4);
}