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 timeY = 60;
|
||||||
var hsXPos = 0;
|
var hsXPos = 0;
|
||||||
var lapTimes = [];
|
var lapTimes = [];
|
||||||
|
var saveTimes = [];
|
||||||
var displayInterval;
|
var displayInterval;
|
||||||
|
|
||||||
function timeToText(t) {
|
function timeToText(t) {
|
||||||
|
|
@ -18,7 +19,7 @@ function updateLabels() {
|
||||||
g.setFontAlign(0,0,3);
|
g.setFontAlign(0,0,3);
|
||||||
g.drawString(started?"STOP":"GO",230,120);
|
g.drawString(started?"STOP":"GO",230,120);
|
||||||
if (!started) g.drawString("RESET",230,50);
|
if (!started) g.drawString("RESET",230,50);
|
||||||
g.drawString("LAP",230,190);
|
g.drawString(started?"LAP":"SAVE",230,190);
|
||||||
g.setFont("6x8",1);
|
g.setFont("6x8",1);
|
||||||
g.setFontAlign(-1,-1);
|
g.setFontAlign(-1,-1);
|
||||||
for (var i in lapTimes) {
|
for (var i in lapTimes) {
|
||||||
|
|
@ -50,6 +51,11 @@ function drawms() {
|
||||||
g.clearRect(hsXPos,timeY,220,timeY+20);
|
g.clearRect(hsXPos,timeY,220,timeY+20);
|
||||||
g.drawString("."+("0"+hs).substr(-2),hsXPos,timeY+10);
|
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
|
setWatch(function() { // Start/stop
|
||||||
started = !started;
|
started = !started;
|
||||||
|
|
@ -85,6 +91,12 @@ setWatch(function() { // Lap
|
||||||
if (started) tCurrent = Date.now();
|
if (started) tCurrent = Date.now();
|
||||||
lapTimes.unshift(tCurrent-tStart);
|
lapTimes.unshift(tCurrent-tStart);
|
||||||
tStart = tCurrent;
|
tStart = tCurrent;
|
||||||
|
if (!started)
|
||||||
|
{
|
||||||
|
var timenow= Date();
|
||||||
|
saveconvert();
|
||||||
|
require("Storage").writeJSON("StpWch-"+timenow.toString(), saveTimes);
|
||||||
|
}
|
||||||
updateLabels();
|
updateLabels();
|
||||||
}, BTN3, {repeat:true});
|
}, BTN3, {repeat:true});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue