Merge branch 'espruino:master' into master

pull/760/head
Weiming 2021-06-11 19:20:33 -04:00
commit 19c456c141
19 changed files with 125 additions and 40 deletions

View File

@ -4,7 +4,7 @@
"tags": "tool,system",
"type":"bootloader",
"icon": "bootloader.png",
"version":"0.25",
"version":"0.26",
"description": "This is needed by Bangle.js to automatically load the clock, menu, widgets and settings",
"storage": [
{"name":".boot0","url":"boot0.js"},
@ -362,13 +362,17 @@
{ "id": "trex",
"name": "T-Rex",
"icon": "trex.png",
"version":"0.02",
"version":"0.03",
"description": "T-Rex game in the style of Chrome's offline game",
"tags": "game",
"allow_emulator":true,
"storage": [
{"name":"trex.app.js","url":"trex.js"},
{"name":"trex.img","url":"trex-icon.js","evaluate":true}
{"name":"trex.img","url":"trex-icon.js","evaluate":true},
{"name":"trex.settings.js","url":"settings.js"}
],
"data": [
{"name":"trex.score", "storageFile": true}
]
},
{ "id": "astroid",
@ -1308,10 +1312,11 @@
{ "id": "barclock",
"name": "Bar Clock",
"icon": "clock-bar.png",
"version":"0.05",
"version":"0.06",
"description": "A simple digital clock showing seconds as a bar",
"tags": "clock",
"type":"clock",
"readme": "README.md",
"allow_emulator":true,
"storage": [
{"name":"barclock.app.js","url":"clock-bar.js"},
@ -1458,7 +1463,7 @@
"name": "OpenStreetMap",
"shortName":"OpenStMap",
"icon": "app.png",
"version":"0.05",
"version":"0.06",
"description": "[BETA] Loads map tiles from OpenStreetMap onto your Bangle.js and displays a map of where you are",
"tags": "outdoors,gps",
"custom": "custom.html",
@ -3208,7 +3213,6 @@
"readme": "README.md",
"description": "An Omnitrix Showpiece",
"tags": "game",
"readme": "README.md",
"storage": [
{"name":"omnitrix.app.js","url":"omnitrix.app.js"},
{"name":"omnitrix.img","url":"omnitrix.icon.js","evaluate":true}

View File

@ -3,3 +3,4 @@
0.03: Fix dates drawing over each other at midnight
0.04: Small bugfix
0.05: Clock does not start if app Languages is not installed
0.06: Improve accuracy

6
apps/barclock/README.md Normal file
View File

@ -0,0 +1,6 @@
# Bar Clock
A simple digital clock showing seconds as a horizontal bar.
| 24hr style | 12hr style |
| --- | --- |
| ![24-hour bar clock](screenshot.png) | ![12-hour bar clock with meridian](screenshot_pm.png) |

View File

@ -124,7 +124,7 @@
g.fillRect(0, timeTop, screen.width, screen.height)
}
let lastSeconds
let lastSeconds, tTick
const tick = function () {
g.reset()
const date = new Date()
@ -136,20 +136,20 @@
}
// the bar only gets larger, so drawing on top of the previous one is fine
drawBar(date)
lastSeconds = seconds
// schedule next update
const millis = date.getMilliseconds()
tTick = setTimeout(tick, 1000-millis)
}
let iTick
const start = function () {
lastSeconds = 99 // force redraw
tick()
iTick = setInterval(tick, 1000)
}
const stop = function () {
if (iTick) {
clearInterval(iTick)
iTick = undefined
if (tTick) {
clearTimeout(tTick)
tTick = undefined
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@ -24,3 +24,4 @@
0.23: Move to a precalculated .boot0 file which should speed up load time
0.24: Add Bangle.setUI polyfill
0.25: Fix error in 'no clock app' message
0.26: Remove buzz in setUI polyfill (#750)

View File

@ -97,25 +97,22 @@ if (Bangle.touchandler) {
Bangle.removeListener("touch", Bangle.touchHandler);
delete Bangle.touchHandler;
}
function b() {
try{Bangle.buzz(20);}catch(e){}
}
if (!mode) return;
else if (mode=="updown") {
Bangle.btnWatches = [
setWatch(function() { b();cb(-1); }, BTN1, {repeat:1}),
setWatch(function() { b();cb(1); }, BTN3, {repeat:1}),
setWatch(function() { b();cb(); }, BTN2, {repeat:1})
setWatch(function() { cb(-1); }, BTN1, {repeat:1}),
setWatch(function() { cb(1); }, BTN3, {repeat:1}),
setWatch(function() { cb(); }, BTN2, {repeat:1})
];
} else if (mode=="leftright") {
Bangle.btnWatches = [
setWatch(function() { b();cb(-1); }, BTN1, {repeat:1}),
setWatch(function() { b();cb(1); }, BTN3, {repeat:1}),
setWatch(function() { b();cb(); }, BTN2, {repeat:1})
setWatch(function() { cb(-1); }, BTN1, {repeat:1}),
setWatch(function() { cb(1); }, BTN3, {repeat:1}),
setWatch(function() { cb(); }, BTN2, {repeat:1})
];
Bangle.swipeHandler = d => {b();cb(d);};
Bangle.swipeHandler = d => {cb(d);};
Bangle.on("swipe", Bangle.swipeHandler);
Bangle.touchHandler = d => {b();cb();};
Bangle.touchHandler = d => {cb();};
Bangle.on("touch", Bangle.touchHandler);
} else
throw new Error("Unknown UI mode");

View File

@ -2,6 +2,9 @@
A configurable, low power GPS widget that runs in the background.
NOTE: This app has been superceded by [gpssetup](https://github.com/espruino/BangleApps/blob/master/apps/gpssetup/README.md)
## Goals
To develop a low power GPS widget that runs in the background and to

View File

@ -3,3 +3,4 @@
0.03: Show widgets (mainly so we can use the GPS recorder widget)
0.04: Move map rendering to a module (fix #396)
0.05: Show currently active gpsrec GPS trace (fix #395)
0.06: Add support for scrolling, option for 3 bit maps

View File

@ -34,7 +34,7 @@ Bangle.on('GPS',function(f) {
g.drawString(txt,120,y1 + 4);
drawMarker();
});
Bangle.setGPSPower(1);
Bangle.setGPSPower(1, "app");
if (HASWIDGETS) {
Bangle.loadWidgets();
@ -55,3 +55,17 @@ setWatch(function() {
m.lon = fix.lon;
redraw();
}, BTN2, {repeat:true});
var hasScrolled = false;
E.on('touch',e=>{
if (e.b) {
g.setClipRect(0,y1,g.getWidth()-1,y2);
g.scroll(e.dx,e.dy);
m.scroll(e.dx,e.dy);
g.setClipRect(0,0,g.getWidth()-1,g.getHeight()-1);
hasScrolled = true;
} else if (hasScrolled) {
hasScrolled = false;
redraw();
}
});

View File

@ -32,6 +32,7 @@
<div id="map">
</div>
<div id="controls">
<div style="display:inline-block;text-align:center;vertical-align: top;"> <input type="checkbox" id="3bit"></input><br/><span>3 bit</span></div>
<button id="getmap" class="btn btn-primary">Get Map</button><br/>
<canvas id="maptiles" style="display:none"></canvas>
<div id="uploadbuttons" style="display:none"><button id="upload" class="btn btn-primary">Upload</button>
@ -49,6 +50,7 @@
TODO:
* Allow a larger tilesize. Currently we use 'evaluate:true' which means we can only send 64x64x8 bit, but with some tweaking we could send 128x128 which would reduce the number of files and make things a bit snappier
* Could maybe use palettised output?
* Could potentially use a custom 16 color palette?
* Allow user to choose size of map area to be uploaded (small/med/large)
@ -75,6 +77,15 @@ TODO:
function tilesLoaded(ctx, width, height) {
var options = { compression:true, mode:"web", output:"string"};
if (document.getElementById("3bit").checked) {
options = {
compression:true,
//mode:"web",
mode:"3bit", brightness:-64,
output:"string"
};
}
console.log("Compression options", options);
var w = Math.round(width / TILESIZE);
var h = Math.round(height / TILESIZE);
var tiles = [];

View File

@ -45,15 +45,12 @@ exports.draw = function() {
for (var y=oy,tty=ty;y<g.getHeight();y+=map.tilesize,tty++) {
var img = s.read("openstmap-"+ttx+"-"+tty+".img");
if (img) g.drawImage(img,x,y);
else {
g.clearRect(x,y,x+map.tilesize-1,y+map.tilesize-1);
g.drawLine(x,y,x+map.tilesize-1,y+map.tilesize-1);
g.drawLine(x,y+map.tilesize-1,x+map.tilesize-1,y);
}
else g.clearRect(x,y,x+map.tilesize-1,y+map.tilesize-1).drawLine(x,y,x+map.tilesize-1,y+map.tilesize-1).drawLine(x,y+map.tilesize-1,x+map.tilesize-1,y);
}
}
};
/// Convert lat/lon to pixels on the screen
exports.latLonToXY = function(lat, lon) {
var p = Bangle.project({lat:m.lat,lon:m.lon});
var q = Bangle.project({lat:lat, lon:lon});
@ -64,3 +61,11 @@ exports.latLonToXY = function(lat, lon) {
y : cy - (q.y-p.y)*4096/map.scale
};
};
/// Given an amount to scroll in pixels on the screen, adjust the lat/lon of the map to match
exports.scroll = function(x,y) {
var a = Bangle.project({lat:this.lat,lon:this.lon});
var b = Bangle.project({lat:this.lat+1,lon:this.lon+1});
this.lon += x * this.map.scale / ((a.x-b.x) * 4096);
this.lat -= y * this.map.scale / ((a.y-b.y) * 4096);
};

View File

@ -1 +1,2 @@
0.02: Add "ram" keyword to allow 2v06 Espruino builds to cache function that needs to be fast
0.03: Enabled BTN2 and BTN3, added highscore (score is saved to storage and can be reset in app settings menu)

19
apps/trex/settings.js Normal file
View File

@ -0,0 +1,19 @@
(function (back) {
const menu = {
'': { 'title': 'T-Rex' },
'< Back': back,
'Reset Highscore': () => {
E.showPrompt('Reset Highscore?').then((v) => {
let delay = 50;
if (v) {
delay = 500;
E.showMessage('Resetting');
var f = require('Storage').open('trex.score', 'w');
f.write('0\n');
}
setTimeout(() => E.showMenu(menu), delay);
});
}
};
E.showMenu(menu);
});

View File

@ -1,3 +1,13 @@
function loadHighScore() {
var f = require("Storage").open("trex.score", "r");
return f.readLine() || 0;
}
function saveHighScore(score) {
var f = require("Storage").open("trex.score", "w");
f.write(score + "\n");
}
greal = g;
g.clear();
g = Graphics.createArrayBuffer(120,64,1,{msb:true});
@ -9,8 +19,8 @@ g.flip = function() {
},0,(240-128)/2,{scale:2});
};
var W = g.getWidth();
var BTNL = BTN4;
var BTNR = BTN5;
var BTNL = BTN2;
var BTNR = BTN3;
var BTNU = BTN1;
// Images can be added like this in Espruino v2.00
@ -134,6 +144,8 @@ var IMG = {
IMG.rex.forEach(i=>i.transparent=0);
IMG.cacti.forEach(i=>i.transparent=0);
var cacti, rex, frame;
// displayedHighScore is not updated before restart
var highScore = loadHighScore(), displayedHighScore;
function gameStart() {
rex = {
@ -152,6 +164,7 @@ function gameStart() {
}
IMG.ground = { width: 128, height: 3, bpp : 1, buffer : random.buffer };
frame = 0;
displayedHighScore = highScore;
setInterval(onFrame, 50);
}
function gameStop() {
@ -159,8 +172,13 @@ function gameStop() {
rex.img = 2; // dead
clearInterval();
setTimeout(function() {
// putting saveHighScore here to not delay the frame drawing
if (rex.score > highScore) {
highScore = rex.score;
saveHighScore(highScore);
}
setWatch(gameStart, BTNU, {repeat:0,debounce:50,edge:"rising"});
}, 1000);
}, 800);
setTimeout(onFrame, 10);
}
@ -190,6 +208,9 @@ function onFrame() {
while (cacti.length && cacti[0].x<0) cacti.shift();
} else {
g.drawString("Game Over!",(W-g.stringWidth("Game Over!"))/2,20);
if (rex.score > highScore) {
g.drawString("New Record!",(W-g.stringWidth("New Record!"))/2,28);
}
}
g.drawLine(0,60,239,60);
cacti.forEach(c=>g.drawImage(IMG.cacti[c.img],c.x,60-IMG.cacti[c.img].height));
@ -213,7 +234,8 @@ function onFrame() {
var groundOffset = frame&127;
g.drawImage(IMG.ground, -groundOffset, 61);
g.drawImage(IMG.ground, 128-groundOffset, 61);
g.drawString(rex.score,(W-1)-g.stringWidth(rex.score));
g.drawString(displayedHighScore,(W-1)-g.stringWidth(displayedHighScore), 0);
g.drawString(rex.score,(W-1)-g.stringWidth(rex.score), 8);
g.flip();
}

View File

@ -2,7 +2,7 @@
(() => {
function draw() {
var id = NRF.getAddress().substr().substr(12).split(":");
g.reset().setColor(0, 0.5, 1).setFont("6x8", 1);
g.reset().setColor(0, 0.49, 1).setFont("6x8", 1);
g.drawString(id[0], this.x+2, this.y+4, true);
g.drawString(id[1], this.x+2, this.y+14, true);
}

View File

@ -5,6 +5,6 @@
});
WIDGETS["lock"]={area:"tl",width:Bangle.isLCDOn()?0:16,draw:function(w) {
if (!Bangle.isLCDOn())
g.reset().drawImage(atob("DhABH+D/wwMMDDAwwMf/v//4f+H/h/8//P/z///f/g=="), w.x, w.y);
g.reset().drawImage(atob("DhABH+D/wwMMDDAwwMf/v//4f+H/h/8//P/z///f/g=="), w.x+1, w.y+4);
}};
})()

2
core

@ -1 +1 @@
Subproject commit 3f2ff467f22b746da94160e59ff89b621601b261
Subproject commit 09133e1991c6430e93f1cab61704614649fc3f5e