Update stopwatch.js

- Remove ability to lap while stopped
- Added ability to save log of laps as dated json array while stopped
master
Red-The-Hunter 2020-03-28 11:07:14 +08:00 committed by GitHub
parent 30912d6825
commit 2c5983e3c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 1 deletions

View File

@ -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});