commit
d4b0fd45ff
|
|
@ -1420,12 +1420,12 @@
|
||||||
{
|
{
|
||||||
"id": "pomodo",
|
"id": "pomodo",
|
||||||
"name": "Pomodoro",
|
"name": "Pomodoro",
|
||||||
"version": "0.01",
|
"version": "0.02",
|
||||||
"description": "A simple pomodoro timer.",
|
"description": "A simple pomodoro timer.",
|
||||||
"icon": "pomodoro.png",
|
"icon": "pomodoro.png",
|
||||||
"type": "app",
|
"type": "app",
|
||||||
"tags": "pomodoro,cooking,tools",
|
"tags": "pomodoro,cooking,tools",
|
||||||
"supports": ["BANGLEJS"],
|
"supports": ["BANGLEJS", "BANGLEJS2"],
|
||||||
"allow_emulator": true,
|
"allow_emulator": true,
|
||||||
"storage": [
|
"storage": [
|
||||||
{"name":"pomodo.app.js","url":"pomodoro.js"},
|
{"name":"pomodo.app.js","url":"pomodoro.js"},
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,9 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 2021-11-18
|
||||||
|
|
||||||
|
- [Feature] Ported to Banglejs2
|
||||||
|
|
||||||
## 2019-11-27
|
## 2019-11-27
|
||||||
|
|
||||||
- [Feature] App now saves the last interval value
|
- [Feature] App now saves the last interval value
|
||||||
|
|
|
||||||
|
|
@ -1 +1,2 @@
|
||||||
|
0.02: Ported to Banglejs2.
|
||||||
0.01: New App!
|
0.01: New App!
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,9 @@ const STATES = {
|
||||||
var counterInterval;
|
var counterInterval;
|
||||||
|
|
||||||
class State {
|
class State {
|
||||||
constructor (state) {
|
constructor (state, device) {
|
||||||
this.state = state;
|
this.state = state;
|
||||||
|
this.device = device;
|
||||||
this.next = null;
|
this.next = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -47,8 +48,8 @@ class State {
|
||||||
}
|
}
|
||||||
|
|
||||||
class InitState extends State {
|
class InitState extends State {
|
||||||
constructor (time) {
|
constructor (device) {
|
||||||
super(STATES.INIT);
|
super(STATES.INIT, device);
|
||||||
|
|
||||||
this.timeCounter = parseInt(storage.read(".pomodo") || DEFAULT_TIME, 10);
|
this.timeCounter = parseInt(storage.read(".pomodo") || DEFAULT_TIME, 10);
|
||||||
}
|
}
|
||||||
|
|
@ -58,7 +59,7 @@ class InitState extends State {
|
||||||
}
|
}
|
||||||
|
|
||||||
setButtons () {
|
setButtons () {
|
||||||
setWatch(() => {
|
this.device.setBTN1(() => {
|
||||||
if (this.timeCounter + 300 > 3599) {
|
if (this.timeCounter + 300 > 3599) {
|
||||||
this.timeCounter = 3599;
|
this.timeCounter = 3599;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -67,23 +68,23 @@ class InitState extends State {
|
||||||
|
|
||||||
this.draw();
|
this.draw();
|
||||||
|
|
||||||
}, BTN1, { repeat: true });
|
});
|
||||||
|
|
||||||
setWatch(() => {
|
this.device.setBTN3(() => {
|
||||||
if (this.timeCounter - 300 > 0) {
|
if (this.timeCounter - 300 > 0) {
|
||||||
this.timeCounter -= 300;
|
this.timeCounter -= 300;
|
||||||
this.draw();
|
this.draw();
|
||||||
}
|
}
|
||||||
}, BTN3, { repeat: true });
|
});
|
||||||
|
|
||||||
setWatch(() => {
|
this.device.setBTN4(() => {
|
||||||
if (this.timeCounter - 60 > 0) {
|
if (this.timeCounter - 60 > 0) {
|
||||||
this.timeCounter -= 60;
|
this.timeCounter -= 60;
|
||||||
this.draw();
|
this.draw();
|
||||||
}
|
}
|
||||||
}, BTN4, { repeat: true });
|
});
|
||||||
|
|
||||||
setWatch(() => {
|
this.device.setBTN5(() => {
|
||||||
if (this.timeCounter + 60 > 3599) {
|
if (this.timeCounter + 60 > 3599) {
|
||||||
this.timeCounter = 3599;
|
this.timeCounter = 3599;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -92,15 +93,15 @@ class InitState extends State {
|
||||||
|
|
||||||
this.draw();
|
this.draw();
|
||||||
|
|
||||||
}, BTN5, { repeat: true });
|
});
|
||||||
|
|
||||||
setWatch(() => {
|
this.device.setBTN2(() => {
|
||||||
this.saveTime();
|
this.saveTime();
|
||||||
const startedState = new StartedState(this.timeCounter);
|
const startedState = new StartedState(this.timeCounter, this.device);
|
||||||
|
|
||||||
this.setNext(startedState);
|
this.setNext(startedState);
|
||||||
this.next.go();
|
this.next.go();
|
||||||
}, BTN2, { repeat: true });
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
draw () {
|
draw () {
|
||||||
|
|
@ -112,14 +113,14 @@ class InitState extends State {
|
||||||
}
|
}
|
||||||
|
|
||||||
class StartedState extends State {
|
class StartedState extends State {
|
||||||
constructor (timeCounter) {
|
constructor (timeCounter, buttons) {
|
||||||
super(STATES.STARTED);
|
super(STATES.STARTED, buttons);
|
||||||
|
|
||||||
this.timeCounter = timeCounter;
|
this.timeCounter = timeCounter;
|
||||||
}
|
}
|
||||||
|
|
||||||
draw () {
|
draw () {
|
||||||
drawCounter(this.timeCounter, 120, 120);
|
drawCounter(this.timeCounter, g.getWidth() / 2, g.getHeight() / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
init () {
|
init () {
|
||||||
|
|
@ -137,15 +138,15 @@ class StartedState extends State {
|
||||||
this.draw();
|
this.draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
const doneState = new DoneState();
|
const doneState = new DoneState(this.device);
|
||||||
this.setNext(doneState);
|
this.setNext(doneState);
|
||||||
counterInterval = setInterval(countDown.bind(this), 1000);
|
counterInterval = setInterval(countDown.bind(this), 1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class BreakState extends State {
|
class BreakState extends State {
|
||||||
constructor () {
|
constructor (buttons) {
|
||||||
super(STATES.BREAK);
|
super(STATES.BREAK, buttons);
|
||||||
}
|
}
|
||||||
|
|
||||||
draw () {
|
draw () {
|
||||||
|
|
@ -153,44 +154,40 @@ class BreakState extends State {
|
||||||
}
|
}
|
||||||
|
|
||||||
init () {
|
init () {
|
||||||
const startedState = new StartedState(TIME_BREAK);
|
const startedState = new StartedState(TIME_BREAK, this.device);
|
||||||
|
|
||||||
this.setNext(startedState);
|
this.setNext(startedState);
|
||||||
this.next.go();
|
this.next.go();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DoneState extends State {
|
class DoneState extends State {
|
||||||
constructor () {
|
constructor (device) {
|
||||||
super(STATES.DONE);
|
super(STATES.DONE, device);
|
||||||
}
|
}
|
||||||
|
|
||||||
setButtons () {
|
setButtons () {
|
||||||
setWatch(() => {
|
this.device.setBTN1(() => {
|
||||||
const initState = new InitState();
|
});
|
||||||
clearTimeout(this.timeout);
|
|
||||||
initState.go();
|
|
||||||
}, BTN1, { repeat: true });
|
|
||||||
|
|
||||||
setWatch(() => {
|
this.device.setBTN3(() => {
|
||||||
const breakState = new BreakState();
|
});
|
||||||
clearTimeout(this.timeout);
|
|
||||||
breakState.go();
|
|
||||||
}, BTN3, { repeat: true });
|
|
||||||
|
|
||||||
setWatch(() => {
|
this.device.setBTN2(() => {
|
||||||
}, BTN2, { repeat: true });
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
draw () {
|
draw () {
|
||||||
g.clear();
|
g.clear();
|
||||||
g.setFont("6x8", 2);
|
E.showPrompt("You are a hero!", {
|
||||||
g.setFontAlign(0, 0, 3);
|
buttons : {"AGAIN":1,"BREAK":2}
|
||||||
g.drawString("AGAIN", 230, 50);
|
}).then((v) => {
|
||||||
g.drawString("BREAK", 230, 190);
|
var nextSate = (v == 1
|
||||||
g.setFont("Vector", 45);
|
? new InitState(this.device)
|
||||||
g.setFontAlign(-1, -1);
|
: new BreakState(this.device));
|
||||||
|
clearTimeout(this.timeout);
|
||||||
g.drawString('You\nare\na\nhero!', 50, 40);
|
nextSate.go();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
init () {
|
init () {
|
||||||
|
|
@ -215,13 +212,61 @@ 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) {
|
||||||
|
Bangle.on('touch', function(zone, e) {
|
||||||
|
if (e.y < g.getHeight() / 2) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
setBTN2(callback) {
|
||||||
|
setWatch(callback, BTN1, { repeat: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
setBTN3(callback) {
|
||||||
|
Bangle.on('touch', function(zone, e) {
|
||||||
|
if (e.y > g.getHeight() / 2) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
setBTN4(callback) { }
|
||||||
|
|
||||||
|
setBTN5(callback) { }
|
||||||
|
}
|
||||||
|
|
||||||
function drawCounter (currentValue, x, y) {
|
function drawCounter (currentValue, x, y) {
|
||||||
if (currentValue < 0) {
|
if (currentValue < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
x = x || 120;
|
x = x || g.getWidth() / 2;
|
||||||
y = y || 120;
|
y = y || g.getHeight() / 2;
|
||||||
|
|
||||||
let minutes = 0;
|
let minutes = 0;
|
||||||
let seconds = 0;
|
let seconds = 0;
|
||||||
|
|
@ -249,7 +294,10 @@ function drawCounter (currentValue, x, y) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function init () {
|
function init () {
|
||||||
const initState = new InitState();
|
device = (process.env.HWVERSION==1
|
||||||
|
? new Bangle1()
|
||||||
|
: new Bangle2());
|
||||||
|
const initState = new InitState(device);
|
||||||
initState.go();
|
initState.go();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue