mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-06 19:47:02 +03:00
add battery indicator
This commit is contained in:
@@ -706,6 +706,24 @@ function checkStatus(){
|
||||
lastMsg = msg;
|
||||
}
|
||||
}
|
||||
if (data.hasOwnProperty('Voltage')) {
|
||||
var voltage = data['Voltage'];
|
||||
var i;
|
||||
if (voltage > 0) {
|
||||
if (inRange(voltage, 5.8, 6.2) || inRange(voltage, 8.8, 9.2)) {
|
||||
i = 0;
|
||||
} else if (inRange(voltage, 6.2, 6.8) || inRange(voltage, 9.2, 10.0)) {
|
||||
i = 1;
|
||||
} else if (inRange(voltage, 6.8, 7.1) || inRange(voltage, 10.0, 10.5)) {
|
||||
i = 2;
|
||||
} else if (inRange(voltage, 7.1, 7.5) || inRange(voltage, 10.5, 11.0)) {
|
||||
i = 3;
|
||||
} else {
|
||||
i = 4;
|
||||
}
|
||||
$("#battery").html('<img src="battery-'+i+'.svg" />');
|
||||
}
|
||||
}
|
||||
blockAjax = false;
|
||||
})
|
||||
.fail(function(xhr, ajaxOptions, thrownError) {
|
||||
@@ -778,3 +796,7 @@ function showMessage(message, severity) {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function inRange(x, min, max) {
|
||||
return ((x-min)*(x-max) <= 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user