Skip to content

Commit c217a4f

Browse files
authored
Merge pull request espruino#3645 from ki9us/master
Poker Timer App
2 parents a30c728 + e112d08 commit c217a4f

File tree

10 files changed

+228
-0
lines changed

10 files changed

+228
-0
lines changed

apps/pokertimer/ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
0.01: Packaged app
2+
0.02: Fix alert buzz time, Indicate when paused
3+
0.03: Start app with paused timer
4+
0.04: Added 20-second warning buzz
5+
0.05: Added screenshots
6+
0.06: Fix bug when play/pause during alert

apps/pokertimer/LICENSE

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
The MIT License (MIT)
2+
3+
Copyright © 2024 Keith Irwin
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

apps/pokertimer/README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Poker Timer
2+
*v.0.06*
3+
4+
A blinds timer for poker. Don't know what that means? See [Wikipedia: Blind (poker)](https://en.wikipedia.org/wiki/Blind_(poker)) and [Wikipedia: Texas hold 'em](https://en.wikipedia.org/wiki/Texas_hold_%27em).
5+
6+
![Screenshot showing countdown paused on start](screenshots/01_paused-start.png)
7+
![Screenshot showing active countdown](screenshots/02_counting-down.png)
8+
![Screenshot showing blinds up alert](screenshots/03_blinds-up.png)
9+
10+
The blinds are hardcoded and go up every ten minutes:
11+
12+
- 1, 2
13+
- 2, 4
14+
- 4, 8
15+
- 5, 10
16+
- 10, 20
17+
- 20, 40
18+
- 40, 80
19+
20+
... and so on, doubling each round.
21+
22+
## Features
23+
24+
- Starts paused
25+
- Button to pause/resume
26+
- 20-second warning buzz
27+
- Auto-exit after round 25
28+
29+
## Usage
30+
31+
The timer will start as soon as you open the app. Time left in the round is on the top of the screen, currnt small and big blinds are shown below. After ten minutes, it will vibrate and flash and show the new blind. Then it starts over.
32+
33+
### Auto-exit
34+
35+
The program will automatically exit after the 25 round. This is not a bug. If the blinds double again, it will perform some kind of overflow and convert the blind values to floats.
36+
37+
The blinds in round 25 are `20971520 / 41943040`. You probably aren't still playing poker at that point and just forgot to exit the program.
38+
39+
## Controls
40+
41+
- **Pause/Resume:** Press the button
42+
- **Exit:** hold down the button
43+
44+
## Roadmap
45+
46+
- Set settings
47+
- Better graphics
48+
49+
## Requests
50+
51+
[Contact Keith Irwin](https://www.ki9.us/contact/)
52+
53+
## Creator
54+
55+
[Keith Irwin](https://www.ki9.us)

apps/pokertimer/app-icon.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/pokertimer/app.js

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
const BLIND_INTERVAL = 600; // 10 minutes in seconds
2+
const BLINDSUP_ALERT_DURATION = 10000; // 10 seconds in ms
3+
4+
// Convert seconds to mm:ss
5+
const secondsToMinutes = (s) => {
6+
const mm = Math.floor(s/60);
7+
const ss = s - mm * 60;
8+
return `${mm}:${String(ss).padStart(2,'0')}`;
9+
};
10+
11+
// Format screen
12+
const fmtDark = () => {
13+
g.clear();
14+
g.setFontAlign(0,0);
15+
g.setBgColor(0,0.5,0);
16+
g.setColor(1,1,1);
17+
};
18+
const fmtLight = () => {
19+
g.clear();
20+
g.setFontAlign(0,0);
21+
g.setBgColor(0.5,1,0.5);
22+
g.setColor(0,0,0);
23+
};
24+
25+
// Start/stop/pause/resume timer
26+
const startTimer = () => {
27+
timer_running = true; tick();
28+
timer = setInterval(tick, 1000);
29+
};
30+
const stopTimer = () => {
31+
clearInterval(timer);
32+
timer_running = false;
33+
};
34+
const pauseResume = () => {
35+
if (is_alerting) return;
36+
if (timer_running) {
37+
stopTimer();
38+
g.setFont('Vector',15);
39+
g.drawString('(PAUSED)',
40+
g.getWidth()/2, g.getHeight()*7/8);
41+
}
42+
else startTimer();
43+
};
44+
45+
// Calculate blinds for a round
46+
const getBlinds = (i) => {
47+
let small;
48+
if (i===0) small = 1;
49+
else if (i===1) small = 2;
50+
else if (i===2) small = 4;
51+
else small = 5*(Math.pow(2,(i-3)));
52+
return [small, small*2];
53+
};
54+
55+
// Sound the alarm
56+
const blindsUp = () => {
57+
is_alerting = true;
58+
// Display message
59+
const showMessage = () => {
60+
g.clear();
61+
g.setFont('Vector',34);
62+
g.drawString('Blinds Up!',
63+
g.getWidth()/2, g.getHeight()/3);
64+
g.setFont('Vector',40);
65+
g.drawString(`${blinds[0]}/${blinds[1]}`,
66+
g.getWidth()/2, g.getHeight()*2/3);
67+
};
68+
stopTimer();
69+
// Increase blinds
70+
b++;
71+
// TODO: Kill program between round 25 and 26
72+
blinds = getBlinds(b);
73+
console.log(`Blinds for round ${b} are ${blinds[0]} / ${blinds[1]}`);
74+
// Buzz and light up every second
75+
const buzzInterval = setInterval(() => {
76+
Bangle.buzz(500);
77+
Bangle.setLCDPower(1);
78+
}, 1000);
79+
// Invert colors every second
80+
fmtLight(); showMessage(); let dark = false;
81+
const flashInterval = setInterval(() => {
82+
if (dark) {
83+
fmtLight();
84+
dark = false;
85+
} else {
86+
fmtDark();
87+
dark = true;
88+
} showMessage();
89+
}, 500);
90+
// Restart timer
91+
setTimeout(() => {
92+
is_alerting = false;
93+
fmtDark(); tick();
94+
clearInterval(buzzInterval);
95+
clearInterval(flashInterval);
96+
time_left = BLIND_INTERVAL + 1;
97+
startTimer();
98+
}, BLINDSUP_ALERT_DURATION);
99+
};
100+
101+
// Tick every second
102+
const tick = () => {
103+
if (!timer_running) return;
104+
time_left--;
105+
// 20-second warning buzz
106+
if (time_left==20) {
107+
const buzzInterval = setInterval(Bangle.buzz, 500);
108+
setTimeout(() => {
109+
clearInterval(buzzInterval);
110+
}, 5000);
111+
}
112+
if (time_left<=0) blindsUp();
113+
else {
114+
g.clear();
115+
g.setFont('Vector',40);
116+
g.drawString(
117+
secondsToMinutes(time_left),
118+
g.getWidth()/2, g.getHeight()/3);
119+
g.drawString(
120+
`${blinds[0]}/${blinds[1]}`,
121+
g.getWidth()/2, g.getHeight()*2/3);
122+
}
123+
return;
124+
};
125+
126+
// button listener
127+
Bangle.setUI({
128+
mode: 'custom',
129+
btn: pauseResume,
130+
});
131+
132+
// RUNTIME
133+
fmtDark();
134+
let time_left = BLIND_INTERVAL + 1;
135+
let b = 0;
136+
let blinds = getBlinds(b);
137+
let timer_running = true;
138+
let is_alerting = false;
139+
let timer = setInterval(tick, 1000);
140+
tick();
141+
// Start paused
142+
pauseResume();

apps/pokertimer/app.png

1.11 KB
Loading

apps/pokertimer/metadata.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"id": "pokertimer",
3+
"name": "Poker Timer",
4+
"shortName":"Poker Timer",
5+
"readme":"README.md",
6+
"icon": "app.png",
7+
"version":"0.06",
8+
"description": "A blinds timer for use with Texas Hold 'Em",
9+
"tags": "poker",
10+
"supports": ["BANGLEJS2"],
11+
"storage": [
12+
{"name":"pokertimer.app.js","url":"app.js"},
13+
{"name":"pokertimer.img","url":"app-icon.js","evaluate":true}
14+
]
15+
}
2.75 KB
Loading
3.24 KB
Loading
3.47 KB
Loading

0 commit comments

Comments
 (0)