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> <script src="sumorobot.js"></script>
</head> </head>
<body> <body>
<div id="bar">Battery: <span id="battery">0</span>%</div>
<div id="stream"> <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"> <div class="btn-group btn-group-justified">
<a href="#" class="btn btn-lg btn-danger btn-close">Close</a> <a href="#" class="btn btn-lg btn-danger btn-close">Close</a>
</div> </div>

View File

@ -71,6 +71,16 @@ input.has-error {
.goog-menuitem-content { .goog-menuitem-content {
font-size: 2em !important; font-size: 2em !important;
} }
#bar {
right: 0px;
z-index: 35;
font-size: 2vw;
color: #ee4d4d;
position: absolute;
}
#bar.connected {
color: #44CC00;
}
#panel { #panel {
z-index: 35; z-index: 35;
width: 100%; width: 100%;

View File

@ -56,7 +56,12 @@ Sumorobot.prototype.connect = function() {
workspace.highlightBlock(evt.data); workspace.highlightBlock(evt.data);
highlighted = evt.data; highlighted = evt.data;
} else { } 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 */ /* when there is an WebSocket error */
@ -434,6 +439,8 @@ window.onload = function() {
$("#panel").hide(); $("#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 */ /* try to close if block bubble canvas */
/*$(document).click(function(e) { /*$(document).click(function(e) {
var target = e.target; var target = e.target;