setTimeout works for every one second but not every 60 seconds
I need to update the timer number every 60 seconds. If I set the timeout
to 1000 milliseconds everything works fine except the number updates every
one second. If I set 60000 milliseconds, the timer number does not update.
//Power off on low battery timer
var resetC=30; //time in minutes to reset timer to.
var c=resetC;
var t;
var timer_is_on=0;
function timedCount() {
$('#timer').html(c);
if(c>=1){
c=c-1;
t=setTimeout(function(){timedCount()},60000);
}else{
$('#batInfo').html('<H4>Powering off device.</H4>');
window.setTimeout(function(){device.powerOff()},4000);
stopCount();
}
}
function doTimer(){
if (!timer_is_on){
timer_is_on=1;
timedCount();
}
}
function stopCount()
{
clearTimeout(t);
timer_is_on=0;
c=resetC;
}
No comments:
Post a Comment