diff --git a/apps.json b/apps.json index 7fe259899..18dff1079 100644 --- a/apps.json +++ b/apps.json @@ -547,7 +547,7 @@ "description": "A random scramble generator for the 3x3 Rubik's cube", "icon": "cube-scramble.png", "tags": "", - "supports" : ["BANGLEJS","BANGLEJS2"], + "supports" : ["BANGLEJS","BANGLEJS2"], "readme": "README.md", "allow_emulator": true, "storage": [ @@ -4278,7 +4278,7 @@ {"name":"a_battery_widget.wid.js","url":"widget.js"} ] }, - { + { "id": "lcars", "name": "LCARS Clock", "shortName":"LCARS", @@ -4288,6 +4288,7 @@ "description": "Library Computer Access Retrieval System (LCARS) clock.", "type": "clock", "tags": "clock", + "screenshots": [{"url":"screenshot.png"}], "storage": [ {"name":"lcars.app.js","url":"lcars.app.js"}, {"name":"lcars.img","url":"lcars.icon.js","evaluate":true} diff --git a/apps/lcars/ChangeLog b/apps/lcars/ChangeLog index c7ec09d30..750e7ddfc 100644 --- a/apps/lcars/ChangeLog +++ b/apps/lcars/ChangeLog @@ -1 +1,2 @@ 0.01: Launch app +0.02: Swipe left/right to set an alarm. diff --git a/apps/lcars/README.md b/apps/lcars/README.md index fdce30c1b..7d2d19687 100644 --- a/apps/lcars/README.md +++ b/apps/lcars/README.md @@ -1,8 +1,14 @@ # LCARS clock -A simple LCARS inspired clock that shows: - * Current time - * Current date - * Battery level - * Steps +A simple LCARS inspired clock +## Features + * Shows the time + * Shows the date + * Shows the current battery level in % + * Shows the number of daily steps + * Swipe left/right to activate an alarm + + +## Creator +Made by [David Peer](https://github.com/peerdavid) \ No newline at end of file diff --git a/apps/lcars/lcars.app.js b/apps/lcars/lcars.app.js index cf884a6b7..2e001643b 100644 --- a/apps/lcars/lcars.app.js +++ b/apps/lcars/lcars.app.js @@ -1,9 +1,9 @@ -const locale = require('locale'); - - /* - * Assets: Images, fonts etc. + * Requirements and globals */ +const locale = require('locale'); +var alarm = -1; + var img = { width : 176, height : 151, bpp : 3, transparent : 0, @@ -22,7 +22,7 @@ Graphics.prototype.setFontMinaLarge = function(scale) { /* - * Queue drawing every minute + * Draw watch face */ var drawTimeout; function queueDraw() { @@ -34,9 +34,6 @@ function queueDraw() { } -/* - * Draw watch face - */ function draw(){ g.reset(); g.clearRect(0, 24, g.getWidth(), g.getHeight()); @@ -66,22 +63,89 @@ function draw(){ g.drawString(bat+"%", 100, 127); // Draw steps - var steps = Bangle.getStepCount(); - g.drawString("STEP:", 40, 147); - g.drawString(steps, 100, 147); + if(alarm < 0){ + var steps = Bangle.getStepCount(); + g.drawString("STEP:", 40, 147); + g.drawString(steps, 100, 147); + } else { + g.drawString("ALRM:", 40, 147); + g.drawString("T-" + alarm, 100, 147); + } // Queue draw in one minute queueDraw(); } -// Clear the screen once, at startup -g.setTheme({bg:"#000",fg:"#fff",dark:true}).clear(); -// draw immediately at first, queue update +/* + * Handle alarm + */ +var alarmTimeout; +function queueAlarm() { + if (alarmTimeout) clearTimeout(alarmTimeout); + alarmTimeout = setTimeout(function() { + alarmTimeout = undefined; + handleAlarm(); + }, 60000 - (Date.now() % 60000)); +} + +function handleAlarm(){ + + // If alarm is zero, inform the user. + if(alarm == 0){ + alarm = -1; + + var t = 300; + Bangle.buzz(t, 1) + .then(() => new Promise(resolve => setTimeout(resolve, t))) + .then(() => Bangle.buzz(t, 1)) + .then(() => new Promise(resolve => setTimeout(resolve, t))) + .then(() => Bangle.buzz(t, 1)) + .then(() => new Promise(resolve => setTimeout(resolve, t))) + .then(() => Bangle.buzz(t, 1)); + + // Draw watch face again to show data instead of alarm. + draw(); + + // If we still have to wait, queue alarm again. + } else if(alarm > 0){ + alarm--; + queueAlarm(); + draw(); + } +} + + +/* + * Swipe to set an alarm + */ +Bangle.on('swipe',function(dir) { + // Increase alarm + if(dir == -1){ + alarm = alarm < 0 ? 0 : alarm; + alarm += 5; + + queueAlarm(); + } + + // Decrease alarm + if(dir == +1){ + alarm -= 5; + alarm = alarm <= 0 ? -1 : alarm; + } + + draw(); +}); + + +// Clear the screen once, at startup and draw clock +g.setTheme({bg:"#000",fg:"#fff",dark:true}).clear(); draw(); -// Stop updates when LCD is off, restart when on +/* + * Stop updates when LCD is off, restart when on + */ Bangle.on('lcdPower',on=>{ if (on) { draw(); // draw immediately, queue redraw diff --git a/apps/lcars/screenshot.png b/apps/lcars/screenshot.png new file mode 100644 index 000000000..6cb48387d Binary files /dev/null and b/apps/lcars/screenshot.png differ