From 3b3168203d6fad80be223785f1a4fb4a3587ef22 Mon Sep 17 00:00:00 2001 From: Silver Kuusik Date: Sun, 22 Oct 2017 21:12:02 +0200 Subject: [PATCH] add battery indicator --- index.html | 2 +- styles.css | 10 ++++++++++ sumorobot.js | 9 ++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 2a66301..8890465 100755 --- a/index.html +++ b/index.html @@ -14,8 +14,8 @@ +
Battery: 0%
- diff --git a/styles.css b/styles.css index bbd1e7c..1a0a90b 100755 --- a/styles.css +++ b/styles.css @@ -71,6 +71,16 @@ input.has-error { .goog-menuitem-content { font-size: 2em !important; } +#bar { + right: 0px; + z-index: 35; + font-size: 2vw; + color: #ee4d4d; + position: absolute; +} +#bar.connected { + color: #44CC00; +} #panel { z-index: 35; width: 100%; diff --git a/sumorobot.js b/sumorobot.js index 7b87e5e..36d7933 100755 --- a/sumorobot.js +++ b/sumorobot.js @@ -56,7 +56,12 @@ Sumorobot.prototype.connect = function() { workspace.highlightBlock(evt.data); highlighted = evt.data; } else { - console.log(evt.data); + var data = evt.data.replace(/'/g, '"').toLowerCase(); + console.log(data); + var battery = JSON.parse(data)["battery_voltage"]; + battery = Math.round((((battery - 3.6) * 100) / (4.2 - 3.6))); + $("#battery").html(battery + ""); + $("#bar").addClass("connected"); } }; /* when there is an WebSocket error */ @@ -434,6 +439,8 @@ window.onload = function() { $("#panel").hide(); }); + $("#stream").prepend(''); + /* try to close if block bubble canvas */ /*$(document).click(function(e) { var target = e.target;