add battery indicator

This commit is contained in:
Silver Kuusik 2017-10-22 21:12:02 +02:00
parent 1ff4ef120b
commit 3b3168203d
3 changed files with 19 additions and 2 deletions

View File

@ -14,8 +14,8 @@
<script src="sumorobot.js"></script>
</head>
<body>
<div id="bar">Battery: <span id="battery">0</span>%</div>
<div id="stream">
<!--<iframe width="100%" height="91%" allowfullscreen="true" src="https://mixer.com/embed/player/14551694"></iframe>-->
<div class="btn-group btn-group-justified">
<a href="#" class="btn btn-lg btn-danger btn-close">Close</a>
</div>

View File

@ -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%;

View File

@ -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('<iframe width="100%" height="91%" allowfullscreen="true" src="https://mixer.com/embed/player/14551694"></iframe>');
/* try to close if block bubble canvas */
/*$(document).click(function(e) {
var target = e.target;