1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
|
/* Copyright 2021 Felix Springer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
RGB_MATRIX_EFFECT(base_effect)
RGB_MATRIX_EFFECT(base_ad_effect)
RGB_MATRIX_EFFECT(vi_effect)
RGB_MATRIX_EFFECT(fn_indicator)
RGB_MATRIX_EFFECT(kb_indicator)
RGB_MATRIX_EFFECT(kitt_effect)
#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
/*
[_LEDS] = LAYOUT_65_ansi(
0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 ,
15 , 16 Q, 17 W, 18 E, 19 R, 20 T, 21 Y, 22 U, 23 I, 24 O, 25 P, 26 , 27 , 28 , 29 ,
30 , 31 A, 32 S, 33 D, 34 F, 35 G, 36 H, 37 J, 38 K, 39 L, 40 , 41 , 42 , 43 ,
44 , 45 Z, 46 X, 47 C, 48 V, 49 B, 50 N, 51 M, 52 , 53 , 54 , 55 , 56 , 57 ,
58 , 59 , 60 , 61 , 62 , 63 , 64 , 65 , 66 , 67
)
*/
// variable for startup animation
bool BASE_EFFECT_NOT_STARTED_YET = true;
uint8_t base_effect_startup_counter = 255;
static HSV base_effect_math(HSV hsv, uint8_t i, uint8_t time) {
if (BASE_EFFECT_NOT_STARTED_YET) {
base_effect_startup_counter = 0;
BASE_EFFECT_NOT_STARTED_YET = false;
}
// startup animation
if (base_effect_startup_counter < 255) {
// jump to correct indices for alpha keys
if (i == 0) { // only run for one key (key 0 is an arbitrary choice)
if (base_effect_startup_counter == 0) {
base_effect_startup_counter = 1;
} else if (base_effect_startup_counter == 1) {
base_effect_startup_counter = 17;
} else if (base_effect_startup_counter == 26) {
base_effect_startup_counter = 31;
} else if (base_effect_startup_counter == 40) {
base_effect_startup_counter = 45;
} else if (base_effect_startup_counter == 52) {
base_effect_startup_counter = 100;
} else if (base_effect_startup_counter == 120) {
base_effect_startup_counter = 255;
} else {
base_effect_startup_counter++;
}
}
// overwrite some highlit keys
if (3 + 39 - i < base_effect_startup_counter - 100 && i >= 36 && i <= 39) {
hsv.s = hsv.s;
} else if (3 + 39 - i < base_effect_startup_counter - 100 && i >= 31 && i <= 34) {
hsv.s = hsv.s;
// light up alpha keys
} else if (i < base_effect_startup_counter && i >= 16 && i <= 25) {
hsv.s = 0;
} else if (31 + 39 - i < base_effect_startup_counter && i >= 31 && i <= 39) {
hsv.s = 0;
} else if (i < base_effect_startup_counter && i >= 45 && i <= 51) {
hsv.s = 0;
// light up number row
} else if (12 + 1 - i < base_effect_startup_counter - 100 && i == 2) {
hsv.s = 0;
hsv.v = 1 * (hsv.v / 8);
} else if (12 + 1 - i < base_effect_startup_counter - 100 && i == 3) {
hsv.s = 0;
hsv.v = 2 * (hsv.v / 8);
} else if (12 + 1 - i < base_effect_startup_counter - 100 && i == 4) {
hsv.s = 0;
hsv.v = 3 * (hsv.v / 8);
} else if (12 + 1 - i < base_effect_startup_counter - 100 && i >= 5 && i <= 8) {
hsv.v = hsv.v;
} else if (12 + 1 - i < base_effect_startup_counter - 100 && i == 9) {
hsv.s = 0;
hsv.v = 3 * (hsv.v / 8);
} else if (12 + 1 - i < base_effect_startup_counter - 100 && i == 10) {
hsv.s = 0;
hsv.v = 2 * (hsv.v / 8);
} else if (12 + 1 - i < base_effect_startup_counter - 100 && i == 11) {
hsv.s = 0;
hsv.v = 1 * (hsv.v / 8);
// light up punctuation keys
} else if (27 + 1 - i < base_effect_startup_counter - 100 && i >= 26 && i <= 27) {
hsv.s = 0;
hsv.v = hsv.v / 8;
} else if (41 + 2 - i < base_effect_startup_counter - 100 && i >= 40 && i <= 41) {
hsv.s = 0;
hsv.v = hsv.v / 8;
} else if (54 + 3 - i < base_effect_startup_counter - 100 && i >= 52 && i <= 54) {
hsv.s = 0;
hsv.v = hsv.v / 8;
// rest
} else {
hsv.v = 0;
}
} else {
switch (i) {
// number row
case 0:
hsv.v = 0;
break;
case 1:
hsv.v = 0;
break;
case 2:
hsv.s = 0;
hsv.v = 1 * (hsv.v / 8);
break;
case 3:
hsv.s = 0;
hsv.v = 2 * (hsv.v / 8);
break;
case 4:
hsv.s = 0;
hsv.v = 3 * (hsv.v / 8);
break;
case 5:
hsv.v = hsv.v;
break;
case 6:
hsv.v = hsv.v;
break;
case 7:
hsv.v = hsv.v;
break;
case 8:
hsv.v = hsv.v;
break;
case 9:
hsv.s = 0;
hsv.v = 3 * (hsv.v / 8);
break;
case 10:
hsv.s = 0;
hsv.v = 2 * (hsv.v / 8);
break;
case 11:
hsv.s = 0;
hsv.v = 1 * (hsv.v / 8);
break;
case 12:
hsv.v = 0;
break;
// punctuation keys
case 26:
hsv.s = 0;
hsv.v = hsv.v / 8;
break;
case 27:
hsv.s = 0;
hsv.v = hsv.v / 8;
break;
case 40:
hsv.s = 0;
hsv.v = hsv.v / 8;
break;
case 41:
hsv.s = 0;
hsv.v = hsv.v / 8;
break;
case 52:
hsv.s = 0;
hsv.v = hsv.v / 8;
break;
case 53:
hsv.s = 0;
hsv.v = hsv.v / 8;
break;
case 54:
hsv.s = 0;
hsv.v = hsv.v / 8;
break;
default:
if (
(i > 15 && i <= 25) ||
(i > 30 && i <= 39) ||
(i > 44 && i <= 51)
) {
if (i > 35 && i <= 39) {
hsv.s = hsv.s;
} else if (i > 30 && i <= 34) {
hsv.s = hsv.s;
} else {
hsv.s = 0;
}
} else {
hsv.v = 0;
}
break;
}
}
return hsv;
}
bool base_effect(effect_params_t* params) {
return effect_runner_i(params, &base_effect_math);
}
static HSV base_ad_effect_math(HSV hsv, uint8_t i, uint8_t time) {
// no startup animation
if (BASE_EFFECT_NOT_STARTED_YET) {
base_effect_startup_counter = 255; // act like startup is already completed
BASE_EFFECT_NOT_STARTED_YET = false;
}
switch (i) {
// delete
case 14:
hsv.h = 0;
hsv.s = 255;
break;
// insert
case 29:
hsv.h = 255/3;
hsv.s = 255;
break;
// home
case 43:
hsv.s = 0;
break;
// end
case 57:
hsv.s = 255;
break;
default:
hsv = base_effect_math(hsv, i, time);
break;
}
return hsv;
}
bool base_ad_effect(effect_params_t* params) {
return effect_runner_i(params, &base_ad_effect_math);
}
static HSV vi_effect_math(HSV hsv, uint8_t i, uint8_t time) {
// no startup animation
if (BASE_EFFECT_NOT_STARTED_YET) {
base_effect_startup_counter = 255; // act like startup is already completed
BASE_EFFECT_NOT_STARTED_YET = false;
}
switch (i) {
// hjkl
case 36:
break;
case 37:
break;
case 38:
break;
case 39:
break;
// page up
case 22:
hsv.s = 0;
break;
// page down
case 33:
hsv.s = 0;
break;
// find
case 54:
hsv.s = 0;
break;
default:
hsv.v = 0;
break;
}
return hsv;
}
bool vi_effect(effect_params_t* params) {
return effect_runner_i(params, &vi_effect_math);
}
static HSV fn_indicator_math(HSV hsv, uint8_t i, uint8_t time) {
// cancel base effect startup
base_effect_startup_counter = 255;
switch (i) {
// F1 - F12
case 1:
hsv.h = 0 * 255 / 3;
hsv.s = 255;
break;
case 2:
hsv.h = 0 * 255 / 3;
hsv.s = 255;
break;
case 3:
hsv.h = 0 * 255 / 3;
hsv.s = 255;
break;
case 4:
hsv.h = 0 * 255 / 3;
hsv.s = 255;
break;
case 5:
hsv.h = 1 * 255 / 3;
hsv.s = 255;
break;
case 6:
hsv.h = 1 * 255 / 3;
hsv.s = 255;
break;
case 7:
hsv.h = 1 * 255 / 3;
hsv.s = 255;
break;
case 8:
hsv.h = 1 * 255 / 3;
hsv.s = 255;
break;
case 9:
hsv.h = 2 * 255 / 3;
hsv.s = 255;
break;
case 10:
hsv.h = 2 * 255 / 3;
hsv.s = 255;
break;
case 11:
hsv.h = 2 * 255 / 3;
hsv.s = 255;
break;
case 12:
hsv.h = 2 * 255 / 3;
hsv.s = 255;
break;
// delete/insert
case 13:
hsv.h = 0;
hsv.s = 255;
break;
case 14:
hsv.h = 1 * (255 / 3);
hsv.s = 255;
break;
// paste/copy/cut
case 29:
hsv.s = 0;
break;
case 43:
hsv.h = 200;
hsv.s = 255;
break;
case 57:
hsv.h = 0;
hsv.s = 255;
break;
// print/scroll/pause
case 25:
hsv.s = 0;
break;
case 26:
hsv.s = 0;
break;
case 27:
hsv.s = 0;
break;
// caps lock
case 30:
hsv.s = 0;
break;
// modifier
case 44:
hsv.s = 0;
hsv.v = hsv.v / 2;
break;
case 55:
hsv.s = 0;
hsv.v = hsv.v / 2;
break;
case 58:
hsv.s = 0;
hsv.v = hsv.v / 2;
break;
case 59:
hsv.s = 0;
hsv.v = hsv.v / 2;
break;
case 60:
hsv.s = 0;
hsv.v = hsv.v / 2;
break;
case 64:
hsv.s = 0;
hsv.v = hsv.v / 2;
break;
// volume
case 18: // mute
hsv.h = 0;
break;
case 17: // increase
hsv.s = 255;
break;
case 32: // decrease
hsv.s = 0;
break;
// brightness
case 33: // increase
hsv.s = 255;
break;
case 31: // decrease
hsv.s = 0;
break;
// media
case 65: // previous
hsv.s = 0;
break;
case 67: // next
hsv.s = 0;
break;
case 56: // stop
hsv.h = 0;
break;
case 66: // play/pause
hsv.h = 255/3;
break;
// menu
case 51:
hsv.s = 0;
break;
// toggle AD layer
case 36:
hsv.h = 0;
break;
// toggle VI layer
case 37:
hsv.h = 255/3;
break;
// KB layer
case 62:
hsv.h = time;
hsv.s = 255;
break;
// no function
default:
hsv.v = 0;
break;
}
return hsv;
}
bool fn_indicator(effect_params_t* params) {
return effect_runner_i(params, &fn_indicator_math);
}
static HSV kb_indicator_math(HSV hsv, uint8_t i, uint8_t time) {
// cancel base effect startup
base_effect_startup_counter = 255;
switch (i) {
// test HSV
case 14:
break;
case 29:
break;
case 43:
break;
case 57:
break;
case 67:
break;
// toggle RGB
case 16:
hsv.s = 0;
if (time < (255 / 2)) {
hsv.v = 255;
} else {
hsv.v = 0;
}
break;
// cycle effect
case 17:
hsv.s = 255;
hsv.v = 255;
if (time < (255 / 3)) {
hsv.h = 0;
} else if (time < (2 * 255 / 3)) {
hsv.h = 255 / 3;
} else {
hsv.h = 2 * 255 / 3;
}
break;
// adjust hue
case 18:
hsv.h = time;
hsv.s = 255;
hsv.v = 255;
break;
case 19:
hsv.h = 255 - time;
hsv.s = 255;
hsv.v = 255;
break;
// adjust saturation
case 32:
hsv.s = 255;
hsv.v = 255;
break;
case 33:
hsv.s = 0;
hsv.v = 255;
break;
// adjust value
case 45:
hsv.v = 255;
break;
case 46:
hsv.v = 63;
break;
// adjust speed
case 4:
if (((time / 8) % 2) == 0) {
hsv.v = 255;
} else {
hsv.v = 63;
}
break;
case 5:
if (((time / 16) % 2) == 0) {
hsv.v = 63;
} else {
hsv.v = 255;
}
break;
// set main effect
case 36: // BASE
hsv.s = 0;
break;
case 37: // KITT
hsv.h = 0;
hsv.s = 255;
if (time < 128) {
hsv.v = time;
} else {
hsv.v = 255 - time;
}
break;
// reset (for flashing)
case 13:
hsv.s = 0;
if (time < 16) {
hsv.v = 255 - time * 128 / 16;
} else {
hsv.v = 127;
}
break;
// reset (reinitialize EEPROM)
case 42:
hsv.s = 0;
hsv.v = 127;
break;
// shift
case 44:
hsv.s = 0;
hsv.v = 63;
break;
case 55:
hsv.s = 0;
hsv.v = 63;
break;
// no function
default:
hsv.v = 0;
}
return hsv;
}
bool kb_indicator(effect_params_t* params) {
return effect_runner_i(params, &kb_indicator_math);
}
uint8_t led_count = 7;
uint8_t led_first = 33;
static uint8_t time_to_led(uint8_t time, uint8_t led_behind) {
uint16_t led_time = led_count * time;
uint16_t step = ((2 * led_count + (led_time / 128)) - led_behind) % (2 * led_count);
uint8_t led;
if (step < led_count) {
led = step;
} else {
led = led_count - 1 - (step - led_count);
}
return led;
}
static HSV kitt_effect_math(HSV hsv, uint8_t i, uint8_t time) {
// reset base effect startup
if (i == 0) {
BASE_EFFECT_NOT_STARTED_YET = true;
}
hsv.h = 0;
hsv.s = 255;
if (i >= led_first && i < led_first + led_count) {
uint8_t j = i - led_first;
if (j == time_to_led(time, 0)) {
hsv.v = hsv.v;
} else if (j == time_to_led(time, 1)) {
hsv.v = hsv.v/2;
} else if (j == time_to_led(time, 2)) {
hsv.v = hsv.v/4;
} else if (j == time_to_led(time, 3)) {
hsv.v = hsv.v/8;
} else {
hsv.v = 0;
}
} else {
hsv.v = 0;
}
return hsv;
}
bool kitt_effect(effect_params_t* params) {
return effect_runner_i(params, &kitt_effect_math);
}
#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
// vim: syntax=c
|