chronowid 0.03
parent
1017090cbe
commit
ae738e9d99
|
|
@ -1,2 +1,3 @@
|
||||||
0.01: New widget and app!
|
0.01: New widget and app!
|
||||||
0.02: Setting to reset values, timer buzzes at 00:00 and not later (see readme)
|
0.02: Setting to reset values, timer buzzes at 00:00 and not later (see readme)
|
||||||
|
0.03: Display only minutes:seconds when less than 1 hour left
|
||||||
|
|
@ -1,93 +1,93 @@
|
||||||
(() => {
|
(() => {
|
||||||
const storage = require('Storage');
|
const storage = require('Storage');
|
||||||
settingsChronowid = storage.readJSON("chronowid.json",1)||{}; //read settingsChronowid from file
|
settingsChronowid = storage.readJSON("chronowid.json",1)||{}; //read settingsChronowid from file
|
||||||
var height = 23;
|
var height = 23;
|
||||||
var width = 58;
|
var width = 58;
|
||||||
var interval = 0; //used for the 1 second interval timer
|
var interval = 0; //used for the 1 second interval timer
|
||||||
var now = new Date();
|
var now = new Date();
|
||||||
|
|
||||||
var time = 0;
|
var time = 0;
|
||||||
var diff = settingsChronowid.goal - now;
|
var diff = settingsChronowid.goal - now;
|
||||||
|
|
||||||
//Convert ms to time
|
//Convert ms to time
|
||||||
function getTime(t) {
|
function getTime(t) {
|
||||||
var milliseconds = parseInt((t % 1000) / 100),
|
var milliseconds = parseInt((t % 1000) / 100),
|
||||||
seconds = Math.floor((t / 1000) % 60),
|
seconds = Math.floor((t / 1000) % 60),
|
||||||
minutes = Math.floor((t / (1000 * 60)) % 60),
|
minutes = Math.floor((t / (1000 * 60)) % 60),
|
||||||
hours = Math.floor((t / (1000 * 60 * 60)) % 24);
|
hours = Math.floor((t / (1000 * 60 * 60)) % 24);
|
||||||
|
|
||||||
hours = (hours < 10) ? "0" + hours : hours;
|
hours = (hours < 10) ? "0" + hours : hours;
|
||||||
minutes = (minutes < 10) ? "0" + minutes : minutes;
|
minutes = (minutes < 10) ? "0" + minutes : minutes;
|
||||||
seconds = (seconds < 10) ? "0" + seconds : seconds;
|
seconds = (seconds < 10) ? "0" + seconds : seconds;
|
||||||
|
|
||||||
return hours + ":" + minutes + ":" + seconds;
|
return hours + ":" + minutes + ":" + seconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
function printDebug() {
|
function printDebug() {
|
||||||
print ("Nowtime: " + getTime(now));
|
print ("Nowtime: " + getTime(now));
|
||||||
print ("Now: " + now);
|
print ("Now: " + now);
|
||||||
print ("Goaltime: " + getTime(settingsChronowid.goal));
|
print ("Goaltime: " + getTime(settingsChronowid.goal));
|
||||||
print ("Goal: " + settingsChronowid.goal);
|
print ("Goal: " + settingsChronowid.goal);
|
||||||
print("Difftime: " + getTime(diff));
|
print("Difftime: " + getTime(diff));
|
||||||
print("Diff: " + diff);
|
print("Diff: " + diff);
|
||||||
print ("Started: " + settingsChronowid.started);
|
print ("Started: " + settingsChronowid.started);
|
||||||
print ("----");
|
print ("----");
|
||||||
}
|
}
|
||||||
|
|
||||||
//counts down, calculates and displays
|
//counts down, calculates and displays
|
||||||
function countDown() {
|
function countDown() {
|
||||||
now = new Date();
|
now = new Date();
|
||||||
diff = settingsChronowid.goal - now; //calculate difference
|
diff = settingsChronowid.goal - now; //calculate difference
|
||||||
WIDGETS["chronowid"].draw();
|
WIDGETS["chronowid"].draw();
|
||||||
//time is up
|
//time is up
|
||||||
if (settingsChronowid.started && diff < 1000) {
|
if (settingsChronowid.started && diff < 1000) {
|
||||||
Bangle.buzz(1500);
|
Bangle.buzz(1500);
|
||||||
//write timer off to file
|
//write timer off to file
|
||||||
settingsChronowid.started = false;
|
settingsChronowid.started = false;
|
||||||
storage.writeJSON('chronowid.json', settingsChronowid);
|
storage.writeJSON('chronowid.json', settingsChronowid);
|
||||||
clearInterval(interval); //stop interval
|
clearInterval(interval); //stop interval
|
||||||
}
|
}
|
||||||
//printDebug();
|
//printDebug();
|
||||||
}
|
}
|
||||||
|
|
||||||
// draw your widget
|
// draw your widget
|
||||||
function draw() {
|
function draw() {
|
||||||
if (!settingsChronowid.started) {
|
if (!settingsChronowid.started) {
|
||||||
width = 0;
|
width = 0;
|
||||||
return; //do not draw anything if timer is not started
|
return; //do not draw anything if timer is not started
|
||||||
}
|
}
|
||||||
g.reset();
|
g.reset();
|
||||||
if (diff >= 0) {
|
if (diff >= 0) {
|
||||||
if (diff < 600000) { //less than 1 hour left
|
if (diff < 3600000) { //less than 1 hour left
|
||||||
width = 58;
|
width = 58;
|
||||||
g.clearRect(this.x,this.y,this.x+width,this.y+height);
|
g.clearRect(this.x,this.y,this.x+width,this.y+height);
|
||||||
g.setFont("6x8", 2);
|
g.setFont("6x8", 2);
|
||||||
g.drawString(getTime(diff).substring(3), this.x+1, this.y+5); //remove hour part 00:00:00 -> 00:00
|
g.drawString(getTime(diff).substring(3), this.x+1, this.y+5); //remove hour part 00:00:00 -> 00:00
|
||||||
}
|
}
|
||||||
if (diff >= 600000) { //one hour or more left
|
if (diff >= 3600000) { //one hour or more left
|
||||||
width = 48;
|
width = 48;
|
||||||
g.clearRect(this.x,this.y,this.x+width,this.y+height);
|
g.clearRect(this.x,this.y,this.x+width,this.y+height);
|
||||||
g.setFont("6x8", 1);
|
g.setFont("6x8", 1);
|
||||||
g.drawString(getTime(diff), this.x+1, this.y+((height/2)-4)); //display hour 00:00:00
|
g.drawString(getTime(diff), this.x+1, this.y+((height/2)-4)); //display hour 00:00:00
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// not needed anymoe, because we check if diff < 1000 now, so 00:00 is displayed.
|
// not needed anymoe, because we check if diff < 1000 now, so 00:00 is displayed.
|
||||||
// else {
|
// else {
|
||||||
// width = 58;
|
// width = 58;
|
||||||
// g.clearRect(this.x,this.y,this.x+width,this.y+height);
|
// g.clearRect(this.x,this.y,this.x+width,this.y+height);
|
||||||
// g.setFont("6x8", 2);
|
// g.setFont("6x8", 2);
|
||||||
// g.drawString("END", this.x+15, this.y+5);
|
// g.drawString("END", this.x+15, this.y+5);
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settingsChronowid.started) interval = setInterval(countDown, 1000); //start countdown each second
|
if (settingsChronowid.started) interval = setInterval(countDown, 1000); //start countdown each second
|
||||||
|
|
||||||
// add the widget
|
// add the widget
|
||||||
WIDGETS["chronowid"]={area:"bl",width:width,draw:draw,reload:function() {
|
WIDGETS["chronowid"]={area:"bl",width:width,draw:draw,reload:function() {
|
||||||
reload();
|
reload();
|
||||||
Bangle.drawWidgets(); // relayout all widgets
|
Bangle.drawWidgets(); // relayout all widgets
|
||||||
}};
|
}};
|
||||||
|
|
||||||
//printDebug();
|
//printDebug();
|
||||||
countDown();
|
countDown();
|
||||||
})();
|
})();
|
||||||
Loading…
Reference in New Issue