Merge branch 'espruino:master' into master

master
Lars Werner 2024-06-20 16:33:06 +02:00 committed by GitHub
commit e81cf2a86d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 577 additions and 38 deletions

View File

@ -5,4 +5,5 @@
0.05: extraneous comments and code removed
display improved
now supports Adjust Clock widget, if installed
0.06: Minor code improvements
0.06: Minor code improvements
0.07: Bangle2: Shift the position of one line on the screen

View File

@ -16,11 +16,12 @@ const B2 = [30,30,30,30,31,31,31,31,31,30,30,30];
const timeColour = "#ffffff";
const dateColours = ["#ff0000","#ff8000","#ffff00","#00ff00","#0080ff","#ff00ff","#ffffff"];
const calen10 = {"size":26,"pt0":[18-g_x_off,16],"step":[16,0],"dx":-4.5,"dy":-4.5}; // positioning for usual calendar line
const calen7 = {"size":26,"pt0":[48-g_x_off,16],"step":[16,0],"dx":-4.5,"dy":-4.5}; // positioning for S-day calendar line
const calen7 = {"size":26,"pt0":[42-g_x_off,16],"step":[16,0],"dx":-4.5,"dy":-4.5}; // positioning for S-day calendar line
const time5 = {"size":42,"pt0":[39-g_x_off,24],"step":[26,0],"dx":-6.5,"dy":-6.5}; // positioning for lull time line
const time6 = {"size":42,"pt0":[26-g_x_off,24],"step":[26,0],"dx":-6.5,"dy":-6.5}; // positioning for twinkling time line ft w 48, 48-g, step 30
const baseYear = 11584;
const baseDate = Date(2020,11,21); // month values run from 0 to 11
let calenDef = calen10;
let accum = new Date(baseDate.getTime());
let sequence = [];
let timeActiveUntil;
@ -139,7 +140,7 @@ function writeDozTime(text,def){
}
}
function writeDozDate(text,def,colour){
dateColour = colour;
//let pts = def.pts;
let x=def.pt0[0];
@ -169,20 +170,22 @@ function drawTime()
let date = "";
let timeDef;
let x = 0;
let time;
let wait;
dt.setDate(dt.getDate());
if(addTimeDigit){
x =
10368*dt.getHours()+172.8*dt.getMinutes()+2.88*dt.getSeconds()+0.00288*dt.getMilliseconds();
let msg = "00000"+Math.floor(x).toString(12);
let time = msg.substr(-5,3)+"."+msg.substr(-2); //TODO: should `time` and `wait` have been defined outside the if block?
let wait = 347*(1-(x%1));
time = msg.substr(-5,3)+"."+msg.substr(-2); //TODO: should `time` and `wait` have been defined outside the if block?
wait = 347*(1-(x%1));
timeDef = time6;
} else {
x =
864*dt.getHours()+14.4*dt.getMinutes()+0.24*dt.getSeconds()+0.00024*dt.getMilliseconds();
let msg = "0000"+Math.floor(x).toString(12);
let time = msg.substr(-4,3)+"."+msg.substr(-1);
let wait = 4167*(1-(x%1));
time = msg.substr(-4,3)+"."+msg.substr(-1);
wait = 4167*(1-(x%1));
timeDef = time5;
}
if(lastX > x){ res = getDate(dt); } // calculate date once at start-up and once when turning over to a new day

View File

@ -2,7 +2,7 @@
"id": "doztime",
"name": "Dozenal Digital Time",
"shortName": "Dozenal Digital",
"version": "0.06",
"version": "0.07",
"description": "A dozenal Holocene calendar and dozenal diurnal digital clock",
"icon": "app.png",
"type": "clock",

View File

@ -412,13 +412,6 @@ module.exports = {
"no-unused-vars"
]
},
"apps/doztime/app-bangle2.js": {
"hash": "81592fe1bc6537f80d7dbe7b2e8145924d2400f98ea780c68dd5bd9694376c8a",
"rules": [
"no-unused-vars",
"no-undef"
]
},
"apps/devstopwatch/app.js": {
"hash": "28ca59e605f280a2d8fd4a74f553783205d51f8bb7042d6f51cf8ec11d44c264",
"rules": [
@ -516,12 +509,6 @@ module.exports = {
"no-undef"
]
},
"apps/astrocalc/astrocalc-app.js": {
"hash": "29f978064e42f947b36c94ab3f212512fb5d0a41fa265354c6039e2cf042b92c",
"rules": [
"no-unused-vars"
]
},
"apps/HRV/app.js": {
"hash": "265b4b0272c43126670b5026079711354cee0a211096bcd2c18139b7a3ee774a",
"rules": [

1
apps/nostt/ChangeLog Normal file
View File

@ -0,0 +1 @@
1.00: NOS Teletekst finished!

12
apps/nostt/README.md Normal file
View File

@ -0,0 +1,12 @@
# NOS Teletekst
Dutch Teletekst using the NOS Teletekst api. Requires http access via BangleJS GadgetBridge. See https://www.espruino.com/Gadgetbridge. Make sure `Allow Internet Access` is enabled.
## Usage
Tap once to bring up a numpad to enter the desired page. You can also swipe left/right to change the page, or swipe up/down to walk through the subpages.
## Creator
[Albert van der Meer](https://github.com/avandermeer)

17
apps/nostt/metadata.json Normal file
View File

@ -0,0 +1,17 @@
{
"id":"nostt",
"name":"NOS Teletekst",
"shortName": "Teletekst",
"version": "1.00",
"description": "Dutch Teletekst using the NOS Teletekst api. Requires http access via BangleJS GadgetBridge.",
"type": "app",
"storage": [
{"name":"nostt.app.js","url":"nostt.app.js"},
{"name":"nostt.img","url":"nostt.icon.js","evaluate":true}
],
"readme": "README.md",
"icon":"nostt_logo.png",
"supports": ["BANGLEJS2"],
"screenshots": [{"url": "nostt_screenshot_1.png"}, {"url": "nostt_screenshot_2.png"}],
"tags": "nos,teletext,teletekst,news,weather"
}

505
apps/nostt/nostt.app.js Normal file
View File

@ -0,0 +1,505 @@
class View {
constructor() {
this.navigationState = {
prevPage: {
p: undefined,
s: undefined,
},
prevSubPage: {
p: undefined,
s: undefined,
},
nextPage: {
p: undefined,
s: undefined,
},
nextSubPage: {
p: undefined,
s: undefined,
},
currentPage: {
p: undefined,
s: undefined,
},
};
this.colorArray = {
0: [0, 0, 0],
1: [1, 0, 0],
2: [0, 1, 0],
3: [1, 1, 0],
4: [0, 0, 1],
5: [1, 0, 1],
6: [0, 1, 1],
7: [1, 1, 1],
16: [0, 0, 0],
17: [1, 0, 0],
18: [0, 1, 0],
19: [1, 1, 0],
20: [0, 0, 1],
21: [1, 0, 1],
22: [0, 1, 1],
23: [1, 1, 1],
};
}
start() {
g.clear();
if (this.nextStartPage) {
this.show(this.nextStartPage);
this.nextStartPage = undefined;
}
else {
if (this.navigationState.currentPage.p) {
this.show(this.navigationState.currentPage.p);
}
else {
this.show(101); //load default
}
}
}
split_at_fourty(res, value) {
res.push(value.substring(0, 40));
if (value.length > 40) { // at least two rows
return this.split_at_fourty(res, value.substring(40));
}
else {
return res;
}
}
// strToUtf8Bytes(str) {
// const utf8 = [];
// for (let ii = 0; ii < str.length; ii++) {
// let charCode = str.charCodeAt(ii);
// if (charCode < 0x80) utf8.push(charCode);
// else if (charCode < 0x800) {
// utf8.push(0xc0 | (charCode >> 6), 0x80 | (charCode & 0x3f));
// } else if (charCode < 0xd800 || charCode >= 0xe000) {
// utf8.push(0xe0 | (charCode >> 12), 0x80 | ((charCode >> 6) & 0x3f), 0x80 | (charCode & 0x3f));
// } else {
// ii++;
// // Surrogate pair:
// // UTF-16 encodes 0x10000-0x10FFFF by subtracting 0x10000 and
// // splitting the 20 bits of 0x0-0xFFFFF into two halves
// charCode = 0x10000 + (((charCode & 0x3ff) << 10) | (str.charCodeAt(ii) & 0x3ff));
// utf8.push(
// 0xf0 | (charCode >> 18),
// 0x80 | ((charCode >> 12) & 0x3f),
// 0x80 | ((charCode >> 6) & 0x3f),
// 0x80 | (charCode & 0x3f),
// );
// }
// }
// return utf8;
// }
loadPrevPage() {
if (this.navigationState.prevPage.p) {
this.show(this.navigationState.prevPage.p, this.navigationState.prevPage.s);
}
}
loadNextPage() {
if (this.navigationState.nextPage.p) {
this.show(this.navigationState.nextPage.p, this.navigationState.nextPage.s);
}
}
loadPrevSubPage() {
if (this.navigationState.prevSubPage.p) {
this.show(this.navigationState.prevSubPage.p, this.navigationState.prevSubPage.s);
}
}
loadNextSubPage() {
if (this.navigationState.nextSubPage.p) {
this.show(this.navigationState.nextSubPage.p, this.navigationState.nextSubPage.s);
}
}
handleSwipe(lr, ud){
if (lr == -1 && ud == 0) {
this.loadNextPage();
}
if (lr == 1 && ud == 0) {
this.loadPrevPage();
}
if (lr == 0 && ud == 1) {
this.loadPrevSubPage();
}
if (lr == 0 && ud == -1) {
this.loadNextSubPage();
}
}
show(pageId, subPageId) {
if(!subPageId){
subPageId = 1;
}
if (Bangle.http) {
Bangle.http('https://teletekst-data.nos.nl/page/' + pageId + '-' + subPageId).then((data) => {
const res = data.resp;
g.clear();
this.navigationState = {
prevPage: {
p: undefined,
s: undefined,
},
prevSubPage: {
p: undefined,
s: undefined,
},
nextPage: {
p: undefined,
s: undefined,
},
nextSubPage: {
p: undefined,
s: undefined,
},
currentPage: {
p: pageId,
s: subPageId,
},
};
// set next -, previous -, next sub - and previous sub page
let navNIndex = res.indexOf('pn=n_');
if (navNIndex > -1) {
this.navigationState.nextPage.p = parseInt(res.substring(navNIndex + 5, navNIndex + 8));
this.navigationState.nextPage.s = parseInt(res.substring(navNIndex + 9, navNIndex + 10));
}
let navPIndex = res.indexOf('pn=p_');
if (navPIndex > -1) {
this.navigationState.prevPage.p = parseInt(res.substring(navPIndex + 5, navPIndex + 8));
this.navigationState.prevPage.s = parseInt(res.substring(navPIndex + 9, navPIndex + 10));
}
let navPSIndex = res.indexOf('pn=ps');
if (navPSIndex > -1) {
this.navigationState.prevSubPage.p = parseInt(res.substring(navPSIndex + 5, navPSIndex + 8));
this.navigationState.prevSubPage.s = parseInt(res.substring(navPSIndex + 9, navPSIndex + 10));
}
let navNSIndex = res.indexOf('pn=ns');
if (navNSIndex > -1) {
this.navigationState.nextSubPage.p = parseInt(res.substring(navNSIndex + 5, navNSIndex + 8));
this.navigationState.nextSubPage.s = parseInt(res.substring(navNSIndex + 9, navNSIndex + 10));
}
let split = E.toString(res.split('<pre>')[1].split('</pre>')[0]);
this.render(split);
});
}
}
render(source) {
g.setFontAlign(-1, -1);
g.setFont('4x6');
const bytes = E.toUint8Array(E.decodeUTF8(source));
let rowIndex = 0;
let totalIndex = 0;
let charIndex = 0;
for (let charByte of bytes) {
{
if ((charByte >= 0 && charByte <= 7) || (charByte >= 16 && charByte <= 23)) {
const color = this.colorArray[charByte];
g.setColor(color[0], color[1], color[2]);
}
}
g.drawString(source[totalIndex], (charIndex * 4) + 6, rowIndex * 7);
charIndex++;
totalIndex++;
if (charIndex == 40) {
rowIndex++;
charIndex = 0;
g.flip();
}
}
}
}
const BUTTON_BORDER_WITH = 2;
class Button {
// position;
// value;
// highlightTimeoutId;
constructor(position, value) {
this.position = position;
this.value = value;
}
draw(highlight) {
g.setColor(g.theme.fg);
g.fillRect(
this.position.x1,
this.position.y1,
this.position.x2,
this.position.y2
);
if (highlight) {
g.setColor(g.theme.bgH);
} else {
g.setColor(g.theme.bg);
}
g.fillRect(
this.position.x1 + BUTTON_BORDER_WITH,
this.position.y1 + BUTTON_BORDER_WITH,
this.position.x2 - BUTTON_BORDER_WITH,
this.position.y2 - BUTTON_BORDER_WITH
);
g.setColor(g.theme.fg);
g.setFontAlign(0, 0);
g.setFont("Vector", 35);
g.drawString(
this.value,
this.position.x1 + (this.position.x2 - this.position.x1) / 2 + 2,
this.position.y1 + (this.position.y2 - this.position.y1) / 2 + 2
);
}
handleTouchInput(n, e) {
if (
e.x >= this.position.x1 &&
e.x <= this.position.x2 &&
e.y >= this.position.y1 &&
e.y <= this.position.y2
) {
this.draw(true); // draw to highlight
this.highlightTimeoutId = setTimeout(() => {
this.draw();
this.highlightTimeoutId = undefined;
}, 100);
return this.value;
}
else {
return undefined;
}
}
disable() {
// disable button
if (this.highlightTimeoutId) {
clearTimeout(this.highlightTimeoutId);
this.highlightTimeoutId = undefined;
}
}
}
class Input {
constructor(callback) {
this.inputCallback = callback;
this.inputVal = "";
let button1 = new Button({ x1: 1, y1: 35, x2: 58, y2: 70 }, '1');
let button2 = new Button({ x1: 60, y1: 35, x2: 116, y2: 70 }, '2');
let button3 = new Button({ x1: 118, y1: 35, x2: 174, y2: 70 }, '3');
let button4 = new Button({ x1: 1, y1: 72, x2: 58, y2: 105 }, '4');
let button5 = new Button({ x1: 60, y1: 72, x2: 116, y2: 105 }, '5');
let button6 = new Button({ x1: 118, y1: 72, x2: 174, y2: 105 }, '6');
let button7 = new Button({ x1: 1, y1: 107, x2: 58, y2: 140 }, '7');
let button8 = new Button({ x1: 60, y1: 107, x2: 116, y2: 140 }, '8');
let button9 = new Button({ x1: 118, y1: 107, x2: 174, y2: 140 }, '9');
let buttonOK = new Button({ x1: 1, y1: 142, x2: 58, y2: 174 }, "OK");
let button0 = new Button({ x1: 60, y1: 142, x2: 116, y2: 174 }, "0");
let buttonDelete = new Button({ x1: 118, y1: 142, x2: 174, y2: 174 }, "<-");
this.inputButtons = [
button1,
button2,
button3,
button4,
button5,
button6,
button7,
button8,
button9,
buttonOK,
button0,
buttonDelete,
];
}
handleTouchInput(n, e) {
let res = 'none';
for (let button of this.inputButtons) {
const touchResult = button.handleTouchInput(n, e);
if (touchResult) {
res = touchResult;
}
}
switch (res) {
case 'OK':
if(this.inputVal.length == 3){
this.inputCallback(parseInt(this.inputVal));
}
break;
case '<-':
this.removeNumber();
this.drawField();
break;
case 'none':
break;
default:
this.appendNumber(parseInt(res));
this.drawField();
}
}
hide() {
for (let button of this.inputButtons) {
button.disable();
}
}
start(preset) {
if (preset) {
this.inputVal = preset.toString();
}
else {
this.inputVal = '';
}
this.draw();
}
appendNumber(number) {
if (number === 0 && this.inputVal.length === 0) {
return;
}
if (this.inputVal.length <= 2) {
this.inputVal = this.inputVal + number;
}
}
removeNumber() {
if (this.inputVal.length > 0) {
this.inputVal = this.inputVal.slice(0, -1);
}
}
reset() {
this.inputVal = "";
}
draw() {
g.clear();
this.drawButtons();
this.drawField();
}
drawButtons() {
for (let button of this.inputButtons) {
button.draw();
}
}
drawField() {
g.clearRect(0, 0, 176, 34);
g.setColor(g.theme.fg);
g.setFontAlign(-1, -1);
g.setFont("Vector:26x40");
g.drawString(this.inputVal, 2, 0);
}
}
// require('./Input');
class NOSTeletekstApp {
constructor() {
console.log("this is the teletekst app!");
this.isLeaving = false;
this.viewMode= 'VIEW';
this.view = new View();
this.input = new Input((newVal)=>this.inputHandler(newVal));
this.view.start();
Bangle.setUI({
mode: "custom",
remove: () => {
this.isLeaving = true;
console.log("teletext app: i am packing my stuff, goodbye");
require("widget_utils").show(); // re-show widgets
},
touch: (n, e) => {
if (this.viewMode == 'VIEW') {
// we need to go to input mode
this.setViewMode('INPUT');
return;
}
if (this.viewMode == 'INPUT') {
this.input.handleTouchInput(n, e);
return;
}
},
swipe: (lr, ud) => {
if (this.viewMode == 'VIEW') {
this.view.handleSwipe(lr,ud);
}
if (this.viewMode == 'INPUT') {
if(lr == 1 && ud == 0){
this.setViewMode('VIEW');
}
}
}
});
}
inputHandler(input){
// set viewMode back to view
this.view.nextStartPage = input;
this.setViewMode('VIEW');
}
setViewMode(newViewMode){
this.viewMode = newViewMode;
if(newViewMode=='INPUT'){
this.input.start();
}
if(newViewMode=='VIEW'){
this.input.hide();
this.view.start();
}
}
}
new NOSTeletekstApp();

1
apps/nostt/nostt.icon.js Normal file
View File

@ -0,0 +1 @@
require("heatshrink").decompress(atob("mEwwZC/AH4A/AH4AWgmSAwn/wACB/0Agf/4EAhMkyVIB4MB/4AB/ARGpIRBpMggEPCIQAC4ARCgQRDkkAv4jEAQIRLAQIRC/4RCiVJIgJKBwARCgPACIxWCCIn8NwQAB8YRFgIRDNARcFPQgRBNYZHB+IRDEYyPDAAPwn4RJIggRBg4RDNYrGCJQQRGkCSCWYP4CIgpCUI7FFCIMfa5DFFCIL7GJQQRLgARBoBXCO4KhBAH4A/AH4A/AD4A="))

BIN
apps/nostt/nostt_logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

View File

@ -2,4 +2,5 @@
0.02: Checks for correct firmware; E.setDST(...) moved to boot.js
0.03: Convert Yes/No On/Off in settings to checkboxes
0.04: Give the boot file the highest priority to ensure it runs before sched (fix #2663)
0.05: Tweaks to ensure Gadgetbridge can't overwrite timezone on 2v19.106 and later
0.05: Tweaks to ensure Gadgetbridge can't overwrite timezone on 2v19.106 and later
0.06: If fastload is present, ensure DST changes are still applied when leaving settings

View File

@ -1,6 +1,6 @@
{ "id": "widdst",
"name": "Daylight Saving",
"version":"0.05",
"version":"0.06",
"description": "Widget to set daylight saving rules. Requires Espruino 2v15 or later - see the instructions below for more information.",
"icon": "icon.png",
"type": "widget",

View File

@ -33,8 +33,11 @@
at: 0
};
var writtenSettings = false;
function writeSettings() {
require('Storage').writeJSON("widdst.json", settings);
writtenSettings = true;
}
function writeSubMenuSettings() {
@ -136,7 +139,15 @@
"": {
"Title": /*LANG*/"Daylight Saving"
},
"< Back": () => back(),
"< Back": () => {
if(writtenSettings && global._load){
// disable fastload to ensure settings are applied
// when we exit the settings app
global.load = global._load;
delete global._load;
}
back();
},
/*LANG*/"Enabled": {
value: !!settings.has_dst,
onchange: v => {

28
package-lock.json generated
View File

@ -730,12 +730,12 @@
}
},
"node_modules/braces": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz",
"integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==",
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz",
"integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==",
"dev": true,
"dependencies": {
"fill-range": "^7.0.1"
"fill-range": "^7.1.1"
},
"engines": {
"node": ">=8"
@ -1437,9 +1437,9 @@
}
},
"node_modules/fill-range": {
"version": "7.0.1",
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz",
"integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==",
"version": "7.1.1",
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz",
"integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==",
"dev": true,
"dependencies": {
"to-regex-range": "^5.0.1"
@ -3984,12 +3984,12 @@
}
},
"braces": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz",
"integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==",
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz",
"integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==",
"dev": true,
"requires": {
"fill-range": "^7.0.1"
"fill-range": "^7.1.1"
}
},
"call-bind": {
@ -4531,9 +4531,9 @@
}
},
"fill-range": {
"version": "7.0.1",
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz",
"integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==",
"version": "7.1.1",
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz",
"integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==",
"dev": true,
"requires": {
"to-regex-range": "^5.0.1"