summaryrefslogtreecommitdiff
path: root/keyboards/winry
diff options
context:
space:
mode:
authorfauxpark <fauxpark@gmail.com>2023-07-08 01:01:36 +1000
committerfauxpark <fauxpark@gmail.com>2023-07-08 01:01:36 +1000
commitea1a9c37ed76aac93205b1aec38b11a310a50591 (patch)
treea9b8c1255aded2d43bc90dc1fdadc739411d8cfb /keyboards/winry
parentb32392f7b20e98f9776ef3f7dd79b1c43bd41c9d (diff)
parent71f0fc59bef7a37b55c7e1c10b1b21b8a86475b7 (diff)
Merge remote-tracking branch 'upstream/master' into develop
Diffstat (limited to 'keyboards/winry')
-rw-r--r--keyboards/winry/winry25tc/info.json5
-rw-r--r--keyboards/winry/winry25tc/keymaps/lightsout/keymap.c136
-rw-r--r--keyboards/winry/winry25tc/keymaps/lightsout/readme.md3
3 files changed, 143 insertions, 1 deletions
diff --git a/keyboards/winry/winry25tc/info.json b/keyboards/winry/winry25tc/info.json
index 26329497fb..a5d3b71a26 100644
--- a/keyboards/winry/winry25tc/info.json
+++ b/keyboards/winry/winry25tc/info.json
@@ -15,7 +15,10 @@
15 "saturation_steps": 8, 15 "saturation_steps": 8,
16 "brightness_steps": 8, 16 "brightness_steps": 8,
17 "led_count": 40, 17 "led_count": 40,
18 "max_brightness": 150 18 "max_brightness": 150,
19 "animations": {
20 "rainbow_swirl": true
21 }
19 }, 22 },
20 "matrix_pins": { 23 "matrix_pins": {
21 "cols": ["F5", "C7", "B7", "B2", "B4"], 24 "cols": ["F5", "C7", "B7", "B2", "B4"],
diff --git a/keyboards/winry/winry25tc/keymaps/lightsout/keymap.c b/keyboards/winry/winry25tc/keymaps/lightsout/keymap.c
new file mode 100644
index 0000000000..f175f36b91
--- /dev/null
+++ b/keyboards/winry/winry25tc/keymaps/lightsout/keymap.c
@@ -0,0 +1,136 @@
1/* Copyright 2023 Tom Parker-Shemilt <palfrey@tevp.net>
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 */
15
16#include <stdlib.h>
17
18#include QMK_KEYBOARD_H
19
20// clang-format off
21
22// Exact keymap is irrelevant as we're using rows/cols
23// but we need _something_ set so we're using no-ops
24const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
25 [0] = LAYOUT(
26 KC_NO, KC_NO, KC_NO, KC_NO, KC_NO,
27 KC_NO, KC_NO, KC_NO, KC_NO, KC_NO,
28 KC_NO, KC_NO, KC_NO, KC_NO, KC_NO,
29 KC_NO, KC_NO, KC_NO, KC_NO, KC_NO,
30 KC_NO, KC_NO, KC_NO, KC_NO, KC_NO
31 )};
32
33bool tiles[5][5] = {
34 {false, false, false, false, false},
35 {false, false, false, false, false},
36 {false, false, false, false, false},
37 {false, false, false, false, false},
38 {false, false, false, false, false},
39};
40
41/* Because snake pattern of leds */
42const uint8_t remap[25] = {
43 20,21,22,23,24,
44 19,6,7,8,9,
45 18,5,0,1,10,
46 17,4,3,2,11,
47 16,15,14,13,12,
48};
49
50// clang-format on
51
52bool is_blank(void) {
53 for (uint8_t y = 0; y < 5; y++) {
54 for (uint8_t x = 0; x < 5; x++) {
55 if (tiles[x][y]) {
56 return false;
57 }
58 }
59 }
60 return true;
61}
62
63void do_move(uint8_t x, uint8_t y) {
64 tiles[x][y] ^= true;
65 if (x > 0) {
66 tiles[x - 1][y] ^= true;
67 }
68 if (y > 0) {
69 tiles[x][y - 1] ^= true;
70 }
71 if (x < 4) {
72 tiles[x + 1][y] ^= true;
73 }
74 if (y < 4) {
75 tiles[x][y + 1] ^= true;
76 }
77}
78
79void refresh_leds(void) {
80 for (uint8_t y = 0; y < 5; y++) {
81 for (uint8_t x = 0; x < 5; x++) {
82 uint8_t tile = tiles[x][y];
83 uint8_t index = (y * 5) + x;
84 if (tile) {
85 setrgb(RGB_RED, &led[remap[index]]);
86 } else {
87 setrgb(RGB_WHITE, &led[remap[index]]);
88 }
89 }
90 }
91 rgblight_set();
92}
93
94uint8_t initial_moves = 1;
95
96void start_game(void) {
97 rgblight_mode(RGBLIGHT_MODE_STATIC_LIGHT);
98 srand(timer_read32());
99 while (true) {
100 for (uint8_t i = 0; i < initial_moves; i++) {
101 do_move(rand() % 5, rand() % 5);
102 }
103 if (!is_blank()) {
104 // Catch the "we picked the same location 2*N times" case
105 break;
106 }
107 }
108 refresh_leds();
109}
110
111void keyboard_post_init_user(void) {
112 rgblight_enable_noeeprom();
113 start_game();
114}
115
116bool won = false;
117
118bool process_record_user(uint16_t keycode, keyrecord_t *record) {
119 if (record->event.pressed) {
120 if (won) {
121 initial_moves++;
122 won = false;
123 start_game();
124 } else {
125 uint8_t x = record->event.key.col;
126 uint8_t y = record->event.key.row;
127 do_move(x, y);
128 if (is_blank()) {
129 rgblight_mode(RGBLIGHT_MODE_RAINBOW_SWIRL);
130 won = true;
131 }
132 }
133 }
134 refresh_leds();
135 return true;
136}
diff --git a/keyboards/winry/winry25tc/keymaps/lightsout/readme.md b/keyboards/winry/winry25tc/keymaps/lightsout/readme.md
new file mode 100644
index 0000000000..4271bff43f
--- /dev/null
+++ b/keyboards/winry/winry25tc/keymaps/lightsout/readme.md
@@ -0,0 +1,3 @@
1# Lights Out game
2
3Implements a "lights out" mode as per https://en.m.wikipedia.org/wiki/Lights_Out_(game) with a single move having been played on start. On completion of the game, the Rainbow Swirl pattern is displayed. If another key is then pressed, the game resets, with the initial number of moves incremented by one.