1
0
Fork 0

bwclk, lcars, notanalog and smpltmr uses now the new alarm library.

master
David Peer 2022-04-02 12:22:16 +02:00
parent 64262c6410
commit b138224878
15 changed files with 164 additions and 176 deletions

View File

@ -8,7 +8,7 @@ In the settings, fullscreen mode can be enabled and disabled:
![](screenshot_2.png)
Additionally, in fullscreen mode a lock icon can be shown...
If you installed the "qalarm" app, you can directly set a timer. Simply tab at
If you installed the "alarm" app, you can directly set a timer. Simply tab at
top / bottom of the screen.
## Thanks to

View File

@ -1,3 +1,4 @@
const TIMER_IDX = "bwclk";
const SETTINGS_FILE = "bwclk.setting.json";
const locale = require('locale');
const storage = require('Storage');
@ -75,41 +76,56 @@ function getSteps() {
return 0;
}
function isAlarmEnabled(){
try{
var qalarm = require('qalarm');
return qalarm.isTimerStarted("bwclk");
var alarm = require('alarm');
var alarmObj = alarm.getAlarm(TIMER_IDX);
if(alarmObj===undefined || !alarmObj.on){
return false;
}
return true;
} catch(ex){ }
return false;
}
function getAlarmMinutes(){
try{
var qalarm = require('qalarm');
return qalarm.getTimerMin("bwclk");
} catch(ex){ }
return -1;
if(!isAlarmEnabled()){
return -1;
}
var alarm = require('alarm');
var alarmObj = alarm.getAlarm(TIMER_IDX);
return Math.round(alarm.getTimeToAlarm(alarmObj)/(60*1000));
}
function increaseAlarm(){
try{
var qalarm = require('qalarm');
var mins = qalarm.getTimerMin("bwclk")+5;
qalarm.deleteTimer("bwclk");
qalarm.editTimer("bwclk", 0, mins, 0);
var minutes = isAlarmEnabled() ? getAlarmMinutes() : 0;
var alarm = require('alarm')
alarm.setAlarm(TIMER_IDX, {
timer : (minutes+5)*60*1000,
});
alarm.reload();
} catch(ex){ }
}
function decreaseAlarm(){
try{
var qalarm = require('qalarm');
var mins = qalarm.getTimerMin("bwclk")-5;
qalarm.deleteTimer("bwclk");
if(mins > 0){
qalarm.editTimer("bwclk", 0, mins, 0);
var minutes = getAlarmMinutes();
minutes -= 5;
var alarm = require('alarm')
alarm.setAlarm(TIMER_IDX, undefined);
if(minutes > 0){
alarm.setAlarm(TIMER_IDX, {
timer : minutes*60*1000,
});
}
alarm.reload();
} catch(ex){ }
}

View File

@ -16,5 +16,5 @@
0.16: Improved stability. Wind can now be shown.
0.17: Settings for mph/kph and other minor improvements.
0.18: Fullscreen mode can now be enabled or disabled in the settings.
0.19: Use qalarm for alarm functionality instead of own implementation.
0.19: Alarms can not go bigger than 100.
0.20: Use alarm for alarm functionality instead of own implementation.

View File

@ -3,7 +3,8 @@
A simple LCARS inspired clock.
Note: To display the steps, the wpedom app is required. To show weather data
such as temperature, humidity or window you BangleJS must be connected
with Gadgetbride and the weather app must be installed.
with Gadgetbride and the weather app must be installed. To use the timer
the "alarm" app must be installed on your device.
## Control
* Tap left / right to change between screens.

View File

@ -1,7 +1,7 @@
const TIMER_IDX = "lcars";
const SETTINGS_FILE = "lcars.setting.json";
const locale = require('locale');
const storage = require('Storage');
const qalarm = require('qalarm');
let settings = {
alarm: -1,
dataRow1: "Steps",
@ -566,25 +566,56 @@ function getWeather(){
* Handle alarm
*/
function isAlarmEnabled(){
return qalarm.isTimerStarted("lcars");
try{
var alarm = require('alarm');
var alarmObj = alarm.getAlarm(TIMER_IDX);
if(alarmObj===undefined || !alarmObj.on){
return false;
}
return true;
} catch(ex){ }
return false;
}
function getAlarmMinutes(){
return qalarm.getTimerMin("lcars");
if(!isAlarmEnabled()){
return -1;
}
var alarm = require('alarm');
var alarmObj = alarm.getAlarm(TIMER_IDX);
return Math.round(alarm.getTimeToAlarm(alarmObj)/(60*1000));
}
function increaseAlarm(){
var mins = qalarm.getTimerMin("lcars")+5;
qalarm.deleteTimer("lcars");
qalarm.editTimer("lcars", 0, mins, 0);
try{
var minutes = isAlarmEnabled() ? getAlarmMinutes() : 0;
var alarm = require('alarm')
alarm.setAlarm(TIMER_IDX, {
timer : (minutes+5)*60*1000,
});
alarm.reload();
} catch(ex){ }
}
function decreaseAlarm(){
var mins = qalarm.getTimerMin("lcars")-5;
qalarm.deleteTimer("lcars");
if(mins > 0){
qalarm.editTimer("lcars", 0, mins, 0);
}
try{
var minutes = getAlarmMinutes();
minutes -= 5;
var alarm = require('alarm')
alarm.setAlarm(TIMER_IDX, undefined);
if(minutes > 0){
alarm.setAlarm(TIMER_IDX, {
timer : minutes*60*1000,
});
}
alarm.reload();
} catch(ex){ }
}
@ -612,15 +643,6 @@ Bangle.on('charging',function(charging) {
});
function increaseAlarm(){
if(isAlarmEnabled() && getAlarmMinutes() < 95){
settings.alarm += 5;
} else {
settings.alarm = getCurrentTimeInMinutes() + 5;
}
}
function feedback(){
Bangle.buzz(40, 0.3);
}

View File

@ -3,7 +3,7 @@
"name": "LCARS Clock",
"shortName":"LCARS",
"icon": "lcars.png",
"version":"0.19",
"version":"0.20",
"readme": "README.md",
"dependencies": {"qalarm":"app"},
"supports": ["BANGLEJS2"],

View File

@ -1,4 +1,4 @@
0.01: Launch app.
0.02: 12k steps are 360 degrees - improves readability of steps.
0.03: Battery improvements through sleep (no minute updates) and partial updates of drawing.
0.04: Use qalarm for timer instead of own alarm implementation.
0.04: Use alarm for timer instead of own alarm implementation.

View File

@ -9,7 +9,7 @@ The selected theme is also respected. Note that this watch face is in fullscreen
mode, but widgets are still loaded in background.
## Other Features
- Set a timer - simply touch top (+5min.) or bottom (-5 min.) - depends on widtmr.
- Set a timer - simply touch top (+5min.) or bottom (-5 min.). This only works if "alarm" is installed.
- If the weather is available through the weather app, the outside temp. will be shown.
- Sleep modus at midnight to save more battery (no minute updates).
- Icons for charging and GPS.

View File

@ -1,11 +1,10 @@
/**
* NOT ANALOG CLOCK
*/
const TIMER_IDX = "notanalog";
const locale = require('locale');
const storage = require('Storage')
const SETTINGS_FILE = "notanalog.setting.json";
const qalarm = require('qalarm');
let settings = {
alarm: -1,
};
@ -394,25 +393,56 @@ function queueDraw() {
* Handle alarm
*/
function isAlarmEnabled(){
return qalarm.isTimerStarted("notanalog");
}
try{
var alarm = require('alarm');
var alarmObj = alarm.getAlarm(TIMER_IDX);
if(alarmObj===undefined || !alarmObj.on){
return false;
}
return true;
} catch(ex){ }
return false;
}
function getAlarmMinutes(){
return qalarm.getTimerMin("notanalog");
if(!isAlarmEnabled()){
return -1;
}
var alarm = require('alarm');
var alarmObj = alarm.getAlarm(TIMER_IDX);
return Math.round(alarm.getTimeToAlarm(alarmObj)/(60*1000));
}
function increaseAlarm(){
var mins = qalarm.getTimerMin("notanalog")+5;
qalarm.deleteTimer("notanalog");
qalarm.editTimer("notanalog", 0, mins, 0);
try{
var minutes = isAlarmEnabled() ? getAlarmMinutes() : 0;
var alarm = require('alarm')
alarm.setAlarm(TIMER_IDX, {
timer : (minutes+5)*60*1000,
});
alarm.reload();
} catch(ex){ }
}
function decreaseAlarm(){
var mins = qalarm.getTimerMin("notanalog")-5;
qalarm.deleteTimer("notanalog");
if(mins > 0){
qalarm.editTimer("notanalog", 0, mins, 0);
}
try{
var minutes = getAlarmMinutes();
minutes -= 5;
var alarm = require('alarm')
alarm.setAlarm(TIMER_IDX, undefined);
if(minutes > 0){
alarm.setAlarm(TIMER_IDX, {
timer : minutes*60*1000,
});
}
alarm.reload();
} catch(ex){ }
}
function feedback(){

View File

@ -4,4 +4,3 @@
Fix app icon
Change menu order so 'back' is at the top
0.04: Fix alarm not activating sometimes.
0.05: Include library that can be used by other apps.

View File

@ -1,108 +0,0 @@
let alarms = require("Storage").readJSON("qalarm.json", 1) || [];
/**
* LIBRARY
*/
function getCurrentTime() {
let time = new Date();
return (
time.getHours() * 3600000 +
time.getMinutes() * 60000 +
time.getSeconds() * 1000
);
}
function getAlarmIndex(idx){
for(var i=0; i<alarms.length; i++){
if(alarms[i].idx == idx){
return i;
}
}
return -1;
}
function alarmExists(idx){
var alarmIndex = getAlarmIndex(idx);
var exists = alarmIndex >= 0 && alarmIndex < alarms.length;
return exists;
}
function isAlarmStarted(idx){
if(!alarmExists(idx)){
return false;
}
var alarmIndex = getAlarmIndex(idx);
var time = new Date();
var t = getCurrentTime();
a = alarms[alarmIndex];
return a.on &&
t <= a.t &&
a.last != time.getDate() &&
(a.timer || a.daysOfWeek[time.getDay()]);
}
function getTimerMin(idx){
if(!isAlarmStarted(idx)){
return 0;
}
var alarmIndex = getAlarmIndex(idx);
var a = alarms[alarmIndex] ;
var diff = a.t - getCurrentTime();
// let hrs = Math.floor(t / 3600000);
var mins = Math.round((diff / 60000) % 60);
// return hrs + ":" + ("0" + mins).substr(-2);
return mins;
}
function reloadQalarm(){
require("Storage").write("qalarm.json", JSON.stringify(alarms));
eval(require("Storage").read("qalarmcheck.js"));
if (WIDGETS["qalarm"]) WIDGETS["qalarm"].reload();
}
function editTimer(idx, hrs, mins, secs){
var alarmIndex = getAlarmIndex(idx);
var a = {
idx: idx,
on: true,
rp: false,
as: false,
hard: false,
};
a.timer = hrs * 3600 + mins * 60 + secs;
a.t = (getCurrentTime() + a.timer * 1000) % 86400000;
if(alarmExists(idx)){
alarms[alarmIndex] = a;
} else {
alarms.push(a)
alarmIndex = alarms.length-1;
}
reloadQalarm();
}
function deleteAlarm(idx){
var alarmIndex = getAlarmIndex(idx);
if(!alarmExists(idx)){
return;
}
alarms.splice(alarmIndex, 1);
reloadQalarm();
}
// Export functions
exports.alarmExists = alarmExists;
exports.isAlarmStarted = isAlarmStarted;
exports.deleteAlarm = deleteAlarm;
exports.timerExists = alarmExists;
exports.isTimerStarted = isAlarmStarted;
exports.getTimerMin = getTimerMin;
exports.editTimer = editTimer;
exports.deleteTimer = deleteAlarm;

View File

@ -3,12 +3,11 @@
"name": "Q Alarm and Timer",
"shortName": "Q Alarm",
"icon": "app.png",
"version": "0.05",
"version": "0.04",
"description": "Alarm and timer app with days of week and 'hard' option.",
"tags": "tool,alarm,widget",
"supports": ["BANGLEJS", "BANGLEJS2"],
"storage": [
{ "name": "qalarm", "url": "lib.js" },
{ "name": "qalarm.app.js", "url": "app.js" },
{ "name": "qalarm.boot.js", "url": "boot.js" },
{ "name": "qalarm.js", "url": "qalarm.js" },

View File

@ -2,6 +2,7 @@
* This file checks for upcoming alarms and schedules qalarm.js to deal with them and itself to continue doing these checks.
*/
print("Checking for alarms...");
if (Bangle.QALARM) {
clearInterval(Bangle.QALARM);

View File

@ -8,7 +8,7 @@
Bangle.loadWidgets();
const qalarm = require('qalarm');
const alarm = require("alarm");
const TIMER_IDX = "smpltmr";
const screenWidth = g.getWidth();
@ -19,6 +19,33 @@ var minutes = 5;
var interval; //used for the 1 second interval timer
function isTimerEnabled(){
var alarmObj = alarm.getAlarm(TIMER_IDX);
if(alarmObj===undefined || !alarmObj.on){
return false;
}
return true;
}
function getTimerMin(){
var alarmObj = alarm.getAlarm(TIMER_IDX);
return Math.round(alarm.getTimeToAlarm(alarmObj)/(60*1000));
}
function setTimer(minutes){
alarm.setAlarm(TIMER_IDX, {
// msg : "Simple Timer",
timer : minutes*60*1000,
});
alarm.reload();
}
function deleteTimer(){
alarm.setAlarm(TIMER_IDX, undefined);
alarm.reload();
}
setWatch(_=>load(), BTN1);
function draw(){
g.clear(1);
@ -32,10 +59,11 @@ function draw(){
// Write time
g.setFontAlign(0, 0, 0);
g.setFont("Vector", 32).setFontAlign(0,-1);
var started = qalarm.isTimerStarted(TIMER_IDX);
var started = isTimerEnabled();
var text = minutes + " min.";
if(started){
var min = qalarm.getTimerMin(TIMER_IDX);
var min = getTimerMin();
text = min + " min.";
}
@ -65,7 +93,7 @@ Bangle.on('touch', function(btn, e){
var isUpper = e.y < upper;
var isLower = e.y > lower;
var isMiddle = !isLeft && !isRight && !isUpper && !isLower;
var started = qalarm.isTimerStarted(TIMER_IDX);
var started = isTimerEnabled();
if(isRight && !started){
minutes += 1;
@ -81,9 +109,9 @@ Bangle.on('touch', function(btn, e){
Bangle.buzz(40, 0.3);
} else if(isMiddle) {
if(!started){
qalarm.editTimer(TIMER_IDX, 0, minutes, 0);
setTimer(minutes);
} else {
qalarm.deleteTimer(TIMER_IDX);
deleteTimer();
}
Bangle.buzz(80, 0.6);
}

View File

@ -3,10 +3,10 @@
"name": "Simple Timer",
"shortName": "Simple Timer",
"version": "0.01",
"description": "A simple app to set a timer.",
"description": "A very simple app to start a timer.",
"icon": "app.png",
"tags": "tool",
"dependencies": {"qalarm":"app"},
"dependencies": {"alarm":"app"},
"supports": ["BANGLEJS2"],
"screenshots": [{"url":"screenshot.png"}, {"url": "screenshot_2.png"}],
"readme": "README.md",