forked from marva/sumorobot-web
add battery indication
This commit is contained in:
BIN
assets/img/battery_disconnected.png
Normal file
BIN
assets/img/battery_disconnected.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.2 KiB |
BIN
assets/img/battery_empty.png
Normal file
BIN
assets/img/battery_empty.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.5 KiB |
BIN
assets/img/battery_full.png
Normal file
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
BIN
assets/img/battery_half.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.7 KiB |
@@ -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;
|
||||
|
Reference in New Issue
Block a user