2 Copyright 2017 Fred Sundvik
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 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 You should have received a copy of the GNU General Public License
12 along with this program. If not, see <http://www.gnu.org/licenses/>.
15 #include "visualizer.h"
18 #include "default_animations.h"
19 #include "led_backlight_keyframes.h"
22 #define BOTHSIDESCAN 16
23 #define FULL_ON LUMA2COLOR(255)
24 #define THREE_QUARTER LUMA2COLOR(200)
25 #define HALF_ON LUMA2COLOR(150)
26 #define ONE_QUARTER LUMA2COLOR(50)
27 #define CROSSFADE_TIME 8000
28 bool KITT_scan_one_side_left_to_right(keyframe_animation_t* animation, visualizer_state_t* state);
29 bool KITT_scan_one_side_right_to_left(keyframe_animation_t* animation, visualizer_state_t* state);
30 keyframe_animation_t Fade_in_all_leds = {
37 led_backlight_keyframe_fade_in_all,
41 * one set left to right. then reverse to go back.
42 * | left side | right side | |
43 |---|---|---|---|---|---|---|:-:|---|---|---|---|---|---|-------|
44 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | phase |
45 _________________________________________________________________
46 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
47 | 3 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
48 | 2 | 3 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 2 |
49 | 1 | 2 | 3 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3 |
50 | 0 | 1 | 2 | 3 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 4 |
51 | 0 | 0 | 1 | 2 | 3 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 5 |
52 | 0 | 0 | 0 | 1 | 2 | 3 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 6 |
53 | 0 | 0 | 0 | 0 | 1 | 2 | 3 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 7 |
54 | 0 | 0 | 0 | 0 | 0 | 1 | 2 | 3 | 0 | 0 | 0 | 0 | 0 | 0 | 8 |
55 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 2 | 3 | 0 | 0 | 0 | 0 | 0 | 9 |
56 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 2 | 3 | 0 | 0 | 0 | 0 | 10 |
57 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 2 | 3 | 0 | 0 | 0 | 11 |
58 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 2 | 3 | 0 | 0 | 12 |
59 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 2 | 3 | 0 | 13 |
60 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 2 | 3 | 14 |
61 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 2 | 15 |
62 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 16 |
65 #ifdef MASTER_IS_ON_RIGHT /*right side*/
67 keyframe_animation_t KITT_Scanner_animation = {
71 CROSSFADE_TIME * BOTHSIDESCAN,
72 CROSSFADE_TIME * BOTHSIDESCAN,
75 KITT_scan_one_side_left_to_right,
76 KITT_scan_one_side_right_to_left,
80 bool KITT_scan_one_side_left_to_right(keyframe_animation_t* animation, visualizer_state_t* state) {
82 float frame_length = animation->frame_lengths[animation->current_frame];
83 float current_pos = frame_length - animation->time_left_in_frame;
84 int phase = current_pos/(frame_length/BOTHSIDESCAN);
86 gdispGClear(LED_DISPLAY, ONE_QUARTER);
87 gdispGDrawPixel(LED_DISPLAY, 14-phase, row, FULL_ON);
88 gdispGDrawPixel(LED_DISPLAY, 15-phase, row, THREE_QUARTER);
89 gdispGDrawPixel(LED_DISPLAY, 16-phase, row, HALF_ON);
90 gdispGDrawPixel(LED_DISPLAY, 6, row, ONE_QUARTER);
94 bool KITT_scan_one_side_right_to_left(keyframe_animation_t* animation, visualizer_state_t* state) {
96 float frame_length = animation->frame_lengths[animation->current_frame];
97 float current_pos = frame_length - animation->time_left_in_frame;
98 int phase = current_pos/(frame_length/BOTHSIDESCAN);
100 gdispGClear(LED_DISPLAY, ONE_QUARTER);
101 gdispGDrawPixel(LED_DISPLAY, phase, row, FULL_ON);
102 gdispGDrawPixel(LED_DISPLAY, phase-1, row, THREE_QUARTER);
103 gdispGDrawPixel(LED_DISPLAY, phase-2, row, HALF_ON);
104 gdispGDrawPixel(LED_DISPLAY, 6, row, ONE_QUARTER);
108 keyframe_animation_t KITT_Scanner_animation = {
112 CROSSFADE_TIME * BOTHSIDESCAN,
113 CROSSFADE_TIME * BOTHSIDESCAN,
116 KITT_scan_one_side_left_to_right,
117 KITT_scan_one_side_right_to_left,
121 bool KITT_scan_one_side_left_to_right(keyframe_animation_t* animation, visualizer_state_t* state) {
123 float frame_length = animation->frame_lengths[animation->current_frame];
124 float current_pos = frame_length - animation->time_left_in_frame;
125 int phase = current_pos/(frame_length/BOTHSIDESCAN);
127 gdispGClear(LED_DISPLAY, ONE_QUARTER);
128 gdispGDrawPixel(LED_DISPLAY, phase, row, FULL_ON);
129 gdispGDrawPixel(LED_DISPLAY, phase-1, row, THREE_QUARTER);
130 gdispGDrawPixel(LED_DISPLAY, phase-2, row, HALF_ON);
131 gdispGDrawPixel(LED_DISPLAY, 6, row, ONE_QUARTER);
135 bool KITT_scan_one_side_right_to_left(keyframe_animation_t* animation, visualizer_state_t* state) {
137 float frame_length = animation->frame_lengths[animation->current_frame];
138 float current_pos = frame_length - animation->time_left_in_frame;
139 int phase = current_pos/(frame_length/BOTHSIDESCAN);
141 gdispGClear(LED_DISPLAY, ONE_QUARTER);
142 gdispGDrawPixel(LED_DISPLAY, (14 - phase), row, FULL_ON);
143 gdispGDrawPixel(LED_DISPLAY, 14 - (phase-1), row, THREE_QUARTER);
144 gdispGDrawPixel(LED_DISPLAY, 14 - (phase-2), row, HALF_ON);
145 gdispGDrawPixel(LED_DISPLAY, 6, row, ONE_QUARTER);
153 #define SPRING_GREEN 64
155 #define TURQUOISE 107
161 #define RASPBERRY 234
163 // This function should be implemented by the keymap visualizer
164 // Don't change anything else than state->target_lcd_color and state->layer_text as that's the only thing
165 // that the simple_visualizer assumes that you are updating
166 // Also make sure that the buffer passed to state->layer_text remains valid until the previous animation is
167 // stopped. This can be done by either double buffering it or by using constant strings
168 static void get_visualizer_layer_and_color(visualizer_state_t* state) {
169 uint8_t saturation = 255;
170 /* if (state->status.leds & (1u << USB_LED_CAPS_LOCK)) {
173 if (state->status.layer & 0x200) {
174 state->target_lcd_color = LCD_COLOR(GREEN, saturation, 0xFF);
175 state->layer_text = "MOUSE";
177 else if (state->status.layer & 0x100) {
178 state->target_lcd_color = LCD_COLOR(MAGENTA, saturation, 0xFF);
179 state->layer_text = "Shortcuts Layer";
181 else if (state->status.layer & 0x80) {
182 state->target_lcd_color = LCD_COLOR(VIOLET, saturation, 0xFF);
183 state->layer_text = "Plover";
184 start_keyframe_animation(&KITT_Scanner_animation);
187 else if (state->status.layer & 0x40) {
188 state->target_lcd_color = LCD_COLOR(RASPBERRY, saturation, 0xFF);
189 state->layer_text = "Mirrored Symbols";
191 else if (state->status.layer & 0x20) {
192 state->target_lcd_color = LCD_COLOR(RED, saturation, 0xFF);
193 state->layer_text = "Symbols";
195 else if (state->status.layer & 0x8) {
196 state->target_lcd_color = LCD_COLOR(OCEAN, saturation, 0xFF);
197 state->layer_text = "Mirrored Dvorak";
199 else if (state->status.layer & 0x4) {
200 state->target_lcd_color = LCD_COLOR(BLUE, saturation, 0xFF);
201 state->layer_text = "Dvorak";
203 else if (state->status.layer & 0x2) {
204 state->target_lcd_color = LCD_COLOR(ORANGE, saturation, 0xFF);
205 state->layer_text = "Mirrored Qwerty";
208 state->target_lcd_color = LCD_COLOR(YELLOW, saturation, 0xFF);
209 state->layer_text = "Qwerty";
210 stop_keyframe_animation(&KITT_Scanner_animation);
211 start_keyframe_animation(&Fade_in_all_leds);