Skip to content

Commit

Permalink
colored battery indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
BotSpace committed Oct 5, 2024
1 parent b5ee7ce commit c9f1003
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

<div class="container" id="interface">
<button id="ble-button">🔗</button>
<button id="battery-level">🔋:?V</button>
<button id="battery-level"> &#x1F50B;&#xFE0E; ?V </button>
<button id="ble-status">not connected</button>

<div id="settings-grid">
Expand Down
11 changes: 10 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,16 @@ function createBleAgent() {
batteryWatchdogReset();
let value = event.target.value.getUint8(0);
let voltage = (value/255.0) * 12
batteryDisplay.innerHTML = "🔋:" + voltage.toFixed(2) + "V";

if(voltage >= 7.6) {
batteryDisplay.style.textShadow = "0 0 2px green, 0 0 2px green, 0 0 2px green, 0 0 2px green";
} else if (voltage >= 7) {
batteryDisplay.style.textShadow = "0 0 2px green, 0 0 2px yellow, 0 0 2px yellow, 0 0 2px yellow";
} else {
batteryDisplay.style.textShadow = "0 0 2px red, 0 0 2px red, 0 0 2px red, 0 0 2px red";
}

batteryDisplay.innerHTML = "&#x1F50B;&#xFE0E; " + voltage.toFixed(1) + "V";
}

async function disconnectBLE() {
Expand Down
1 change: 1 addition & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ body {

#battery-level {
background-color: grey;
color: white;
border-radius: 1vw;
font-size: 2vw;
grid-row: 1;
Expand Down

0 comments on commit c9f1003

Please sign in to comment.