From bc813feaa3545042c741bbf104a50998bf03fd32 Mon Sep 17 00:00:00 2001 From: Adam Schmalhofer Date: Thu, 18 Nov 2021 15:09:00 +0100 Subject: [PATCH 1/5] Use getWidth(), getHeight() instead of fixed values --- apps/pomodo/pomodoro.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/pomodo/pomodoro.js b/apps/pomodo/pomodoro.js index 3e11739da..d3cc0e089 100644 --- a/apps/pomodo/pomodoro.js +++ b/apps/pomodo/pomodoro.js @@ -119,7 +119,7 @@ class StartedState extends State { } draw () { - drawCounter(this.timeCounter, 120, 120); + drawCounter(this.timeCounter, g.getWidth() / 2, g.getHeight() / 2); } init () { @@ -220,8 +220,8 @@ function drawCounter (currentValue, x, y) { return; } - x = x || 120; - y = y || 120; + x = x || g.getWidth() / 2; + y = y || g.getHeight() / 2; let minutes = 0; let seconds = 0; From 3dba1342e8010cda583ed892d3a9143fc2a8dad0 Mon Sep 17 00:00:00 2001 From: Adam Schmalhofer Date: Thu, 18 Nov 2021 15:43:23 +0100 Subject: [PATCH 2/5] Use Adapter to generalize Buttons beween devices --- apps/pomodo/pomodoro.js | 103 ++++++++++++++++++++++++++++------------ 1 file changed, 72 insertions(+), 31 deletions(-) diff --git a/apps/pomodo/pomodoro.js b/apps/pomodo/pomodoro.js index d3cc0e089..4ece65d1b 100644 --- a/apps/pomodo/pomodoro.js +++ b/apps/pomodo/pomodoro.js @@ -11,8 +11,9 @@ const STATES = { var counterInterval; class State { - constructor (state) { + constructor (state, device) { this.state = state; + this.device = device; this.next = null; } @@ -47,8 +48,8 @@ class State { } class InitState extends State { - constructor (time) { - super(STATES.INIT); + constructor (device) { + super(STATES.INIT, device); this.timeCounter = parseInt(storage.read(".pomodo") || DEFAULT_TIME, 10); } @@ -58,7 +59,7 @@ class InitState extends State { } setButtons () { - setWatch(() => { + this.device.setBTN1(() => { if (this.timeCounter + 300 > 3599) { this.timeCounter = 3599; } else { @@ -67,23 +68,23 @@ class InitState extends State { this.draw(); - }, BTN1, { repeat: true }); + }); - setWatch(() => { + this.device.setBTN3(() => { if (this.timeCounter - 300 > 0) { this.timeCounter -= 300; this.draw(); } - }, BTN3, { repeat: true }); + }); - setWatch(() => { + this.device.setBTN4(() => { if (this.timeCounter - 60 > 0) { this.timeCounter -= 60; this.draw(); } - }, BTN4, { repeat: true }); + }); - setWatch(() => { + this.device.setBTN5(() => { if (this.timeCounter + 60 > 3599) { this.timeCounter = 3599; } else { @@ -92,15 +93,15 @@ class InitState extends State { this.draw(); - }, BTN5, { repeat: true }); + }); - setWatch(() => { + this.device.setBTN2(() => { this.saveTime(); - const startedState = new StartedState(this.timeCounter); + const startedState = new StartedState(this.timeCounter, this.device); this.setNext(startedState); this.next.go(); - }, BTN2, { repeat: true }); + }); } draw () { @@ -112,8 +113,8 @@ class InitState extends State { } class StartedState extends State { - constructor (timeCounter) { - super(STATES.STARTED); + constructor (timeCounter, buttons) { + super(STATES.STARTED, buttons); this.timeCounter = timeCounter; } @@ -137,15 +138,15 @@ class StartedState extends State { this.draw(); } - const doneState = new DoneState(); + const doneState = new DoneState(this.device); this.setNext(doneState); counterInterval = setInterval(countDown.bind(this), 1000); } } class BreakState extends State { - constructor () { - super(STATES.BREAK); + constructor (buttons) { + super(STATES.BREAK, buttons); } draw () { @@ -153,32 +154,33 @@ class BreakState extends State { } init () { - const startedState = new StartedState(TIME_BREAK); + const startedState = new StartedState(TIME_BREAK, this.device); this.setNext(startedState); this.next.go(); } } + class DoneState extends State { - constructor () { - super(STATES.DONE); + constructor (device) { + super(STATES.DONE, device); } setButtons () { - setWatch(() => { - const initState = new InitState(); + this.device.setBTN1(() => { + const initState = new InitState(this.device); clearTimeout(this.timeout); initState.go(); - }, BTN1, { repeat: true }); + }); - setWatch(() => { - const breakState = new BreakState(); + this.device.setBTN3(() => { + const breakState = new BreakState(this.device); clearTimeout(this.timeout); breakState.go(); - }, BTN3, { repeat: true }); + }); - setWatch(() => { - }, BTN2, { repeat: true }); + this.device.setBTN2(() => { + }); } draw () { @@ -215,6 +217,42 @@ class DoneState extends State { } } +class Bangle1 { + setBTN1(callback) { + setWatch(callback, BTN1, { repeat: true }); + } + + setBTN2(callback) { + setWatch(callback, BTN2, { repeat: true }); + } + + setBTN3(callback) { + setWatch(callback, BTN3, { repeat: true }); + } + + setBTN4(callback) { + setWatch(callback, BTN4, { repeat: true }); + } + + setBTN5(callback) { + setWatch(callback, BTN5, { repeat: true }); + } +} + +class Bangle2 { + setBTN1(callback) { } + + setBTN2(callback) { + setWatch(callback, BTN1, { repeat: true }); + } + + setBTN3(callback) { } + + setBTN4(callback) { } + + setBTN5(callback) { } +} + function drawCounter (currentValue, x, y) { if (currentValue < 0) { return; @@ -249,7 +287,10 @@ function drawCounter (currentValue, x, y) { } function init () { - const initState = new InitState(); + device = (process.env.HWVERSION==1 + ? new Bangle1() + : new Bangle2()); + const initState = new InitState(device); initState.go(); } From f035f36ba93d2578b1af37957ce1321ac49f6265 Mon Sep 17 00:00:00 2001 From: Adam Schmalhofer Date: Thu, 18 Nov 2021 16:27:09 +0100 Subject: [PATCH 3/5] Use showPromt() instead of own implementation as it works with Bangle.js2 --- apps/pomodo/pomodoro.js | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/apps/pomodo/pomodoro.js b/apps/pomodo/pomodoro.js index 4ece65d1b..dafc04a33 100644 --- a/apps/pomodo/pomodoro.js +++ b/apps/pomodo/pomodoro.js @@ -168,15 +168,9 @@ class DoneState extends State { setButtons () { this.device.setBTN1(() => { - const initState = new InitState(this.device); - clearTimeout(this.timeout); - initState.go(); }); this.device.setBTN3(() => { - const breakState = new BreakState(this.device); - clearTimeout(this.timeout); - breakState.go(); }); this.device.setBTN2(() => { @@ -185,14 +179,15 @@ class DoneState extends State { draw () { g.clear(); - g.setFont("6x8", 2); - g.setFontAlign(0, 0, 3); - g.drawString("AGAIN", 230, 50); - g.drawString("BREAK", 230, 190); - g.setFont("Vector", 45); - g.setFontAlign(-1, -1); - - g.drawString('You\nare\na\nhero!', 50, 40); + E.showPrompt("You are a hero!", { + buttons : {"AGAIN":1,"BREAK":2} + }).then((v) => { + var nextSate = (v == 1 + ? new InitState(this.device) + : new BreakState(this.device)); + clearTimeout(this.timeout); + nextSate.go(); + }); } init () { From f5317862c857172e73ce8114498bad6836e1e151 Mon Sep 17 00:00:00 2001 From: Adam Schmalhofer Date: Thu, 18 Nov 2021 16:40:11 +0100 Subject: [PATCH 4/5] Use touch to set duration on Banglejs2 --- apps/pomodo/pomodoro.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/apps/pomodo/pomodoro.js b/apps/pomodo/pomodoro.js index dafc04a33..96d2e8d6a 100644 --- a/apps/pomodo/pomodoro.js +++ b/apps/pomodo/pomodoro.js @@ -235,13 +235,25 @@ class Bangle1 { } class Bangle2 { - setBTN1(callback) { } + setBTN1(callback) { + Bangle.on('touch', function(zone, e) { + if (e.y < g.getHeight() / 2) { + callback(); + } + }); + } setBTN2(callback) { setWatch(callback, BTN1, { repeat: true }); } - setBTN3(callback) { } + setBTN3(callback) { + Bangle.on('touch', function(zone, e) { + if (e.y > g.getHeight() / 2) { + callback(); + } + }); + } setBTN4(callback) { } From 08383611c10004cfd42be679eb763f45b4963c92 Mon Sep 17 00:00:00 2001 From: Adam Schmalhofer Date: Thu, 18 Nov 2021 16:45:17 +0100 Subject: [PATCH 5/5] Chore: New pomodo release --- apps.json | 4 ++-- apps/pomodo/CHANGELOG.md | 4 ++++ apps/pomodo/ChangeLog | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/apps.json b/apps.json index 148833678..6ce1c442d 100644 --- a/apps.json +++ b/apps.json @@ -1420,12 +1420,12 @@ { "id": "pomodo", "name": "Pomodoro", - "version": "0.01", + "version": "0.02", "description": "A simple pomodoro timer.", "icon": "pomodoro.png", "type": "app", "tags": "pomodoro,cooking,tools", - "supports": ["BANGLEJS"], + "supports": ["BANGLEJS", "BANGLEJS2"], "allow_emulator": true, "storage": [ {"name":"pomodo.app.js","url":"pomodoro.js"}, diff --git a/apps/pomodo/CHANGELOG.md b/apps/pomodo/CHANGELOG.md index b8c5dd621..b4667aff8 100644 --- a/apps/pomodo/CHANGELOG.md +++ b/apps/pomodo/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 2021-11-18 + +- [Feature] Ported to Banglejs2 + ## 2019-11-27 - [Feature] App now saves the last interval value diff --git a/apps/pomodo/ChangeLog b/apps/pomodo/ChangeLog index 5560f00bc..3630ae7b6 100644 --- a/apps/pomodo/ChangeLog +++ b/apps/pomodo/ChangeLog @@ -1 +1,2 @@ +0.02: Ported to Banglejs2. 0.01: New App!