add battery indication

This commit is contained in:
Silver Kuusik
2018-08-18 18:48:27 +02:00
parent ec2e6f41ac
commit 2af99f108b
6 changed files with 14 additions and 10 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

BIN
assets/img/battery_full.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

BIN
assets/img/battery_half.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

View File

@@ -31,8 +31,7 @@ Sumorobot.prototype.connect = function() {
// Setup connection watchdog interval
self.connectionTimer = setInterval(function() {
if (self.watchdogCounter == 0 && !self.terminate) {
$('#battery').removeClass('connected');
$('#battery').html('Disconnected');
$("#battery img").attr("src", "assets/img/battery_disconnected.png");
}
// Reset watchdog counter
self.watchdogCounter = 0;
@@ -66,8 +65,13 @@ Sumorobot.prototype.connect = function() {
self.sensors = JSON.parse(data);
// When sensor data received
if (self.sensors['battery_voltage']) {
$('#battery').html(self.sensors['battery_voltage'] + 'V');
$('#battery').addClass('connected');
if (self.sensors['battery_voltage'] > 4.0) {
$("#battery img").attr("src", "assets/img/battery_full.png");
} else if (self.sensors['battery_voltage'] > 3.1) {
$("#battery img").attr("src", "assets/img/battery_half.png");
} else {
$("#battery img").attr("src", "assets/img/battery_empty.png");
}
}
// Count data received packets
self.watchdogCounter += 1;