diff --git a/apps/pokertimer/ChangeLog b/apps/pokertimer/ChangeLog new file mode 100644 index 0000000000..ceddbf5337 --- /dev/null +++ b/apps/pokertimer/ChangeLog @@ -0,0 +1,6 @@ +0.01: Packaged app +0.02: Fix alert buzz time, Indicate when paused +0.03: Start app with paused timer +0.04: Added 20-second warning buzz +0.05: Added screenshots +0.06: Fix bug when play/pause during alert diff --git a/apps/pokertimer/LICENSE b/apps/pokertimer/LICENSE new file mode 100644 index 0000000000..a2bb2da017 --- /dev/null +++ b/apps/pokertimer/LICENSE @@ -0,0 +1,9 @@ +The MIT License (MIT) + +Copyright © 2024 Keith Irwin + +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: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +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. diff --git a/apps/pokertimer/README.md b/apps/pokertimer/README.md new file mode 100644 index 0000000000..ce8316def6 --- /dev/null +++ b/apps/pokertimer/README.md @@ -0,0 +1,55 @@ +# Poker Timer +*v.0.06* + +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). + +![Screenshot showing countdown paused on start](screenshots/01_paused-start.png) +![Screenshot showing active countdown](screenshots/02_counting-down.png) +![Screenshot showing blinds up alert](screenshots/03_blinds-up.png) + +The blinds are hardcoded and go up every ten minutes: + +- 1, 2 +- 2, 4 +- 4, 8 +- 5, 10 +- 10, 20 +- 20, 40 +- 40, 80 + +... and so on, doubling each round. + +## Features + +- Starts paused +- Button to pause/resume +- 20-second warning buzz +- Auto-exit after round 25 + +## Usage + +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. + +### Auto-exit + +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. + +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. + +## Controls + + - **Pause/Resume:** Press the button + - **Exit:** hold down the button + +## Roadmap + +- Set settings +- Better graphics + +## Requests + +[Contact Keith Irwin](https://www.ki9.us/contact/) + +## Creator + +[Keith Irwin](https://www.ki9.us) diff --git a/apps/pokertimer/app-icon.js b/apps/pokertimer/app-icon.js new file mode 100644 index 0000000000..bf7227a801 --- /dev/null +++ b/apps/pokertimer/app-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("kso4cB7nW///7fWm2Vw8p7fOgH6lM6hEqgQCDkNCgmSpMkyUQqkEAQsJBYIOBkGohACD8dIiQaCpFBhUQAQVD+9qDQeQwWgkGCikg1lxknZBwUhgkooICCnMjpO1qIOBoUKwGCAQXt32TtMkwUkwkVgIdFg3SGQOBNYoCChuklfAgBQCPokqjdBluCNAJTBkN4UwVBm2C5ckxFBqEQq/+BYKMBtstz1JiBuC/+T2gjC7VYlmSkMFoFOQQON0mShO0iFNkhuC8iCBk4aBwdpFgNENwMOVgft1Ms9uiwNJLIM/VgWTxUFjdrtsUiUQ0NPXYe0qE27XRoLdC/wpCpxvBtuzpMiboX8DQXtQYPbtto0jdCm87zvOIwMh23YgDdBNwNBh/bYoL7BtuapDdE2VGWYMgw3brUpbocF/mcIYMIlu10WCpL4FihEB3PboBaBiFUGQOhAQcbqkgLQL1CdIYCBm2oIgNIru36VJkD+BboUgxMkyGcyOk1VIkGFboWhiRuBrHiqpBBIgUVboJEBoUf3dSK4IpBhUTtEiIgOEjlpGolBg3QoiuBJoZWCAQMN0kJFIIyCIIQCBkNb1JEBc4Ul2zKBAQW7qLzDBw7pBBYYCDwgpCoUEBYoCC0A7CBY4CCykooALIBwcRAoQ")) diff --git a/apps/pokertimer/app.js b/apps/pokertimer/app.js new file mode 100644 index 0000000000..9d584b3b2a --- /dev/null +++ b/apps/pokertimer/app.js @@ -0,0 +1,142 @@ +const BLIND_INTERVAL = 600; // 10 minutes in seconds +const BLINDSUP_ALERT_DURATION = 10000; // 10 seconds in ms + +// Convert seconds to mm:ss +const secondsToMinutes = (s) => { + const mm = Math.floor(s/60); + const ss = s - mm * 60; + return `${mm}:${String(ss).padStart(2,'0')}`; +}; + +// Format screen +const fmtDark = () => { + g.clear(); + g.setFontAlign(0,0); + g.setBgColor(0,0.5,0); + g.setColor(1,1,1); +}; +const fmtLight = () => { + g.clear(); + g.setFontAlign(0,0); + g.setBgColor(0.5,1,0.5); + g.setColor(0,0,0); +}; + +// Start/stop/pause/resume timer +const startTimer = () => { + timer_running = true; tick(); + timer = setInterval(tick, 1000); +}; +const stopTimer = () => { + clearInterval(timer); + timer_running = false; +}; +const pauseResume = () => { + if (is_alerting) return; + if (timer_running) { + stopTimer(); + g.setFont('Vector',15); + g.drawString('(PAUSED)', + g.getWidth()/2, g.getHeight()*7/8); + } + else startTimer(); +}; + +// Calculate blinds for a round +const getBlinds = (i) => { + let small; + if (i===0) small = 1; + else if (i===1) small = 2; + else if (i===2) small = 4; + else small = 5*(Math.pow(2,(i-3))); + return [small, small*2]; +}; + +// Sound the alarm +const blindsUp = () => { + is_alerting = true; + // Display message + const showMessage = () => { + g.clear(); + g.setFont('Vector',34); + g.drawString('Blinds Up!', + g.getWidth()/2, g.getHeight()/3); + g.setFont('Vector',40); + g.drawString(`${blinds[0]}/${blinds[1]}`, + g.getWidth()/2, g.getHeight()*2/3); + }; + stopTimer(); + // Increase blinds + b++; + // TODO: Kill program between round 25 and 26 + blinds = getBlinds(b); + console.log(`Blinds for round ${b} are ${blinds[0]} / ${blinds[1]}`); + // Buzz and light up every second + const buzzInterval = setInterval(() => { + Bangle.buzz(500); + Bangle.setLCDPower(1); + }, 1000); + // Invert colors every second + fmtLight(); showMessage(); let dark = false; + const flashInterval = setInterval(() => { + if (dark) { + fmtLight(); + dark = false; + } else { + fmtDark(); + dark = true; + } showMessage(); + }, 500); + // Restart timer + setTimeout(() => { + is_alerting = false; + fmtDark(); tick(); + clearInterval(buzzInterval); + clearInterval(flashInterval); + time_left = BLIND_INTERVAL + 1; + startTimer(); + }, BLINDSUP_ALERT_DURATION); +}; + +// Tick every second +const tick = () => { + if (!timer_running) return; + time_left--; + // 20-second warning buzz + if (time_left==20) { + const buzzInterval = setInterval(Bangle.buzz, 500); + setTimeout(() => { + clearInterval(buzzInterval); + }, 5000); + } + if (time_left<=0) blindsUp(); + else { + g.clear(); + g.setFont('Vector',40); + g.drawString( + secondsToMinutes(time_left), + g.getWidth()/2, g.getHeight()/3); + g.drawString( + `${blinds[0]}/${blinds[1]}`, + g.getWidth()/2, g.getHeight()*2/3); + } + return; +}; + +// button listener +Bangle.setUI({ + mode: 'custom', + btn: pauseResume, +}); + +// RUNTIME +fmtDark(); +let time_left = BLIND_INTERVAL + 1; +let b = 0; +let blinds = getBlinds(b); +let timer_running = true; +let is_alerting = false; +let timer = setInterval(tick, 1000); +tick(); +// Start paused +pauseResume(); diff --git a/apps/pokertimer/app.png b/apps/pokertimer/app.png new file mode 100644 index 0000000000..31a48dbb0a Binary files /dev/null and b/apps/pokertimer/app.png differ diff --git a/apps/pokertimer/metadata.json b/apps/pokertimer/metadata.json new file mode 100644 index 0000000000..a22229e4fb --- /dev/null +++ b/apps/pokertimer/metadata.json @@ -0,0 +1,15 @@ +{ + "id": "pokertimer", + "name": "Poker Timer", + "shortName":"Poker Timer", + "readme":"README.md", + "icon": "app.png", + "version":"0.06", + "description": "A blinds timer for use with Texas Hold 'Em", + "tags": "poker", + "supports": ["BANGLEJS2"], + "storage": [ + {"name":"pokertimer.app.js","url":"app.js"}, + {"name":"pokertimer.img","url":"app-icon.js","evaluate":true} + ] +} diff --git a/apps/pokertimer/screenshots/01_paused-start.png b/apps/pokertimer/screenshots/01_paused-start.png new file mode 100644 index 0000000000..929bd473eb Binary files /dev/null and b/apps/pokertimer/screenshots/01_paused-start.png differ diff --git a/apps/pokertimer/screenshots/02_counting-down.png b/apps/pokertimer/screenshots/02_counting-down.png new file mode 100644 index 0000000000..38425a68b5 Binary files /dev/null and b/apps/pokertimer/screenshots/02_counting-down.png differ diff --git a/apps/pokertimer/screenshots/03_blinds-up.png b/apps/pokertimer/screenshots/03_blinds-up.png new file mode 100644 index 0000000000..b017497190 Binary files /dev/null and b/apps/pokertimer/screenshots/03_blinds-up.png differ