Update to use Bangle.setUI instead of setWatch

pull/765/head
Gordon Williams 2021-06-24 13:12:59 +01:00
parent 0abc0ae213
commit 03ee6aea83
22 changed files with 568 additions and 555 deletions

View File

@ -4,7 +4,7 @@
"tags": "tool,system,b2",
"type":"bootloader",
"icon": "bootloader.png",
"version":"0.26",
"version":"0.27",
"description": "This is needed by Bangle.js to automatically load the clock, menu, widgets and settings",
"storage": [
{"name":".boot0","url":"boot0.js"},
@ -1030,7 +1030,7 @@
{ "id": "bclock",
"name": "Binary Clock",
"icon": "clock-binary.png",
"version":"0.02",
"version":"0.03",
"description": "A simple binary clock watch face",
"tags": "clock",
"type":"clock",
@ -1106,9 +1106,9 @@
"name": "Large Digit Blob Clock",
"shortName" : "Blob Clock",
"icon": "clock-blob.png",
"version":"0.05",
"version":"0.06",
"description": "A clock with big digits",
"tags": "clock",
"tags": "clock,b2",
"type":"clock",
"allow_emulator":true,
"storage": [
@ -1155,7 +1155,7 @@
{ "id": "berlinc",
"name": "Berlin Clock",
"icon": "berlin-clock.png",
"version":"0.03",
"version":"0.04",
"description": "Berlin Clock (see https://en.wikipedia.org/wiki/Mengenlehreuhr)",
"tags": "clock",
"type":"clock",
@ -1313,7 +1313,7 @@
{ "id": "barclock",
"name": "Bar Clock",
"icon": "clock-bar.png",
"version":"0.06",
"version":"0.07",
"description": "A simple digital clock showing seconds as a bar",
"tags": "clock",
"type":"clock",
@ -1572,7 +1572,7 @@
"name": "Numerals Clock",
"shortName": "Numerals Clock",
"icon": "numerals.png",
"version":"0.08",
"version":"0.09",
"description": "A simple big numerals clock",
"tags": "numerals,clock",
"type":"clock",
@ -1986,7 +1986,7 @@
"id": "beebclock",
"name": "Beeb Clock",
"icon": "beebclock.png",
"version":"0.03",
"version":"0.04",
"description": "Clock face that may be coincidentally familiar to BBC viewers",
"tags": "clock",
"type": "clock",
@ -2114,7 +2114,7 @@
"name": "Binary Clock",
"shortName":"Binary Clock",
"icon": "app.png",
"version":"0.02",
"version":"0.03",
"description": "A binary clock with hours and minutes. BTN1 toggles a digital clock.",
"tags": "clock,binary",
"type": "clock",
@ -2755,7 +2755,7 @@
{ "id": "astral",
"name": "Astral Clock",
"icon": "app-icon.png",
"version":"0.02",
"version":"0.03",
"readme": "README.md",
"description": "Clock that calculates and displays Alt Az positions of all planets, Sun as well as several other astronomy targets (customizable) and current Moon phase. Coordinates are calculated by GPS & time and onscreen compass assists orienting. See Readme before using.",
"tags": "clock",
@ -3223,7 +3223,7 @@
"name": "Bat Clock",
"shortName":"Bat Clock",
"icon": "bat-clock.png",
"version":"0.01",
"version":"0.02",
"description": "Morphing Clock, with an awesome \"The Dark Knight\" themed logo.",
"tags": "clock",
"type": "clock",
@ -3278,7 +3278,7 @@
{ "id": "mysticdock",
"name": "Mystic Dock",
"icon": "mystic-dock.png",
"version":"1.0",
"version":"1.00",
"description": "A retro-inspired dockface that displays the current time and battery charge while plugged in, and which features an interactive mode that shows the time, date, and a rotating data display line.",
"tags": "dock",
"type":"dock",

View File

@ -1,2 +1,3 @@
0.01: Create astral clock app
0.02: Fixed Whirlpool galaxy RA/DA, larger compass display, fixed moonphase overlapping battery widget
0.03: Update to use Bangle.setUI instead of setWatch

View File

@ -796,10 +796,11 @@ Bangle.on('lcdPower', on => {
Bangle.setCompassPower(1);
Bangle.setGPSPower(1);
// Buttons
setWatch(Bangle.showLauncher, BTN2, { repeat: false, edge: "falling" });
// Show launcher when button pressed
Bangle.setClockMode();
setWatch(function () {
Bangle.setUI("clockupdown", btn => {
if (btn==0) {
if (!processing) {
if (!modeswitch) {
modeswitch = true;
@ -809,12 +810,11 @@ setWatch(function () {
else
modeswitch = false;
}
}, BTN3, { repeat: true });
setWatch(function () {
} else {
if (!processing)
ready_to_compute = true;
}, BTN1, { repeat: true });
}
});
setWatch(function () {
if (!astral_settings.astral_default) {

View File

@ -4,3 +4,4 @@
0.04: Small bugfix
0.05: Clock does not start if app Languages is not installed
0.06: Improve accuracy
0.07: Update to use Bangle.setUI instead of setWatch

View File

@ -2,7 +2,6 @@
/**
* A simple digital clock showing seconds as a bar
**/
{
// Check settings for what type our clock should be
const is12Hour = (require('Storage').readJSON('setting.json', 1) || {})['12hour']
let locale = require('locale')
@ -157,8 +156,8 @@
g.clear()
Bangle.loadWidgets()
Bangle.drawWidgets()
// Show launcher when middle button pressed
setWatch(Bangle.showLauncher, BTN2, {repeat: false, edge: 'falling'})
// Show launcher when button pressed
Bangle.setUI("clock");
Bangle.on('lcdPower', function (on) {
if (on) {
@ -168,4 +167,3 @@
}
})
start()
}

View File

@ -1 +1,2 @@
0.01: App Created!
0.02: Update to use Bangle.setUI instead of setWatch

View File

@ -256,8 +256,5 @@ Bangle.drawWidgets();
timeInterval = setInterval(showTime, 1000);
showTime();
// Show launcher when middle button pressed
setWatch(Bangle.showLauncher, BTN2, {
repeat: false,
edge: "falling"
});
// Show launcher when button pressed
Bangle.setUI("clock");

View File

@ -1 +1,2 @@
0.02: Modified for use with new bootloader and firmware
0.03: Update to use Bangle.setUI instead of setWatch

View File

@ -105,5 +105,5 @@ Bangle.loadWidgets();
Bangle.drawWidgets();
setInterval(() => { drawClock(); }, 1000);
drawClock();
// Show launcher when middle button pressed
setWatch(Bangle.showLauncher, BTN2, {repeat:false,edge:"falling"});
// Show launcher when button pressed
Bangle.setUI("clock");

View File

@ -1,3 +1,4 @@
0.01: Initial commit. Not very efficient, and widgets not working for some reason.
0.02: Fixes; widget support
0.03: Remove hardcoded hour buzz (you can install widchime if you miss it)
0.04: Update to use Bangle.setUI instead of setWatch

View File

@ -51,8 +51,6 @@ Graphics.prototype.drawRotLine = function (sina, cosa, cx, cy, r1, r2) {
);
};
(function(g) {
// Display modes
//
// 0: full-screen
@ -277,16 +275,11 @@ Graphics.prototype.drawRotLine = function (sina, cosa, cx, cy, r1, r2) {
};
const setButtons = () => {
const opts = { repeat: true, edge:'rising', debounce:30};
// BTN1: enable/disable second hand
setWatch(changeSeconds, BTN1, opts);
// BTN2: return to launcher
setWatch(Bangle.showLauncher, BTN2, { repeat:false, edge:'falling' });
// BTN3: change display mode
setWatch(function () { ++mode; setMode(); drawAll(true); }, BTN3, opts);
// Show launcher when button pressed
Bangle.setUI("clockupdown", btn=> {
if (btn==0) changeSeconds();
if (btn==1) { ++mode; setMode(); drawAll(true); }
});
};
// Load display parameters based on `mode`
@ -387,5 +380,3 @@ Graphics.prototype.drawRotLine = function (sina, cosa, cx, cy, r1, r2) {
clearTimeout();
}
});
})(g);

View File

@ -1,2 +1,3 @@
0.02: Modified for use with new bootloader and firmware
0.03: Shrinked size to avoid cut-off edges on the physical device. BTN3: show date. BTN1: show time in decimal.
0.04: Update to use Bangle.setUI instead of setWatch

View File

@ -100,9 +100,11 @@ g.clear();
Bangle.loadWidgets();
Bangle.drawWidgets();
drawBerlinClock();
if (BTN3) {
// Toggle date display, when BTN3 is pressed
setWatch(toggleTime,BTN1, { repeat : true, edge: "falling"});
// Toggle date display, when BTN3 is pressed
setWatch(toggleDate,BTN3, { repeat : true, edge: "falling"});
// Show launcher when middle button pressed
setWatch(Bangle.showLauncher, BTN2, { repeat: false, edge: "falling" });
}
// Show launcher when button pressed
Bangle.setUI("clock");

View File

@ -1,2 +1,3 @@
0.01: New App!
0.02: Fixed bug where screen didn't clear so incorrect time displayed.
0.03: Update to use Bangle.setUI instead of setWatch

View File

@ -167,12 +167,12 @@ Bangle.on('lcdPower',on=>{
// Load widgets
Bangle.loadWidgets();
Bangle.drawWidgets();
// Show launcher when middle button pressed
setWatch(Bangle.showLauncher, BTN2, { repeat: false, edge: "falling" });
setWatch(function() {
// Show launcher when button pressed
Bangle.setUI("clockupdown", btn=>{
if (btn!=1) return;
if(displayTime == 0){
displayTime = 1;
} else{
displayTime = 0;
}
}, BTN, {edge:"rising", debounce:50, repeat:true});
});

View File

@ -4,3 +4,4 @@
0.03: Modified for use with new bootloader and firmware
0.04: Modified to account for changes in the behavior of Graphics.fillPoly
0.05: Slight increase to draw speed after LCD on
0.06: Update to use Bangle.setUI instead of setWatch, allow themes and different size screens

View File

@ -1,4 +1,6 @@
const buf = Graphics.createArrayBuffer(144,200,1,{msb:true});
let big = g.getHeight() > 200;
const buf = Graphics.createArrayBuffer(big ? 144 : 120, big ? 180 : 150,1,{msb:true});
// TODO: convert these to Polys -> much faster and cleaner!
const NUMBERS = [
[1,1,1,1,3,1,1,0,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1],//0
[0,1,1,1,3,0,0,1,1,1,0,0,1,1,1,0,0,1,1,1,0,0,1,1,1],//1
@ -14,8 +16,10 @@ const NUMBERS = [
let intervalRef = null;
let digits = [-1,-1,-1,-1,-1,-1];
function flip() {
g.setColor(1,1,1);
g.drawImage({width:buf.getWidth(),height:buf.getHeight(),buffer:buf.buffer},55,26);
g.reset();
g.drawImage({width:buf.getWidth(),height:buf.getHeight(),buffer:buf.buffer},
(g.getWidth() - buf.getWidth())/2,
26 + (g.getHeight() - (buf.getHeight()+24))/2);
}
function drawPixel(ox,oy,x,y,r,p) {
let x1 = ox+x*(r*2);
@ -53,26 +57,31 @@ function redraw() {
let newDigits = [Math.floor(hours/10),hours%10,Math.floor(mins/10),mins%10,Math.floor(secs/10),secs%10];
let s = big?6:5; // size of main digits
let y2 = big?72:55;
let y3 = big?144:110;
for (var p = 0;p<25;p++) {
var px = p%5;
var py = Math.floor(p/5);
if (digits[0] === -1 || NUMBERS[newDigits[0]][p] !== NUMBERS[digits[0]][p] ) {
drawPixel(0,20,px,py,6,NUMBERS[newDigits[0]][p]);
drawPixel(0,0,px,py,s,NUMBERS[newDigits[0]][p]);
}
if (digits[1] === -1 || NUMBERS[newDigits[1]][p] !== NUMBERS[digits[1]][p] ) {
drawPixel(78,20,px,py,6,NUMBERS[newDigits[1]][p]);
drawPixel(13*s,0,px,py,s,NUMBERS[newDigits[1]][p]);
}
if (digits[2] === -1 || NUMBERS[newDigits[2]][p] !== NUMBERS[digits[2]][p] ) {
drawPixel(0,92,px,py,6,NUMBERS[newDigits[2]][p]);
drawPixel(0,y2,px,py,s,NUMBERS[newDigits[2]][p]);
}
if (digits[3] === -1 || NUMBERS[newDigits[3]][p] !== NUMBERS[digits[3]][p] ) {
drawPixel(78,92,px,py,6,NUMBERS[newDigits[3]][p]);
drawPixel(13*s,y2,px,py,s,NUMBERS[newDigits[3]][p]);
}
if (digits[4] === -1 || NUMBERS[newDigits[4]][p] !== NUMBERS[digits[4]][p] ) {
drawPixel(69,164,px,py,3,NUMBERS[newDigits[4]][p]);
drawPixel(17*s - 3*12,y3,px,py,3,NUMBERS[newDigits[4]][p]);
}
if (digits[5] === -1 || NUMBERS[newDigits[5]][p] !== NUMBERS[digits[5]][p] ) {
drawPixel(108,164,px,py,3,NUMBERS[newDigits[5]][p]);
drawPixel(17*s,y3,px,py,3,NUMBERS[newDigits[5]][p]);
}
}
digits = newDigits;
@ -99,5 +108,5 @@ Bangle.on('lcdPower',function(on) {
clearTimers();
}
});
// Show launcher when middle button pressed
setWatch(Bangle.showLauncher, BTN2, {repeat:false,edge:"falling"});
// Show launcher when button pressed
Bangle.setUI("clock");

View File

@ -25,3 +25,4 @@
0.24: Add Bangle.setUI polyfill
0.25: Fix error in 'no clock app' message
0.26: Remove buzz in setUI polyfill (#750)
0.27: Update polyfill for most recent changes

View File

@ -3,6 +3,7 @@ recalculates, but this avoids us doing a whole bunch of reconfiguration most
of the time. */
E.showMessage("Updating boot0...");
var s = require('Storage').readJSON('setting.json',1)||{};
var isB2 = process.env.HWVERSION; // Is Bangle.js 2
var boot = "";
var CRC = E.CRC32(require('Storage').read('setting.json'))+E.CRC32(require('Storage').list(/\.boot\.js/));
boot += `if (E.CRC32(require('Storage').read('setting.json'))+E.CRC32(require('Storage').list(/\.boot\.js/))!=${CRC}) { eval(require('Storage').read('bootupdate.js'));} else {\n`;
@ -81,9 +82,9 @@ if (s.passkey!==undefined && s.passkey.length==6) boot+=`NRF.setSecurity({passke
if (s.whitelist) boot+=`NRF.on('connect', function(addr) { if (!(require('Storage').readJSON('setting.json',1)||{}).whitelist.includes(addr)) NRF.disconnect(); });\n`;
// Pre-2v10 firmwares without a theme/setUI
if (!g.theme) {
boot += `g.theme={fg:-1,bg:0,fg2:-1,bg2:7,fgH:-1,bgH:0x02F7};\n`;
boot += `g.theme={fg:-1,bg:0,fg2:-1,bg2:7,fgH:-1,bgH:0x02F7,dark:true};\n`;
}
if (!Bangle.setUI) {
if (!Bangle.setUI) { // assume this is just for F18 - Q3 should already have it
boot += `Bangle.setUI=function(mode, cb) {
if (Bangle.btnWatches) {
Bangle.btnWatches.forEach(clearWatch);
@ -114,6 +115,18 @@ else if (mode=="updown") {
Bangle.on("swipe", Bangle.swipeHandler);
Bangle.touchHandler = d => {cb();};
Bangle.on("touch", Bangle.touchHandler);
} else if (mode=="clock") {
Bangle.CLOCK=1;
Bangle.btnWatches = [
setWatch(Bangle.showLauncher, BTN2, {repeat:1,edge:"falling"})
];
} else if (mode=="clockupdown") {
Bangle.CLOCK=1;
Bangle.btnWatches = [
setWatch(function() { cb(-1); }, BTN1, {repeat:1}),
setWatch(function() { cb(1); }, BTN3, {repeat:1}),
setWatch(Bangle.showLauncher, BTN2, {repeat:1,edge:"falling"})
];
} else
throw new Error("Unknown UI mode");
};\n`;

View File

@ -6,3 +6,4 @@
0.06: Improve rendering of Numeral 1, fix issue with alarms not showing up
0.07: Add date on touch and some improvements (see settings and readme)
0.08: Add new draw styles, tidy up draw functionality
0.09: Tweak for faster rendering

View File

@ -22,16 +22,17 @@ var _12hour = (require("Storage").readJSON("setting.json",1)||{})["12hour"]||fal
var _hCol = ["#ff5555","#ffff00","#FF9901","#2F00FF"];
var _mCol = ["#55ff55","#ffffff","#00EFEF","#FFBF00"];
var _rCol = 0;
var scale = g.getWidth()/240;
var interval = 0;
const REFRESH_RATE = 10E3;
var drawFuncs = {
fill : function(poly,isHole){
if (isHole) g.setColor(0);
if (isHole) g.setColor(g.theme.bg);
g.fillPoly(poly,true);
},
framefill : function(poly,isHole){
var c = g.getColor();
g.setColor(isHole ? 0 : ((c&0b1111011111011110)>>1)); // 16 bit half bright
g.setColor(isHole ? g.theme.bg : ((c&0b1111011111011110)>>1)); // 16 bit half bright
g.fillPoly(poly,true);
g.setColor(c);
g.drawPoly(poly,true);
@ -48,7 +49,8 @@ var drawFuncs = {
};
function translate(tx, ty, p){
return p.map((x, i)=> x+((i&1)?ty:tx));
//return p.map((x, i)=> x+((i&1)?ty:tx));
return g.transformVertices(p, {x:tx,y:ty,scale:scale});
}
@ -57,15 +59,14 @@ if (!settings) {
settings = {
color:0,
drawMode:"fill",
menuButton:24,
showDate:0
};
}
function drawNum(num,col,x,y,func,funcName){
g.setColor(col);
let tx = x*100+25;
let ty = y*104+32;
let tx = (x*100+25) * scale;
let ty = (y*104+32) * scale;
for (let i=0;i<numerals[num].length;i++){
g.setColor(col);
func(translate(tx,ty,numerals[num][i]), i>0);
@ -98,9 +99,9 @@ function setUpdateInt(set){
if (set) interval=setInterval(draw, REFRESH_RATE);
}
Bangle.setLCDMode();
g.reset().clear();
setWatch(Bangle.showLauncher, settings.menuButton, {repeat:false,edge:"falling"});
g.clear(1);
// Show launcher when button pressed
Bangle.setUI("clock");
if (settings.color>0) _rCol=settings.color-1;
setUpdateInt(1);
draw();

View File

@ -6,14 +6,12 @@
numeralsSettings = {
color:0,
drawMode:"fill",
menuButton:22,
showDate:0
};
updateSettings();
}
let numeralsSettings = storage.readJSON('numerals.json',1);
if (!numeralsSettings) resetSettings();
if (numeralsSettings.menuButton===undefined) numeralsSettings.menuButton=22;
let dm = ["fill","frame","framefill","thickframe"];
let col = ["rnd","r/g","y/w","o/c","b/y"];
let btn = [[24,"BTN1"],[22,"BTN2"],[23,"BTN3"],[11,"BTN4"],[16,"BTN5"]];
@ -31,12 +29,6 @@
format: v=>dm[v],
onchange: v=> { numeralsSettings.drawMode=dm[v]; updateSettings();}
},
"Menu button": {
value: btn.findIndex(e=>e[0]==numeralsSettings.menuButton),
min:0,max:btn.length-1,
format: v=>btn[v][1],
onchange: v=> { numeralsSettings.menuButton=btn[v][0]; updateSettings();}
},
"Date on touch": {
value: 0|numeralsSettings.showDate,
min:0,max:1,