1
0
Fork 0

Added alarm via swipe left/right.

master
David Peer 2021-11-19 18:19:16 +01:00
parent 100384f2e8
commit b4a355cfe1
5 changed files with 94 additions and 22 deletions

View File

@ -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}

View File

@ -1 +1,2 @@
0.01: Launch app
0.02: Swipe left/right to set an alarm.

View File

@ -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)

View File

@ -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

BIN
apps/lcars/screenshot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB