Skip to content

Commit 1d3b27e

Browse files
committed
Merge remote-tracking branch 'origin/master' into develop
2 parents 62b89f8 + d7225ea commit 1d3b27e

File tree

2 files changed

+360
-0
lines changed

2 files changed

+360
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,355 @@
1+
/* Copyright 2021 customMK, Moritz Plattner
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, either version 2 of the License, or
6+
* (at your option) any later version.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License
14+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
*/
16+
17+
#include QMK_KEYBOARD_H
18+
19+
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
20+
21+
[0] = LAYOUT_1800_all( /* keymap for layer 0 */
22+
KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_INS, KC_HOME, KC_PGUP, KC_PSCR,
23+
KC_DEL, KC_END, KC_PGDN, KC_SCRL,
24+
KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_NUM, KC_PSLS, KC_PAST, KC_PAUS,
25+
KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_KP_7, KC_KP_8, KC_KP_9, KC_PMNS,
26+
KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_NUHS, KC_ENT, KC_KP_4, KC_KP_5, KC_KP_6, KC_PPLS,
27+
KC_LSFT, KC_NUBS, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, KC_KP_1, KC_KP_2, KC_KP_3, KC_PENT,
28+
KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT, KC_RGUI, LT(1, KC_APP), KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT, KC_KP_0, KC_PDOT),
29+
30+
[1] = LAYOUT_1800_all( /* keymap for layer 1 */
31+
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, BL_UP, KC_TRNS,
32+
KC_TRNS, BL_TOGG, BL_DOWN, BL_BRTG,
33+
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MPLY,
34+
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_VOLU, KC_TRNS, KC_TRNS,
35+
CL_TOGG, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MPRV, KC_MUTE, KC_MNXT, KC_TRNS,
36+
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, NK_TOGG, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_VOLD, KC_TRNS, KC_TRNS,
37+
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS),
38+
39+
[2] = LAYOUT_1800_all( /* keymap for layer 2 */
40+
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
41+
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
42+
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
43+
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
44+
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
45+
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
46+
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS)
47+
48+
};
49+
50+
/* Bongocat animation copied from the evo70 by customMK, slight modifications to make it standalone */
51+
#ifdef OLED_ENABLE
52+
#include "matrix.h"
53+
#include OLED_FONT_H
54+
55+
extern matrix_row_t matrix[MATRIX_ROWS];
56+
57+
#define ANIM_FRAME_DURATION 100
58+
#define IDLE_FRAMES 5
59+
#define IDLE_TIMEOUT 750
60+
#define SLEEP_TIMEOUT 15000
61+
62+
static bool OLED_redraw = true;
63+
64+
static const uint8_t bongofont[] PROGMEM = { \
65+
0xC1, 0xC1, 0xC2, 0x04, 0x08, 0x10, \
66+
0xC0, 0x38, 0x04, 0x03, 0x00, 0x00, \
67+
0xA0, 0x22, 0x24, 0x14, 0x12, 0x12, \
68+
0xA0, 0x21, 0x22, 0x12, 0x11, 0x11, \
69+
0x83, 0x7C, 0x41, 0x41, 0x40, 0x40, \
70+
0x82, 0x82, 0x84, 0x08, 0x10, 0x20, \
71+
0x80, 0x80, 0x00, 0x00, 0x00, 0x00, \
72+
0x80, 0x70, 0x19, 0x06, 0x00, 0x00, \
73+
0x80, 0x70, 0x0C, 0x03, 0x00, 0x00, \
74+
0x80, 0x00, 0x30, 0x30, 0x00, 0xC0, \
75+
0x80, 0x00, 0x30, 0x30, 0x00, 0x00, \
76+
0x49, 0x88, 0x08, 0x08, 0x08, 0x00, \
77+
0x44, 0x84, 0x04, 0x04, 0x00, 0x00, \
78+
0x40, 0x80, 0x00, 0x00, 0x00, 0x00, \
79+
0x40, 0x40, 0x20, 0x20, 0x20, 0x20, \
80+
0x3C, 0xC2, 0x01, 0x01, 0x02, 0x02, \
81+
0x35, 0x01, 0x8A, 0x7C, 0x00, 0x00, \
82+
0x20, 0x40, 0x80, 0x00, 0x00, 0x00, \
83+
0x20, 0x21, 0x22, 0x12, 0x11, 0x11, \
84+
0x20, 0x20, 0x10, 0x10, 0x10, 0x10, \
85+
0x1E, 0xE1, 0x00, 0x00, 0x01, 0x01, \
86+
0x1C, 0xE2, 0x01, 0x01, 0x02, 0x02, \
87+
0x18, 0x64, 0x82, 0x02, 0x02, 0x02, \
88+
0x18, 0x60, 0x80, 0x00, 0x00, 0x00, \
89+
0x18, 0x18, 0x1B, 0x03, 0x00, 0x40, \
90+
0x18, 0x06, 0x05, 0x98, 0x99, 0x84, \
91+
0x12, 0x0B, 0x08, 0x08, 0x08, 0x08, \
92+
0x11, 0x09, 0x08, 0x08, 0x08, 0x08, \
93+
0x10, 0x10, 0xD0, 0x11, 0x0F, 0x21, \
94+
0x10, 0x10, 0x10, 0x11, 0x0F, 0x01, \
95+
0x10, 0x08, 0x08, 0x04, 0x04, 0x04, \
96+
0x10, 0x08, 0x04, 0x02, 0x02, 0x04, \
97+
0x0C, 0x30, 0x40, 0x80, 0x00, 0x00, \
98+
0x0C, 0x0C, 0x0D, 0x01, 0x00, 0x40, \
99+
0x08, 0xE8, 0x08, 0x07, 0x10, 0x24, \
100+
0x08, 0x30, 0x40, 0x80, 0x00, 0x00, \
101+
0x08, 0x08, 0x08, 0x07, 0x00, 0x00, \
102+
0x08, 0x08, 0x04, 0x02, 0x02, 0x02, \
103+
0x08, 0x04, 0x02, 0x01, 0x01, 0x02, \
104+
0x05, 0x05, 0x09, 0x09, 0x10, 0x10, \
105+
0x04, 0x38, 0x40, 0x80, 0x00, 0x00, \
106+
0x04, 0x04, 0x08, 0x08, 0x10, 0x10, \
107+
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, \
108+
0x04, 0x04, 0x02, 0x01, 0x00, 0x00, \
109+
0x02, 0x02, 0x81, 0x80, 0x80, 0x00, \
110+
0x02, 0x02, 0x04, 0x04, 0x08, 0x08, \
111+
0x02, 0x02, 0x02, 0x01, 0x01, 0x01, \
112+
0x02, 0x02, 0x01, 0x00, 0x00, 0x00, \
113+
0x01, 0xE1, 0x1A, 0x06, 0x09, 0x31, \
114+
0x01, 0x01, 0x02, 0x04, 0x08, 0x10, \
115+
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, \
116+
0x00, 0x80, 0x80, 0x00, 0x00, 0x00, \
117+
0x00, 0x80, 0x40, 0x40, 0x20, 0x20, \
118+
0x00, 0x00, 0x80, 0x80, 0x40, 0x40, \
119+
0x00, 0x00, 0x60, 0x60, 0x00, 0x81, \
120+
0x00, 0x00, 0x01, 0x01, 0x00, 0x40, \
121+
0x00, 0x00, 0x00, 0x00, 0x00, 0x18, \
122+
0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, \
123+
0x00, 0x00, 0x00, 0x00, 0x00, 0x03, \
124+
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, \
125+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
126+
127+
128+
static const uint8_t bongo_line_x[] = {51, 49, 48, 57};
129+
static const uint8_t bongo_line_y[] = {0, 8, 16, 24};
130+
static const uint8_t bongo_line_len[] = {5, 7, 8, 6};
131+
132+
const uint8_t bongo_line_data[8][26] PROGMEM = {
133+
{ //idle1
134+
60, 52, 19, 30, 35, \
135+
22, 47, 51, 60, 9, 0, 17, \
136+
1, 57, 33, 3, 27, 41, 29, 50, \
137+
45, 36, 60, 60, 60, 60}, \
138+
{ //idle2
139+
60, 52, 19, 30, 35, \
140+
22, 47, 51, 60, 9, 0, 17, \
141+
1, 57, 33, 3, 27, 41, 29, 50, \
142+
45, 36, 60, 60, 60, 60}, \
143+
{ //idle3
144+
60, 53, 14, 31, 23, \
145+
15, 43, 60, 60, 54, 5, 13, \
146+
7, 56, 24, 2, 26, 39, 29, 50, \
147+
45, 36, 60, 60, 60, 60}, \
148+
{ //idle4
149+
6, 52, 19, 38, 32, \
150+
20, 47, 51, 60, 9, 0, 17, \
151+
8, 57, 33, 3, 27, 41, 29, 50, \
152+
45, 36, 60, 60, 60, 60}, \
153+
{ //idle5
154+
60, 52, 19, 37, 40, \
155+
21, 47, 51, 60, 9, 0, 17, \
156+
8, 57, 33, 3, 27, 41, 29, 50, \
157+
45, 36, 60, 60, 60, 60}, \
158+
{ //prep
159+
6, 52, 19, 38, 32, \
160+
20, 44, 51, 60, 10, 48, 16, \
161+
8, 25, 4, 18, 27, 42, 46, 50, \
162+
60, 60, 60, 60, 60, 60}, \
163+
{ //tap1
164+
6, 52, 19, 38, 32, \
165+
20, 44, 51, 60, 10, 49, 17, \
166+
8, 25, 4, 18, 27, 41, 28, 11, \
167+
60, 60, 60, 60, 58, 59}, \
168+
{ //tap2
169+
6, 52, 19, 38, 32, \
170+
20, 47, 51, 60, 10, 48, 16, \
171+
8, 60, 55, 3, 27, 42, 46, 50, \
172+
45, 34, 12, 60, 60, 60}
173+
};
174+
175+
enum anin_states { sleep, idle, prep, tap };
176+
uint8_t anim_state = idle;
177+
uint32_t idle_timeout_timer = 0;
178+
uint32_t anim_timer = 0;
179+
uint8_t current_idle_frame = 0;
180+
uint8_t current_tap_frame = 6;
181+
uint8_t last_bongo_frame = 12;
182+
183+
void write_bongochar_at_pixel_xy(uint8_t x, uint8_t y, uint8_t data, bool invert) {
184+
uint8_t i, j, temp;
185+
for (i = 0; i < 6 ; i++) { // 6 = font width
186+
temp = pgm_read_byte(&bongofont[data * 6]+i);
187+
for (j = 0; j < 8; j++) { // 8 = font height
188+
if (temp & 0x01) {
189+
oled_write_pixel(x + i, y + j, !invert);
190+
} else {
191+
oled_write_pixel(x + i, y + j, invert);
192+
}
193+
temp >>= 1;
194+
}
195+
}
196+
}
197+
198+
bool is_key_down(void) {
199+
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
200+
if (matrix[i] > 0) {
201+
return true;
202+
}
203+
}
204+
return false;
205+
}
206+
207+
void eval_anim_state(void) {
208+
bool key_down;
209+
key_down = is_key_down();
210+
211+
switch (anim_state) {
212+
case sleep:
213+
if(key_down) { anim_state = tap; }
214+
break;
215+
case idle:
216+
if(key_down) { anim_state = tap; }
217+
else if (timer_elapsed32(idle_timeout_timer) >= SLEEP_TIMEOUT) //prep to idle
218+
{
219+
anim_state = sleep;
220+
current_idle_frame = 0;
221+
}
222+
break;
223+
case prep:
224+
if(key_down) { anim_state = tap; }
225+
else if (timer_elapsed32(idle_timeout_timer) >= IDLE_TIMEOUT) //prep to idle
226+
{
227+
anim_state = idle;
228+
current_idle_frame = 0;
229+
}
230+
break;
231+
case tap:
232+
if (!key_down)
233+
{
234+
anim_state = prep;
235+
idle_timeout_timer = timer_read32();
236+
}
237+
break;
238+
default:
239+
break;
240+
}
241+
}
242+
243+
void draw_bongo_table(void) {
244+
//draws the table edge for bongocat, this edge doesn't change during the animation
245+
uint8_t i;
246+
uint8_t y = 31;
247+
uint8_t j = 0;
248+
for (i = 17; i < 57; i++) {
249+
oled_write_pixel(i, y, true); //every five horizontal pixels, move up one pixel to make a diagonal line
250+
if (j == 4) {
251+
--y;
252+
j=0;
253+
} else {
254+
j++;
255+
}
256+
}
257+
258+
y=15;
259+
j=0;
260+
for (i = 91; i < 128; i++) {
261+
262+
oled_write_pixel(i, y, true); //every four horizontal pixels, move up one pixel to make a diagonal line
263+
if (j == 3) {
264+
--y;
265+
j=0;
266+
} else {
267+
j++;
268+
}
269+
}
270+
271+
272+
}
273+
274+
275+
void draw_bongocat_frame(int framenumber) {
276+
//only redraw if the animation frame has changed
277+
if (framenumber != last_bongo_frame) {
278+
last_bongo_frame = framenumber;
279+
uint8_t i, j, current_bongochar = 0;
280+
for (i = 0; i < 4; i++) {
281+
for (j = 0; j < bongo_line_len[i]; j++) {
282+
write_bongochar_at_pixel_xy(bongo_line_x[i] + j*6, bongo_line_y[i], pgm_read_byte(&bongo_line_data[framenumber][current_bongochar]), false);
283+
current_bongochar++;
284+
}
285+
}
286+
}
287+
288+
}
289+
290+
bool is_new_tap(void) {
291+
static matrix_row_t old_matrix[] = { 0, 0, 0, 0, 0, 0, 0 };
292+
bool new_tap = false;
293+
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
294+
if (matrix[i] > old_matrix[i]) { // more 1's detected, there was a new tap
295+
new_tap = true;
296+
}
297+
old_matrix[i] = matrix[i];
298+
}
299+
return new_tap;
300+
}
301+
302+
void draw_bongocat(void) {
303+
static bool already_tapped = false;
304+
if (is_new_tap()) {
305+
already_tapped = false;
306+
};
307+
eval_anim_state();
308+
switch (anim_state) {
309+
case sleep:
310+
draw_bongocat_frame(4);
311+
break;
312+
case idle:
313+
draw_bongocat_frame(4 - current_idle_frame);
314+
if (timer_elapsed32(anim_timer) > ANIM_FRAME_DURATION) {
315+
current_idle_frame = (current_idle_frame + 1) % 5;
316+
anim_timer = timer_read32();
317+
}
318+
break;
319+
case prep:
320+
draw_bongocat_frame(5);
321+
already_tapped = false;
322+
break;
323+
case tap:
324+
draw_bongocat_frame(current_tap_frame);
325+
if (already_tapped == false) {
326+
if (current_tap_frame == 6) {
327+
current_tap_frame = 7;
328+
}
329+
else {
330+
current_tap_frame = 6;
331+
}
332+
}
333+
already_tapped = true;
334+
break;
335+
default:
336+
draw_bongocat_frame(4);
337+
already_tapped = false;
338+
break;
339+
340+
}
341+
}
342+
343+
bool oled_task_user(void) {
344+
345+
if (OLED_redraw){
346+
oled_clear();
347+
last_bongo_frame = 12; //force a redraw
348+
draw_bongo_table();
349+
OLED_redraw = false;
350+
}
351+
draw_bongocat();
352+
return false;
353+
}
354+
355+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
VIA_ENABLE = yes
2+
3+
OLED_ENABLE = yes
4+
OLED_DRIVER = SSD1306
5+
WPM_ENABLE = yes

0 commit comments

Comments
 (0)