From 30a349f3feb8bb757670b7d683f88e44b850b2bd Mon Sep 17 00:00:00 2001 From: Keith Irwin Date: Wed, 6 Nov 2024 07:25:14 -0700 Subject: [PATCH] Re-added pokertimer not as a submodule --- apps/pokertimer/ChangeLog | 1 + apps/pokertimer/LICENSE | 9 +++ apps/pokertimer/README.md | 32 +++++++++ apps/pokertimer/ROADMAP.md | 17 +++++ apps/pokertimer/app-icon.js | 1 + apps/pokertimer/app.img | Bin 0 -> 714 bytes apps/pokertimer/app.js | 124 ++++++++++++++++++++++++++++++++++ apps/pokertimer/app.png | Bin 0 -> 1132 bytes apps/pokertimer/metadata.json | 15 ++++ 9 files changed, 199 insertions(+) create mode 100644 apps/pokertimer/ChangeLog create mode 100644 apps/pokertimer/LICENSE create mode 100644 apps/pokertimer/README.md create mode 100644 apps/pokertimer/ROADMAP.md create mode 100644 apps/pokertimer/app-icon.js create mode 100644 apps/pokertimer/app.img create mode 100644 apps/pokertimer/app.js create mode 100644 apps/pokertimer/app.png create mode 100644 apps/pokertimer/metadata.json diff --git a/apps/pokertimer/ChangeLog b/apps/pokertimer/ChangeLog new file mode 100644 index 000000000..642dbcc7e --- /dev/null +++ b/apps/pokertimer/ChangeLog @@ -0,0 +1 @@ +0.0.1: Packaged app diff --git a/apps/pokertimer/LICENSE b/apps/pokertimer/LICENSE new file mode 100644 index 000000000..a2bb2da01 --- /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 000000000..09aa2d6a1 --- /dev/null +++ b/apps/pokertimer/README.md @@ -0,0 +1,32 @@ +# Poker Timer + +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). + +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. + +## 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. + +## Controls + + - **Pause/Resume:** Press the button + - **Exit:** hold down the button. + +## Requests + +[Contact Keith Irwin](https://www.ki9.us/contact/) + +## Creator + +[Keith Irwin](https://www.ki9.us) diff --git a/apps/pokertimer/ROADMAP.md b/apps/pokertimer/ROADMAP.md new file mode 100644 index 000000000..b182c5b38 --- /dev/null +++ b/apps/pokertimer/ROADMAP.md @@ -0,0 +1,17 @@ +# Roadmap + +## Bugs + +- Unlock before vibrate/flash + +## Improvements + +- Screenshots in README +- Start app paused +- Indicate when paused +- 20-second warning + +## Long-term projects + +- Set settings +- Better graphics diff --git a/apps/pokertimer/app-icon.js b/apps/pokertimer/app-icon.js new file mode 100644 index 000000000..bf7227a80 --- /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.img b/apps/pokertimer/app.img new file mode 100644 index 0000000000000000000000000000000000000000..e2e05ea17aef14d8efd6130ffe6d010ade2347b4 GIT binary patch literal 714 zcmb7?KTE?<6va;(trRIj1qG`RC4*9QYmwrRL7`C*ovo0;L7@TNT5xy;LEK7Eadhwl zbgBg%3WDI`Bt;2GR~`KV_1<^WKda&8a?kDWop+KnlX*76w{G`hK6|~C_dciF!MPo{ z|6B$1u4rRVA|+OlK2`|5Ib zY$f(P7@A_V9*EEOeN!QM<57#qa^*3)IT>r2U8A0Q33{Xdtb5 zH+I?)KB?H>uD%yV$6K0r5_h6akNsV1VpX(J*L=;~7EPak{RaU`nja3p{=7oJLF-HN ddcra+3onfJ?D5R-Alfb_bdWUtN`C;?`UC5bn?C>m literal 0 HcmV?d00001 diff --git a/apps/pokertimer/app.js b/apps/pokertimer/app.js new file mode 100644 index 000000000..26b72c481 --- /dev/null +++ b/apps/pokertimer/app.js @@ -0,0 +1,124 @@ +const BLIND_INTERVAL = 600; // 10 minutes +const BLINDSUP_ALERT_DURATION = 5000; // 30 seconds + +// 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 (timer_running) stopTimer(); + 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 = () => { + // 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(); + 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(() => { + 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--; + 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 timer = setInterval(tick, 1000); +tick(); diff --git a/apps/pokertimer/app.png b/apps/pokertimer/app.png new file mode 100644 index 0000000000000000000000000000000000000000..31a48dbb0a211500937af6a7bb7fc058d2f3164f GIT binary patch literal 1132 zcmV-y1e5!TP)Ic-y-^{?acbn_=_PT5Dl6#UTlbzX1p5M&P?Ch*0WtCM{afJvwjR*s~EMqz(*(p22 z>y|PF;9yG|JpAM`XlnIjCcyf4wm?q78Yr)PH}e1n10i_qnOrz;fyJpngX&Vy@}c>)0Uci-xLdILow z4_Xdz*yDp``Gq39?&Srm;mC2HX#nNNQ*gQZWf(tm8kna^fT-S|Mj%NPF1`BZ69uh@YwkT0Q4dN+-4a-eo=`jfP%GCPhO+7$0gzG>lT1A z&=dbY%ot7Y^+*EEeoK z#(2J^0LQ*R2@9WE5fhT{GNVh~{64p@D`|jVKYBeDfUvHV!Y2aY_H^}$my}g&)O(i%0$_B-ruPH@-%gnMon`>g+>J5q z0abm-c7V>l0a)~Ot^nX=r++XdfZsRf82>)wDThxMAgHL5`yk!LrRAdD48XO@JP3zJ z4HKB|upMBwK3BL1j?`|C+ZK*!jFx=w1D-uh-ky-g(v4>`6K}@A;0NLB3_a8J@5|R8_r8noIHZ8xdN9F#ATv z^fxnqDVflADV^j7m=_{iF5gv(qw*O5LRfo4N@s-#S-?MD$b@?NyKYSHWBTv#_|FeW ynWD3*dbf<#b%@X=nb1r8%gkJ7$|@@