Expose timer functions for other apps. Updated notanalog and lcars to use this lib.

pull/1513/head
David Peer 2022-02-25 17:55:47 +01:00
parent a03fdec826
commit b8215908a6
11 changed files with 85 additions and 119 deletions

View File

@ -15,4 +15,5 @@
0.15: Using wpedom to count steps.
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.18: Fullscreen mode can now be enabled or disabled in the settings.
0.19: Use widtmr for alarm functionality instead of own implementation.

View File

@ -15,7 +15,7 @@ with Gadgetbride and the weather app must be installed.
* Tab on left/right to switch between different screens.
* Cusomizable data that is shown on screen 1 (steps, weather etc.)
* Shows random and real images of planets.
* Tap on top/bottom of screen 1 to activate an alarm.
* Tap on top/bottom of screen 1 to activate an alarm. Depends on widtmr.
* The lower orange line indicates the battery level.
* Display graphs (day or month) for steps + hrm on the second screen.
@ -36,8 +36,9 @@ Access different screens via tap on the left/ right side of the screen
![](screenshot_1.png)
![](screenshot_2.png)
## Creator
- [David Peer](https://github.com/peerdavid)
## Contributors
- [David Peer](https://github.com/peerdavid).
- [Adam Schmalhofer](https://github.com/adamschmalhofer).
- [Jon Warrington](https://github.com/BartokW).
- [Adam Schmalhofer](https://github.com/adamschmalhofer)
- [Jon Warrington](https://github.com/BartokW)

View File

@ -480,9 +480,6 @@ function draw(){
// Queue draw first to ensure that its called in one minute again.
queueDraw();
// First handle alarm to show this correctly afterwards
handleAlarm();
// Next draw the watch face
g.reset();
g.clearRect(0, 0, g.getWidth(), g.getHeight());
@ -561,43 +558,21 @@ function getWeather(){
/*
* Handle alarm
*/
function getCurrentTimeInMinutes(){
return Math.floor(Date.now() / (1000*60));
}
function isAlarmEnabled(){
return settings.alarm >= 0;
return WIDGETS["widtmr"].isStarted();
}
function getAlarmMinutes(){
var currentTime = getCurrentTimeInMinutes();
return settings.alarm - currentTime;
return WIDGETS["widtmr"].getRemainingMinutes();
}
function handleAlarm(){
if(!isAlarmEnabled()){
return;
}
function increaseAlarm(){
WIDGETS["widtmr"].increaseTimer(5);
WIDGETS["widtmr"].setStarted(true);
}
if(getAlarmMinutes() > 0){
return;
}
// Alarm
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))
.then(() => new Promise(resolve => setTimeout(resolve, 5E3)))
.then(() => {
// Update alarm state to disabled
settings.alarm = -1;
storage.writeJSON(SETTINGS_FILE, settings);
});
function decreaseAlarm(){
WIDGETS["widtmr"].decreaseTimer(5);
}
@ -625,26 +600,6 @@ Bangle.on('charging',function(charging) {
});
function increaseAlarm(){
if(isAlarmEnabled()){
settings.alarm += 5;
} else {
settings.alarm = getCurrentTimeInMinutes() + 5;
}
storage.writeJSON(SETTINGS_FILE, settings);
}
function decreaseAlarm(){
if(isAlarmEnabled() && (settings.alarm-5 > getCurrentTimeInMinutes())){
settings.alarm -= 5;
} else {
settings.alarm = -1;
}
storage.writeJSON(SETTINGS_FILE, settings);
}
function feedback(){
Bangle.buzz(40, 0.3);

View File

@ -3,8 +3,9 @@
"name": "LCARS Clock",
"shortName":"LCARS",
"icon": "lcars.png",
"version":"0.18",
"version":"0.19",
"readme": "README.md",
"dependencies": {"widtmr":"app"},
"supports": ["BANGLEJS2"],
"description": "Library Computer Access Retrieval System (LCARS) clock.",
"type": "clock",

View File

@ -1,3 +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.03: Battery improvements through sleep (no minute updates) and partial updates of drawing.
0.04: Use widtmr widget for timer instead of own alarm implementation.

View File

@ -8,8 +8,8 @@ black one the battery level (100% = 360 degrees).
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.).
## Other Features
- Set a timer - simply touch top (+5min.) or bottom (-5 min.) - depends on widtmr.
- 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.
@ -29,5 +29,5 @@ which helped a lot for this development.
Icons from <a href="https://www.flaticon.com/free-icons" title="icons">by Freepik - Flaticon</a>
## Contributors
## Creator
- [David Peer](https://github.com/peerdavid).

View File

@ -3,10 +3,11 @@
"name": "Not Analog",
"shortName":"Not Analog",
"icon": "notanalog.png",
"version":"0.03",
"version":"0.04",
"readme": "README.md",
"supports": ["BANGLEJS2"],
"description": "An analog watch face for people that can not read analog watch faces.",
"dependencies": {"widtmr":"app"},
"type": "clock",
"tags": "clock",
"screenshots": [

View File

@ -291,7 +291,6 @@ function drawSleep(){
function draw(fastUpdate){
// Execute handlers
handleState(fastUpdate);
handleAlarm();
if(state.sleep){
drawSleep();
@ -388,71 +387,28 @@ function queueDraw() {
/*
* Handle alarm
*/
function getCurrentTimeInMinutes(){
return Math.floor(Date.now() / (1000*60));
}
function isAlarmEnabled(){
return settings.alarm >= 0;
return WIDGETS["widtmr"].isStarted();
}
function getAlarmMinutes(){
var currentTime = getCurrentTimeInMinutes();
return settings.alarm - currentTime;
return WIDGETS["widtmr"].getRemainingMinutes();
}
function handleAlarm(){
if(!isAlarmEnabled()){
return;
}
if(getAlarmMinutes() > 0){
return;
}
// Alarm
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))
.then(() => new Promise(resolve => setTimeout(resolve, 5E3)))
.then(() => {
// Update alarm state to disabled
settings.alarm = -1;
storage.writeJSON(SETTINGS_FILE, settings);
});
}
function increaseAlarm(){
if(isAlarmEnabled()){
settings.alarm += 5;
} else {
settings.alarm = getCurrentTimeInMinutes() + 5;
}
storage.writeJSON(SETTINGS_FILE, settings);
WIDGETS["widtmr"].increaseTimer(5);
WIDGETS["widtmr"].setStarted(true);
}
function decreaseAlarm(){
if(isAlarmEnabled() && (settings.alarm-5 > getCurrentTimeInMinutes())){
settings.alarm -= 5;
} else {
settings.alarm = -1;
}
storage.writeJSON(SETTINGS_FILE, settings);
WIDGETS["widtmr"].decreaseTimer(5);
}
function feedback(){
Bangle.buzz(40, 0.6);
}
/*
* Lets start widgets, listen for btn etc.
*/

View File

@ -1,4 +1,4 @@
# Simple Chronometer Widget
# Timer Widget
This is a fork of the Chrono Widget, but implements a
simpler UI which to be able to set a timer faster with
@ -6,7 +6,17 @@ less interaction. Additionally, it exposes some functions
that can be used by other apps or clocks to easily
implement a timer. It is used e.g. by lcars or notanalog.
# Contributors
Originally from [Purple-Tentacle](https://github.com/Purple-Tentacle)
# Lib
Different functions are exposed to integrate a timer
into your own app.
Forked and adapted by [David Peer](https://github.com/peerdavid)
Example:
```Javascript
WIDGETS["widtmr"].isStarted();
WIDGETS["widtmr"].reload();
WIDGETS["widtmr"].getRemainingMinutes();
```
# Creator
[David Peer](https://github.com/peerdavid)
forked from [Purple-Tentacle](https://github.com/Purple-Tentacle)

View File

@ -1,4 +1,6 @@
/*
* TIMER WIDGET
*
* This is a fork of the Chrono Widget, but implements a
* simpler UI which to be able to set a timer faster with
* less interaction. Additionally, it exposes some functions
@ -18,7 +20,7 @@ let settings;
const screenWidth = g.getWidth();
const screenHeight = g.getHeight();
const cx = parseInt(screenWidth/2);
const cy = parseInt(screenHeight/2);
const cy = parseInt(screenHeight/2)-12;
function updateSettings() {

View File

@ -34,6 +34,18 @@
}
function updateSettings(){
var now = new Date();
const goal = new Date(now.getFullYear(), now.getMonth(), now.getDate(),
now.getHours(), now.getMinutes() + settings.minutes, now.getSeconds());
settings.goal = goal.getTime();
settings.goal = goal.getTime();
storage.writeJSON('widtmr.json', settings);
WIDGETS["widtmr"].reload();
}
/*
* Add the widgets and functions for other apps
*/
@ -92,6 +104,32 @@
}, isStarted: function(){
settings = storage.readJSON("widtmr.json",1)||{started: false};
return settings.started;
}, setStarted: function(started){
settings.started=started;
updateSettings();
}, increaseTimer: function(m){
settings.minutes += m;
updateSettings();
}, decreaseTimer: function(m){
settings.minutes -= m;
if(settings.minutes <= 0){
settings.started=false;
settings.minutes=0;
}
updateSettings();
}, getRemainingMinutes: function(){
settings = storage.readJSON("widtmr.json",1)||{started: false};
if(!settings.started){
return -1;
}
var now = new Date();
var diff = settings.goal - now;
return Math.floor(diff / (1000*60));
}
};