From 5e525f081fbd3ae740503945b9823603eb89600f Mon Sep 17 00:00:00 2001 From: Bruce Blore Date: Wed, 2 Nov 2022 12:06:17 -0700 Subject: [PATCH] Added bgtimer, gallery, infoclk, pomoplus, random, rpnsci, stlap, stlapview bgtimer: A timer that runs in the background and can be set with a keypad gallery: An app to present a list of images in a menu and allow the user to pick from them infoclk: A clock face that displays more information and some app shortcuts when unlocked pomoplus: A configurable pomodoro timer that runs in the background random: Random number generator rpnsci: Scientific calculator using reverse polish notation stlap: A stopwatch with lap timer that runs in the background stlapview: An optional app that displays data collected by stlap --- apps/bgtimer/app.js | 27 ++ apps/bgtimer/boot.js | 11 + apps/bgtimer/common.js | 42 +++ apps/bgtimer/icon.js | 1 + apps/bgtimer/icon.png | Bin 0 -> 414 bytes apps/bgtimer/img/pause.png | Bin 0 -> 2891 bytes apps/bgtimer/img/play.png | Bin 0 -> 2891 bytes apps/bgtimer/img/reset.png | Bin 0 -> 2891 bytes apps/bgtimer/keypad.js | 136 +++++++++ apps/bgtimer/metadata.json | 44 +++ apps/bgtimer/ring.js | 28 ++ apps/bgtimer/timerview.js | 107 +++++++ apps/gallery/README.md | 18 ++ apps/gallery/app.js | 52 ++++ apps/gallery/icon.js | 1 + apps/gallery/icon.png | Bin 0 -> 249 bytes apps/gallery/metadata.json | 26 ++ apps/infoclk/README.md | 33 ++ apps/infoclk/app.js | 405 +++++++++++++++++++++++++ apps/infoclk/font.js | 23 ++ apps/infoclk/font/am.png | Bin 0 -> 360 bytes apps/infoclk/font/colon.png | Bin 0 -> 216 bytes apps/infoclk/font/digit0.png | Bin 0 -> 290 bytes apps/infoclk/font/digit1.png | Bin 0 -> 183 bytes apps/infoclk/font/digit2.png | Bin 0 -> 305 bytes apps/infoclk/font/digit3.png | Bin 0 -> 270 bytes apps/infoclk/font/digit4.png | Bin 0 -> 247 bytes apps/infoclk/font/digit5.png | Bin 0 -> 302 bytes apps/infoclk/font/digit6.png | Bin 0 -> 309 bytes apps/infoclk/font/digit7.png | Bin 0 -> 227 bytes apps/infoclk/font/digit8.png | Bin 0 -> 309 bytes apps/infoclk/font/digit9.png | Bin 0 -> 319 bytes apps/infoclk/font/pm.png | Bin 0 -> 327 bytes apps/infoclk/icon.js | 2 + apps/infoclk/icon.png | Bin 0 -> 1989 bytes apps/infoclk/metadata.json | 38 +++ apps/infoclk/settings.js | 571 +++++++++++++++++++++++++++++++++++ apps/pomoplus/app.js | 157 ++++++++++ apps/pomoplus/boot.js | 19 ++ apps/pomoplus/common.js | 118 ++++++++ apps/pomoplus/icon.js | 1 + apps/pomoplus/icon.png | Bin 0 -> 2122 bytes apps/pomoplus/img/pause.png | Bin 0 -> 2891 bytes apps/pomoplus/img/play.png | Bin 0 -> 2891 bytes apps/pomoplus/img/reset.png | Bin 0 -> 2891 bytes apps/pomoplus/img/skip.png | Bin 0 -> 2891 bytes apps/pomoplus/metadata.json | 37 +++ apps/pomoplus/settings.js | 94 ++++++ apps/random/app.js | 205 +++++++++++++ apps/random/icon.js | 1 + apps/random/icon.png | Bin 0 -> 378 bytes apps/random/metadata.json | 24 ++ apps/rpnsci/README.md | 38 +++ apps/rpnsci/app.js | 403 ++++++++++++++++++++++++ apps/rpnsci/icon.js | 1 + apps/rpnsci/icon.png | Bin 0 -> 765 bytes apps/rpnsci/icon.xcf | Bin 0 -> 4021 bytes apps/rpnsci/metadata.json | 24 ++ apps/stlap/app.js | 304 +++++++++++++++++++ apps/stlap/icon.js | 1 + apps/stlap/icon.png | Bin 0 -> 1566 bytes apps/stlap/img/pause.png | Bin 0 -> 2891 bytes apps/stlap/img/play.png | Bin 0 -> 2891 bytes apps/stlap/img/reset.png | Bin 0 -> 2891 bytes apps/stlap/metadata.json | 24 ++ apps/stlapview/app.js | 110 +++++++ apps/stlapview/icon.js | 1 + apps/stlapview/icon.png | Bin 0 -> 1566 bytes apps/stlapview/metadata.json | 27 ++ 69 files changed, 3154 insertions(+) create mode 100644 apps/bgtimer/app.js create mode 100644 apps/bgtimer/boot.js create mode 100644 apps/bgtimer/common.js create mode 100644 apps/bgtimer/icon.js create mode 100644 apps/bgtimer/icon.png create mode 100644 apps/bgtimer/img/pause.png create mode 100644 apps/bgtimer/img/play.png create mode 100644 apps/bgtimer/img/reset.png create mode 100644 apps/bgtimer/keypad.js create mode 100644 apps/bgtimer/metadata.json create mode 100644 apps/bgtimer/ring.js create mode 100644 apps/bgtimer/timerview.js create mode 100644 apps/gallery/README.md create mode 100644 apps/gallery/app.js create mode 100644 apps/gallery/icon.js create mode 100644 apps/gallery/icon.png create mode 100644 apps/gallery/metadata.json create mode 100644 apps/infoclk/README.md create mode 100644 apps/infoclk/app.js create mode 100644 apps/infoclk/font.js create mode 100644 apps/infoclk/font/am.png create mode 100644 apps/infoclk/font/colon.png create mode 100644 apps/infoclk/font/digit0.png create mode 100644 apps/infoclk/font/digit1.png create mode 100644 apps/infoclk/font/digit2.png create mode 100644 apps/infoclk/font/digit3.png create mode 100644 apps/infoclk/font/digit4.png create mode 100644 apps/infoclk/font/digit5.png create mode 100644 apps/infoclk/font/digit6.png create mode 100644 apps/infoclk/font/digit7.png create mode 100644 apps/infoclk/font/digit8.png create mode 100644 apps/infoclk/font/digit9.png create mode 100644 apps/infoclk/font/pm.png create mode 100644 apps/infoclk/icon.js create mode 100644 apps/infoclk/icon.png create mode 100644 apps/infoclk/metadata.json create mode 100644 apps/infoclk/settings.js create mode 100644 apps/pomoplus/app.js create mode 100644 apps/pomoplus/boot.js create mode 100644 apps/pomoplus/common.js create mode 100644 apps/pomoplus/icon.js create mode 100644 apps/pomoplus/icon.png create mode 100644 apps/pomoplus/img/pause.png create mode 100644 apps/pomoplus/img/play.png create mode 100644 apps/pomoplus/img/reset.png create mode 100644 apps/pomoplus/img/skip.png create mode 100644 apps/pomoplus/metadata.json create mode 100644 apps/pomoplus/settings.js create mode 100644 apps/random/app.js create mode 100644 apps/random/icon.js create mode 100644 apps/random/icon.png create mode 100644 apps/random/metadata.json create mode 100644 apps/rpnsci/README.md create mode 100644 apps/rpnsci/app.js create mode 100644 apps/rpnsci/icon.js create mode 100644 apps/rpnsci/icon.png create mode 100644 apps/rpnsci/icon.xcf create mode 100644 apps/rpnsci/metadata.json create mode 100644 apps/stlap/app.js create mode 100644 apps/stlap/icon.js create mode 100644 apps/stlap/icon.png create mode 100644 apps/stlap/img/pause.png create mode 100644 apps/stlap/img/play.png create mode 100644 apps/stlap/img/reset.png create mode 100644 apps/stlap/metadata.json create mode 100644 apps/stlapview/app.js create mode 100644 apps/stlapview/icon.js create mode 100644 apps/stlapview/icon.png create mode 100644 apps/stlapview/metadata.json diff --git a/apps/bgtimer/app.js b/apps/bgtimer/app.js new file mode 100644 index 000000000..66f22a7a2 --- /dev/null +++ b/apps/bgtimer/app.js @@ -0,0 +1,27 @@ +Bangle.BGTIMER_ACTIVE = true; +const common = require("bgtimer-com.js"); +const storage = require("Storage"); + +const keypad = require("bgtimer-keys.js"); +const timerView = require("bgtimer-tview.js"); + +Bangle.loadWidgets(); +Bangle.drawWidgets(); + +//Save our state when the app is closed +E.on('kill', () => { + storage.writeJSON(common.STATE_PATH, common.state); +}); + +//Handle touch here. I would implement these separately in each view, but I can't figure out how to clear the event listeners. +Bangle.on('touch', (button, xy) => { + if (common.state.wasRunning) timerView.touch(button, xy); + else keypad.touch(button, xy); +}); + +Bangle.on('swipe', dir => { + if (!common.state.wasRunning) keypad.swipe(dir); +}); + +if (common.state.wasRunning) timerView.show(common); +else keypad.show(common); diff --git a/apps/bgtimer/boot.js b/apps/bgtimer/boot.js new file mode 100644 index 000000000..67840b3ce --- /dev/null +++ b/apps/bgtimer/boot.js @@ -0,0 +1,11 @@ +const BGTIMER_common = require("bgtimer-com.js"); + +//Only start the timeout if the timer is running +if (BGTIMER_common.state.running) { + setTimeout(() => { + //Check now to avoid race condition + if (Bangle.BGTIMER_ACTIVE === undefined) { + load('bgtimer-ring.js'); + } + }, BGTIMER_common.getTimeLeft()); +} \ No newline at end of file diff --git a/apps/bgtimer/common.js b/apps/bgtimer/common.js new file mode 100644 index 000000000..67a6660d3 --- /dev/null +++ b/apps/bgtimer/common.js @@ -0,0 +1,42 @@ +const storage = require("Storage"); +const heatshrink = require("heatshrink"); + +exports.STATE_PATH = "bgtimer.state.json"; + +exports.BUTTON_ICONS = { + play: heatshrink.decompress(atob("jEYwMAkAGBnACBnwCBn+AAQPgAQPwAQP8AQP/AQXAAQPwAQP8AQP+AQgICBwQUCEAn4FggyBHAQ+CIgQ")), + pause: heatshrink.decompress(atob("jEYwMA/4BBAX4CEA")), + reset: heatshrink.decompress(atob("jEYwMA/4BB/+BAQPDAQPnAQIAKv///0///8j///EP//wAQQICBwQUCEhgyCHAQ+CIgI=")) +}; + +//Store the minimal amount of information to be able to reconstruct the state of the timer at any given time. +//This is necessary because it is necessary to write to flash to let the timer run in the background, so minimizing the writes is necessary. +exports.STATE_DEFAULT = { + wasRunning: false, //If the timer ever was running. Used to determine whether to display a reset button + running: false, //Whether the timer is currently running + startTime: 0, //When the timer was last started. Difference between this and now is how long timer has run continuously. + pausedTime: 0, //When the timer was last paused. Used for expiration and displaying timer while paused. + elapsedTime: 0, //How much time the timer had spent running before the current start time. Update on pause or user skipping stages. + setTime: 0, //How long the user wants the timer to run for + inputString: '0' //The string of numbers the user typed in. +}; +exports.state = storage.readJSON(exports.STATE_PATH); +if (!exports.state) { + exports.state = exports.STATE_DEFAULT; +} + +//Get the number of milliseconds until the timer expires +exports.getTimeLeft = function () { + if (!exports.state.wasRunning) { + //If the timer never ran, the time left is just the set time + return exports.setTime + } else if (exports.state.running) { + //If the timer is running, the time left is current time - start time + preexisting time + var runningTime = (new Date()).getTime() - exports.state.startTime + exports.state.elapsedTime; + } else { + //If the timer is not running, the same as above but use when the timer was paused instead of now. + var runningTime = exports.state.pausedTime - exports.state.startTime + exports.state.elapsedTime; + } + + return exports.state.setTime - runningTime; +} \ No newline at end of file diff --git a/apps/bgtimer/icon.js b/apps/bgtimer/icon.js new file mode 100644 index 000000000..a47eb21f8 --- /dev/null +++ b/apps/bgtimer/icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEwwcAkmSpICOggRPpEACJ9AgESCJxMBhu27dtARVgCIMBCJpxDmwRL7ARDgwRL4CWECJaoFjYRJ2ARFgYRJwDNGCJFsb46SIRgQAFSRAQHSRCMEAAqSGRgoAFRhaSKRgySKRg6SIRhCSIRhCSICBqSCRhSSGRhY2FkARPhMkCJ9JkiONgECCIOQCJsSCIOSCJuSCIVACBcECIdICJYOBCIVJRhYRFSRSMBCIiSKBwgCCSRCMCCIqSIRgYCFRhYCFSQyMEAQqSGBw6SIRgySKRgtO4iSJBAmT23bOIqSCRgvtCINsSQ4aEndtCINt2KSGIggOBCIW2JQlARgZECCIhKEpBEGCIpKEA==")) \ No newline at end of file diff --git a/apps/bgtimer/icon.png b/apps/bgtimer/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..7dcf44b88254d3f31f6c94d8d3f4933fc2f1f3ec GIT binary patch literal 414 zcmV;P0b%}$P)S|NQ$gCcl(vO0I@(u75S@S(5l8z2uoB`P_zbWw zrm4RZMDIcW0M2=s5|PIQSAQ9GhHvoa~#6ticgf|`rupkieP=E%3iiZOv2xNQ+ zpoT!lhXFW5M0_aViHM312i)5=&)tvz$Ko#bnHY2Xe6J}65d|BRBpJU;*HZzryneBR}MeU;y^`QaBd! zMnDd_rQtXTd(f>Pd22WZ@_N-k7mo_}L-v@ literal 0 HcmV?d00001 diff --git a/apps/bgtimer/img/pause.png b/apps/bgtimer/img/pause.png new file mode 100644 index 0000000000000000000000000000000000000000..ad31dadcff3ecffba6c7e015a4b2ecdcccc15b0f GIT binary patch literal 2891 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1|%Pp+x}o+U~I{Bb`J1#c2+1T%1_J8No8Qr zm{>c}*5j~)%+dJZrAngg+8q`tEBwU%ILU0~a$O;i)fy)2qxZK-jn}iQd+~#)f)B|X zUp;uVW_9yw1&+D~3oA>_T^^nPy}5LgY%Ja#-(B6mySyPl-}vk+31*YKX2G31W}IBt zwJ@CJV!yyKLuKRBGbS%lsX2b#mZ@fM_eY)o#r1u1rs;+X3PR_N4sYo+?^tf0+x*$C zuthX=>W?`USC()K*%!rr{Lx!{Ftst=?MzA5JPRisv0D+D$zdj@k2D{xSoLy>eu_<) zWq#qcQ=!-PsMjZ2EMKovJolM^P{a`-m5zV_SI*QM9T!(kPEvIJT`2#5!RzTKmQGmB z;?~C+vcR$I?}PdeyQ8)3Eg!13K6ZHC{kVpQd135=z~VXYlaFW4VK|unz$^c!c4@-1 z$zP(pyX6@7-ac@&)I0cF!)e)s2PY@^-kjQG(pn=|VZS*46jSYXhwrnlM;FU4=XaR3 z%j+Hkd;0;8#!c62@7=w6@Am%mS%3dB99mg)Jm;_40${YTC3(BM0BIoj>AbrhNO2Z; zL>4nJ=qZCRW5rVYGN2%PiKnkC`!i-yb}Jpb3EHthA;}Wgh!W@g+}zZ>5(ej@)Wnk1 z6ovB4k_-iRPv3y>Mm}+%S<0R+jv*erj1rvBzcKy?0-#2mfDs6AN&+Pa>1V>HnHqAV z77z@@(I6TPB7z}6P{C*_8Vw?XAwW>UXet^FB7z}6Pyx+TQT{Ft9Zp`Z43JAaUHx3v IIVCg!009H(%m4rY literal 0 HcmV?d00001 diff --git a/apps/bgtimer/img/play.png b/apps/bgtimer/img/play.png new file mode 100644 index 0000000000000000000000000000000000000000..6c20c24c54d72382a69d5aa3685e3ad8fa6174ba GIT binary patch literal 2891 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1|%Pp+x}o+U~I{Bb`J1#c2+1T%1_J8No8Qr zm{>c}*5j~)%+dJZrAngg+8q`tEBwU%ILU0~a$O;i)fy)2qxZK-jn}iQd+~#)f)B|X zUp;uVW_9yw1&+D~3oA>_T^^nPy}5LgY%Ja#-(B6mySyPl-}vk+31*YKX2G31W}IBt zwJ@CJV!yyKLuKRBGbS%lsX2b#mZ@fM_eY)o#r1u1rs;+X3PR_N4sYo+?^tf0+x*$C zuthX=>W?`USC()K*%!rr{Lx!{Ftst=?MzA5JPRisv0D+D$zdj@k2D{xSoLy>eu_<) zWq#qcQ=!-PsMjZ2EMKovJolM^P{a`-m5zV_SI*QM9T!(kPEvIJT`2#5!RzTKmQGmB z;?~C+vcR$I?}PdeyQ8)3Eg!13K6ZHC{kVpQd135=z~VXYlaFW4VK|unz$^c!c4@-1 z$zP(pyX6@7-ac@&)I0cF!)e)s2PY@^-kjQG(pn=|VZS*46jSYXhwrnlM;FU4=XaR3 z%j+Hkd;0;8#!c62@7=w6@Am%mS%3dB99mg)Jm;_40${YTC3(BM0BIoj>AbrhNO2Z; zL>4nJ=qZCRW5rVYGN2%PiKnkC`!i-yc1y0~8~!E(g(OQ{BTAg}b8}PkN*J7rQWHy3 zQxwWGOEMJPJ$(bh8~Mb6W+{8RIEHxeGD>hh{|3|p0snyj#-=9C2r~@X0!AQ!iBn3$ z4MMg6W+*i*!fOFFEF#JRN-Sc6X(ooo7L0`Sk>mqp!-$O^vMqpFM#v(HEg)nO)hxhe z5!Ed~w}_-v1k+3m4NGw}vjFA@nppr#T`Vx0s71pJhM7k-3(yUwngzHFrq}{P2E!~M zE0T#d9ApVeaX^Z}FdqmdKI;Vst0LE7sJpcdz literal 0 HcmV?d00001 diff --git a/apps/bgtimer/img/reset.png b/apps/bgtimer/img/reset.png new file mode 100644 index 0000000000000000000000000000000000000000..7a317d09795c09aabab4836c8b9ec4a6c5fe4db8 GIT binary patch literal 2891 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1|%Pp+x}o+U~I{Bb`J1#c2+1T%1_J8No8Qr zm{>c}*5j~)%+dJZrAngg+8q`tEBwU%ILU0~a$O;i)fy)2qxZK-jn}iQd+~#)f)B|X zUp;uVW_9yw1&+D~3oA>_T^^nPy}5LgY%Ja#-(B6mySyPl-}vk+31*YKX2G31W}IBt zwJ@CJV!yyKLuKRBGbS%lsX2b#mZ@fM_eY)o#r1u1rs;+X3PR_N4sYo+?^tf0+x*$C zuthX=>W?`USC()K*%!rr{Lx!{Ftst=?MzA5JPRisv0D+D$zdj@k2D{xSoLy>eu_<) zWq#qcQ=!-PsMjZ2EMKovJolM^P{a`-m5zV_SI*QM9T!(kPEvIJT`2#5!RzTKmQGmB z;?~C+vcR$I?}PdeyQ8)3Eg!13K6ZHC{kVpQd135=z~VXYlaFW4VK|unz$^c!c4@-1 z$zP(pyX6@7-ac@&)I0cF!)e)s2PY@^-kjQG(pn=|VZS*46jSYXhwrnlM;FU4=XaR3 z%j+Hkd;0;8#!c62@7=w6@Am%mS%3dB99mg)Jm;_40${YTC3(BM0BIoj>AbrhNO2Z; zL>4nJ=qZCRW5rVYGN2%PiKnkC`!i-y4rWEypL5fJLXst}5hc#~xw)x%B@E6*sfi`2 zDGKG8B^e6tp1uL$jeO!jvy?qu978;K86`NMe`EX)1VD{A0V5FLlmto;($9oXGe{1f z0r=!#<`T33mnFm)4$@1M1?ZL#YdAG9F5Ihr6 z+Y*@Ba0@^#qn0Hw!$D@ESU?R+kPQc!NApyK;scrn5w#2l1q%qkf(q;dY8wu*0%FN% zSp*9WoHWgoDM=Q9QU(a%bS@SNqAfr+7@3X5OcWuaEWl { + common.state.inputString = '0'; + common.state.setTime = 0; + updateDisplay(); + feedback(true); + } +}; + +let StartButton = { + label: 'Go', + onclick: () => { + common.state.startTime = (new Date()).getTime(); + common.state.elapsedTime = 0; + common.state.wasRunning = true; + common.state.running = true; + feedback(true); + require('bgtimer-tview.js').show(common); + } +}; + +const BUTTONS = [ + [new NumberButton(7), new NumberButton(8), new NumberButton(9), ClearButton], + [new NumberButton(4), new NumberButton(5), new NumberButton(6), new NumberButton(0)], + [new NumberButton(1), new NumberButton(2), new NumberButton(3), StartButton] +]; + +function feedback(acceptable) { + if (acceptable) Bangle.buzz(50, 0.5); + else Bangle.buzz(200, 1); +} + +function drawButtons() { + g.reset().clearRect(0, 44, 175, 175).setFont("Vector", 15).setFontAlign(0, 0); + //Draw lines + for (let x = 44; x <= 176; x += 44) { + g.drawLine(x, 44, x, 175); + } + for (let y = 44; y <= 176; y += 44) { + g.drawLine(0, y, 175, y); + } + for (let row = 0; row < 3; row++) { + for (let col = 0; col < 4; col++) { + g.drawString(BUTTONS[row][col].label, 22 + 44 * col, 66 + 44 * row); + } + } +} + +function getFontSize(length) { + let size = Math.floor(176 / length); //Characters of width needed per pixel + size *= (20 / 12); //Convert to height + // Clamp to between 6 and 20 + if (size < 6) return 6; + else if (size > 20) return 20; + else return Math.floor(size); +} + +function updateDisplay() { + let displayString = inputStringToDisplayString(common.state.inputString); + g.clearRect(0, 24, 175, 43).setColor(storage.readJSON('setting.json').theme.fg2).setFontAlign(1, -1).setFont("Vector", getFontSize(displayString.length)).drawString(displayString, 176, 24); +} + +exports.show = function (callerCommon) { + common = callerCommon; + g.reset(); + drawButtons(); + updateDisplay(); +}; + +exports.touch = function (button, xy) { + let row = Math.floor((xy.y - 44) / 44); + let col = Math.floor(xy.x / 44); + if (row < 0) return; + if (row > 2) row = 2; + if (col < 0) col = 0; + if (col > 3) col = 3; + + BUTTONS[row][col].onclick(); +}; + +exports.swipe = function (dir) { + if (dir == -1) { + if (common.state.inputString.length == 1) common.state.inputString = '0'; + else common.state.inputString = common.state.inputString.substring(0, common.state.inputString.length - 1); + + common.state.setTime = inputStringToTime(common.state.inputString); + + feedback(true); + updateDisplay(); + } else if (dir == 0) { + EnterButton.onclick(); + } +}; \ No newline at end of file diff --git a/apps/bgtimer/metadata.json b/apps/bgtimer/metadata.json new file mode 100644 index 000000000..3f63d0ec5 --- /dev/null +++ b/apps/bgtimer/metadata.json @@ -0,0 +1,44 @@ +{ + "id": "bgtimer", + "name": "Timer", + "version": "0.02", + "description": "A timer with a keypad that runs in the background", + "icon": "icon.png", + "type": "app", + "tags": "tools", + "supports": [ + "BANGLEJS2" + ], + "allow_emulator": true, + "storage": [ + { + "name": "bgtimer.app.js", + "url": "app.js" + }, + { + "name": "bgtimer.img", + "url": "icon.js", + "evaluate": true + }, + { + "name": "bgtimer.boot.js", + "url": "boot.js" + }, + { + "name": "bgtimer-com.js", + "url": "common.js" + }, + { + "name": "bgtimer-ring.js", + "url": "ring.js" + }, + { + "name": "bgtimer-keys.js", + "url": "keypad.js" + }, + { + "name": "bgtimer-tview.js", + "url": "timerview.js" + } + ] +} \ No newline at end of file diff --git a/apps/bgtimer/ring.js b/apps/bgtimer/ring.js new file mode 100644 index 000000000..9df5cb4bd --- /dev/null +++ b/apps/bgtimer/ring.js @@ -0,0 +1,28 @@ +const common = require('bgtimer-com.js'); + +Bangle.loadWidgets() +Bangle.drawWidgets() + +Bangle.setLocked(false); +Bangle.setLCDPower(true); + +let brightness = 0; + +setInterval(() => { + Bangle.buzz(200); + Bangle.setLCDBrightness(1 - brightness); + brightness = 1 - brightness; +}, 400); +Bangle.buzz(200); + +function stopTimer() { + common.state.wasRunning = false; + common.state.running = false; + require("Storage").writeJSON(common.STATE_PATH, common.state); +} + +E.showAlert("Timer expired!").then(() => { + stopTimer(); + load(); +}); +E.on('kill', stopTimer); \ No newline at end of file diff --git a/apps/bgtimer/timerview.js b/apps/bgtimer/timerview.js new file mode 100644 index 000000000..4c9f7acd3 --- /dev/null +++ b/apps/bgtimer/timerview.js @@ -0,0 +1,107 @@ +let common; + +function drawButtons() { + //Draw the backdrop + const BAR_TOP = g.getHeight() - 24; + g.setColor(0, 0, 1).setFontAlign(0, -1) + .clearRect(0, BAR_TOP, g.getWidth(), g.getHeight()) + .fillRect(0, BAR_TOP, g.getWidth(), g.getHeight()) + .setColor(1, 1, 1) + .drawLine(g.getWidth() / 2, BAR_TOP, g.getWidth() / 2, g.getHeight()) + + //Draw the buttons + .drawImage(common.BUTTON_ICONS.reset, g.getWidth() / 4, BAR_TOP); + if (common.state.running) { + g.drawImage(common.BUTTON_ICONS.pause, g.getWidth() * 3 / 4, BAR_TOP); + } else { + g.drawImage(common.BUTTON_ICONS.play, g.getWidth() * 3 / 4, BAR_TOP); + } +} + +function drawTimer() { + let timeLeft = common.getTimeLeft(); + g.reset() + .setFontAlign(0, 0) + .setFont("Vector", 36) + .clearRect(0, 24, 176, 152) + + //Draw the timer + .drawString((() => { + let hours = timeLeft / 3600000; + let minutes = (timeLeft % 3600000) / 60000; + let seconds = (timeLeft % 60000) / 1000; + + function pad(number) { + return ('00' + parseInt(number)).slice(-2); + } + + if (hours >= 1) return `${parseInt(hours)}:${pad(minutes)}:${pad(seconds)}`; + else return `${parseInt(minutes)}:${pad(seconds)}`; + })(), g.getWidth() / 2, g.getHeight() / 2) + + if (timeLeft <= 0) load('bgtimer-ring.js'); +} + +let timerInterval; + +function setupTimerInterval() { + if (timerInterval !== undefined) { + clearInterval(timerInterval); + } + setTimeout(() => { + timerInterval = setInterval(drawTimer, 1000); + drawTimer(); + }, common.timeLeft % 1000); +} + +exports.show = function (callerCommon) { + common = callerCommon; + drawButtons(); + drawTimer(); + if (common.state.running) { + setupTimerInterval(); + } +} + +function clearTimerInterval() { + if (timerInterval !== undefined) { + clearInterval(timerInterval); + timerInterval = undefined; + } +} + +exports.touch = (button, xy) => { + if (xy.y < 152) return; + + if (button == 1) { + //Reset the timer + let setTime = common.state.setTime; + let inputString = common.state.inputString; + common.state = common.STATE_DEFAULT; + common.state.setTime = setTime; + common.state.inputString = inputString; + clearTimerInterval(); + require('bgtimer-keys.js').show(common); + } else { + if (common.state.running) { + //Record the exact moment that we paused + let now = (new Date()).getTime(); + common.state.pausedTime = now; + + //Stop the timer + common.state.running = false; + clearTimerInterval(); + drawTimer(); + drawButtons(); + } else { + //Start the timer and record when we started + let now = (new Date()).getTime(); + common.state.elapsedTime += common.state.pausedTime - common.state.startTime; + common.state.startTime = now; + common.state.running = true; + drawTimer(); + setupTimerInterval(); + drawButtons(); + } + } +}; \ No newline at end of file diff --git a/apps/gallery/README.md b/apps/gallery/README.md new file mode 100644 index 000000000..b70fa07c2 --- /dev/null +++ b/apps/gallery/README.md @@ -0,0 +1,18 @@ +# Gallery + +A simple gallery app + +## Usage + +Upon opening the gallery app, you will be presented with a list of images that you can display. Tap the image to show it. Brightness will be set to full, and the screen timeout will be disabled. When you are done viewing the image, you can tap the screen to go back to the list of images. Press BTN1 to flip the image upside down. + +## Adding images + +1. The gallery app does not perform any scaling, and does not support panning. Therefore, you should use your favorite image editor to produce an image of the appropriate size for your watch. (240x240 for Bangle 1 or 176x176 for Bangle 2.) How you achieve this is up to you. If on a Bangle 2, I recommend adjusting the colors here to comply with the color restrictions. + +2. Upload your image to the [Espruino image converter](https://www.espruino.com/Image+Converter). I recommend enabling compression and choosing one of the following color settings: + * 16 bit RGB565 for Bangle 1 + * 3 bit RGB for Bangle 2 + * 1 bit black/white for monochrome images that you want to respond to your system theme. (White will be rendered as your foreground color and black will be rendered as your background color.) + +3. Set the output format to an image string, copy it into the [IDE](https://www.espruino.com/ide/), and set the destination to a file in storage. The file name should begin with "gal-" (without the quotes) and end with ".img" (without the quotes) to appear in the gallery. Note that the gal- prefix and .img extension will be removed in the UI. Upload the file. \ No newline at end of file diff --git a/apps/gallery/app.js b/apps/gallery/app.js new file mode 100644 index 000000000..ca9392f13 --- /dev/null +++ b/apps/gallery/app.js @@ -0,0 +1,52 @@ +const storage = require('Storage'); + +let imageFiles = storage.list(/^gal-.*\.img/).sort(); + +let imageMenu = { '': { 'title': 'Gallery' } }; + +for (let fileName of imageFiles) { + let displayName = fileName.substr(4, fileName.length - 8); // Trim off the 'gal-' and '.img' for a friendly display name + imageMenu[displayName] = eval(`() => { drawImage("${fileName}"); }`); // Unfortunately, eval is the only reasonable way to do this +} + +let cachedOptions = Bangle.getOptions(); // We will change the backlight and timeouts later, and need to restore them when displaying the menu +let backlightSetting = storage.readJSON('setting.json').brightness; // LCD brightness is not included in there for some reason + +let angle = 0; // Store the angle of rotation +let image; // Cache the image here because we access it in multiple places + +function drawMenu() { + Bangle.removeListener('touch', drawMenu); // We no longer want touching to reload the menu + Bangle.setOptions(cachedOptions); // The drawImage function set no timeout, undo that + Bangle.setLCDBrightness(backlightSetting); // Restore backlight + image = undefined; // Delete the image from memory + + E.showMenu(imageMenu); +} + +function drawImage(fileName) { + E.showMenu(); // Remove the menu to prevent it from breaking things + setTimeout(() => { Bangle.on('touch', drawMenu); }, 300); // Touch the screen to go back to the image menu (300ms timeout to allow user to lift finger) + Bangle.setOptions({ // Disable display power saving while showing the image + lockTimeout: 0, + lcdPowerTimeout: 0, + backlightTimeout: 0 + }); + Bangle.setLCDBrightness(1); // Full brightness + + image = eval(storage.read(fileName)); // Sadly, the only reasonable way to do this + g.clear().reset().drawImage(image, 88, 88, { rotate: angle }); +} + +setWatch(info => { + if (image) { + if (angle == 0) angle = Math.PI; + else angle = 0; + Bangle.buzz(); + + g.clear().reset().drawImage(image, 88, 88, { rotate: angle }) + } +}, BTN1, { repeat: true }); + +// We don't load the widgets because there is no reasonable way to unload them +drawMenu(); \ No newline at end of file diff --git a/apps/gallery/icon.js b/apps/gallery/icon.js new file mode 100644 index 000000000..11fee53eb --- /dev/null +++ b/apps/gallery/icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEwgIOLgf/AAX8Av4FBJgkMAos/CIfMAv4Fe4AF/Apq5EAAw")) \ No newline at end of file diff --git a/apps/gallery/icon.png b/apps/gallery/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..71835e93da29808335d7f39c2ca849373b083d94 GIT binary patch literal 249 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezpUt1D-C9AsNnZXE|~mP~c&C{9iuz z8E5bbG@o`agQ-${dF&4QA(@#tDiuj)}sXJrCW}qOH(Be|C&4}kl zK$oM0z`>iR3=*6**%BRC(zUIR9hiOMb7|FdaVe<{ykC3EQnx{~p>pFDf+|Lvz(7tMOYcx7L0GSDv!p00i_>zopr0ApiXkN^Mx literal 0 HcmV?d00001 diff --git a/apps/gallery/metadata.json b/apps/gallery/metadata.json new file mode 100644 index 000000000..89f7606aa --- /dev/null +++ b/apps/gallery/metadata.json @@ -0,0 +1,26 @@ +{ + "id": "gallery", + "name": "Gallery", + "version": "0.02", + "description": "A gallery that lets you view images uploaded with the IDE (see README)", + "readme": "README.md", + "icon": "icon.png", + "type": "app", + "tags": "tools", + "supports": [ + "BANGLEJS2", + "BANGLEJS" + ], + "allow_emulator": true, + "storage": [ + { + "name": "gallery.app.js", + "url": "app.js" + }, + { + "name": "gallery.img", + "url": "icon.js", + "evaluate": true + } + ] +} \ No newline at end of file diff --git a/apps/infoclk/README.md b/apps/infoclk/README.md new file mode 100644 index 000000000..1dd563bec --- /dev/null +++ b/apps/infoclk/README.md @@ -0,0 +1,33 @@ +# Informational clock + +A configurable clock with extra info and shortcuts when unlocked, but large time when locked + +## Information + +The clock has two different screen arrangements, depending on whether the watch is locked or unlocked. The most commonly viewed piece of information is the time, so when the watch is locked it optimizes for the time being visible at a glance without the backlight. The hours and minutes take up nearly the entire top half of the display, with the date and seconds taking up nearly the entire bottom half. The day progress bar is between them if enabled, unless configured to be on the bottom row. The bottom row can be configured to display a weather summary, step count, step count and heart rate, the daily progress bar, or nothing. + +When the watch is unlocked, it can be assumed that the backlight is on and the user is actively looking at the watch, so instead we can optimize for information density. The bottom half of the display becomes shortcuts, and the top half of the display becomes 4 rows of information (date and time, step count and heart rate, 2 line weather summary) + an optional daily progress bar. (The daily progress bar can be independently enabled when locked and unlocked.) + +Most things are self-explanatory, but the day progress bar might not be. The day progress bar is intended to show approximately how far through the day you are, in the form of a progress bar. You might want to configure it to show how far you are through your waking hours, or you might want to use it to show how far you are through your work or school day. + +## Shortcuts + +There are generally a few apps that the user uses far more frequently than the others. For example, they might use a timer, alarm clock, and calculator every day, while everything else (such as the settings app) gets used only occasionally. This clock has space for 8 apps in the bottom half of the screen only one tap away, avoiding the need to wait for the launcher to open and then scroll through it. Tapping the top of the watch opens the launcher, eliminating the need for the button (which still opens the launcher due to bangle.js conventions). There is also handling for left, right, and vertical swipes. A vertical swipe by default opens the messages app, mimicking mobile operating systems which use a swipe down to view the notification shade. + +## Configurability + +Displaying the seconds allows for more precise timing, but waking up the CPU to refresh the display more often consumes battery. The user can enable or disable them completely, but can also configure them to be enabled or disabled automatically based on some hueristics: + +* They can be hidden while the display is locked, if the user expects to unlock their watch when they need the seconds. +* They can be hidden when the battery is too low, to make the last portion of the battery last a little bit longer. +* They can be hidden during a period of time such as when the user is asleep and therefore unlikely to need very much precision. + +The date format can be changed. + +As described earlier, the contents of the bottom row when locked can be changed. + +The 8 tap-based shortcuts on the bottom and the 3 swipe-based shortcuts can be changed to nothing, the launcher, or any app on the watch. + +The start and end time of the day progress bar can be changed. It can be enabled or disabled separately when the watch is locked and unlocked. The color can be changed. The time when it resets from full to empty can be changed. + +When the battery is below a defined point, the watch's color can change to another chosen color to help the user notice that the battery is low. \ No newline at end of file diff --git a/apps/infoclk/app.js b/apps/infoclk/app.js new file mode 100644 index 000000000..6bc626018 --- /dev/null +++ b/apps/infoclk/app.js @@ -0,0 +1,405 @@ +const SETTINGS_FILE = "infoclk.json"; +const FONT = require('infoclk-font.js'); + +const storage = require("Storage"); +const locale = require("locale"); +const weather = require('weather'); + +let config = Object.assign({ + seconds: { + // Displaying the seconds can reduce battery life because the CPU must wake up more often to update the display. + // The seconds will be shown unless one of these conditions is enabled here, and currently true. + hideLocked: false, // Hide the seconds when the display is locked. + hideBattery: 20, // Hide the seconds when the battery is at or below a defined percentage. + hideTime: true, // Hide the seconds when between a certain period of time. Useful for when you are sleeping and don't need the seconds + hideStart: 2200, // The time when the seconds are hidden: first 2 digits are hours on a 24 hour clock, last 2 are minutes + hideEnd: 700, // The time when the seconds are shown again + hideAlways: false, // Always hide (never show) the seconds + }, + + date: { + // Settings related to the display of the date + mmdd: true, // If true, display the month first. If false, display the date first. + separator: '-', // The character that goes between the month and date + monthName: false, // If false, display the month as a number. If true, display the name. + monthFullName: false, // If displaying the name: If false, display an abbreviation. If true, display a full name. + dayFullName: false, // If false, display the day of the week's abbreviation. If true, display the full name. + }, + + bottomLocked: { + display: 'weather' // What to display in the bottom row when locked: + // 'weather': The current temperature and weather description + // 'steps': Step count + // 'health': Step count and bpm + // 'progress': Day progress bar + // false: Nothing + }, + + shortcuts: [ + //8 shortcuts, displayed in the bottom half of the screen (2 rows of 4 shortcuts) when unlocked + // false = no shortcut + // '#LAUNCHER' = open the launcher + // any other string = name of app to open + 'stlap', 'bgtimer', 'pomoplus', 'alarm', + 'rpnsci', 'calendar', 'torch', 'weather' + ], + + swipe: { + // 3 shortcuts to launch upon swiping: + // false = no shortcut + // '#LAUNCHER' = open the launcher + // any other string = name of app to open + up: 'messages', // Swipe up or swipe down, due to limitation of event handler + left: '#LAUNCHER', + right: '#LAUNCHER', + }, + + dayProgress: { + // A progress bar representing how far through the day you are + enabledLocked: true, // Whether this bar is enabled when the watch is locked + enabledUnlocked: false, // Whether the bar is enabled when the watch is unlocked + color: [0, 0, 1], // The color of the bar + start: 700, // The time of day that the bar starts filling + end: 2200, // The time of day that the bar becomes full + reset: 300 // The time of day when the progress bar resets from full to empty + }, + + lowBattColor: { + // The text can change color to indicate that the battery is low + level: 20, // The percentage where this happens + color: [1, 0, 0] // The color that the text changes to + } +}, storage.readJSON(SETTINGS_FILE)); + +// Return whether the given time (as a date object) is between start and end (as a number where the first 2 digits are hours on a 24 hour clock and the last 2 are minutes), with end time wrapping to next day if necessary +function timeInRange(start, time, end) { + + // Convert the given date object to a time number + let timeNumber = time.getHours() * 100 + time.getMinutes(); + + // Normalize to prevent the numbers from wrapping around at midnight + if (end <= start) { + end += 2400; + if (timeNumber < start) timeNumber += 2400; + } + + return start <= timeNumber && timeNumber <= end; +} + +// Return whether settings should be displayed based on the user's configuration +function shouldDisplaySeconds(now) { + return !( + (config.seconds.hideAlways) || + (config.seconds.hideLocked && Bangle.isLocked()) || + (E.getBattery() <= config.seconds.hideBattery) || + (config.seconds.hideTime && timeInRange(config.seconds.hideStart, now, config.seconds.hideEnd)) + ); +} + +// Determine the font size needed to fit a string of the given length widthin maxWidth number of pixels, clamped between minSize and maxSize +function getFontSize(length, maxWidth, minSize, maxSize) { + let size = Math.floor(maxWidth / length); //Number of pixels of width available to character + size *= (20 / 12); //Convert to height, assuming 20 pixels of height for every 12 of width + + // Clamp to within range + if (size < minSize) return minSize; + else if (size > maxSize) return maxSize; + else return Math.floor(size); +} + +// Get the current day of the week according to user settings +function getDayString(now) { + if (config.date.dayFullName) return ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][now.getDay()]; + else return ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'][now.getDay()]; +} + +// Pad a number with zeros to be the given number of digits +function pad(number, digits) { + let result = '' + number; + while (result.length < digits) result = '0' + result; + return result; +} + +// Get the current date formatted according to the user settings +function getDateString(now) { + let month; + if (!config.date.monthName) month = pad(now.getMonth() + 1, 2); + else if (config.date.monthFullName) month = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'][now.getMonth()]; + else month = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][now.getMonth()]; + + if (config.date.mmdd) return `${month}${config.date.separator}${pad(now.getDate(), 2)}`; + else return `${pad(now.getDate(), 2)}${config.date.separator}${month}`; +} + +// Get a floating point number from 0 to 1 representing how far between the user-defined start and end points we are +function getDayProgress(now) { + let start = config.dayProgress.start; + let current = now.getHours() * 100 + now.getMinutes(); + let end = config.dayProgress.end; + let reset = config.dayProgress.reset; + + // Normalize + if (end <= start) end += 2400; + if (current < start) current += 2400; + if (reset < start) reset += 2400; + + // Convert an hhmm number into a floating-point hours + function toDecimalHours(time) { + let hours = Math.floor(time / 100); + let minutes = time % 100; + + return hours + (minutes / 60); + } + + start = toDecimalHours(start); + current = toDecimalHours(current); + end = toDecimalHours(end); + reset = toDecimalHours(reset); + + let progress = (current - start) / (end - start); + + if (progress < 0 || progress > 1) { + if (current < reset) return 1; + else return 0; + } else { + return progress; + } +} + +// Get a Gadgetbridge weather string +function getWeatherString() { + let current = weather.get(); + if (current) return locale.temp(current.temp - 273.15) + ', ' + current.txt; + else return 'Weather unknown!'; +} + +// Get a second weather row showing humidity, wind speed, and wind direction +function getWeatherRow2() { + let current = weather.get(); + if (current) return `${current.hum}%, ${locale.speed(current.wind)} ${current.wrose}`; + else return 'Check Gadgetbridge'; +} + +// Get a step string +function getStepsString() { + return '' + Bangle.getHealthStatus('day').steps + ' steps'; +} + +// Get a health string including daily steps and recent bpm +function getHealthString() { + return `${Bangle.getHealthStatus('day').steps} steps ${Bangle.getHealthStatus('last').bpm} bpm`; +} + +// Set the next timeout to draw the screen +let drawTimeout; +function setNextDrawTimeout() { + if (drawTimeout) { + clearTimeout(drawTimeout); + drawTimeout = undefined; + } + + let time; + let now = new Date(); + if (shouldDisplaySeconds(now)) time = 1000 - (now.getTime() % 1000); + else time = 60000 - (now.getTime() % 60000); + + drawTimeout = setTimeout(draw, time); +} + + +const DIGIT_WIDTH = 40; // How much width is allocated for each digit, 37 pixels + 3 pixels of space (which will go off of the screen on the right edge) +const COLON_WIDTH = 19; // How much width is allocated for the colon, 16 pixels + 3 pixels of space +const HHMM_TOP = 27; // 24 pixels for widgets + 3 pixels of space +const DIGIT_HEIGHT = 64; // How tall the digits are + +const SECONDS_TOP = HHMM_TOP + DIGIT_HEIGHT + 3; // The top edge of the seconds, top of hours and minutes + digit height + space +const SECONDS_LEFT = 2 * DIGIT_WIDTH + COLON_WIDTH; // The left edge of the seconds: displayed after 2 digits and the colon +const DATE_LETTER_HEIGHT = DIGIT_HEIGHT / 2; // Each letter of the day of week and date will be half the height of the time digits + +const DATE_CENTER_X = SECONDS_LEFT / 2; // Day of week and date will be centered between left edge of screen and where seconds start +const DOW_CENTER_Y = SECONDS_TOP + (DATE_LETTER_HEIGHT / 2); // Day of week will be the top row +const DATE_CENTER_Y = DOW_CENTER_Y + DATE_LETTER_HEIGHT; // Date will be the bottom row +const DOW_DATE_CENTER_Y = SECONDS_TOP + (DIGIT_HEIGHT / 2); // When displaying both on one row, center it +const BOTTOM_CENTER_Y = ((SECONDS_TOP + DIGIT_HEIGHT + 3) + g.getHeight()) / 2; + +// Draw the clock +function draw() { + //Prepare to draw + g.reset() + .setFontAlign(0, 0); + + if (E.getBattery() <= config.lowBattColor.level) { + let color = config.lowBattColor.color; + g.setColor(color[0], color[1], color[2]); + } + now = new Date(); + + if (Bangle.isLocked()) { //When the watch is locked + g.clearRect(0, 24, g.getWidth(), g.getHeight()); + + //Draw the hours and minutes + let x = 0; + + for (let digit of locale.time(now, 1)) { //apparently this is how you get an hh:mm time string adjusting for the user's 12/24 hour preference + if (digit != ' ') g.drawImage(FONT[digit], x, HHMM_TOP); + if (digit == ':') x += COLON_WIDTH; + else x += DIGIT_WIDTH; + } + if (storage.readJSON('setting.json')['12hour']) g.drawImage(FONT[(now.getHours() < 12) ? 'am' : 'pm'], 0, HHMM_TOP); + + //Draw the seconds if necessary + if (shouldDisplaySeconds(now)) { + let tens = Math.floor(now.getSeconds() / 10); + let ones = now.getSeconds() % 10; + g.drawImage(FONT[tens], SECONDS_LEFT, SECONDS_TOP) + .drawImage(FONT[ones], SECONDS_LEFT + DIGIT_WIDTH, SECONDS_TOP); + + // Draw the day of week and date assuming the seconds are displayed + + g.setFont('Vector', getFontSize(getDayString(now).length, SECONDS_LEFT, 6, DATE_LETTER_HEIGHT)) + .drawString(getDayString(now), DATE_CENTER_X, DOW_CENTER_Y) + .setFont('Vector', getFontSize(getDateString(now).length, SECONDS_LEFT, 6, DATE_LETTER_HEIGHT)) + .drawString(getDateString(now), DATE_CENTER_X, DATE_CENTER_Y); + + } else { + //Draw the day of week and date without the seconds + + let string = getDayString(now) + ' ' + getDateString(now); + g.setFont('Vector', getFontSize(string.length, g.getWidth(), 6, DATE_LETTER_HEIGHT)) + .drawString(string, g.getWidth() / 2, DOW_DATE_CENTER_Y); + } + + // Draw the bottom area + if (config.bottomLocked.display == 'progress') { + let color = config.dayProgress.color; + g.setColor(color[0], color[1], color[2]) + .fillRect(0, SECONDS_TOP + DIGIT_HEIGHT + 3, g.getWidth() * getDayProgress(now), g.getHeight()); + } else { + let bottomString; + + if (config.bottomLocked.display == 'weather') bottomString = getWeatherString(); + else if (config.bottomLocked.display == 'steps') bottomString = getStepsString(); + else if (config.bottomLocked.display == 'health') bottomString = getHealthString(); + else bottomString = ' '; + + g.setFont('Vector', getFontSize(bottomString.length, 176, 6, g.getHeight() - (SECONDS_TOP + DIGIT_HEIGHT + 3))) + .drawString(bottomString, g.getWidth() / 2, BOTTOM_CENTER_Y); + } + + // Draw the day progress bar between the rows if necessary + if (config.dayProgress.enabledLocked && config.bottomLocked.display != 'progress') { + let color = config.dayProgress.color; + g.setColor(color[0], color[1], color[2]) + .fillRect(0, HHMM_TOP + DIGIT_HEIGHT, g.getWidth() * getDayProgress(now), SECONDS_TOP); + } + } else { + + //If the watch is unlocked + g.clearRect(0, 24, g.getWidth(), g.getHeight() / 2); + rows = [ + `${getDayString(now)} ${getDateString(now)} ${locale.time(now, 1)}`, + getHealthString(), + getWeatherString(), + getWeatherRow2() + ]; + if (shouldDisplaySeconds(now)) rows[0] += ':' + pad(now.getSeconds(), 2); + if (storage.readJSON('setting.json')['12hour']) rows[0] += ((now.getHours() < 12) ? ' AM' : ' PM'); + + let maxHeight = ((g.getHeight() / 2) - HHMM_TOP) / (config.dayProgress.enabledUnlocked ? (rows.length + 1) : rows.length); + + let y = HHMM_TOP + maxHeight / 2; + for (let row of rows) { + let size = getFontSize(row.length, g.getWidth(), 6, maxHeight); + g.setFont('Vector', size) + .drawString(row, g.getWidth() / 2, y); + y += maxHeight; + } + + if (config.dayProgress.enabledUnlocked) { + let color = config.dayProgress.color; + g.setColor(color[0], color[1], color[2]) + .fillRect(0, y - maxHeight / 2, 176 * getDayProgress(now), y + maxHeight / 2); + } + } + + setNextDrawTimeout(); +} + +// Draw the icons. This is done separately from the main draw routine to avoid having to scale and draw a bunch of images repeatedly. +function drawIcons() { + g.reset().clearRect(0, 24, g.getWidth(), g.getHeight()); + for (let i = 0; i < 8; i++) { + let x = [0, 44, 88, 132, 0, 44, 88, 132][i]; + let y = [88, 88, 88, 88, 132, 132, 132, 132][i]; + let appId = config.shortcuts[i]; + let appInfo = storage.readJSON(appId + '.info', 1); + if (!appInfo) continue; + icon = storage.read(appInfo.icon); + g.drawImage(icon, x, y, { + scale: 0.916666666667 + }); + } +} + +weather.on("update", draw); +Bangle.on("step", draw); +Bangle.on('lock', locked => { + //If the watch is unlocked, draw the icons + if (!locked) drawIcons(); + draw(); +}); + +// Show launcher when middle button pressed +Bangle.setUI("clock"); +// Load widgets +Bangle.loadWidgets(); +Bangle.drawWidgets(); + +// Launch an app given the current ID. Handles special cases: +// false: Do nothing +// '#LAUNCHER': Open the launcher +// nonexistent app: Do nothing +function launch(appId) { + if (appId == false) return; + else if (appId == '#LAUNCHER') { + Bangle.buzz(); + Bangle.showLauncher(); + } else { + let appInfo = storage.readJSON(appId + '.info', 1); + if (appInfo) { + Bangle.buzz(); + load(appInfo.src); + } + } +} + +//Set up touch to launch the selected app +Bangle.on('touch', function (button, xy) { + let x = Math.floor(xy.x / 44); + if (x < 0) x = 0; + else if (x > 3) x = 3; + + let y = Math.floor(xy.y / 44); + if (y < 0) y = -1; + else if (y > 3) y = 1; + else y -= 2; + + if (y < 0) { + Bangle.buzz(); + Bangle.showLauncher(); + } else { + let i = 4 * y + x; + launch(config.shortcuts[i]); + } +}); + +//Set up swipe handler +Bangle.on('swipe', function (direction) { + if (direction == -1) launch(config.swipe.left); + else if (direction == 0) launch(config.swipe.up); + else launch(config.swipe.right); +}); + +if (!Bangle.isLocked()) drawIcons(); + +draw(); \ No newline at end of file diff --git a/apps/infoclk/font.js b/apps/infoclk/font.js new file mode 100644 index 000000000..6063958e7 --- /dev/null +++ b/apps/infoclk/font.js @@ -0,0 +1,23 @@ +const heatshrink = require("heatshrink") + +function decompress(string) { + return heatshrink.decompress(atob(string)) +} + +exports = { + '0': decompress("ktAwIEB////EAj4EB+EDAYP/8E/AgWDAYX+CIX/+IDC//PBoYIDAAvwgEHAgOAgAnB/kAgIvCgEPAgJCBv5CCHwXAI4X+KAYk/En4kmAA4qBAAP7BAePAYX4BofBAYX8F4Q+BEwRHBIQI5BA"), + '1': decompress("ktAwIGDj/4AgX/4ADBg/+BAU/+ADBgP/wAEBh/8BoV/8ADBgf/En4k/En4k/EgQ="), + '2': decompress("ktAwMA/4AB/EHAgXwn4EC8IDC/+PAYX+v4EC+YND74NDBAYAE4A0Bg/+HIU/+ADBgP/wAEBh/8BoV/8ADBgf/BAUf/AECElQdBPA2HAYX8OYfHBAYRD8Z3Dj6TG/kPPYZm4EiwAHO4f7BAfPfI/xBoaTEPAfgQwY"), + '3': decompress("ktAwMA/4AB/EHAgXwn4EC8IDC/+PAYX+v4EC+YND74NDBAYAE4A0Bg/+HIU/+ADBgP/wAEBh/8BoV/8ADBgf/BAUf/AECElJWIAEpu/EhpgS34DC/IID54DC/l/AgXDAYX4j57DA"), + '4': decompress("ktAwMA//AgEf//+BYP///wgEHAgOAgE///8gEBBAPggEPAgIWBv///EAgYIBEn4kXABf9AgfnAgY4BAAP4BAfDAYX+EwfwIQRRCJIJRBJIRRBJIQICj5RBJIRRBJIJRCNwJRBNwQk/Ei4A=="), + '5': decompress("ktAwIEB/4AB/EfAgXDAYX+n4EC+YDC/+fAYX9BAfvAgYAJ+AwBgP/wAEBh/8H4V/8ADBgf/BAUf/AEC//AAYMH/wICn4kpPYUPAgXgv4EC4JfDg4DC/iFD8ANDwaTDCQfwEoZ2/EhrXNAAm/AYX5BAfPQoaTD4ahDj57DA=="), + '6': decompress("ktAwIEB/4AB/EfAgXDAYX+n4EC+YDC/+fAYX9BAfvAgYAJ+AwBgP/wAEBh/8H4V/8ADBgf/BAUf/AEC//AAYMH/wICn4kpPYUPAgXgv6AG/6JD/gID84ED358NJIIsCKIQ0BKIRJCFgJJCSYcHAgJuBXYJuBKIQkpAA58D/YIDx6PDBofBQoYvCHwImCI4KUCwA="), + '7': decompress("ktAwMA/4AB/EHAgXwn4EC8IDC/+PAYX+v4EC+YND74NDBAYAE4A0Bg/+HIU/+ADBgP/wAEBh/8BoV/8ADBgf/BAUf/AECEn4k/En4kVA"), + '8': decompress("ktAwIEB////EAj4EB+EDAYP/8E/AgWDAYX+CIX/+IDC//PBoYIDAAvwgEHAgOAgAnB/kAgIvCgEPAgJCBv5CCHwXAI4X+KAYkpAFpu/EhwAHFQIAB/YIDx4DC/AND4IDC/ieD4AmCI4JCBHIIA=="), + '9': decompress("ktAwIEB////EAj4EB+EDAYP/8E/AgWDAYX+CIX/+IDC//PBoYIDAAvwgEHAgOAgAnB/kAgIvCgEPAgJCBv5CCHwXAI4X+KAYkpABf9AgfnAgaFD/AID4Z8DEwfwIQRRCJIJRBJIRRBJIQICj5RBJIRRBJIJRCNwJRBNwQkoPhoAE34DC/L0H/iwBQAv4WAJ7CA=="), + + ':': decompress("iFAwITQg/gj/4n/8v/+AIP/ABQPDCoIZBDoJTfH94A=="), + + 'am': decompress("jFAwIEBngCEvwCH/4CFwEBAQkD//AgfnAQcH4fgAQsPwPwAQf/+Ef//4AQn8n0AvgCCHQN+vkAnwCC/EAj4CF+EAh4CCNIoLFC4v8gE/AQv+gF/AQpwB/4CDwICG+/D94CD8/v+fn54CC+P/x4CF+H/IgICFvwCEngCD"), + 'pm': decompress("jFAwMAn///l///+/4AE+EAh4CaEYoABFgX8BwMAAUwAFIIv4gEfAQX8OYICF/0Av4CF/8AKQICCwICG+/D94CD8/v+fn54CC+P/x4CF+H/IgICFvwCEngCDA") +} \ No newline at end of file diff --git a/apps/infoclk/font/am.png b/apps/infoclk/font/am.png new file mode 100644 index 0000000000000000000000000000000000000000..a76ad25fc8bd5b987689eda614a1bfb519259243 GIT binary patch literal 360 zcmV-u0hj)XP)fJj5NVp zUZW%r0XQG8upV*+rNxE7=eg4Y&JKH3P?Fr-8o0L`pn7UhLqTzOB=2izQx`x>a%HlU zg7pAu5Kw*T=164G;{X*=)AQD7CA^D8RW}#6qSvegIWYr!!j6nAqBH+AfD#pO8etZ# z0dQ2%VNF@o1;8M3)N~Zg2XGr88WyZirZZ_g4!GumjhdE%bXe_0{5=4qBI?%g8lXP< zvXFM#djXD3^dhM&S_8mT$iE^Si@E?J2pXL2N>=wT3-AMt$$=hV8R&5U0000FtYi*xWC%KNFBJ~#n2-^57*E11a! zmI=JzNm4=(y?sQ{BLG1`4tg@9iEJf(z+L5yVrgYB$yQ8KabY>TT^_c6v#p!Ui87*$ za=7Zo2^)&l7qK6Rlw&_A+L5py>?c52&gOx#tn6--(n1D*@uSQ9TmMhz7ny<}HUB<5 SKmY&$07*qoM6N<$f&c&qqgFit literal 0 HcmV?d00001 diff --git a/apps/infoclk/font/digit0.png b/apps/infoclk/font/digit0.png new file mode 100644 index 0000000000000000000000000000000000000000..5470154ee601c8829b3f254c35a8ed21ef90245f GIT binary patch literal 290 zcmV+-0p0$IP)c zQ7Z%$fv1+MsFi{$VXj4apmfqIq}++}Bq-5}q<$@GxC)DFx&**N3Q-c$>_2gqx?$2- zOrM(Rkb;yUCCNS&7Nj6`B|w!RWdv1%x*tIbQsVC%MV@LENI^=iTOb9gh5$t#MV^ur zY%?sLicfNklvH>MPp$NnVeGk3i_zysGW7O%2$|0NVw2Vn!^h5q2G<{907*qoM6N<$f)`wN#sB~S literal 0 HcmV?d00001 diff --git a/apps/infoclk/font/digit1.png b/apps/infoclk/font/digit1.png new file mode 100644 index 0000000000000000000000000000000000000000..26a35fd1be9685e70fba18845d231e5087436a99 GIT binary patch literal 183 zcmeAS@N?(olHy`uVBq!ia0vp^szB_(!3HGfF5mYGNY#0|IEG|6zrD1PmqCGt#cCllQ1FmvHB)s96`^Y4Bm2~FN2i??W?-cZ2{06micQ(n!twLzqq1zurlY7_^s%tLA)M4(T zmSpNOrYShdYZ|Fm!bDRo@hjJ~`zS0)Ns1DnIx{6H zN`UHcrjU@1Iztz`9hMX+ujM0@&I1KAMQE8RLg{vTMnCwdL;1BCwHY1AnVF)nBqb?I zfa=VYq$mNZGgH$^A*6KF89Mjqlwu;OxId$X!ZiIvpp(#m`T$(9bRFaYu zsi;GP+K-tsQ)cQyz|jTu4u?G2J0vA3_~+z%?lf~`?*7~yG1Xt&_m${?nxaiwQj$uPr`1PcNlH?b x0M(f(Nl^k+XQm`Y2~eGxk`yICb!O^SQadKJTLI?SZzBKz002ovPDHLkV1lOcXY>F7 literal 0 HcmV?d00001 diff --git a/apps/infoclk/font/digit5.png b/apps/infoclk/font/digit5.png new file mode 100644 index 0000000000000000000000000000000000000000..5647ad00a4203ac500bbc91a35a969826f5674e4 GIT binary patch literal 302 zcmV+}0nz@6P)Nkl`;@!S-AC%m-A63B`=}+G zddgJfz9c*RLPWL%vQRYB1=|hPozx2{{nSKFMDmw4wXyx=k%!8V60h+S=TmiIZnH-I z;=T??pdxKO%c2J~6zy)CvZ-0iRoC5pRF+NI6g5C|t|^5)ttI0m}&-?-8Ch5k~bXh4s1|BAkDn&#{d8T07*qoM6N<$g7N~2 AhyVZp literal 0 HcmV?d00001 diff --git a/apps/infoclk/font/digit6.png b/apps/infoclk/font/digit6.png new file mode 100644 index 0000000000000000000000000000000000000000..56c44688139cda32620387169e5deb5952a6ef6f GIT binary patch literal 309 zcmV-50m}Y~P)*_2HMO3~FvW!aQXwFZ1jKovogW<^|N?^`h+8l&cklr2T5 za__63f~~?M50xQz+ByWO{8n<}n04tltPNlC?s~^la6=(KE3i=@8qlkn00000NkvXX Hu0mjfeT0Q( literal 0 HcmV?d00001 diff --git a/apps/infoclk/font/digit7.png b/apps/infoclk/font/digit7.png new file mode 100644 index 0000000000000000000000000000000000000000..1fb6a64237347be6e572ef6b3bfe9e56dfbe5d9f GIT binary patch literal 227 zcmeAS@N?(olHy`uVBq!ia0vp^szB_(!3HGfF5mYGNUid8aSX|DetX4{>wtm)%fY+< z?X4UY=egYSj#*fI)}ifGhT9S0|Mok7rBqigx^g`;>Rrjo%$-_GqjoL~TX{tzO|#;} z=2;>CTSdLU9-Y5u`LgJA0AC4(2Ql0u6QU>ezLM@*1^<-!raS<}F_u*7E z4Av8xLN9Dbp_L(p-z-slfTjYEX&P-ea2~S(ryj^Ca=Sn#%DQ3@@%8EX00000NkvXX Hu0mjf3Gst1 literal 0 HcmV?d00001 diff --git a/apps/infoclk/font/digit9.png b/apps/infoclk/font/digit9.png new file mode 100644 index 0000000000000000000000000000000000000000..990a3a43bbb16093a9aa37e999b57a60e04fa01a GIT binary patch literal 319 zcmV-F0l@x=P)9rRKuR68M;BUa9{j4h>G zm(m0(_fu6@M&IN$rwFoiJYH)A3Qc%02>n4r(Mj5-YzlTBUie*8t|`~lf&m)pwa=!g z0UC#E3I)suX+_e~LlDg_)357zhHk;Au>pp-JWvaUs{{RbVQ4q_& R&KCdx002ovPDHLkV1hy|g)IO8 literal 0 HcmV?d00001 diff --git a/apps/infoclk/font/pm.png b/apps/infoclk/font/pm.png new file mode 100644 index 0000000000000000000000000000000000000000..a3db97eb8c51fc817b78d347b41b5ce7d4851d3e GIT binary patch literal 327 zcmV-N0l5B&P)kh*p2!-|iA9_ohbwdjruwL4Q{aBi4{mQ`{(42n17kTdSn72jtzm!t%#g7ln8(`Gp zJ7fvqkgYWjg(6%80SJlU<_d|fO9WT&OjzPYo)1KGhuZbG;MDcts@WA$jd0Tdpp8?G zM-HG~AyG&K6@U}EIwwb)0_a^2*7rs9Xa$p4O*oyFq^_bhH)cRf6zo|~>x;Zm+z;T9 zNjwUp*3l}{eE}Ak)SCh%(G-9Nf%hDi2%ZP9`V%M5>0PNWl3u3f*&RT0Atl!wfppEL zUBR(qTI;CEWFAAkDct9uq)^Xt)#T>`q-4|WT3fnHqW=JBQE(N{EzuMJ2a)P^Qv}U` ZH{YFl6>+g)wEzGB07*qoM6N<$f&h;Vja~o% literal 0 HcmV?d00001 diff --git a/apps/infoclk/icon.js b/apps/infoclk/icon.js new file mode 100644 index 000000000..2db8a7a9a --- /dev/null +++ b/apps/infoclk/icon.js @@ -0,0 +1,2 @@ +//TODO replace app icon with my own +require("heatshrink").decompress(atob("mEwgX/AH4A/AAf+14BBAoPq/Wq1QFB+EP+kLAoNA+CdB3//yEP6ALB/sABYf8gEMgALB6ALJqoLB+tVgH//kQhkQhUABYImCIwPwh3whcA94UCgJHD+AXB/4LCcQQLCKYQLB+EDBZQFCBY/Qh4LJ4ALLl4LFioLCgE/KZMAv4XFBYimBC4/+BYw7DRwQLIV4ILWTQQLDOIUA/ALDAC+t1uv/263/6/Pq/YLC3vv//vM4Oq33rBYP6/u//2/C4Pr1YXC12vBwO+BYO69XmJDQA/ACIA==")) diff --git a/apps/infoclk/icon.png b/apps/infoclk/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a38093c5f3b6f88dbc9b75017422dbe237d4407f GIT binary patch literal 1989 zcmV;$2RitPP)jLx_$n|!#a_+a7!4?Zj*KoBI+mq8Z8#{*+o z7DHwNZgKLU(NGK;MJHm2(2Z3wlN9^G$Dl3PLZR*L$JxWF_g-#q5pXO%?4OgH|2gM( z&iUPY&i~`w2to*6Cz0Salm7|*Pv});Rk#kH&o?nKVKf?JV`CKxgR&1SYr2-&`UyG$k%PDI4SU@#m$e3%a_DJdBl84(40z238D&kClk zs;Y82oqX8o)29U(i^UQ;n+PGB&6b*)8u|?i3JT`t=0fr3&YhD;M7F-UxtYZ<46||L z#$^(^di83!ed+D(C4@{&Ojs-yi^VcGH|KCTl9H16n23l7R(HGIbWWX4$8TSNkjR^L zcXzY8Ua#-%?PaT@qoV@@0~H&dOV(ykrCQkT3X65OnG@Zi=UX7pvt31 zj}{pcL)2{nR~LU?!AoakWJE?r@;{iv;h@Tm8#ky@Q&Y1{D-)+L zk?;ux0)h4G*YjJ(#>Q^nzRiCh09LE@!i5U}3JVKgYOOCJ6uR+Sw{CU2-NC`D<_&Lc zZ7nJ)ve|63T3A>ZA0H23aBz^e?A^OJbi$<(>ged0o}Lzbr0D2qQLxA3VcF#5df&c%%k%pC z_wR3NYGVEE(W6Hhh8Y?fqAfC+OyD3EODH`({lS9=J9q8`AeBm6T3YzMGcz-7ZEYHj zMx)V~&1Q$gG4w*>jhws#}m#f8yXryC+C~U z`1tsuqP^K{Rw|XD3shHEi{?XpeSM+eoSYo1)w(dD#ik#GkY~@Hm6eqVUYB7Q5=Ndr zeOgynw`b2D8Znxin?>0WLatxGUQtm|QBiU7#}wE{v` zE79qQ-%ki34hQ+;590L_Ldfha>Fp)d!~y~G@F9PBpO089!Qyrkhl5){BH^9@$<8K( zknwSGHUObsMZ!iMoIj7rNmN(E>qSis+-{VX!tckAKO!Om1qJYW@$I*me+7H^5OR62 z3=ZN&Qctf5g8}2?{1^qN6CZvUtlqoFPd{WbR8}H06H+N04!rjsKKcl1 zHT-^*mm?zsDJcj9aOMowuALuH=N;9*{^ImQhp>7z6pDG^{(i2SkbpPdKwMlnD;pTV zci*9=hFgSsgt0MHSEIZfVy=i!h!F4{kf=Wi^-z~Cfu=;}wcszLg7?YD27=Y7B$L-n$w>wz2ZCjda2n2$gD3L&|#yjuu z2}MPrp#d%zrl%1bi`-l|95{0Zk&&pa4elc$u-j2t3A-JBKOHBPB04%)Buo62QdtSL z8t=akwHjq*n3-7tKg75Bwl+ctsi@#u^m@|L64uIo{WZ*0`actu3LkvHRe$=4-LlzP zG&h4@(OoVyHR0!>Q z7SEqkLVx}VyB!`6&AgGFjjSwOzRV5%{dYK>@c97X&K-RDB~&Whx&>fx5P5mX%|&i5 zES9AaijKycZ{po|gH^j7J|8vvUAr(f#a_qZa-p>qnVHb*(cO)YKgK7YfW2`_r7##U zGXuN*KZ*8JQ)q0&kt0Y?hs%Wn2Ovn)Km8PaeXKu8NC11$U9)D%%lmw+13^*}qN6FH z-+sfTOGr$_fdjDHVKCt4O^lA>^Up#50d{oY$`u$4$j*jDf}1ztbmFV80BqTUEnC3* z|HA1lEy&D-(a5<(Lh$z69KdWwOblM!|B#xBHEXEZd%eW%CT=(JdO4k+urdq>AVk>9 z6Q`5N<>FSIpHBh-Vlss_`<9lKNk2L}#ngwjPIdq7ye|T3ar}q0{vjtPwx88zODg-bLj7E4oP%5!@EeCk*lKg)F X^{k9p7{Urq00000NkvXXu0mjf6Vk;2 literal 0 HcmV?d00001 diff --git a/apps/infoclk/metadata.json b/apps/infoclk/metadata.json new file mode 100644 index 000000000..bb6dea3a4 --- /dev/null +++ b/apps/infoclk/metadata.json @@ -0,0 +1,38 @@ +{ + "id": "infoclk", + "name": "Informational clock", + "version": "0.08", + "description": "A configurable clock with extra info and shortcuts when unlocked, but large time when locked", + "readme": "README.md", + "icon": "icon.png", + "type": "clock", + "tags": "clock", + "supports": [ + "BANGLEJS2" + ], + "allow_emulator": true, + "storage": [ + { + "name": "infoclk.app.js", + "url": "app.js" + }, + { + "name": "infoclk.settings.js", + "url": "settings.js" + }, + { + "name": "infoclk-font.js", + "url": "font.js" + }, + { + "name": "infoclk.img", + "url": "icon.js", + "evaluate": true + } + ], + "data": [ + { + "name": "infoclk.json" + } + ] +} \ No newline at end of file diff --git a/apps/infoclk/settings.js b/apps/infoclk/settings.js new file mode 100644 index 000000000..d12225f99 --- /dev/null +++ b/apps/infoclk/settings.js @@ -0,0 +1,571 @@ +(function (back) { + const SETTINGS_FILE = "infoclk.json"; + const storage = require('Storage'); + + let config = Object.assign({ + seconds: { + // Displaying the seconds can reduce battery life because the CPU must wake up more often to update the display. + // The seconds will be shown unless one of these conditions is enabled here, and currently true. + hideLocked: false, // Hide the seconds when the display is locked. + hideBattery: 20, // Hide the seconds when the battery is at or below a defined percentage. + hideTime: true, // Hide the seconds when between a certain period of time. Useful for when you are sleeping and don't need the seconds + hideStart: 2200, // The time when the seconds are hidden: first 2 digits are hours on a 24 hour clock, last 2 are minutes + hideEnd: 700, // The time when the seconds are shown again + hideAlways: false, // Always hide (never show) the seconds + }, + + date: { + // Settings related to the display of the date + mmdd: true, // If true, display the month first. If false, display the date first. + separator: '-', // The character that goes between the month and date + monthName: false, // If false, display the month as a number. If true, display the name. + monthFullName: false, // If displaying the name: If false, display an abbreviation. If true, display a full name. + dayFullName: false, // If false, display the day of the week's abbreviation. If true, display the full name. + }, + + bottomLocked: { + display: 'weather' // What to display in the bottom row when locked: + // 'weather': The current temperature and weather description + // 'steps': Step count + // 'health': Step count and bpm + // 'progress': Day progress bar + // false: Nothing + }, + + shortcuts: [ + //8 shortcuts, displayed in the bottom half of the screen (2 rows of 4 shortcuts) when unlocked + // false = no shortcut + // '#LAUNCHER' = open the launcher + // any other string = name of app to open + 'stlap', 'bgtimer', 'pomoplus', 'alarm', + 'rpnsci', 'calendar', 'torch', 'weather' + ], + + swipe: { + // 3 shortcuts to launch upon swiping: + // false = no shortcut + // '#LAUNCHER' = open the launcher + // any other string = name of app to open + up: 'messages', // Swipe up or swipe down, due to limitation of event handler + left: '#LAUNCHER', + right: '#LAUNCHER', + }, + + dayProgress: { + // A progress bar representing how far through the day you are + enabledLocked: true, // Whether this bar is enabled when the watch is locked + enabledUnlocked: false, // Whether the bar is enabled when the watch is unlocked + color: [0, 0, 1], // The color of the bar + start: 700, // The time of day that the bar starts filling + end: 2200, // The time of day that the bar becomes full + reset: 300 // The time of day when the progress bar resets from full to empty + }, + + lowBattColor: { + // The text can change color to indicate that the battery is low + level: 20, // The percentage where this happens + color: [1, 0, 0] // The color that the text changes to + } + }, storage.readJSON(SETTINGS_FILE)); + + function saveSettings() { + storage.writeJSON(SETTINGS_FILE, config); + } + + function hourToString(hour) { + if (storage.readJSON('setting.json')['12hour']) { + if (hour == 0) return '12 AM'; + else if (hour < 12) return `${hour} AM`; + else if (hour == 12) return '12 PM'; + else return `${hour - 12} PM`; + } else return '' + hour; + } + + // The menu for configuring when the seconds are shown + function showSecondsMenu() { + E.showMenu({ + '': { + 'title': 'Seconds display', + 'back': showMainMenu + }, + 'Show seconds': { + value: !config.seconds.hideAlways, + onchange: value => { + config.seconds.hideAlways = !value; + saveSettings(); + } + }, + '...unless locked': { + value: config.seconds.hideLocked, + onchange: value => { + config.seconds.hideLocked = value; + saveSettings(); + } + }, + '...unless battery below': { + value: config.seconds.hideBattery, + min: 0, + max: 100, + format: value => `${value}%`, + onchange: value => { + config.seconds.hideBattery = value; + saveSettings(); + } + }, + '...unless between these 2 times...': () => { + E.showMenu({ + '': { + 'title': 'Hide seconds between', + 'back': showSecondsMenu + }, + 'Enabled': { + value: config.seconds.hideTime, + onchange: value => { + config.seconds.hideTime = value; + saveSettings(); + } + }, + 'Start hour': { + value: Math.floor(config.seconds.hideStart / 100), + format: hourToString, + min: 0, + max: 23, + wrap: true, + onchange: hour => { + minute = config.seconds.hideStart % 100; + config.seconds.hideStart = (100 * hour) + minute; + saveSettings(); + } + }, + 'Start minute': { + value: config.seconds.hideStart % 100, + min: 0, + max: 59, + wrap: true, + onchange: minute => { + hour = Math.floor(config.seconds.hideStart / 100); + config.seconds.hideStart = (100 * hour) + minute; + saveSettings(); + } + }, + 'End hour': { + value: Math.floor(config.seconds.hideEnd / 100), + format: hourToString, + min: 0, + max: 23, + wrap: true, + onchange: hour => { + minute = config.seconds.hideEnd % 100; + config.seconds.hideEnd = (100 * hour) + minute; + saveSettings(); + } + }, + 'End minute': { + value: config.seconds.hideEnd % 100, + min: 0, + max: 59, + wrap: true, + onchange: minute => { + hour = Math.floor(config.seconds.hideEnd / 100); + config.seconds.hideEnd = (100 * hour) + minute; + saveSettings(); + } + } + }); + } + }); + } + + // Available month/date separators + const SEPARATORS = [ + { name: 'Slash', char: '/' }, + { name: 'Dash', char: '-' }, + { name: 'Space', char: ' ' }, + { name: 'Comma', char: ',' }, + { name: 'None', char: '' } + ]; + + // Available bottom row display options + const BOTTOM_ROW_OPTIONS = [ + { name: 'Weather', val: 'weather' }, + { name: 'Step count', val: 'steps' }, + { name: 'Steps + BPM', val: 'health' }, + { name: 'Day progresss bar', val: 'progress' }, + { name: 'Nothing', val: false } + ]; + + // The menu for configuring which apps have shortcut icons + function showShortcutMenu() { + //Builds the shortcut options + let shortcutOptions = [ + { name: 'Nothing', val: false }, + { name: 'Launcher', val: '#LAUNCHER' }, + ]; + + let infoFiles = storage.list(/\.info$/).sort((a, b) => { + if (a.name < b.name) return -1; + else if (a.name > b.name) return 1; + else return 0; + }); + for (let infoFile of infoFiles) { + let appInfo = storage.readJSON(infoFile); + if (appInfo.src) shortcutOptions.push({ + name: appInfo.name, + val: appInfo.id + }); + } + + E.showMenu({ + '': { + 'title': 'Shortcuts', + 'back': showMainMenu + }, + 'Top first': { + value: shortcutOptions.map(item => item.val).indexOf(config.shortcuts[0]), + format: value => shortcutOptions[value].name, + min: 0, + max: shortcutOptions.length - 1, + wrap: false, + onchange: value => { + config.shortcuts[0] = shortcutOptions[value].val; + saveSettings(); + } + }, + 'Top second': { + value: shortcutOptions.map(item => item.val).indexOf(config.shortcuts[1]), + format: value => shortcutOptions[value].name, + min: 0, + max: shortcutOptions.length - 1, + wrap: false, + onchange: value => { + config.shortcuts[1] = shortcutOptions[value].val; + saveSettings(); + } + }, + 'Top third': { + value: shortcutOptions.map(item => item.val).indexOf(config.shortcuts[2]), + format: value => shortcutOptions[value].name, + min: 0, + max: shortcutOptions.length - 1, + wrap: false, + onchange: value => { + config.shortcuts[2] = shortcutOptions[value].val; + saveSettings(); + } + }, + 'Top fourth': { + value: shortcutOptions.map(item => item.val).indexOf(config.shortcuts[3]), + format: value => shortcutOptions[value].name, + min: 0, + max: shortcutOptions.length - 1, + wrap: false, + onchange: value => { + config.shortcuts[3] = shortcutOptions[value].val; + saveSettings(); + } + }, + 'Bottom first': { + value: shortcutOptions.map(item => item.val).indexOf(config.shortcuts[4]), + format: value => shortcutOptions[value].name, + min: 0, + max: shortcutOptions.length - 1, + wrap: false, + onchange: value => { + config.shortcuts[4] = shortcutOptions[value].val; + saveSettings(); + } + }, + 'Bottom second': { + value: shortcutOptions.map(item => item.val).indexOf(config.shortcuts[5]), + format: value => shortcutOptions[value].name, + min: 0, + max: shortcutOptions.length - 1, + wrap: false, + onchange: value => { + config.shortcuts[5] = shortcutOptions[value].val; + saveSettings(); + } + }, + 'Bottom third': { + value: shortcutOptions.map(item => item.val).indexOf(config.shortcuts[6]), + format: value => shortcutOptions[value].name, + min: 0, + max: shortcutOptions.length - 1, + wrap: false, + onchange: value => { + config.shortcuts[6] = shortcutOptions[value].val; + saveSettings(); + } + }, + 'Bottom fourth': { + value: shortcutOptions.map(item => item.val).indexOf(config.shortcuts[7]), + format: value => shortcutOptions[value].name, + min: 0, + max: shortcutOptions.length - 1, + wrap: false, + onchange: value => { + config.shortcuts[7] = shortcutOptions[value].val; + saveSettings(); + } + }, + 'Swipe up': { + value: shortcutOptions.map(item => item.val).indexOf(config.swipe.up), + format: value => shortcutOptions[value].name, + min: 0, + max: shortcutOptions.length - 1, + wrap: false, + onchange: value => { + config.swipe.up = shortcutOptions[value].val; + saveSettings(); + } + }, + 'Swipe left': { + value: shortcutOptions.map(item => item.val).indexOf(config.swipe.left), + format: value => shortcutOptions[value].name, + min: 0, + max: shortcutOptions.length - 1, + wrap: false, + onchange: value => { + config.swipe.left = shortcutOptions[value].val; + saveSettings(); + } + }, + 'Swipe right': { + value: shortcutOptions.map(item => item.val).indexOf(config.swipe.right), + format: value => shortcutOptions[value].name, + min: 0, + max: shortcutOptions.length - 1, + wrap: false, + onchange: value => { + config.swipe.right = shortcutOptions[value].val; + saveSettings(); + } + }, + }); + } + + const COLOR_OPTIONS = [ + { name: 'Black', val: [0, 0, 0] }, + { name: 'Blue', val: [0, 0, 1] }, + { name: 'Green', val: [0, 1, 0] }, + { name: 'Cyan', val: [0, 1, 1] }, + { name: 'Red', val: [1, 0, 0] }, + { name: 'Magenta', val: [1, 0, 1] }, + { name: 'Yellow', val: [1, 1, 0] }, + { name: 'White', val: [1, 1, 1] } + ]; + + // Workaround for being unable to use == on arrays: convert them into strings + function colorString(color) { + return `${color[0]} ${color[1]} ${color[2]}`; + } + + //Shows the top level menu + function showMainMenu() { + E.showMenu({ + '': { + 'title': 'Informational Clock', + 'back': back + }, + 'Seconds display': showSecondsMenu, + 'Day of week format': { + value: config.date.dayFullName, + format: value => value ? 'Full name' : 'Abbreviation', + onchange: value => { + config.date.dayFullName = value; + saveSettings(); + } + }, + 'Date format': () => { + E.showMenu({ + '': { + 'title': 'Date format', + 'back': showMainMenu, + }, + 'Order': { + value: config.date.mmdd, + format: value => value ? 'Month first' : 'Date first', + onchange: value => { + config.date.mmdd = value; + saveSettings(); + } + }, + 'Separator': { + value: SEPARATORS.map(item => item.char).indexOf(config.date.separator), + format: value => SEPARATORS[value].name, + min: 0, + max: SEPARATORS.length - 1, + wrap: true, + onchange: value => { + config.date.separator = SEPARATORS[value].char; + saveSettings(); + } + }, + 'Month format': { + // 0 = number only + // 1 = abbreviation + // 2 = full name + value: config.date.monthName ? (config.date.monthFullName ? 2 : 1) : 0, + format: value => ['Number', 'Abbreviation', 'Full name'][value], + min: 0, + max: 2, + wrap: true, + onchange: value => { + if (value == 0) config.date.monthName = false; + else { + config.date.monthName = true; + config.date.monthFullName = (value == 2); + } + saveSettings(); + } + } + }); + }, + 'Bottom row': { + value: BOTTOM_ROW_OPTIONS.map(item => item.val).indexOf(config.bottomLocked.display), + format: value => BOTTOM_ROW_OPTIONS[value].name, + min: 0, + max: BOTTOM_ROW_OPTIONS.length - 1, + wrap: true, + onchange: value => { + config.bottomLocked.display = BOTTOM_ROW_OPTIONS[value].val; + saveSettings(); + } + }, + 'Shortcuts': showShortcutMenu, + 'Day progress': () => { + E.showMenu({ + '': { + 'title': 'Day progress', + 'back': showMainMenu + }, + 'Enable while locked': { + value: config.dayProgress.enabledLocked, + onchange: value => { + config.dayProgress.enableLocked = value; + saveSettings(); + } + }, + 'Enable while unlocked': { + value: config.dayProgress.enabledUnlocked, + onchange: value => { + config.dayProgress.enabledUnlocked = value; + saveSettings(); + } + }, + 'Color': { + value: COLOR_OPTIONS.map(item => colorString(item.val)).indexOf(colorString(config.dayProgress.color)), + format: value => COLOR_OPTIONS[value].name, + min: 0, + max: COLOR_OPTIONS.length - 1, + wrap: false, + onchange: value => { + config.dayProgress.color = COLOR_OPTIONS[value].val; + saveSettings(); + } + }, + 'Start hour': { + value: Math.floor(config.dayProgress.start / 100), + format: hourToString, + min: 0, + max: 23, + wrap: true, + onchange: hour => { + minute = config.dayProgress.start % 100; + config.dayProgress.start = (100 * hour) + minute; + saveSettings(); + } + }, + 'Start minute': { + value: config.dayProgress.start % 100, + min: 0, + max: 59, + wrap: true, + onchange: minute => { + hour = Math.floor(config.dayProgress.start / 100); + config.dayProgress.start = (100 * hour) + minute; + saveSettings(); + } + }, + 'End hour': { + value: Math.floor(config.dayProgress.end / 100), + format: hourToString, + min: 0, + max: 23, + wrap: true, + onchange: hour => { + minute = config.dayProgress.end % 100; + config.dayProgress.end = (100 * hour) + minute; + saveSettings(); + } + }, + 'End minute': { + value: config.dayProgress.end % 100, + min: 0, + max: 59, + wrap: true, + onchange: minute => { + hour = Math.floor(config.dayProgress.end / 100); + config.dayProgress.end = (100 * hour) + minute; + saveSettings(); + } + }, + 'Reset hour': { + value: Math.floor(config.dayProgress.reset / 100), + format: hourToString, + min: 0, + max: 23, + wrap: true, + onchange: hour => { + minute = config.dayProgress.reset % 100; + config.dayProgress.reset = (100 * hour) + minute; + saveSettings(); + } + }, + 'Reset minute': { + value: config.dayProgress.reset % 100, + min: 0, + max: 59, + wrap: true, + onchange: minute => { + hour = Math.floor(config.dayProgress.reset / 100); + config.dayProgress.reset = (100 * hour) + minute; + saveSettings(); + } + } + }); + }, + 'Low battery color': () => { + E.showMenu({ + '': { + 'title': 'Low battery color', + back: showMainMenu + }, + 'Low battery threshold': { + value: config.lowBattColor.level, + min: 0, + max: 100, + format: value => `${value}%`, + onchange: value => { + config.lowBattColor.level = value; + saveSettings(); + } + }, + 'Color': { + value: COLOR_OPTIONS.map(item => colorString(item.val)).indexOf(colorString(config.lowBattColor.color)), + format: value => COLOR_OPTIONS[value].name, + min: 0, + max: COLOR_OPTIONS.length - 1, + wrap: false, + onchange: value => { + config.lowBattColor.color = COLOR_OPTIONS[value].val; + saveSettings(); + } + } + }); + }, + }); + } + + showMainMenu(); +}); \ No newline at end of file diff --git a/apps/pomoplus/app.js b/apps/pomoplus/app.js new file mode 100644 index 000000000..73af5c935 --- /dev/null +++ b/apps/pomoplus/app.js @@ -0,0 +1,157 @@ +Bangle.POMOPLUS_ACTIVE = true; //Prevent the boot code from running. To avoid having to reload on every interaction, we'll control the vibrations from here when the user is in the app. + +const storage = require("Storage"); +const common = require("pomoplus-com.js"); + +//Expire the state if necessary +if ( + common.settings.pausedTimerExpireTime != 0 && + !common.state.running && + (new Date()).getTime() - common.state.pausedTime > common.settings.pausedTimerExpireTime +) { + common.state = common.STATE_DEFAULT; +} + +function drawButtons() { + //Draw the backdrop + const BAR_TOP = g.getHeight() - 24; + g.setColor(0, 0, 1).setFontAlign(0, -1) + .clearRect(0, BAR_TOP, g.getWidth(), g.getHeight()) + .fillRect(0, BAR_TOP, g.getWidth(), g.getHeight()) + .setColor(1, 1, 1); + + if (!common.state.wasRunning) { //If the timer was never started, only show a play button + g.drawImage(common.BUTTON_ICONS.play, g.getWidth() / 2, BAR_TOP); + } else { + g.drawLine(g.getWidth() / 2, BAR_TOP, g.getWidth() / 2, g.getHeight()); + if (common.state.running) { + g.drawImage(common.BUTTON_ICONS.pause, g.getWidth() / 4, BAR_TOP) + .drawImage(common.BUTTON_ICONS.skip, g.getWidth() * 3 / 4, BAR_TOP); + } else { + g.drawImage(common.BUTTON_ICONS.reset, g.getWidth() / 4, BAR_TOP) + .drawImage(common.BUTTON_ICONS.play, g.getWidth() * 3 / 4, BAR_TOP); + } + } +} + +function drawTimerAndMessage() { + g.reset() + .setFontAlign(0, 0) + .setFont("Vector", 36) + .clearRect(0, 24, 176, 152) + + //Draw the timer + .drawString((() => { + let timeLeft = common.getTimeLeft(); + let hours = timeLeft / 3600000; + let minutes = (timeLeft % 3600000) / 60000; + let seconds = (timeLeft % 60000) / 1000; + + function pad(number) { + return ('00' + parseInt(number)).slice(-2); + } + + if (hours >= 1) return `${parseInt(hours)}:${pad(minutes)}:${pad(seconds)}`; + else return `${parseInt(minutes)}:${pad(seconds)}`; + })(), g.getWidth() / 2, g.getHeight() / 2) + + //Draw the phase label + .setFont("Vector", 12) + .drawString(((currentPhase, numShortBreaks) => { + if (!common.state.wasRunning) return "Not started"; + else if (currentPhase == common.PHASE_WORKING) return `Work ${numShortBreaks + 1}/${common.settings.numShortBreaks + 1}` + else if (currentPhase == common.PHASE_SHORT_BREAK) return `Short break ${numShortBreaks + 1}/${common.settings.numShortBreaks}`; + else return "Long break!"; + })(common.state.phase, common.state.numShortBreaks), + g.getWidth() / 2, g.getHeight() / 2 + 18); + + //Update phase with vibation if needed + if (common.getTimeLeft() <= 0) { + common.nextPhase(true); + } +} + +drawButtons(); +Bangle.on("touch", (button, xy) => { + //If we support full touch and we're not touching the keys, ignore. + //If we don't support full touch, we can't tell so just assume we are. + if (xy !== undefined && xy.y <= g.getHeight() - 24) return; + + if (!common.state.wasRunning) { + //If we were never running, there is only one button: the start button + let now = (new Date()).getTime(); + common.state = { + wasRunning: true, + running: true, + startTime: now, + pausedTime: now, + elapsedTime: 0, + phase: common.PHASE_WORKING, + numShortBreaks: 0 + }; + setupTimerInterval(); + drawButtons(); + + } else if (common.state.running) { + //If we are running, there are two buttons: pause and skip + if (button == 1) { + //Record the exact moment that we paused + let now = (new Date()).getTime(); + common.state.pausedTime = now; + + //Stop the timer + common.state.running = false; + clearInterval(timerInterval); + timerInterval = undefined; + drawTimerAndMessage(); + drawButtons(); + + } else { + common.nextPhase(false); + } + + } else { + //If we are stopped, there are two buttons: Reset and continue + if (button == 1) { + //Reset the timer + common.state = common.STATE_DEFAULT; + drawTimerAndMessage(); + drawButtons(); + + } else { + //Start the timer and record old elapsed time and when we started + let now = (new Date()).getTime(); + common.state.elapsedTime += common.state.pausedTime - common.state.startTime; + common.state.startTime = now; + common.state.running = true; + drawTimerAndMessage(); + setupTimerInterval(); + drawButtons(); + } + } +}); + +let timerInterval; + +function setupTimerInterval() { + if (timerInterval !== undefined) { + clearInterval(timerInterval); + } + setTimeout(() => { + timerInterval = setInterval(drawTimerAndMessage, 1000); + drawTimerAndMessage(); + }, common.timeLeft % 1000); +} + +drawTimerAndMessage(); +if (common.state.running) { + setupTimerInterval(); +} + +//Save our state when the app is closed +E.on('kill', () => { + storage.writeJSON(common.STATE_PATH, common.state); +}); + +Bangle.loadWidgets(); +Bangle.drawWidgets(); \ No newline at end of file diff --git a/apps/pomoplus/boot.js b/apps/pomoplus/boot.js new file mode 100644 index 000000000..edc233853 --- /dev/null +++ b/apps/pomoplus/boot.js @@ -0,0 +1,19 @@ +const POMOPLUS_storage = require("Storage"); +const POMOPLUS_common = require("pomoplus-com.js"); + +function setNextTimeout() { + setTimeout(() => { + //Make sure that the pomoplus app isn't in the foreground. The pomoplus app handles the vibrations when it is in the foreground in order to avoid having to reload every time the user changes state. That means that when the app is in the foreground, we shouldn't do anything here. + //We do this after the timer rather than before because the timer will start before the app executes. + if (Bangle.POMOPLUS_ACTIVE === undefined) { + POMOPLUS_common.nextPhase(true); + setNextTimeout(); + POMOPLUS_storage.writeJSON(POMOPLUS_common.STATE_PATH, POMOPLUS_common.state) + } + }, POMOPLUS_common.getTimeLeft()); +} + +//Only start the timeout if the timer is running +if (POMOPLUS_common.state.running) { + setNextTimeout(); +} \ No newline at end of file diff --git a/apps/pomoplus/common.js b/apps/pomoplus/common.js new file mode 100644 index 000000000..b1cd42de8 --- /dev/null +++ b/apps/pomoplus/common.js @@ -0,0 +1,118 @@ +const storage = require("Storage"); +const heatshrink = require("heatshrink"); + +exports.STATE_PATH = "pomoplus.state.json"; +exports.SETTINGS_PATH = "pomoplus.json"; + +exports.PHASE_WORKING = 0; +exports.PHASE_SHORT_BREAK = 1; +exports.PHASE_LONG_BREAK = 2; + +exports.BUTTON_ICONS = { + play: heatshrink.decompress(atob("jEYwMAkAGBnACBnwCBn+AAQPgAQPwAQP8AQP/AQXAAQPwAQP8AQP+AQgICBwQUCEAn4FggyBHAQ+CIgQ")), + pause: heatshrink.decompress(atob("jEYwMA/4BBAX4CEA")), + reset: heatshrink.decompress(atob("jEYwMA/4BB/+BAQPDAQPnAQIAKv///0///8j///EP//wAQQICBwQUCEhgyCHAQ+CIgI=")), + skip: heatshrink.decompress(atob("jEYwMAwEIgHAhkA8EOgHwh8A/EPwH8h/A/0P8H/h/w/+P/H/5/8//v/3/AAoICBwQUCDQIgCEwQsCGQQ4CHwRECA")) +}; + +exports.settings = storage.readJSON(exports.SETTINGS_PATH); +if (!exports.settings) { + exports.settings = { + workTime: 1500000, //Work for 25 minutes + shortBreak: 300000, //5 minute short break + longBreak: 900000, //15 minute long break + numShortBreaks: 3, //3 short breaks for every long break + pausedTimerExpireTime: 21600000, //If the timer was left paused for >6 hours, reset it on next launch + widget: false //If a widget is added in the future, whether the user wants it + }; +} + +//Store the minimal amount of information to be able to reconstruct the state of the timer at any given time. +//This is necessary because it is necessary to write to flash to let the timer run in the background, so minimizing the writes is necessary. +exports.STATE_DEFAULT = { + wasRunning: false, //If the timer ever was running. Used to determine whether to display a reset button + running: false, //Whether the timer is currently running + startTime: 0, //When the timer was last started. Difference between this and now is how long timer has run continuously. + pausedTime: 0, //When the timer was last paused. Used for expiration and displaying timer while paused. + elapsedTime: 0, //How much time the timer had spent running before the current start time. Update on pause or user skipping stages. + phase: exports.PHASE_WORKING, //What phase the timer is currently in + numShortBreaks: 0 //Number of short breaks that have occured so far +}; +exports.state = storage.readJSON(exports.STATE_PATH); +if (!exports.state) { + exports.state = exports.STATE_DEFAULT; +} + +//Get the number of milliseconds until the next phase change +exports.getTimeLeft = function () { + if (!exports.state.wasRunning) { + //If the timer never ran, the time left is just the amount of work time. + return exports.settings.workTime; + } else if (exports.state.running) { + //If the timer is running, the time left is current time - start time + preexisting time + var runningTime = (new Date()).getTime() - exports.state.startTime + exports.state.elapsedTime; + } else { + //If the timer is not running, the same as above but use when the timer was paused instead of now. + var runningTime = exports.state.pausedTime - exports.state.startTime + exports.state.elapsedTime; + } + + if (exports.state.phase == exports.PHASE_WORKING) { + return exports.settings.workTime - runningTime; + } else if (exports.state.phase == exports.PHASE_SHORT_BREAK) { + return exports.settings.shortBreak - runningTime; + } else { + return exports.settings.longBreak - runningTime; + } +} + +//Get the next phase to change to +exports.getNextPhase = function () { + if (exports.state.phase == exports.PHASE_WORKING) { + if (exports.state.numShortBreaks < exports.settings.numShortBreaks) { + return exports.PHASE_SHORT_BREAK; + } else { + return exports.PHASE_LONG_BREAK; + } + } else { + return exports.PHASE_WORKING; + } +} + +//Change to the next phase and update numShortBreaks, and optionally vibrate. DOES NOT WRITE STATE CHANGE TO STORAGE! +exports.nextPhase = function (vibrate) { + a = { + startTime: 0, //When the timer was last started. Difference between this and now is how long timer has run continuously. + pausedTime: 0, //When the timer was last paused. Used for expiration and displaying timer while paused. + elapsedTime: 0, //How much time the timer had spent running before the current start time. Update on pause or user skipping stages. + phase: exports.PHASE_WORKING, //What phase the timer is currently in + numShortBreaks: 0 //Number of short breaks that have occured so far + } + let now = (new Date()).getTime(); + exports.state.startTime = now; //The timer is being reset, so say it starts now. + exports.state.pausedTime = now; //This prevents a paused timer from having the start time moved to the future and therefore having been run for negative time. + exports.state.elapsedTime = 0; //Because we are resetting the timer, we no longer need to care about whether it was paused previously. + + let oldPhase = exports.state.phase; //Cache the old phase because we need to remember it when counting the number of short breaks + exports.state.phase = exports.getNextPhase(); + + if (oldPhase == exports.PHASE_SHORT_BREAK) { + //If we just left a short break, increase the number of short breaks + exports.state.numShortBreaks++; + } else if (oldPhase == exports.PHASE_LONG_BREAK) { + //If we just left a long break, set the number of short breaks to zero + exports.state.numShortBreaks = 0; + } + + if (vibrate) { + if (exports.state.phase == exports.PHASE_WORKING) { + Bangle.buzz(750, 1); + } else if (exports.state.phase == exports.PHASE_SHORT_BREAK) { + Bangle.buzz(); + setTimeout(Bangle.buzz, 400); + } else { + Bangle.buzz(); + setTimeout(Bangle.buzz, 400); + setTimeout(Bangle.buzz, 600); + } + } +} \ No newline at end of file diff --git a/apps/pomoplus/icon.js b/apps/pomoplus/icon.js new file mode 100644 index 000000000..020df6f5c --- /dev/null +++ b/apps/pomoplus/icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEwwgQNhvQFCoXX7ooQFy0N7vdCYQDDIJ4YDC6QwC7oDBDwYcLN4QRDAApELEYYWGBQKEFCAoWKBIRaIBIIFEEA5iEEooUEDgYhEFxgDB6BfFGAgeFCAYXCBhAEJGYYrGMxQJDC4aIHHIjhGBQQXNE5L5DCIq3GIgiuHWQ7SHhoXKABRCBC6plDC6xVKJBgXVGIIWVAH5pTQK4X/cRAXvJCnQC7JIUCwQwTFwYwTCwgwSC4owQIwowQCw4wPCxAYNFxIYMCxgYJCpoZHBpI=")) diff --git a/apps/pomoplus/icon.png b/apps/pomoplus/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..4ea72f270d5633755b90ede38c67cdc7e121e4c5 GIT binary patch literal 2122 zcmV-Q2(|Z#P)vh7l(-y(Eff0j)pz+4-E-b}m z^l1UU0sJkAf_|W6kOHNyIGvr_*sva<9~!I?Jkb@W=RYLoDrwjOgGsO==$POP?*AJ? zSCc6Ck74~?@$_KUUg&FvZ4|l$oLEWlunY$TCD7ZzgDoC!VDxiJA(A+Jtq2t^n77$H1Ng ztpSQwJ=k^Nu))U!-!rTvwB5Ja32X+Mq1>xv*ma?1pdWZDjMKW-$&wBvQB$WupU?w9 zFK{%B)8p>9U^DQr!3MA%P`fHo9R~uS18maZgis$YDz)Squsw{^_eP_jRZs}y^!ls0GZ8n#dH z^Dv&C9gUiH2t91@Tj0&EIK5Gq1D=PW!B4^ZgbI06{(jkDXIGq_NTQ$!+zsqv6mw|`o zg7=_i!6pRb9(?3y>1l7U;M-m`?1t|@Db$~vvm$VpVeLZi14p{zbP%jZ@Pe>I8F=5L z7kCBit4S2J)N}xs0S*~N`OwS>(*S4}a2{A|a0q9B%voSo@OL3!an)hi+dy1y0nLI< zz<#iONffk!t^)r6a&)omZ#U?mVcYUx%GkVTuNyo#e_>b(y6hIB?FCI4gu>net*aO+ z_dEsm3TQXbZ5V>nhMtgfcpK1S6=Kc^{lT#PUGemA5(OQ=m%%=7XajJkUrPWb;B!J} z!Z@vpz+(%5pK&v-=Yg*SyFn%3KEY83KAX{Og;-+F$pkEL;035xu43;2ju8I%e1*p{Kx30%;{fu|?QEU?W&o)OuZ<%HtroAJ{S) zHBlUmnhLmzx*?nP+=6WZwj25rKv$ezPom&u;39A@ZlTQp4fl|t$ z7sA#9?{vk}Q^2c96ubt6-gXNx0XiARX(@?7^hdlI8A_G`D+o;W#C$cLIC=B_G=Oao4_uF@$@C&Qog5K&^!sYRXOl; z^i4u*in!v_n-5Vw3g$xlUEtm%3SI!-4HwvTX7vNu0{p^Y3>c7Ggv^~BgTsE`^g3`B zYz7nn_W@r5HoLk3^C=|2)`0FRdZRs6b2nda1^WColtjU4;NON_6ABDIfvX4Wb1&Td7KEh zU=eoQupi?#Y6I?>x)-NMeY#+Ema3{`ad=C+2iy&Mb~FlBh4J(?p&tRC4ddxCzX9Cr zdRVS^S?nM!CY?iI5<=5loaB~kDJ*y?-)mWsqeSz<9ANPyo19{{_7HH!>iw-`23 ztbn!!n$%8kR;TVIH2D7f#8~_FrXC%bEXr*Ks>3qRiHfdy+R}P8e``Hoj?P2@m)^>Q z=kK+|a&udc-iWh}=^8G84QB?KcQH?|%tC#7cG*Xu1OF<3&Sf5Xugdq#*SuaSBK7H& z;5bv{C411A^+qI?ijNyRSpOe z!E-{FZ?!BWGy!&$IVTv^`!+90)U*xsODad|Rbn|4_2?@gCEPar#knUU3x1_Ecnxke?*w|O7WgF{$T@O9*mppEU@fBZwzZU=8L*tOCG;6XX9Y)r-z`L&ywqE?`h_kT z{6+3`y0eiS-e8eBf;;^lSqi+f(V+N`4^JERsL)!2wrrqfQmACuh)@h13*&TfsSbHr z7Dbb&33K0vzX4cTFmT@BoX|VKP#C8(jbiywY1*Giw*sADcN(k{ zx(Dbs_q^zhq=rp_62U)#L32kf6N1Tls8UP*2Ty*k3rtPI!Tc}*5j~)%+dJZrAngg+8q`tEBwU%ILU0~a$O;i)fy)2qxZK-jn}iQd+~#)f)B|X zUp;uVW_9yw1&+D~3oA>_T^^nPy}5LgY%Ja#-(B6mySyPl-}vk+31*YKX2G31W}IBt zwJ@CJV!yyKLuKRBGbS%lsX2b#mZ@fM_eY)o#r1u1rs;+X3PR_N4sYo+?^tf0+x*$C zuthX=>W?`USC()K*%!rr{Lx!{Ftst=?MzA5JPRisv0D+D$zdj@k2D{xSoLy>eu_<) zWq#qcQ=!-PsMjZ2EMKovJolM^P{a`-m5zV_SI*QM9T!(kPEvIJT`2#5!RzTKmQGmB z;?~C+vcR$I?}PdeyQ8)3Eg!13K6ZHC{kVpQd135=z~VXYlaFW4VK|unz$^c!c4@-1 z$zP(pyX6@7-ac@&)I0cF!)e)s2PY@^-kjQG(pn=|VZS*46jSYXhwrnlM;FU4=XaR3 z%j+Hkd;0;8#!c62@7=w6@Am%mS%3dB99mg)Jm;_40${YTC3(BM0BIoj>AbrhNO2Z; zL>4nJ=qZCRW5rVYGN2%PiKnkC`!i-yb}Jpb3EHthA;}Wgh!W@g+}zZ>5(ej@)Wnk1 z6ovB4k_-iRPv3y>Mm}+%S<0R+jv*erj1rvBzcKy?0-#2mfDs6AN&+Pa>1V>HnHqAV z77z@@(I6TPB7z}6P{C*_8Vw?XAwW>UXet^FB7z}6Pyx+TQT{Ft9Zp`Z43JAaUHx3v IIVCg!009H(%m4rY literal 0 HcmV?d00001 diff --git a/apps/pomoplus/img/play.png b/apps/pomoplus/img/play.png new file mode 100644 index 0000000000000000000000000000000000000000..6c20c24c54d72382a69d5aa3685e3ad8fa6174ba GIT binary patch literal 2891 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1|%Pp+x}o+U~I{Bb`J1#c2+1T%1_J8No8Qr zm{>c}*5j~)%+dJZrAngg+8q`tEBwU%ILU0~a$O;i)fy)2qxZK-jn}iQd+~#)f)B|X zUp;uVW_9yw1&+D~3oA>_T^^nPy}5LgY%Ja#-(B6mySyPl-}vk+31*YKX2G31W}IBt zwJ@CJV!yyKLuKRBGbS%lsX2b#mZ@fM_eY)o#r1u1rs;+X3PR_N4sYo+?^tf0+x*$C zuthX=>W?`USC()K*%!rr{Lx!{Ftst=?MzA5JPRisv0D+D$zdj@k2D{xSoLy>eu_<) zWq#qcQ=!-PsMjZ2EMKovJolM^P{a`-m5zV_SI*QM9T!(kPEvIJT`2#5!RzTKmQGmB z;?~C+vcR$I?}PdeyQ8)3Eg!13K6ZHC{kVpQd135=z~VXYlaFW4VK|unz$^c!c4@-1 z$zP(pyX6@7-ac@&)I0cF!)e)s2PY@^-kjQG(pn=|VZS*46jSYXhwrnlM;FU4=XaR3 z%j+Hkd;0;8#!c62@7=w6@Am%mS%3dB99mg)Jm;_40${YTC3(BM0BIoj>AbrhNO2Z; zL>4nJ=qZCRW5rVYGN2%PiKnkC`!i-yc1y0~8~!E(g(OQ{BTAg}b8}PkN*J7rQWHy3 zQxwWGOEMJPJ$(bh8~Mb6W+{8RIEHxeGD>hh{|3|p0snyj#-=9C2r~@X0!AQ!iBn3$ z4MMg6W+*i*!fOFFEF#JRN-Sc6X(ooo7L0`Sk>mqp!-$O^vMqpFM#v(HEg)nO)hxhe z5!Ed~w}_-v1k+3m4NGw}vjFA@nppr#T`Vx0s71pJhM7k-3(yUwngzHFrq}{P2E!~M zE0T#d9ApVeaX^Z}FdqmdKI;Vst0LE7sJpcdz literal 0 HcmV?d00001 diff --git a/apps/pomoplus/img/reset.png b/apps/pomoplus/img/reset.png new file mode 100644 index 0000000000000000000000000000000000000000..7a317d09795c09aabab4836c8b9ec4a6c5fe4db8 GIT binary patch literal 2891 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1|%Pp+x}o+U~I{Bb`J1#c2+1T%1_J8No8Qr zm{>c}*5j~)%+dJZrAngg+8q`tEBwU%ILU0~a$O;i)fy)2qxZK-jn}iQd+~#)f)B|X zUp;uVW_9yw1&+D~3oA>_T^^nPy}5LgY%Ja#-(B6mySyPl-}vk+31*YKX2G31W}IBt zwJ@CJV!yyKLuKRBGbS%lsX2b#mZ@fM_eY)o#r1u1rs;+X3PR_N4sYo+?^tf0+x*$C zuthX=>W?`USC()K*%!rr{Lx!{Ftst=?MzA5JPRisv0D+D$zdj@k2D{xSoLy>eu_<) zWq#qcQ=!-PsMjZ2EMKovJolM^P{a`-m5zV_SI*QM9T!(kPEvIJT`2#5!RzTKmQGmB z;?~C+vcR$I?}PdeyQ8)3Eg!13K6ZHC{kVpQd135=z~VXYlaFW4VK|unz$^c!c4@-1 z$zP(pyX6@7-ac@&)I0cF!)e)s2PY@^-kjQG(pn=|VZS*46jSYXhwrnlM;FU4=XaR3 z%j+Hkd;0;8#!c62@7=w6@Am%mS%3dB99mg)Jm;_40${YTC3(BM0BIoj>AbrhNO2Z; zL>4nJ=qZCRW5rVYGN2%PiKnkC`!i-y4rWEypL5fJLXst}5hc#~xw)x%B@E6*sfi`2 zDGKG8B^e6tp1uL$jeO!jvy?qu978;K86`NMe`EX)1VD{A0V5FLlmto;($9oXGe{1f z0r=!#<`T33mnFm)4$@1M1?ZL#YdAG9F5Ihr6 z+Y*@Ba0@^#qn0Hw!$D@ESU?R+kPQc!NApyK;scrn5w#2l1q%qkf(q;dY8wu*0%FN% zSp*9WoHWgoDM=Q9QU(a%bS@SNqAfr+7@3X5OcWuaEWlc}*5j~)%+dJZrAngg+8q`tEBwU%ILU0~a$O;i)fy)2qxZK-jn}iQd+~#)f)B|X zUp;uVW_9yw1&+D~3oA>_T^^nPy}5LgY%Ja#-(B6mySyPl-}vk+31*YKX2G31W}IBt zwJ@CJV!yyKLuKRBGbS%lsX2b#mZ@fM_eY)o#r1u1rs;+X3PR_N4sYo+?^tf0+x*$C zuthX=>W?`USC()K*%!rr{Lx!{Ftst=?MzA5JPRisv0D+D$zdj@k2D{xSoLy>eu_<) zWq#qcQ=!-PsMjZ2EMKovJolM^P{a`-m5zV_SI*QM9T!(kPEvIJT`2#5!RzTKmQGmB z;?~C+vcR$I?}PdeyQ8)3Eg!13K6ZHC{kVpQd135=z~VXYlaFW4VK|unz$^c!c4@-1 z$zP(pyX6@7-ac@&)I0cF!)e)s2PY@^-kjQG(pn=|VZS*46jSYXhwrnlM;FU4=XaR3 z%j+Hkd;0;8#!c62@7=w6@Am%mS%3dB99mg)Jm;_40${YTC3(BM0BIoj>AbrhNO2Z; zL>4nJ=qZCRW5rVYGN2%PiKnkC`!i-y4mSQL5h-thLXst}5hc#~xw)x%B@E6*sfi`2 zDGKG8B^e6tp1uL$jeO!jvy?qu978;K86`NMe`EL$1VD{M15(v9flMY<6DjJ!7SPfX zxCOMb1jPbcSb|{zwJpJF0W~ebX#uq?!D|6EEFowCrIrw70VS3&l9DSy7Lf{w_5rB| z!_<>x0V5E=G!jFD)Dvw1IfjEAL6imL8cvi2lo(FX0!j_XYXLP3$7unz4998#H4VqG mfZB$mSU?NIK^D-oMFBE@re=!7?Z%8XAhxHgpUXO@geCy$z({uh literal 0 HcmV?d00001 diff --git a/apps/pomoplus/metadata.json b/apps/pomoplus/metadata.json new file mode 100644 index 000000000..fcacae35d --- /dev/null +++ b/apps/pomoplus/metadata.json @@ -0,0 +1,37 @@ +{ + "id": "pomoplus", + "name": "Pomodoro Plus", + "version": "0.05", + "description": "A configurable pomodoro timer that runs in the background.", + "icon": "pomodoro.png", + "type": "app", + "tags": "pomodoro,cooking,tools", + "supports": [ + "BANGLEJS", + "BANGLEJS2" + ], + "allow_emulator": true, + "storage": [ + { + "name": "pomoplus.app.js", + "url": "app.js" + }, + { + "name": "pomoplus.img", + "url": "icon.js", + "evaluate": true + }, + { + "name": "pomoplus.boot.js", + "url": "boot.js" + }, + { + "name": "pomoplus-com.js", + "url": "common.js" + }, + { + "name": "pomoplus.settings.js", + "url": "settings.js" + } + ] +} \ No newline at end of file diff --git a/apps/pomoplus/settings.js b/apps/pomoplus/settings.js new file mode 100644 index 000000000..1ff52340a --- /dev/null +++ b/apps/pomoplus/settings.js @@ -0,0 +1,94 @@ +const SETTINGS_PATH = 'pomoplus.json'; +const storage = require("Storage"); + +(function (back) { + let settings = storage.readJSON(SETTINGS_PATH); + if (!settings) { + settings = { + workTime: 1500000, //Work for 25 minutes + shortBreak: 300000, //5 minute short break + longBreak: 900000, //15 minute long break + numShortBreaks: 3, //3 short breaks for every long break + pausedTimerExpireTime: 21600000, //If the timer was left paused for >6 hours, reset it on next launch + widget: false //If a widget is added in the future, whether the user wants it + }; + } + + function save() { + storage.writeJSON(SETTINGS_PATH, settings); + } + + const menu = { + '': { 'title': 'Pomodoro Plus' }, + '< Back': back, + 'Work time': { + value: settings.workTime, + step: 60000, //1 minute + min: 60000, + // max: 10800000, + // wrap: true, + onchange: function (value) { + settings.workTime = value; + save(); + }, + format: function (value) { + return '' + (value / 60000) + 'm' + } + }, + 'Short break time': { + value: settings.shortBreak, + step: 60000, + min: 60000, + // max: 10800000, + // wrap: true, + onchange: function (value) { + settings.shortBreak = value; + save(); + }, + format: function (value) { + return '' + (value / 60000) + 'm' + } + }, + '# Short breaks': { + value: settings.numShortBreaks, + step: 1, + min: 0, + // max: 10800000, + // wrap: true, + onchange: function (value) { + settings.numShortBreaks = value; + save(); + } + }, + 'Long break time': { + value: settings.longBreak, + step: 60000, + min: 60000, + // max: 10800000, + // wrap: true, + onchange: function (value) { + settings.longBreak = value; + save(); + }, + format: function (value) { + return '' + (value / 60000) + 'm' + } + }, + 'Timer expiration': { + value: settings.pausedTimerExpireTime, + step: 900000, //15 minutes + min: 0, + // max: 10800000, + // wrap: true, + onchange: function (value) { + settings.pausedTimerExpireTime = value; + save(); + }, + format: function (value) { + if (value == 0) return "Off" + else return `${Math.floor(value / 3600000)}h ${(value % 3600000) / 60000}m` + } + }, + }; + E.showMenu(menu) +}) \ No newline at end of file diff --git a/apps/random/app.js b/apps/random/app.js new file mode 100644 index 000000000..c3001a6d1 --- /dev/null +++ b/apps/random/app.js @@ -0,0 +1,205 @@ +let n = 1; +let diceSides = 6; +let replacement = false; +let min = 1; +let max = 10; + +Bangle.loadWidgets(); +Bangle.drawWidgets(); + +function showCoinMenu() { + E.showMenu({ + '': { + 'title': 'Coin flip', + 'back': showMainMenu + }, + '# of coins': { + value: n, + step: 1, + min: 1, + onchange: value => n = value + }, + 'Go': () => { + let resultMenu = { + '': { + 'title': 'Result', + 'back': showCoinMenu + } + }; + let heads = 0; + for (let i = 0; i < n; i++) { + let coin = Math.random() < 0.5; + if (coin) heads++; + resultMenu[`${i + 1}: ${coin ? 'Heads' : 'Tails'}`] = () => { }; + } + let tails = n - heads; + resultMenu[`${heads} heads, ${Math.round(100 * heads / n)}%`] = () => { }; + resultMenu[`${tails} tails, ${Math.round(100 * tails / n)}%`] = () => { }; + + E.showMenu(resultMenu); + } + }); +} + + +function showDiceMenu() { + E.showMenu({ + '': { + 'title': 'Dice roll', + 'back': showMainMenu + }, + '# of dice': { + value: n, + step: 1, + min: 1, + onchange: value => n = value + }, + '# of sides': { + value: diceSides, + step: 1, + min: 2, + onchange: value => diceSides = value + }, + 'Go': () => { + let resultMenu = { + '': { + 'title': 'Result', + 'back': showDiceMenu + } + }; + let sum = 0; + let min = diceSides + 1; + let max = 0; + for (let i = 0; i < n; i++) { + let roll = Math.floor(Math.random() * diceSides + 1); + sum += roll; + if (roll < min) min = roll; + if (roll > max) max = roll; + resultMenu[`${i + 1}: ${roll}`] = () => { }; + } + resultMenu[`Sum: ${sum}`] = () => { }; + resultMenu[`Min: ${min}`] = () => { }; + resultMenu[`Max: ${max}`] = () => { }; + resultMenu[`Average: ${sum / n}`] = () => { }; + + E.showMenu(resultMenu); + } + }); +} + + +function showCardMenu() { + E.showMenu({ + '': { + 'title': 'Card draw', + 'back': showMainMenu + }, + '# of cards': { + value: Math.min(52, n), + step: 1, + min: 1, + max: 52, + onchange: value => n = value + }, + 'Replacement': { + value: replacement, + onchange: value => { + replacement = value; + if (replacement && n > 52) n = 52; + } + }, + 'Go': () => { + n = Math.min(n, 52); + SUITS = ['Spades', 'Diamonds', 'Clubs', 'Hearts']; + RANKS = ['Ace', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King']; + class Card { + constructor(suit, rank) { + this.suit = suit; + this.rank = rank; + } + + //Can't use == to check equality, so using Java-inspired .equals() + equals(other) { + return this.suit == other.suit && this.rank == other.rank; + } + } + + let resultMenu = { + '': { + 'title': 'Result', + 'back': showCardMenu + } + }; + let cards = []; + for (let i = 0; i < n; i++) { + let newCard; + while (true) { + newCard = new Card( + SUITS[Math.floor(Math.random() * SUITS.length)], + RANKS[Math.floor(Math.random() * RANKS.length)]); + + if (replacement) break; //If we are doing replacement, skip the check for duplicates and stop looping + + if (!cards.map(card => card.equals(newCard)).includes(true)) break; //If there are no duplicates found, stop looping + } + + cards.push(newCard); + resultMenu[`${newCard.rank} of ${newCard.suit}`] = () => { }; + } + + E.showMenu(resultMenu); + } + }); +} + +function showNumberMenu() { + E.showMenu({ + '': { + 'title': 'Number choice', + 'back': showMainMenu + }, + 'Minimum': { + value: min, + step: 1, + onchange: value => min = value + }, + 'Maximum': { + value: max, + step: 1, + onchange: value => max = value + }, + '# of choices': { + value: n, + min: 1, + step: 1, + onchange: value => n = value + }, + 'Go': () => { + let resultMenu = { + '': { + 'title': 'Result', + 'back': showNumberMenu + } + }; + for (let i = 0; i < n; i++) { + let value = Math.floor(min + Math.random() * (max - min + 1)); + resultMenu[`${i + 1}: ${value}`] = () => { }; + } + E.showMenu(resultMenu); + } + }); +} + +function showMainMenu() { + E.showMenu({ + '': { + 'title': 'Random' + }, + 'Coin': showCoinMenu, + 'Dice': showDiceMenu, + 'Card': showCardMenu, + 'Number': showNumberMenu + }); +} + +showMainMenu(); \ No newline at end of file diff --git a/apps/random/icon.js b/apps/random/icon.js new file mode 100644 index 000000000..de84a0893 --- /dev/null +++ b/apps/random/icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEwwIEBgf///AAoMHAoPgAoMPAoPwAoMfAoP4AoM/AoP8AoN/AoP+AoIEBAAMAgIbBD4OAAoPgFYIFC4A3BAoQCFEAQFBEwV/AoIyCn+ALYYFFCIIFDDoIECFIQFCGoQFCIIQFCJoQFCNoIuEHwQuCHwQuCQYQuCR4QuCTYQuGAoIcDg4oEg4oEg6mCAoQuDAoIuDAFQvFAsIA==")) \ No newline at end of file diff --git a/apps/random/icon.png b/apps/random/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..e4af7d7a19d5228f8758605027b3c506d0fa4c77 GIT binary patch literal 378 zcmV-=0fqjFP)sE>U;ut)p4tfn;FzDPnNEiEK2=o<)73=@l|)GEJl_#* zl$1?^bb6QUus%x6BtRPI3t=b+N{+-)JTlMjM9B`M%rg)+09(Ptxw~#J4`7dKdJLRS zAoDNHWjnx_UlxEhza)TSemMZu{89i>^S5Nq>jcEa&CdiVF+U4HH80&w(qUt)O3hby zpxk^Vz!dYV01S=sQ1H!8upJoAKP=FJU;rYyBO(_N2q2a>CUk { + if (entryTerminated) { + if (liftOnNumberPress) liftStack(); + x = '0.'; + entryTerminated = false; + liftOnNumberPress = false; + feedback(true); + updateDisplay(); + } else if (!x.includes('.')) { + x += '.'; + feedback(true); + updateDisplay(); + } else { + feedback(false); + } + } +}; + +class ModeButton { + constructor(currentMode) { + if (currentMode == 'memstore' || currentMode == 'memrec') { + this.label = 'Exit'; + } else if (currentMode == 'operation') { + this.label = 'Num'; + } else { + this.label = 'Op'; + } + } + + onclick() { + if (mode == 'memstore' || mode == 'memrec') { + mode = 'operation'; + } else if (mode == 'operation') { + mode = 'number'; + } else { + mode = 'operation'; + } + feedback(true); + drawButtons(); + } +} + +class OperationButton { + constructor(label) { + this.label = label; + } + + onclick() { + if (this.label == '/' && parseFloat(x) == 0) { + feedback(false); + return; + } + let result = this.getResult(); + x = '' + result; + y = z; + z = t; + entryTerminated = true; + liftOnNumberPress = true; + feedback(true); + updateDisplay(); + } + + getResult() { + let numX = parseFloat(x); + return { + '+': y + numX, + '-': y - numX, + '/': y / numX, + '*': y * numX, + '^': Math.pow(y, numX) + }[this.label]; + } +} + +class OneNumOpButton { + constructor(label) { + this.label = label; + } + + onclick() { + result = { + '+-': '' + -parseFloat(x), + 'Sin': '' + Math.sin(parseFloat(x)), + 'Cos': '' + Math.cos(parseFloat(x)), + 'Tan': '' + Math.tan(parseFloat(x)), + 'Asin': '' + Math.asin(parseFloat(x)), + 'Acos': '' + Math.acos(parseFloat(x)), + 'Atan': '' + Math.atan(parseFloat(x)), + 'Log': '' + (Math.log(parseFloat(x)) / Math.log(10)) + }[this.label]; + if (isNaN(result) || result == 'NaN') feedback(false); + else { + x = result; + entryTerminated = true; + liftOnNumberPress = true; + feedback(true); + updateDisplay(); + } + } +} + +let ClearButton = { + label: 'Clr', + onclick: () => { + if (x != '0') { + x = '0'; + updateDisplay(); + } else if (y != 0 || z != 0 || t != 0) { + y = 0; + z = 0; + t = 0; + E.showMessage('Registers cleared!'); + setTimeout(() => { + drawButtons(); + updateDisplay(); + }, 250); + } else { + memory = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + storage.writeJSON(MEMORY_FILE, memory); + E.showMessage('Memory cleared!'); + setTimeout(() => { + drawButtons(); + updateDisplay(); + }, 250); + } + entryTerminated = false; + liftOnNumberPress = false; + feedback(true); + } +}; + +let SwapButton = { + label: 'Swp', + onclick: () => { + oldX = x; + x = '' + y; + y = parseFloat(oldX); + entryTerminated = true; + liftOnNumberPress = true; + feedback(true); + updateDisplay(); + } +}; + +let RotateButton = { + label: 'Rot', + onclick: () => { + oldX = x; + x = '' + y; + y = z; + z = t; + t = parseFloat(oldX); + entryTerminated = true; + liftOnNumberPress = true; + feedback(true); + updateDisplay(); + } +}; + +let EnterButton = { + label: 'Ent', + onclick: () => { + liftStack(); + entryTerminated = true; + liftOnNumberPress = false; + feedback(true); + updateDisplay(); + } +}; + +let ScientificButton = { + label: 'Sci', + onclick: () => { + mode = 'scientific'; + feedback(true); + drawButtons(); + } +}; + +class ConstantButton { + constructor(label, value) { + this.label = label; + this.value = value; + } + + onclick() { + if (entryTerminated && liftOnNumberPress) liftStack(); + x = '' + this.value; + entryTerminated = true; + liftOnNumberPress = true; + feedback(true); + updateDisplay(); + } +} + +let MemStoreButton = { + label: 'Sto', + onclick: () => { + mode = 'memstore'; + feedback(true); + drawButtons(); + } +}; + +let MemRecallButton = { + label: 'Rec', + onclick: () => { + mode = 'memrec'; + feedback(true); + drawButtons(); + } +}; + +class MemStoreIn { + constructor(register) { + this.register = register; + this.label = '' + register; + } + + onclick() { + memory[this.register] = parseFloat(x); + storage.writeJSON(MEMORY_FILE, memory); + mode = 'scientific'; + entryTerminated = true; + liftOnNumberPress = true; + feedback(true); + drawButtons(); + } +} + +class MemRecFrom { + constructor(register) { + this.register = register; + this.label = '' + register; + } + + onclick() { + x = '' + memory[this.register]; + mode = 'scientific'; + entryTerminated = true; + liftOnNumberPress = true; + feedback(true); + updateDisplay(); + drawButtons(); + } +} + +const BUTTONS = { + 'number': [ + [new NumberButton(7), new NumberButton(8), new NumberButton(9), new ModeButton('number')], + [new NumberButton(4), new NumberButton(5), new NumberButton(6), new NumberButton(0)], + [new NumberButton(1), new NumberButton(2), new NumberButton(3), DecimalPointButton] + ], + 'operation': [ + [new OperationButton('+'), new OperationButton('-'), ClearButton, new ModeButton('operation')], + [new OperationButton('*'), new OperationButton('/'), SwapButton, EnterButton], + [new OperationButton('^'), new OneNumOpButton('+-'), RotateButton, ScientificButton] + ], + 'scientific': [ + [new OneNumOpButton('Sin'), new OneNumOpButton('Cos'), new OneNumOpButton('Tan'), new ModeButton('scientific')], + [new OneNumOpButton('Asin'), new OneNumOpButton('Acos'), new OneNumOpButton('Atan'), MemStoreButton], + [new OneNumOpButton('Log'), new ConstantButton('e', Math.E), new ConstantButton('pi', Math.PI), MemRecallButton] + ], + 'memstore': [ + [new MemStoreIn(7), new MemStoreIn(8), new MemStoreIn(9), new ModeButton('memstore')], + [new MemStoreIn(4), new MemStoreIn(5), new MemStoreIn(6), new MemStoreIn(0)], + [new MemStoreIn(1), new MemStoreIn(2), new MemStoreIn(3), new ModeButton('memstore')] + ], + 'memrec': [ + [new MemRecFrom(7), new MemRecFrom(8), new MemRecFrom(9), new ModeButton('memrec')], + [new MemRecFrom(4), new MemRecFrom(5), new MemRecFrom(6), new MemRecFrom(0)], + [new MemRecFrom(1), new MemRecFrom(2), new MemRecFrom(3), new ModeButton('memrec')] + ], +}; + +let x = '0'; +let y = 0; +let z = 0; +let t = 0; +let memJSON = storage.readJSON(MEMORY_FILE); +if (memJSON) { + let memory = memJSON; +} else { + let memory = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; +} +let mode = 'number'; +let entryTerminated = false; +let liftOnNumberPress = false; + +function liftStack() { + t = z; + z = y; + y = parseFloat(x); +} + +function feedback(acceptable) { + if (acceptable) Bangle.buzz(50, 0.5); + else Bangle.buzz(200, 1); +} + +function drawButtons() { + g.reset().clearRect(0, 44, 175, 175).setFont("Vector", 15).setFontAlign(0, 0); + //Draw lines + for (let x = 44; x <= 176; x += 44) { + g.drawLine(x, 44, x, 175); + } + for (let y = 44; y <= 176; y += 44) { + g.drawLine(0, y, 175, y); + } + for (let row = 0; row < 3; row++) { + for (let col = 0; col < 4; col++) { + g.drawString(BUTTONS[mode][row][col].label, 22 + 44 * col, 66 + 44 * row); + } + } +} + +function getFontSize(length) { + let size = Math.floor(176 / length); //Characters of width needed per pixel + size *= (20 / 12); //Convert to height + // Clamp to between 6 and 20 + if (size < 6) return 6; + else if (size > 20) return 20; + else return Math.floor(size); +} + +function updateDisplay() { + g.clearRect(0, 24, 175, 43).setColor(storage.readJSON('setting.json').theme.fg2).setFontAlign(1, -1).setFont("Vector", getFontSize(x.length)).drawString(x, 176, 24); +} + +Bangle.on("touch", (button, xy) => { + let row = Math.floor((xy.y - 44) / 44); + let col = Math.floor(xy.x / 44); + if (row < 0) { // Tap number to show registers + g.clearRect(0, 24, 175, 43).setColor(storage.readJSON('setting.json').theme.fg2).setFontAlign(1, -1) + .setFont("Vector", getFontSize(x.length)).drawString('' + t, 176, 24); + + g.clearRect(0, 44, 175, 63).setColor(storage.readJSON('setting.json').theme.fg2).setFontAlign(1, -1) + .setFont("Vector", getFontSize(x.length)).drawString('' + z, 176, 44); + + g.clearRect(0, 64, 175, 83).setColor(storage.readJSON('setting.json').theme.fg2).setFontAlign(1, -1) + .setFont("Vector", getFontSize(x.length)).drawString('' + y, 176, 64); + + g.clearRect(0, 84, 175, 103).setColor(storage.readJSON('setting.json').theme.fg2).setFontAlign(1, -1) + .setFont("Vector", getFontSize(x.length)).drawString(x, 176, 84); + + setTimeout(() => { + drawButtons(); + updateDisplay(); + }, 500); + } else { + if (row > 2) row = 2; + if (col < 0) col = 0; + if (col > 3) col = 3; + + BUTTONS[mode][row][col].onclick(); + } +}); + +Bangle.on("swipe", dir => { + if (dir == -1) { + if (entryTerminated) ClearButton.onclick(); + else if (x.length == 1) x = '0'; + else x = x.substring(0, x.length - 1); + + feedback(true); + updateDisplay(); + } else if (dir == 0) { + EnterButton.onclick(); + } +}); + +g.clear().reset(); + +drawButtons(); +updateDisplay(); + +Bangle.loadWidgets(); +Bangle.drawWidgets(); \ No newline at end of file diff --git a/apps/rpnsci/icon.js b/apps/rpnsci/icon.js new file mode 100644 index 000000000..24ea29035 --- /dev/null +++ b/apps/rpnsci/icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEwwcCkmSpICEpEEBAwCICP4CCk/yCP4RVyf/AAXkCK0///5Nf4RffcYR/AQkAAERr/CKn+CK9//+f/41O/mT5IRO/+eLJ8/CIw+BAAP8CIkn+QRQMQY1MCKM8z5rP8mf/KzO8mTCJ1/CIP/8j7pCP4RMA==")) \ No newline at end of file diff --git a/apps/rpnsci/icon.png b/apps/rpnsci/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..474abf7e3358c8f47326adacfdf4cd4bd2918cba GIT binary patch literal 765 zcmVEX>4Tx04R}tkv&MmKpe$iTcsiuQ9Fn@1guUL#ELj-6^c+H)C#RSm|Xe=O&XFE z7e~Rh;NZt%)xpJCR|i)?5c~jfbaGO3krMxx6k5c1aNLh~_a1le0DryARI_6OP&La) zCE`LRyD9`<5kNosFoKxGOnpuilkgm0_we!cF3PjK&;2=il$^-`pFljzbi*RvAfDc| zbk6(4VOEqB;&bA0gDyz?$aUG}H_ioz{X8>lq*L?6VPc`s#&R38qM;H`5l0kNqkMnH zWrgz=XSG~q&3p0}hH~1nGy0}1FmMZWuerT7_i_3Fq^Yaq4RCM> zj1?$*-Q(R|?Y;ebrrF;Qq{ni*j5N?100006VoOIv00000008+zyMF)x010qNS#tmY zE+YT{E+YYWr9XB6000McNliru<^vKDD+ff07Ipvt02y>eSad^gZEa<4bO1wgWnpw> zWFU8GbZ8()Nlj2!fese{007lVL_t(&-tCy(4udcVMvL+NUzy#k$)aO}W>o49Hzr1_ zhw}GTT2pOlCeLf$C$_e@0RX@(0M*=dX9oZPV9a(aVLv7FsozR5fZ1j_%;OmG7RUZn z%-hUD002;?3SC($2_XOgxG{jF_IY-|)dw_rgBj)k03f2wqGwO{oklJ3e!Tz7DRpG6 zubTLs7FP9stWX*4ApV~(B4|W%4t1kzT29*{FIV$^NK(e*e~v``k4DzL{u)Zl09YZD vmDuT>c$p;jcw+3pcXB62(4YqZ03g*KO-@5vd@SZ300000NkvXXu0mjfLa#qu literal 0 HcmV?d00001 diff --git a/apps/rpnsci/icon.xcf b/apps/rpnsci/icon.xcf new file mode 100644 index 0000000000000000000000000000000000000000..9a41dbe325b45a3a516fe41d2dd3bcab725a4fc4 GIT binary patch literal 4021 zcmd^C&ubGw6rN4mSd%7g?GF_^j8U<*ZfT;e-UNG44}xItx=ALR(PX#mZfqh#Jc{5^ z{|BMqMW~<`=|A92{{(Le9tGF$?as7YX+1;=p}ytK``&xAv-9Jdon2eD)_A8{=Z_Xk zB?ehkO86CY0%{m2CZQuM2$4djphM6j&>4lP-Zb*^5I)`E*6Y3qcvL@uW4OCA^*JHN z^Vk`>AKMWc4r@w;`Rtj0xqqjzFYoId&VQ<3-_^ZJ(O1SiUf8(i7D{x(;s!9)f?eZiiD3+I}GG zU0wyp1y!xM9kb=u1h1nP#90cg%Np2TzNFlSkai=0zfih*Wl04i=52SK`bt!#j?f@bXvWYoK+<1g8M3@=|Is?52#-n(u@%eFTn0c!-AsW{9&Tu z(sEgU { + let hours = Math.floor(time / 3600000); + let minutes = Math.floor((time % 3600000) / 60000); + let seconds = Math.floor((time % 60000) / 1000); + let hundredths = Math.floor((time % 1000) / 10); + + if (hours >= 1) return `${hours}:${pad(minutes)}:${pad(seconds)}`; + else return `${minutes}:${pad(seconds)}:${pad(hundredths)}`; + })(), g.getWidth() / 2, g.getHeight() / 2); + + //Draw the lap labels if necessary + if (lapHistory.splits.length >= 1) { + let lastLap = lapHistory.splits.length; + let curLap = lastLap + 1; + + g.setFont("Vector", 12) + .drawString((() => { + let lapTime = time - lapHistory.splits[lastLap - 1]; + let hours = Math.floor(lapTime / 3600000); + let minutes = Math.floor((lapTime % 3600000) / 60000); + let seconds = Math.floor((lapTime % 60000) / 1000); + let hundredths = Math.floor((lapTime % 1000) / 10); + + if (hours == 0) return `Lap ${curLap}: ${pad(minutes)}:${pad(seconds)}:${pad(hundredths)}`; + else return `Lap ${curLap}: ${hours}:${pad(minutes)}:${pad(seconds)}:${pad(hundredths)}`; + })(), g.getWidth() / 2, g.getHeight() / 2 + 18) + .drawString((() => { + let lapTime; + if (lastLap == 1) lapTime = lapHistory.splits[lastLap - 1]; + else lapTime = lapHistory.splits[lastLap - 1] - lapHistory.splits[lastLap - 2]; + let hours = Math.floor(lapTime / 3600000); + let minutes = Math.floor((lapTime % 3600000) / 60000); + let seconds = Math.floor((lapTime % 60000) / 1000); + let hundredths = Math.floor((lapTime % 1000) / 10); + + if (hours == 0) return `Lap ${lastLap}: ${pad(minutes)}:${pad(seconds)}:${pad(hundredths)}`; + else return `Lap ${lastLap}: ${hours}:${pad(minutes)}:${pad(seconds)}:${pad(hundredths)}`; + })(), g.getWidth() / 2, g.getHeight() / 2 + 30); + } +} + +drawButtons(); + +function firstTimeStart(now, time) { + state = { + wasRunning: true, + sessionStart: Math.floor(now), + running: true, + startTime: now, + pausedTime: 0, + elapsedTime: 0, + }; + lapFile = 'stlap-' + state.sessionStart + '.json'; + setupTimerInterval(); + Bangle.buzz(200); + drawButtons(); +} + +function split(now, time) { + lapHistory.splits.push(time); + Bangle.buzz(); +} + +function pause(now, time) { + //Record the exact moment that we paused + state.pausedTime = now; + + //Stop the timer + state.running = false; + stopTimerInterval(); + Bangle.buzz(200); + drawTime(); + drawButtons(); +} + +function reset(now, time) { + //Record the time + lapHistory.splits.push(time); + lapHistory.final = true; + storage.writeJSON(lapFile, lapHistory); + + //Reset the timer + state = STATE_DEFAULT; + lapHistory = { + final: false, + splits: [] + }; + Bangle.buzz(500); + drawTime(); + drawButtons(); +} + +function start(now, time) { + //Start the timer and record when we started + state.elapsedTime += (state.pausedTime - state.startTime); + state.startTime = now; + state.running = true; + setupTimerInterval(); + Bangle.buzz(200); + drawTime(); + drawButtons(); +} + +Bangle.on("touch", (button, xy) => { + //In gesture mode, just turn on the light and then return + if (gestureMode) { + Bangle.setLCDPower(true); + return; + } + + //If we support full touch and we're not touching the keys, ignore. + //If we don't support full touch, we can't tell so just assume we are. + if (xy !== undefined && xy.y <= g.getHeight() - 48) return; + + let now = (new Date()).getTime(); + let time = getTime(); + + if (!state.wasRunning) { + if (storage.read('stlapview.app.js') !== undefined) { + //If we were never running and stlapview is installed, there are two buttons: open stlapview and start the timer + if (button == 1) load('stlapview.app.js'); + else firstTimeStart(now, time); + } + //If stlapview there is only one button: the start button + else firstTimeStart(now, time); + } else if (state.running) { + //If we are running, there are two buttons: lap and pause + if (button == 1) split(now, time); + else pause(now, time); + + } else { + //If we are stopped, there are two buttons: reset and continue + if (button == 1) reset(now, time); + else start(now, time); + } +}); + +Bangle.on('swipe', direction => { + let now = (new Date()).getTime(); + let time = getTime(); + + if (gestureMode) { + Bangle.setLCDPower(true); + if (!state.wasRunning) firstTimeStart(now, time); + else if (state.running) pause(now, time); + else start(now, time); + } else { + gestureMode = true; + Bangle.setOptions({ + lockTimeout: 0 + }); + drawTime(); + drawButtons(); + } +}); + +setWatch(() => { + let now = (new Date()).getTime(); + let time = getTime(); + + if (gestureMode) { + Bangle.setLCDPower(true); + if (state.running) split(now, time); + else reset(now, time); + } +}, BTN1, { repeat: true }); + +let timerInterval; + +function setupTimerInterval() { + if (timerInterval !== undefined) { + clearInterval(timerInterval); + } + timerInterval = setInterval(drawTime, 10); +} + +function stopTimerInterval() { + if (timerInterval !== undefined) { + clearInterval(timerInterval); + timerInterval = undefined; + } +} + +drawTime(); +if (state.running) { + setupTimerInterval(); +} + +//Save our state when the app is closed +E.on('kill', () => { + storage.writeJSON(STATE_PATH, state); + if (state.wasRunning) { + storage.writeJSON(lapFile, lapHistory); + } +}); + +Bangle.loadWidgets(); +Bangle.drawWidgets(); \ No newline at end of file diff --git a/apps/stlap/icon.js b/apps/stlap/icon.js new file mode 100644 index 000000000..32281b7ab --- /dev/null +++ b/apps/stlap/icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEw4UA///vvvvEF/muH+cDHgPABf4AElWoKhILClALH1WqAQIWHBYIABwAKEgQKD1WgBYkK1X1r4XHlWtqtVvQLG1XVBYNXHYsC1YJBBoPqC4kKEQILCvQ7EhW1BYdeBYkqytVqwCCQwkqCgILCq4LFIoILCqoLEIwIsBGQJIBBZ+pA4Na0oDBtQLGvSFCBaYjIHYR3CI5AADBYhrCAAaDHAASDGQASGCBYizCAASzFZYQACZYrjCIwb7QHgIkCvQ6EGAWq+tf1QuEGAWqAAQuFEgQKBEQw9DHIwAuA=")) diff --git a/apps/stlap/icon.png b/apps/stlap/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..92ffe73b7f172f7019486231d5bc0ba327c13a67 GIT binary patch literal 1566 zcmV+(2I2XMP)rZGih zXw&#$)jrm=iAGIK8xtz&C7L#UsP>_)mll=wMNO+ffoiD_T1#yUim(D(ys%vMfQPei zrVqOZR|L*1ZtO$(Kh4bfZvQzm-^@2KjcNS9p~TbJ{=+BFgR;y*?EJRZOY-C8(-tp7 zVORza@KQWI#+kt5$25We8u2D@-cmyFb37f!H4B+o`PybN-uT(0hvM!pG2RAaMai~Z zb8H5+fL|F7l^*}>gRWTg<2NIR8$39)H7FE$0)fri3@0JG9e^ZV$1ylSfBMXW2&%E$ zPO&yWxOMB+q<~{)6;Ked;unf2IeFmyUmqWV%KAJEV+T+Q%#hR?1dbK`*5J(O?<*bi zO;Z%!IDVk)sEnbh6R5b5f)d(`!dpynDcXcVZikO&eb-4ajOeKPP8=vpld&G6#BUZr!wEAw+((0R3 zrXbzLH_tucuqlj0hL$qu+9ey79D&OEyhyeIpghm3SOpJZ0ylh<6M!&@vIX9#5%D$^ zHQ6$u$q@+W`9uhB*iAW^QhKevc3RtRO1aoFFEin3XYxR#>%x|>M@G*&ki!ig!iN+9 z<#}G0?8a$r^U>1QCMBx?`|`Zb`y*l_6*ZQ>*_wbuTSMf8&2iX+vZ=DKzn?&FFTtQn zcOW38Q<&~zjy+M0be$yF)>!FS6Hq8Jo3G6BI3^Q~Myv1s(rIb4-UlX1veWFN9dY0H zM6f0xl*MMVIK!PJ8_3nan@8J?SO1b#qd3!TkLoU-P%r|SKQP~H&P}mTCOL|}{(ipr z>d0vS%cB+Cx!WzJJ2&|OAM+=YGa>N@@R-ePyWG|3Y)vhL_wLbMu#!7PtICQ=hz{kT!_!z`=nUlJl03sr&j0}&?P-3E-D?`>v1Tssg-)!E}hoy|JDk@}lRu&l- zYRIfV%j~QyRj3EpMT1a)jt8Ss%SYLw_Cy$ zv}^iU-;=_cfKaZ0SOQSht?Gs8E~%aDal2W+_GKB-2XL;tKLmucox&9>d6`XIZ8j@! z_e$Lm9|hmt>bvj55SBaNntrAr?+kNN?GIAf(_O<-+) z5IAObcQpIe7!!pQ3<2AlI-_PsIm(6=ma`>W50nETfTn>V*P-_A5exa4aj@g=$hAS; zoP8Zd*(akXM__&7H4yvF?#}Ce>f^YS>UvamU;ih1=wsFuSY{xIr6LQ8JwOA1AxJ1~ z^l9-RQP-pLYNJmx>tf&nGX~z3)sL;HKUp^iAua-QAzWIPE%35s-uOlRWH1CA?7VC2 zZtlWBm=oEKVJu<83hC#?DLkvxEdp_h2nm2Zr(G@2&2bfG$kht9Ju2IqI@PE(573Um z8a5O*#uCodUgj!lva#8|1C~Y)XWJ9ib=hh5;!L+aCpigk)WcS%7NR;3)K7Nx>QSlE zjN%tYjFMPp{?P~koIaf#emxNH08UH!@u4HcM>q%HlYK@Ri${Olt*FTk7vN$e@QR9l#uqzNePq-K{A831lR^T#FgJGPOIi#jBjcHipUslrouSl-W Q%m4rY07*qoM6N<$g48qYF8}}l literal 0 HcmV?d00001 diff --git a/apps/stlap/img/pause.png b/apps/stlap/img/pause.png new file mode 100644 index 0000000000000000000000000000000000000000..ad31dadcff3ecffba6c7e015a4b2ecdcccc15b0f GIT binary patch literal 2891 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1|%Pp+x}o+U~I{Bb`J1#c2+1T%1_J8No8Qr zm{>c}*5j~)%+dJZrAngg+8q`tEBwU%ILU0~a$O;i)fy)2qxZK-jn}iQd+~#)f)B|X zUp;uVW_9yw1&+D~3oA>_T^^nPy}5LgY%Ja#-(B6mySyPl-}vk+31*YKX2G31W}IBt zwJ@CJV!yyKLuKRBGbS%lsX2b#mZ@fM_eY)o#r1u1rs;+X3PR_N4sYo+?^tf0+x*$C zuthX=>W?`USC()K*%!rr{Lx!{Ftst=?MzA5JPRisv0D+D$zdj@k2D{xSoLy>eu_<) zWq#qcQ=!-PsMjZ2EMKovJolM^P{a`-m5zV_SI*QM9T!(kPEvIJT`2#5!RzTKmQGmB z;?~C+vcR$I?}PdeyQ8)3Eg!13K6ZHC{kVpQd135=z~VXYlaFW4VK|unz$^c!c4@-1 z$zP(pyX6@7-ac@&)I0cF!)e)s2PY@^-kjQG(pn=|VZS*46jSYXhwrnlM;FU4=XaR3 z%j+Hkd;0;8#!c62@7=w6@Am%mS%3dB99mg)Jm;_40${YTC3(BM0BIoj>AbrhNO2Z; zL>4nJ=qZCRW5rVYGN2%PiKnkC`!i-yb}Jpb3EHthA;}Wgh!W@g+}zZ>5(ej@)Wnk1 z6ovB4k_-iRPv3y>Mm}+%S<0R+jv*erj1rvBzcKy?0-#2mfDs6AN&+Pa>1V>HnHqAV z77z@@(I6TPB7z}6P{C*_8Vw?XAwW>UXet^FB7z}6Pyx+TQT{Ft9Zp`Z43JAaUHx3v IIVCg!009H(%m4rY literal 0 HcmV?d00001 diff --git a/apps/stlap/img/play.png b/apps/stlap/img/play.png new file mode 100644 index 0000000000000000000000000000000000000000..6c20c24c54d72382a69d5aa3685e3ad8fa6174ba GIT binary patch literal 2891 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1|%Pp+x}o+U~I{Bb`J1#c2+1T%1_J8No8Qr zm{>c}*5j~)%+dJZrAngg+8q`tEBwU%ILU0~a$O;i)fy)2qxZK-jn}iQd+~#)f)B|X zUp;uVW_9yw1&+D~3oA>_T^^nPy}5LgY%Ja#-(B6mySyPl-}vk+31*YKX2G31W}IBt zwJ@CJV!yyKLuKRBGbS%lsX2b#mZ@fM_eY)o#r1u1rs;+X3PR_N4sYo+?^tf0+x*$C zuthX=>W?`USC()K*%!rr{Lx!{Ftst=?MzA5JPRisv0D+D$zdj@k2D{xSoLy>eu_<) zWq#qcQ=!-PsMjZ2EMKovJolM^P{a`-m5zV_SI*QM9T!(kPEvIJT`2#5!RzTKmQGmB z;?~C+vcR$I?}PdeyQ8)3Eg!13K6ZHC{kVpQd135=z~VXYlaFW4VK|unz$^c!c4@-1 z$zP(pyX6@7-ac@&)I0cF!)e)s2PY@^-kjQG(pn=|VZS*46jSYXhwrnlM;FU4=XaR3 z%j+Hkd;0;8#!c62@7=w6@Am%mS%3dB99mg)Jm;_40${YTC3(BM0BIoj>AbrhNO2Z; zL>4nJ=qZCRW5rVYGN2%PiKnkC`!i-yc1y0~8~!E(g(OQ{BTAg}b8}PkN*J7rQWHy3 zQxwWGOEMJPJ$(bh8~Mb6W+{8RIEHxeGD>hh{|3|p0snyj#-=9C2r~@X0!AQ!iBn3$ z4MMg6W+*i*!fOFFEF#JRN-Sc6X(ooo7L0`Sk>mqp!-$O^vMqpFM#v(HEg)nO)hxhe z5!Ed~w}_-v1k+3m4NGw}vjFA@nppr#T`Vx0s71pJhM7k-3(yUwngzHFrq}{P2E!~M zE0T#d9ApVeaX^Z}FdqmdKI;Vst0LE7sJpcdz literal 0 HcmV?d00001 diff --git a/apps/stlap/img/reset.png b/apps/stlap/img/reset.png new file mode 100644 index 0000000000000000000000000000000000000000..7a317d09795c09aabab4836c8b9ec4a6c5fe4db8 GIT binary patch literal 2891 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1|%Pp+x}o+U~I{Bb`J1#c2+1T%1_J8No8Qr zm{>c}*5j~)%+dJZrAngg+8q`tEBwU%ILU0~a$O;i)fy)2qxZK-jn}iQd+~#)f)B|X zUp;uVW_9yw1&+D~3oA>_T^^nPy}5LgY%Ja#-(B6mySyPl-}vk+31*YKX2G31W}IBt zwJ@CJV!yyKLuKRBGbS%lsX2b#mZ@fM_eY)o#r1u1rs;+X3PR_N4sYo+?^tf0+x*$C zuthX=>W?`USC()K*%!rr{Lx!{Ftst=?MzA5JPRisv0D+D$zdj@k2D{xSoLy>eu_<) zWq#qcQ=!-PsMjZ2EMKovJolM^P{a`-m5zV_SI*QM9T!(kPEvIJT`2#5!RzTKmQGmB z;?~C+vcR$I?}PdeyQ8)3Eg!13K6ZHC{kVpQd135=z~VXYlaFW4VK|unz$^c!c4@-1 z$zP(pyX6@7-ac@&)I0cF!)e)s2PY@^-kjQG(pn=|VZS*46jSYXhwrnlM;FU4=XaR3 z%j+Hkd;0;8#!c62@7=w6@Am%mS%3dB99mg)Jm;_40${YTC3(BM0BIoj>AbrhNO2Z; zL>4nJ=qZCRW5rVYGN2%PiKnkC`!i-y4rWEypL5fJLXst}5hc#~xw)x%B@E6*sfi`2 zDGKG8B^e6tp1uL$jeO!jvy?qu978;K86`NMe`EX)1VD{A0V5FLlmto;($9oXGe{1f z0r=!#<`T33mnFm)4$@1M1?ZL#YdAG9F5Ihr6 z+Y*@Ba0@^#qn0Hw!$D@ESU?R+kPQc!NApyK;scrn5w#2l1q%qkf(q;dY8wu*0%FN% zSp*9WoHWgoDM=Q9QU(a%bS@SNqAfr+7@3X5OcWuaEWl lapTimes[slowestIndex]) slowestIndex = i; + } + + let lapMenu = { + '': { + 'title': fileNameToDateString(fileName), + 'back': () => { E.showMenu(mainMenu); } + }, + }; + lapMenu[`Total time: ${msToHumanReadable(fileData[fileData.length - 1])}`] = () => { }; + lapMenu[`Fastest lap: ${fastestIndex + 1}: ${msToHumanReadable(lapTimes[fastestIndex])}`] = () => { }; + lapMenu[`Slowest lap: ${slowestIndex + 1}: ${msToHumanReadable(lapTimes[slowestIndex])}`] = () => { }; + lapMenu[`Average lap: ${msToHumanReadable(fileData[fileData.length - 1] / fileData.length)}`] = () => { }; + + for (let i = 0; i < lapTimes.length; i++) { + lapMenu[`Lap ${i + 1}: ${msToHumanReadable(lapTimes[i])}`] = () => { }; + } + + lapMenu.Delete = () => { + E.showMenu({ + '': { + 'title': 'Are you sure?', + 'back': () => { E.showMenu(lapMenu); } + }, + 'Yes': () => { + storage.erase(fileName); + showMainMenu(); + }, + 'No': () => { E.showMenu(lapMenu); } + }); + }; + + E.showMenu(lapMenu); +} + +function showMainMenu() { + let LAP_FILES = storage.list(/stlap-[0-9]*\.json/); + LAP_FILES.sort(); + LAP_FILES.reverse(); + + let mainMenu = { + '': { + 'title': 'Sessions' + } + }; + + //I know eval is evil, but I can't think of any other way to do this. + for (let lapFile of LAP_FILES) { + mainMenu[fileNameToDateString(lapFile)] = eval(`(function() { + view('${lapFile}'); + })`); + } + + if (LAP_FILES.length == 0) { + mainMenu['No data'] = _ => { load(); }; + } + + E.showMenu(mainMenu); +} + +showMainMenu(); \ No newline at end of file diff --git a/apps/stlapview/icon.js b/apps/stlapview/icon.js new file mode 100644 index 000000000..32281b7ab --- /dev/null +++ b/apps/stlapview/icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEw4UA///vvvvEF/muH+cDHgPABf4AElWoKhILClALH1WqAQIWHBYIABwAKEgQKD1WgBYkK1X1r4XHlWtqtVvQLG1XVBYNXHYsC1YJBBoPqC4kKEQILCvQ7EhW1BYdeBYkqytVqwCCQwkqCgILCq4LFIoILCqoLEIwIsBGQJIBBZ+pA4Na0oDBtQLGvSFCBaYjIHYR3CI5AADBYhrCAAaDHAASDGQASGCBYizCAASzFZYQACZYrjCIwb7QHgIkCvQ6EGAWq+tf1QuEGAWqAAQuFEgQKBEQw9DHIwAuA=")) diff --git a/apps/stlapview/icon.png b/apps/stlapview/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..92ffe73b7f172f7019486231d5bc0ba327c13a67 GIT binary patch literal 1566 zcmV+(2I2XMP)rZGih zXw&#$)jrm=iAGIK8xtz&C7L#UsP>_)mll=wMNO+ffoiD_T1#yUim(D(ys%vMfQPei zrVqOZR|L*1ZtO$(Kh4bfZvQzm-^@2KjcNS9p~TbJ{=+BFgR;y*?EJRZOY-C8(-tp7 zVORza@KQWI#+kt5$25We8u2D@-cmyFb37f!H4B+o`PybN-uT(0hvM!pG2RAaMai~Z zb8H5+fL|F7l^*}>gRWTg<2NIR8$39)H7FE$0)fri3@0JG9e^ZV$1ylSfBMXW2&%E$ zPO&yWxOMB+q<~{)6;Ked;unf2IeFmyUmqWV%KAJEV+T+Q%#hR?1dbK`*5J(O?<*bi zO;Z%!IDVk)sEnbh6R5b5f)d(`!dpynDcXcVZikO&eb-4ajOeKPP8=vpld&G6#BUZr!wEAw+((0R3 zrXbzLH_tucuqlj0hL$qu+9ey79D&OEyhyeIpghm3SOpJZ0ylh<6M!&@vIX9#5%D$^ zHQ6$u$q@+W`9uhB*iAW^QhKevc3RtRO1aoFFEin3XYxR#>%x|>M@G*&ki!ig!iN+9 z<#}G0?8a$r^U>1QCMBx?`|`Zb`y*l_6*ZQ>*_wbuTSMf8&2iX+vZ=DKzn?&FFTtQn zcOW38Q<&~zjy+M0be$yF)>!FS6Hq8Jo3G6BI3^Q~Myv1s(rIb4-UlX1veWFN9dY0H zM6f0xl*MMVIK!PJ8_3nan@8J?SO1b#qd3!TkLoU-P%r|SKQP~H&P}mTCOL|}{(ipr z>d0vS%cB+Cx!WzJJ2&|OAM+=YGa>N@@R-ePyWG|3Y)vhL_wLbMu#!7PtICQ=hz{kT!_!z`=nUlJl03sr&j0}&?P-3E-D?`>v1Tssg-)!E}hoy|JDk@}lRu&l- zYRIfV%j~QyRj3EpMT1a)jt8Ss%SYLw_Cy$ zv}^iU-;=_cfKaZ0SOQSht?Gs8E~%aDal2W+_GKB-2XL;tKLmucox&9>d6`XIZ8j@! z_e$Lm9|hmt>bvj55SBaNntrAr?+kNN?GIAf(_O<-+) z5IAObcQpIe7!!pQ3<2AlI-_PsIm(6=ma`>W50nETfTn>V*P-_A5exa4aj@g=$hAS; zoP8Zd*(akXM__&7H4yvF?#}Ce>f^YS>UvamU;ih1=wsFuSY{xIr6LQ8JwOA1AxJ1~ z^l9-RQP-pLYNJmx>tf&nGX~z3)sL;HKUp^iAua-QAzWIPE%35s-uOlRWH1CA?7VC2 zZtlWBm=oEKVJu<83hC#?DLkvxEdp_h2nm2Zr(G@2&2bfG$kht9Ju2IqI@PE(573Um z8a5O*#uCodUgj!lva#8|1C~Y)XWJ9ib=hh5;!L+aCpigk)WcS%7NR;3)K7Nx>QSlE zjN%tYjFMPp{?P~koIaf#emxNH08UH!@u4HcM>q%HlYK@Ri${Olt*FTk7vN$e@QR9l#uqzNePq-K{A831lR^T#FgJGPOIi#jBjcHipUslrouSl-W Q%m4rY07*qoM6N<$g48qYF8}}l literal 0 HcmV?d00001 diff --git a/apps/stlapview/metadata.json b/apps/stlapview/metadata.json new file mode 100644 index 000000000..aa54a7b67 --- /dev/null +++ b/apps/stlapview/metadata.json @@ -0,0 +1,27 @@ +{ + "id": "stlapview", + "name": "Stopwatch laps", + "version": "0.02", + "description": "Optional lap viewer for my stopwatch app", + "icon": "icon.png", + "type": "app", + "tags": "tools,app", + "supports": [ + "BANGLEJS2" + ], + "allow_emulator": true, + "storage": [ + { + "name": "stlapview.app.js", + "url": "app.js" + }, + { + "name": "stlapview.img", + "url": "icon.js", + "evaluate": true + } + ], + "dependencies": { + "stlap": "app" + } +} \ No newline at end of file