forked from FOSS/BangleApps
Added alarm via swipe left/right.
parent
100384f2e8
commit
b4a355cfe1
|
@ -547,7 +547,7 @@
|
||||||
"description": "A random scramble generator for the 3x3 Rubik's cube",
|
"description": "A random scramble generator for the 3x3 Rubik's cube",
|
||||||
"icon": "cube-scramble.png",
|
"icon": "cube-scramble.png",
|
||||||
"tags": "",
|
"tags": "",
|
||||||
"supports" : ["BANGLEJS","BANGLEJS2"],
|
"supports" : ["BANGLEJS","BANGLEJS2"],
|
||||||
"readme": "README.md",
|
"readme": "README.md",
|
||||||
"allow_emulator": true,
|
"allow_emulator": true,
|
||||||
"storage": [
|
"storage": [
|
||||||
|
@ -4278,7 +4278,7 @@
|
||||||
{"name":"a_battery_widget.wid.js","url":"widget.js"}
|
{"name":"a_battery_widget.wid.js","url":"widget.js"}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "lcars",
|
"id": "lcars",
|
||||||
"name": "LCARS Clock",
|
"name": "LCARS Clock",
|
||||||
"shortName":"LCARS",
|
"shortName":"LCARS",
|
||||||
|
@ -4288,6 +4288,7 @@
|
||||||
"description": "Library Computer Access Retrieval System (LCARS) clock.",
|
"description": "Library Computer Access Retrieval System (LCARS) clock.",
|
||||||
"type": "clock",
|
"type": "clock",
|
||||||
"tags": "clock",
|
"tags": "clock",
|
||||||
|
"screenshots": [{"url":"screenshot.png"}],
|
||||||
"storage": [
|
"storage": [
|
||||||
{"name":"lcars.app.js","url":"lcars.app.js"},
|
{"name":"lcars.app.js","url":"lcars.app.js"},
|
||||||
{"name":"lcars.img","url":"lcars.icon.js","evaluate":true}
|
{"name":"lcars.img","url":"lcars.icon.js","evaluate":true}
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
0.01: Launch app
|
0.01: Launch app
|
||||||
|
0.02: Swipe left/right to set an alarm.
|
||||||
|
|
|
@ -1,8 +1,14 @@
|
||||||
# LCARS clock
|
# LCARS clock
|
||||||
|
|
||||||
A simple LCARS inspired clock that shows:
|
A simple LCARS inspired clock
|
||||||
* Current time
|
|
||||||
* Current date
|
|
||||||
* Battery level
|
|
||||||
* Steps
|
|
||||||
|
|
||||||
|
## 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)
|
|
@ -1,9 +1,9 @@
|
||||||
const locale = require('locale');
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Assets: Images, fonts etc.
|
* Requirements and globals
|
||||||
*/
|
*/
|
||||||
|
const locale = require('locale');
|
||||||
|
var alarm = -1;
|
||||||
|
|
||||||
var img = {
|
var img = {
|
||||||
width : 176, height : 151, bpp : 3,
|
width : 176, height : 151, bpp : 3,
|
||||||
transparent : 0,
|
transparent : 0,
|
||||||
|
@ -22,7 +22,7 @@ Graphics.prototype.setFontMinaLarge = function(scale) {
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Queue drawing every minute
|
* Draw watch face
|
||||||
*/
|
*/
|
||||||
var drawTimeout;
|
var drawTimeout;
|
||||||
function queueDraw() {
|
function queueDraw() {
|
||||||
|
@ -34,9 +34,6 @@ function queueDraw() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Draw watch face
|
|
||||||
*/
|
|
||||||
function draw(){
|
function draw(){
|
||||||
g.reset();
|
g.reset();
|
||||||
g.clearRect(0, 24, g.getWidth(), g.getHeight());
|
g.clearRect(0, 24, g.getWidth(), g.getHeight());
|
||||||
|
@ -66,22 +63,89 @@ function draw(){
|
||||||
g.drawString(bat+"%", 100, 127);
|
g.drawString(bat+"%", 100, 127);
|
||||||
|
|
||||||
// Draw steps
|
// Draw steps
|
||||||
var steps = Bangle.getStepCount();
|
if(alarm < 0){
|
||||||
g.drawString("STEP:", 40, 147);
|
var steps = Bangle.getStepCount();
|
||||||
g.drawString(steps, 100, 147);
|
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
|
// Queue draw in one minute
|
||||||
queueDraw();
|
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();
|
draw();
|
||||||
|
|
||||||
|
|
||||||
// Stop updates when LCD is off, restart when on
|
/*
|
||||||
|
* Stop updates when LCD is off, restart when on
|
||||||
|
*/
|
||||||
Bangle.on('lcdPower',on=>{
|
Bangle.on('lcdPower',on=>{
|
||||||
if (on) {
|
if (on) {
|
||||||
draw(); // draw immediately, queue redraw
|
draw(); // draw immediately, queue redraw
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 2.1 KiB |
Loading…
Reference in New Issue