1
0
Fork 0

Merge branch 'master' of github.com:espruino/BangleApps

master
Gordon Williams 2022-02-04 07:59:49 +00:00
commit 3be35ef5d2
27 changed files with 359 additions and 26 deletions

View File

@ -5,3 +5,4 @@
0.04: Android icon now goes to settings page with 'find phone'
0.05: Fix handling of message actions
0.06: Option to keep messages after a disconnect (default false) (fix #1186)
0.07: Include charging state in battery updates to phone

View File

@ -50,8 +50,9 @@
};
// Battery monitor
function sendBattery() { gbSend({ t: "status", bat: E.getBattery() }); }
function sendBattery() { gbSend({ t: "status", bat: E.getBattery(), chg: Bangle.isCharging()?1:0 }); }
NRF.on("connect", () => setTimeout(sendBattery, 2000));
Bangle.on("charging", sendBattery);
if (!settings.keep)
NRF.on("disconnect", () => require("messages").clearAll()); // remove all messages on disconnect
setInterval(sendBattery, 10*60*1000);

View File

@ -2,7 +2,7 @@
"id": "android",
"name": "Android Integration",
"shortName": "Android",
"version": "0.06",
"version": "0.07",
"description": "Display notifications/music/etc sent from the Gadgetbridge app on Android. This replaces the old 'Gadgetbridge' Bangle.js widget.",
"icon": "app.png",
"tags": "tool,system,messages,notifications,gadgetbridge",

View File

@ -26,3 +26,4 @@
0.24: tag HRM power requests to allow this to work alongside other widgets/apps (fix #799)
0.25: workaround call notification
Fix inflated step number
0.26: Include charging status in battery updates to phone

View File

@ -11,11 +11,12 @@ t can be one of "info", "warn", "error"
## report battery level
```
{ "t": "status", "bat": 30, "volt": 30 }
{ "t": "status", "bat": 30, "volt": 30, "chg": 0 }
```
* bat is in range 0 to 100
* volt is optional and should be greater than 0
* chg is optional and should be either 0 or 1 to indicate the watch is charging
## find phone

View File

@ -1,7 +1,7 @@
{
"id": "gbridge",
"name": "Gadgetbridge",
"version": "0.25",
"version": "0.26",
"description": "(NOT RECOMMENDED) Displays Gadgetbridge notifications from Android. Please use the 'Android' Bangle.js app instead.",
"icon": "app.png",
"type": "widget",

View File

@ -256,7 +256,7 @@
}
function sendBattery() {
gbSend({ t: "status", bat: E.getBattery() });
gbSend({ t: "status", bat: E.getBattery(), chg: Bangle.isCharging()?1:0 });
}
// Send a summary of activity to Gadgetbridge
@ -268,6 +268,7 @@
// Battery monitor
NRF.on("connect", () => setTimeout(sendBattery, 2000));
Bangle.on("charging", sendBattery);
setInterval(sendBattery, 10*60*1000);
sendBattery();
// Activity monitor

View File

@ -10,3 +10,5 @@
After 10s of being locked, the launcher goes back to the clock screen
0.10: added in selectable font in settings including scalable vector font
0.11: Merge Bangle.js 1 and 2 launchers, again
0.12: Add an option to hide clocks from the app list (fix #1015)
Add /*LANG*/ tags for internationalisation

View File

@ -1,9 +1,9 @@
var s = require("Storage");
let fonts = g.getFonts();
var scaleval = 1;
var vectorval = 20;
var font = g.getFonts().includes("12x20") ? "12x20" : "6x8:2";
let settings = require('Storage').readJSON("launch.json", true) || {};
let settings = Object.assign({ showClocks: true }, s.readJSON("launch.json", true) || {});
if ("vectorsize" in settings) {
vectorval = parseInt(settings.vectorsize);
}
@ -14,10 +14,10 @@ if ("font" in settings){
}
else{
font = settings.font;
scaleval = (font.split('x')[1])/20;
scaleval = (font.split("x")[1])/20;
}
}
var apps = s.list(/\.info$/).map(app=>{var a=s.readJSON(app,1);return a&&{name:a.name,type:a.type,icon:a.icon,sortorder:a.sortorder,src:a.src};}).filter(app=>app && (app.type=="app" || app.type=="clock" || !app.type));
var apps = s.list(/\.info$/).map(app=>{var a=s.readJSON(app,1);return a&&{name:a.name,type:a.type,icon:a.icon,sortorder:a.sortorder,src:a.src};}).filter(app=>app && (app.type=="app" || (app.type=="clock" && settings.showClocks) || !app.type));
apps.sort((a,b)=>{
var n=(0|a.sortorder)-(0|b.sortorder);
if (n) return n; // do sortorder first
@ -54,10 +54,10 @@ E.showScroller({
var app = apps[i];
if (!app) return;
if (!app.src || require("Storage").read(app.src)===undefined) {
E.showMessage("App Source\nNot found");
E.showMessage(/*LANG*/"App Source\nNot found");
setTimeout(drawMenu, 2000);
} else {
E.showMessage("Loading...");
E.showMessage(/*LANG*/"Loading...");
load(app.src);
}
}
@ -72,7 +72,7 @@ if (process.env.HWVERSION==2) {
// 10s of inactivity goes back to clock
Bangle.setLocked(false); // unlock initially
var lockTimeout;
Bangle.on('lock', locked => {
Bangle.on("lock", locked => {
if (lockTimeout) clearTimeout(lockTimeout);
lockTimeout = undefined;
if (locked)

View File

@ -2,7 +2,7 @@
"id": "launch",
"name": "Launcher",
"shortName": "Launcher",
"version": "0.11",
"version": "0.12",
"description": "This is needed to display a menu allowing you to choose your own applications. You can replace this with a customised launcher.",
"icon": "app.png",
"type": "launch",

View File

@ -1,24 +1,30 @@
// make sure to enclose the function in parentheses
(function(back) {
let settings = require('Storage').readJSON('launch.json',1)||{};
let settings = Object.assign({ showClocks: true }, require("Storage").readJSON("launch.json", true) || {});
let fonts = g.getFonts();
function save(key, value) {
settings[key] = value;
require('Storage').write('launch.json',settings);
require("Storage").write("launch.json",settings);
}
const appMenu = {
'': {'title': 'Launcher Settings'},
'< Back': back,
'Font': {
/*LANG*/"": {"title": /*LANG*/"Launcher Settings"},
/*LANG*/"< Back": back,
/*LANG*/"Font": {
value: fonts.includes(settings.font)? fonts.indexOf(settings.font) : fonts.indexOf("12x20"),
min:0, max:fonts.length-1, step:1,wrap:true,
onchange: (m) => {save('font', fonts[m])},
onchange: (m) => {save("font", fonts[m])},
format: v => fonts[v]
},
'Vector font size': {
/*LANG*/"Vector font size": {
value: settings.vectorsize || 10,
min:10, max: 20,step:1,wrap:true,
onchange: (m) => {save('vectorsize', m)}
onchange: (m) => {save("vectorsize", m)}
},
/*LANG*/"Show clocks": {
value: settings.showClocks == true,
format: v => v ? /*LANG*/"Yes" : /*LANG*/"No",
onchange: (m) => {save("showClocks", m)}
}
};
E.showMenu(appMenu);

1
apps/lazybones/ChangeLog Normal file
View File

@ -0,0 +1 @@
0.01: first release

45
apps/lazybones/README.md Normal file
View File

@ -0,0 +1,45 @@
# Lazybones
'Warns when you have been sat still for too long.'
![](screenshot_lazybones2.png)
![](screenshot_lazybones.png)
- Spending too much time sat down is destructive to our health and fitness.
- Lazy bones checks the step count every minute and if this
has not changed after 26 minutes the buzzer will sound and a pop up
screen will show.
- It gives 3 warnings before giving up
- Standing up and walking around until the step counting threshold is reached will automatically dismiss the warning.
- When the warning is not displaying the apps is a simple clock
- The timer only goes off between the hours 9am to 9pm.
- The app is a basic proof of concept that can be used in other clocks
- A settings menu may be added in a future release
## Dedication
This is app is dedicated in memory of my friend, Huw Evans 1960-2019,
poet, writer, actor, archiologist, technical author, husband, father,
friend.
In May 2017, Huw Evans received a terminal cancer diagnosis. [Not
Long Now](https://www.youtube.com/watch?v=HD_Xysb6ZEA) is his
response to that diagnosis and the drastic shortening of his life
expectancy. Not Long Now is a one-man show, which uses poetry,
story-telling, puppetry and video to address one basic question:
given we are all going to die, how then shall we live?
## Why the Skull ?
![](lazybones.png)
The Skull is a [Memento
mori](https://en.wikipedia.org/wiki/Memento_mori) (Latin for
'remember that you [have to] die') is an artistic or symbolic trope
acting as a reminder of the inevitability of death.
Let us choose not to die from sitting too long.
Written by: [Hugh Barney](https://github.com/hughbarney) For support and discussion please post in the [Bangle JS Forum](http://forum.espruino.com/microcosms/1424/)

View File

@ -0,0 +1,204 @@
Graphics.prototype.setFontRoboto = function(scale) {
// Actual height 21 (20 - 0)
this.setFontCustom(atob("AAAAAAAAAAAAAAAAAAAAAAAAH/zA/+YAAAAAAAHwAAwAAHwAA+AAAAAAAAAAAQACDAAYbADP4B/8A/zAGYZADH4A/+A/7AHYYADCAAAAAAAQAeHgH4eBzgwMMHnhw88GGBw4wHj+AcPgAAAAAAAAAAB4AA/gAGMAAwhwGMcAfuABzgABzgAc+AOMYBhBAAMYAB/AAHwAAAAAHwD5+A/8YGPDAw8YGPzA/HYD4fAADwAB/AAOYAABAAAAHwAA4AAAAAAAAAAH/gD//B8A+cAA7AADAAAAAAAYAAbwAHHgHwf/4A/8AAAAEAABiAAGwAA8AA/AAH+AAGwAByAAEAAAAAAAMAABgAAMAABgAH/wA/+AAMAABgAAMAABgAAAAAAAIAA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ODQ4NDA0ODRMNDQ0GCQYJCQYLDAsMCwcMDAUFCwUSDAwMDAcLBwwKEAoKCgcFBw4A"), 21+(scale<<8)+(1<<16));
return this;
}
function setSmallFont() {
g.setFontRoboto();
}
const h = g.getHeight();
const w = g.getWidth();
function draw() {
if (!idle)
drawClock();
else
drawIdle();
queueDraw();
}
function drawClock() {
var date = new Date();
var timeStr = require("locale").time(date,1);
g.reset();
g.setColor(g.theme.bg);
g.fillRect(Bangle.appRect);
g.setFont('Vector', w/3);
g.setFontAlign(0, 0);
g.setColor(g.theme.fg);
g.drawString(timeStr, w/2, h/2);
setSmallFont();
g.drawString('Last Step ' + lastStepTime, w/2, 3*h/4);
}
///////////////// IDLE TIMER /////////////////////////////////////
function log_debug(o) {
//print(o);
}
// variable for controlling idle alert
let lastStep = getTime();
let lastStepTime = '??';
let warned = 0;
let idle = false;
let IDLE_MINUTES = 26;
function drawIdle() {
let mins = Math.round((getTime() - lastStep) / 60);
g.reset();
g.setColor(g.theme.bg);
g.fillRect(Bangle.appRect);
g.setColor(g.theme.fg);
setSmallFont();
g.setFontAlign(0, 0);
g.drawString('Last step was', w/2, (h/3));
g.drawString(mins + ' minutes ago', w/2, 20+(h/3));
dismissBtn.draw();
}
/////////////// BUTTON CLASS ///////////////////////////////////////////
// simple on screen button class
function BUTTON(name,x,y,w,h,c,f,tx) {
this.name = name;
this.x = x;
this.y = y;
this.w = w;
this.h = h;
this.color = c;
this.callback = f;
this.text = tx;
}
// if pressed the callback
BUTTON.prototype.check = function(x,y) {
//console.log(this.name + ":check() x=" + x + " y=" + y +"\n");
if (x>= this.x && x<= (this.x + this.w) && y>= this.y && y<= (this.y + this.h)) {
log_debug(this.name + ":callback\n");
this.callback();
return true;
}
return false;
};
BUTTON.prototype.draw = function() {
g.setColor(this.color);
g.fillRect(this.x, this.y, this.x + this.w, this.y + this.h);
g.setColor("#000"); // the icons and boxes are drawn black
setSmallFont();
g.setFontAlign(0, 0);
g.drawString(this.text, (this.x + this.w/2), (this.y + this.h/2));
g.drawRect(this.x, this.y, (this.x + this.w), (this.y + this.h));
};
function dismissPrompt() {
idle = false;
warned = false;
lastStep = getTime();
Bangle.buzz(100);
draw();
}
var dismissBtn = new BUTTON("big",0, 3*h/4 ,w, h/4, "#0ff", dismissPrompt, "Dismiss");
Bangle.on('touch', function(button, xy) {
if (idle && dismissBtn.check(xy.x, xy.y)) return;
});
// if we get a step then we are not idle
Bangle.on('step', s => {
setLastStepTime();
lastStep = getTime();
// redraw if we had been idle
if (idle == true) {
dismissPrompt();
}
idle = false;
warned = 0;
});
function setLastStepTime() {
var date = new Date();
lastStepTime = require("locale").time(date,1);
}
function checkIdle() {
let hour = (new Date()).getHours();
let active = (hour >= 9 && hour < 21);
//let active = true;
let dur = getTime() - lastStep;
if (active && dur > IDLE_MINUTES * 60) {
drawIdle();
if (warned++ < 3) {
buzzer(warned);
log_debug("checkIdle: warned=" + warned);
Bangle.setLocked(false);
}
idle = true;
} else {
idle = false;
warned = 0;
}
}
setLastStepTime();
// timeout for multi-buzzer
var buzzTimeout;
// n buzzes
function buzzer(n) {
log_debug("buzzer n=" + n);
if (n-- < 1) return;
Bangle.buzz(250);
if (buzzTimeout) clearTimeout(buzzTimeout);
buzzTimeout = setTimeout(function() {
buzzTimeout = undefined;
buzzer(n);
}, 500);
}
///////////////////////////////////////////////////////////////////////////////
// timeout used to update every minute
var drawTimeout;
const DRAW_PERIOD = 60000;
// schedule a draw for the next minute
function queueDraw() {
if (drawTimeout) clearTimeout(drawTimeout);
drawTimeout = setTimeout(function() {
drawTimeout = undefined;
checkIdle();
draw();
}, DRAW_PERIOD - (Date.now() % DRAW_PERIOD));
}
// Stop updates when LCD is off, restart when on
Bangle.on('lcdPower',on=>{
if (on) {
draw(); // draw immediately, queue redraw
} else { // stop draw timer
if (drawTimeout) clearTimeout(drawTimeout);
drawTimeout = undefined;
}
});
g.clear();
// Show launcher when middle button pressed
Bangle.setUI("clock");
Bangle.loadWidgets();
Bangle.drawWidgets();
draw();

View File

@ -0,0 +1 @@
require("heatshrink").decompress(atob("mEwgIEBn/8BIUD///4AFBh/AgfwAoM8AQlwAQMOgEB8AFBg+AgeAAoMBDQIxD4EGAodghg9EAosYAocYApcwAocMAshgBLwIFBg/4j/ghkxh0cnFwxkZxgOBmOYjcYg1gjHYAosPAofwhwFDuEGAodgAoIjBAoYvBAoUP/Of+AFBg/j4/gAoLGBYgNgU4IjBU4MBwEOuADBgHwhuwh5nBvEP+EeAoMcg/gnBzCWQQCBggCBkACBZgQqBAo0HAQLsCIAJCCAAP//6eDn/8AYI"))

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -0,0 +1,16 @@
{
"id": "lazybones",
"name": "Lazybones",
"version": "0.01",
"description": "Idleness timer, warns when you have been sat too long",
"icon": "lazybones.png",
"screenshots": [{"url":"screenshot_lazybones.png"}],
"readme": "README.md",
"type": "clock",
"tags": "clock",
"supports": ["BANGLEJS","BANGLEJS2"],
"storage": [
{"name":"lazybones.app.js","url":"lazybones.app.js"},
{"name":"lazybones.img","url":"lazybones.icon.js","evaluate":true}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

@ -12,3 +12,4 @@
Record all HRM events
Move recording for CoreTemp to its own app
0.08: Memory usage improvements for recorder app itself
0.09: Show correct number for log in overwrite prompt

View File

@ -2,7 +2,7 @@
"id": "recorder",
"name": "Recorder",
"shortName": "Recorder",
"version": "0.08",
"version": "0.09",
"description": "Record GPS position, heart rate and more in the background, then download to your PC.",
"icon": "app.png",
"tags": "tool,outdoors,gps,widget",

View File

@ -228,7 +228,7 @@
},setRecording:function(isOn) {
var settings = loadSettings();
if (isOn && !settings.recording && require("Storage").list(settings.file).length)
return E.showPrompt("Overwrite\nLog 0?",{title:"Recorder",buttons:{Yes:"yes",No:"no"}}).then(selection=>{
return E.showPrompt("Overwrite\nLog " + settings.file.match(/\d+/)[0] + "?",{title:"Recorder",buttons:{Yes:"yes",No:"no"}}).then(selection=>{
if (selection=="no") return false; // just cancel
if (selection=="yes") require("Storage").open(settings.file,"r").erase();
// TODO: Add 'new file' option

View File

@ -3,3 +3,5 @@
The simplest working clock, acts as a tutorial piece
![](screenshot.jpg)
Written by: [Hugh Barney](https://github.com/hughbarney) For support and discussion please post in the [Bangle JS Forum](http://forum.espruino.com/microcosms/1424/)

View File

@ -1,2 +1,3 @@
0.01: New App!
0.02: Change start sequence to BTN1/3/1/3 to avoid accidental turning on (fix #342)
0.03: Add Color Changing Settings

View File

@ -1,6 +1,16 @@
const SETTINGS_FILE = "torch.json";
let settings;
function loadSettings() {
settings = require("Storage").readJSON(SETTINGS_FILE,1)|| {'bg': '#FFFFFF', 'color': 'White'};
}
loadSettings();
Bangle.setLCDPower(1);
Bangle.setLCDTimeout(0);
g.reset();
g.setColor(settings.bg);
g.fillRect(0,0,g.getWidth(),g.getHeight());
// Any button turns off
setWatch(()=>load(), BTN1);

View File

@ -2,14 +2,15 @@
"id": "torch",
"name": "Torch",
"shortName": "Torch",
"version": "0.02",
"description": "Turns screen white to help you see in the dark. Select from the launcher or press BTN1,BTN3,BTN1,BTN3 quickly to start when in any app that shows widgets",
"version": "0.03",
"description": "Turns screen white to help you see in the dark. Select from the launcher or press BTN1,BTN3,BTN1,BTN3 quickly to start when in any app that shows widgets. You can also set the color through the apps settings menu.",
"icon": "app.png",
"tags": "tool,torch",
"supports": ["BANGLEJS"],
"storage": [
{"name":"torch.app.js","url":"app.js"},
{"name":"torch.wid.js","url":"widget.js"},
{"name":"torch.img","url":"app-icon.js","evaluate":true}
{"name":"torch.img","url":"app-icon.js","evaluate":true},
{"name":"torch.settings.js","url":"settings.js"}
]
}

38
apps/torch/settings.js Normal file
View File

@ -0,0 +1,38 @@
(function(back) {
const SETTINGS_FILE = "torch.json";
// initialize with default settings...
let s = {'bg': '#FFFFFF', 'color': 'White'}
// ...and overwrite them with any saved values
// This way saved values are preserved if a new version adds more settings
const storage = require('Storage')
let settings = storage.readJSON(SETTINGS_FILE, 1) || s;
const saved = settings || {}
for (const key in saved) {
s[key] = saved[key]
}
function save() {
settings = s
storage.write(SETTINGS_FILE, settings)
}
var color_options = ['Green','Orange','Cyan','Purple','Red','Blue','Yellow','White'];
var bg_code = ['#0f0','#FFA500','#0ff','#f0f','#f00','#00f','#ffef00','#FFFFFF'];
E.showMenu({
'': { 'title': 'Torch' },
'< Back': back,
'Colour': {
value: 0 | color_options.indexOf(s.color),
min: 0, max: 7,
format: v => color_options[v],
onchange: v => {
s.color = color_options[v];
s.bg = bg_code[v];
save();
},
}
});
})