From 292d6ab5c932a52f6d9cd424a22b7d3a3bd92dfd Mon Sep 17 00:00:00 2001 From: MaBecker Date: Thu, 7 Nov 2019 22:44:05 +0100 Subject: [PATCH] word-clock Dispaly Time as Text --- apps.json | 11 +++ apps/word-clock-icon.js | 1 + apps/word-clock.js | 145 ++++++++++++++++++++++++++++++++++++++++ apps/word-clock.json | 5 ++ apps/word-clock.png | Bin 0 -> 843 bytes 5 files changed, 162 insertions(+) create mode 100644 apps/word-clock-icon.js create mode 100644 apps/word-clock.js create mode 100644 apps/word-clock.json create mode 100644 apps/word-clock.png diff --git a/apps.json b/apps.json index 976c3c8ad..7afc83309 100644 --- a/apps.json +++ b/apps.json @@ -216,5 +216,16 @@ {"name":"+route"}, {"name":"=route"} ] + }, + { "id": "wclock", + "name": "Word Clock", + "icon": "word-clock.png", + "description": "Display Time as Text", + "tags": "", + "storage": [ + {"name":"+wclock","url":"word-clock.json"}, + {"name":"-wclock","url":"word-clock.js"}, + {"name":"*wclock","url":"word-clock-icon.js","evaluate":true} + ] } ] diff --git a/apps/word-clock-icon.js b/apps/word-clock-icon.js new file mode 100644 index 000000000..6bc31ba81 --- /dev/null +++ b/apps/word-clock-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("AAsRwEAkFBvE/wFgmHD/kwgFAmGBgAFFn4FBjOB/AFDgOACIUbgIXDh4FDsEOgf8iALBg0B/hBFjwvD/gpBsE5AoMxwFAj4IBnACBh4CBBANAhwFBg4RBBYUhAoMbAoIdCjJoBNYUx4FgHAUgQY8/zHin/BgEuxnmn53BgkM80wMoIFB8gFDhu0CIcF3gLDg8cAokYAoOAAoQvB/A9H4BBDwPwX4P4nEDnAFBEAMGFIPDhk4g0MAoN8n4FD/ARBAoODuAFBjExwYdBEYMZwYOBgPwh8DhhBHACo=")) \ No newline at end of file diff --git a/apps/word-clock.js b/apps/word-clock.js new file mode 100644 index 000000000..038353516 --- /dev/null +++ b/apps/word-clock.js @@ -0,0 +1,145 @@ +/* jshint esversion: 6 */ +(function() { + + var buf = Graphics.createArrayBuffer(240, 240, 2, { msb: true }); + + function flip() { + g.drawImage({ width: buf.getWidth(), height: buf.getHeight(), bpp: 2, transparent: 0, buffer: buf.buffer }, 0, 0); + } + + const allWords = [ + "ATWENTYD", + "QUARTERY", + "FIVEHALF", + "DPASTORO", + "FIVEIGHT", + "SIXTHREE", + "TWELEVEN", + "FOURNINE" + ]; + const hours = { + 0: ["", 0, 0], + 1: ["ONE", 17, 47, 77], + 2: ["TWO", 06, 16, 17], + 3: ["THREE", 35, 45, 55, 65, 75], + 4: ["FOUR", 07, 17, 27, 37], + 5: ["FIVE", 04, 14, 24, 34], + 6: ["SIX", 05, 15, 25], + 7: ["SEVEN", 05, 46, 56, 66, 67], + 8: ["EIGHT", 34, 44, 54, 64, 74], + 9: ["NINE", 47, 57, 67, 77], + 10: ["TEN", 74, 75, 76], + 11: ["ELEVEN", 26, 36, 46, 56, 66, 76], + 12: ["TWELVE", 06, 16, 26, 36, 56, 66] + }; + + const mins = { + 0: ["A", 0, 0], + 1: ["FIVE", 02, 12, 22, 32], + 2: ["TEN", 10, 30, 40], + 3: ["QUARTER", 01, 11, 21, 31, 41, 51, 61], + 4: ["TWENTY", 10, 20, 30, 40, 50, 60], + 5: ["HALF", 42, 52, 62, 72], + 6: ["PAST", 13, 23, 33, 43], + 7: ["TO", 43, 53] + }; + + // offsets and incerments + const xs = 30; + const ys = 20; + const dy = 22; + const dx = 25; + + // font size and color + const wordFontSize = 20; + const timeFontSize = 30; + const passivColor = 1; + const activeColor = 2; + + function drawWordClock() { + + // get time + var t = new Date(); + var h = t.getHours(); + var m = t.getMinutes(); + var time = ("0" + h).substr(-2) + ":" + ("0" + m).substr(-2); + + var hidx; + var midx; + var midxA; + + buf.clear(); + buf.setFontVector(wordFontSize); + buf.setColor(passivColor); + buf.setFontAlign(0, -1, 0); + + // draw allWords + var c; + var y = ys; + var x = xs; + allWords.forEach((line) => { + x = xs; + for (c in line) { + buf.drawString(line[c], x, y); + x += dx; + } + y += dy; + }); + + + // calc indexes + midx = Math.round(m / 5); + hidx = h % 12; + if (hidx === 0) { hidx = 12; } + if (midx > 6) { + if (midx == 12) { midx = 0; } + hidx++; + } + if (midx !== 0) { + if (midx <= 6) { + midxA = [midx, 6]; + } else { + midxA = [12 - midx, 7]; + } + } + + // write hour in active color + buf.setColor(activeColor); + buf.setFontVector(wordFontSize); + + hours[hidx][0].split('').forEach((c, pos) => { + x = xs + (hours[hidx][pos + 1] / 10 | 0) * dx; + y = ys + (hours[hidx][pos + 1] % 10) * dy; + buf.drawString(c, x, y); + }); + + // write min words in active color + midxA.forEach(idx => { + mins[idx][0].split('').forEach((c, pos) => { + x = xs + (mins[idx][pos + 1] / 10 | 0) * dx; + y = ys + (mins[idx][pos + 1] % 10) * dy; + buf.drawString(c, x, y); + }); + }); + + // display digital time + buf.setColor(activeColor); + buf.setFontVector(timeFontSize); + buf.drawString(time, 120, 200); + + // display buf + flip(); + } + + Bangle.on('lcdPower', function(on) { + if (on) { + drawWordClock(); + drawWidgets(); + } + }); + + g.clear(); + setInterval(drawWordClock, 1E4); + drawWordClock(); + +})(); \ No newline at end of file diff --git a/apps/word-clock.json b/apps/word-clock.json new file mode 100644 index 000000000..3235aeee2 --- /dev/null +++ b/apps/word-clock.json @@ -0,0 +1,5 @@ +{ + "name":"Word Clock", + "icon":"*wclock", + "src":"-wclock" +} diff --git a/apps/word-clock.png b/apps/word-clock.png new file mode 100644 index 0000000000000000000000000000000000000000..f8cbdbf046f4fd8b6f1717736221719e18289079 GIT binary patch literal 843 zcmV-R1GM~!P)aG&CtGDLy_vARr((I5=TpVM9YhSXfwoetvIn zZ!Ik?FE1~3b#-TFXRxraQc_Y+PfvMyc}hx3ii(Pzot=`Bl7xhWQ}IOn0007}Nklfg7)YND{jSK$MFpzyPQya55IrWZ*1H0PysD2tAPvD$w#f17D)Z z{6zwr;aN<8B^-bi0F6d*79&>ysRnX3F~TVWw{g4#1v-O=ka%IFJS3#94rzGH;gQwE z=c2%*o9Zdm9-z)nH@?=#I!P`nR-)G00jgF525kz3z@qS<4zS*HlN07qj>7X%Cn?gY z@_?d_C5MuMwE&UyX9Yx>D`pmE)#6)yw1nzmYFxj2_!ULBH3z`>V{4SHLIsrkIqf6R z&@>)^I~BUs#yYmfZ~zu6XW;D0_n=2f^Y#!Dh~S=)RBdIaCDsxhw&U0A_R(EqYhfXN z98t&Tz0xFT(RfclgJfq(^G&m@h+}z`QzifOk5_W-s3COz`q`59Mc>~H-drThP2+|j zW6)!2;9@F?azs4<_i>U0i7X9ztAPNmwyk|o=UT1>z&-SRkFqq?Ku-XhB!JCN%W;56 zlYyfLGj6H;vY}_7YhsM*VKjIE_^V&dovZkn!}D(*8g5Sql%eF{ob#Gq-14ysIK4NJ zf+1{SK&2F`Tu!+$Vi#$3MK((9Fsv!cxwz!g;>BupVH?^U)f6ObN2cgJKV1l+7dE?I z4d(l2qHc8@%)n2pHZ}vx(5_ZObv^JsuRxc9Q%d=2dAk{$?11LegM4bJ9@5Z~10<(t zdiEXPf$oP-OaYCeg%?HdbK&qahhBj>I<83~8#K54L&$qf0&HadCS-S2S3cR%