diff --git a/apps.json b/apps.json index 8feb713e9..cd77b1a2f 100644 --- a/apps.json +++ b/apps.json @@ -1775,6 +1775,19 @@ {"name":"widviz.wid.js","url":"widget.js"} ] }, + { "id": "binclock", + "name": "Binary Clock", + "shortName":"Binary Clock", + "icon": "app.png", + "version":"0.02", + "description": "A binary clock with hours and minutes. BTN1 toggles a digital clock.", + "tags": "clock,binary", + "type": "clock", + "storage": [ + {"name":"binclock.app.js","url":"app.js"}, + {"name":"binclock.img","url":"app-icon.js","evaluate":true} + ] + } , { "id": "pizzatimer", "name": "Pizza Timer", diff --git a/apps/binclock/ChangeLog b/apps/binclock/ChangeLog new file mode 100644 index 000000000..2378e52f8 --- /dev/null +++ b/apps/binclock/ChangeLog @@ -0,0 +1,2 @@ +0.01: New App! +0.02: Fixed bug where screen didn't clear so incorrect time displayed. diff --git a/apps/binclock/app-icon.js b/apps/binclock/app-icon.js new file mode 100644 index 000000000..206c1ee42 --- /dev/null +++ b/apps/binclock/app-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEwwkEIf4A/AH8AgP/iAECiIJCj/xAgURBoUAn8gAYMP//wAgIMBBwX//4gCAIUAgf/EIUfC5QEBC5MCI4gNCEIPyAgRGDLQMwBIwEJEAYEFAH7v3dQTpDAZ6cDdIYDPdQbpDAZ8QYgTpDAZ5IEAaYAeM4cRTYSuQiABBiQCBbckjmQzFmcggUzGJkBBoMDQgcSkMAAIIXOgL8CC6gvRL4b2CL4MwTIotJAAJfJiIiCC5RfHF4LdHC4wvGAwIvHL5UDYQIuBF44A/AH4A/AH4AbA")) diff --git a/apps/binclock/app.js b/apps/binclock/app.js new file mode 100644 index 000000000..65ada5ff3 --- /dev/null +++ b/apps/binclock/app.js @@ -0,0 +1,178 @@ +// Load fonts +require("Font7x11Numeric7Seg").add(Graphics); +// position on screen +const X = 160, Y = 180; +var displayTime = 0; +var minuteLED = [0,0,0,0,0,0]; +var hourLED = [0,0,0,0,0]; +var prevMinute = [0,0,0,0,0,0]; +var prevHour = [0,0,0,0,0]; + + +function drawTime(d) { + // work out how to display the current time + var h = d.getHours(), m = d.getMinutes(); + var time = (" "+h).substr(-2) + ":" + ("0"+m).substr(-2); + // draw the current time (4x size 7 segment) + g.setFont("7x11Numeric7Seg",4); + g.setFontAlign(1,1); // align right bottom + g.drawString(time, X, Y, true /*clear background*/); + // draw the seconds (2x size 7 segment) + g.setFont("7x11Numeric7Seg",2); + g.drawString(("0"+d.getSeconds()).substr(-2), X+30, Y, true /*clear background*/); +} + +function updateHourArray(hours){ + + var j; + for(j=0;j 15){ + hourLED[0] = 1; + hours = hours - 16; + } + if(hours > 7){ + hourLED[1] = 1; + hours = hours - 8; + } + if(hours > 3){ + hourLED[2] = 1; + hours = hours - 4; + } + if(hours > 1){ + hourLED[3] = 1; + hours = hours - 2; + } + if(hours > 0){ + hourLED[4] = 1; + } + + return hourLED; + +} + +function updateMinuteArray(minutes){ + var j; + for(j=0;j 31){ + minuteLED[0] = 1; + minutes = minutes - 32; + } + if(minutes > 15){ + minuteLED[1] = 1; + minutes = minutes - 16; + } + if(minutes > 7){ + minuteLED[2] = 1; + minutes = minutes - 8; + } + if(minutes > 3){ + minuteLED[3] = 1; + minutes = minutes - 4; + } + if(minutes > 1){ + minuteLED[4] = 1; + minutes = minutes - 2; + } + if(minutes > 0){ + minuteLED[5] = 1; + } + + return minuteLED; + +} + +function draw(){ + + // work out how to display the current time + var d = new Date(); + var h = d.getHours(), m = d.getMinutes(); + + updateHourArray(h); + updateMinuteArray(m); + + var i; + //Draw hour circles + for(i=0; i{ + if (secondInterval) clearInterval(secondInterval); + secondInterval = undefined; + if (on) { + setInterval(draw, 1000); + draw(); // draw immediately + } +}); +// Load widgets +Bangle.loadWidgets(); +Bangle.drawWidgets(); +// Show launcher when middle button pressed +setWatch(Bangle.showLauncher, BTN2, { repeat: false, edge: "falling" }); +setWatch(function() { + if(displayTime == 0){ + displayTime = 1; + } else{ + displayTime = 0; + } +}, BTN, {edge:"rising", debounce:50, repeat:true}); diff --git a/apps/binclock/app.png b/apps/binclock/app.png new file mode 100644 index 000000000..b22feb36b Binary files /dev/null and b/apps/binclock/app.png differ