Update stopwatch.js
- Remove ability to lap while stopped - Added ability to save log of laps as dated json array while stoppedmaster
parent
30912d6825
commit
2c5983e3c1
|
|
@ -4,6 +4,7 @@ var started = false;
|
|||
var timeY = 60;
|
||||
var hsXPos = 0;
|
||||
var lapTimes = [];
|
||||
var saveTimes = [];
|
||||
var displayInterval;
|
||||
|
||||
function timeToText(t) {
|
||||
|
|
@ -18,7 +19,7 @@ function updateLabels() {
|
|||
g.setFontAlign(0,0,3);
|
||||
g.drawString(started?"STOP":"GO",230,120);
|
||||
if (!started) g.drawString("RESET",230,50);
|
||||
g.drawString("LAP",230,190);
|
||||
g.drawString(started?"LAP":"SAVE",230,190);
|
||||
g.setFont("6x8",1);
|
||||
g.setFontAlign(-1,-1);
|
||||
for (var i in lapTimes) {
|
||||
|
|
@ -50,6 +51,11 @@ function drawms() {
|
|||
g.clearRect(hsXPos,timeY,220,timeY+20);
|
||||
g.drawString("."+("0"+hs).substr(-2),hsXPos,timeY+10);
|
||||
}
|
||||
function saveconvert() {
|
||||
for (var v in lapTimes){
|
||||
saveTimes[v]=v+1+"-"+timeToText(lapTimes[(lapTimes.length-1)-v]);
|
||||
}
|
||||
}
|
||||
|
||||
setWatch(function() { // Start/stop
|
||||
started = !started;
|
||||
|
|
@ -85,6 +91,12 @@ setWatch(function() { // Lap
|
|||
if (started) tCurrent = Date.now();
|
||||
lapTimes.unshift(tCurrent-tStart);
|
||||
tStart = tCurrent;
|
||||
if (!started)
|
||||
{
|
||||
var timenow= Date();
|
||||
saveconvert();
|
||||
require("Storage").writeJSON("StpWch-"+timenow.toString(), saveTimes);
|
||||
}
|
||||
updateLabels();
|
||||
}, BTN3, {repeat:true});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue