]> git.donarmstrong.com Git - qmk_firmware.git/commitdiff
Rename led test to led_keyframes and move animation to Ergodox
authorFred Sundvik <fsundvik@gmail.com>
Sat, 8 Apr 2017 20:04:27 +0000 (23:04 +0300)
committerFred Sundvik <fsundvik@gmail.com>
Sun, 9 Apr 2017 15:34:59 +0000 (18:34 +0300)
keyboards/ergodox/infinity/animations.c
keyboards/ergodox/infinity/animations.h
quantum/visualizer/led_keyframes.c [new file with mode: 0644]
quantum/visualizer/led_keyframes.h [new file with mode: 0644]
quantum/visualizer/led_test.c [deleted file]
quantum/visualizer/led_test.h [deleted file]
quantum/visualizer/visualizer.mk

index 54ab994607c14afb7871d48a1298cc30accb875b..4c9f6d9c85a65f8b6308f756fbd413b2552518a6 100644 (file)
@@ -14,6 +14,8 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#if defined(VISUALIZER_ENABLE)
+
 #include "animations.h"
 #include "visualizer.h"
 #ifdef LCD_ENABLE
 #include "lcd_backlight_keyframes.h"
 #endif
 
-#if defined(VISUALIZER_ENABLE) && defined(LCD_ENABLE) && defined(LCD_BACKLIGHT_ENABLE)
+#ifdef LED_ENABLE
+#include "led_keyframes.h"
+#endif
+
+#include "visualizer_keyframes.h"
+
+
+#if defined(LCD_ENABLE) && defined(LCD_BACKLIGHT_ENABLE)
 
 // Don't worry, if the startup animation is long, you can use the keyboard like normal
 // during that time
@@ -50,5 +59,49 @@ keyframe_animation_t default_suspend_animation = {
             backlight_keyframe_disable,
     },
 };
+#endif
+
+#if defined(LED_ENABLE)
+#define CROSSFADE_TIME 1000
+#define GRADIENT_TIME 3000
+
+keyframe_animation_t led_test_animation = {
+    .num_frames = 14,
+    .loop = true,
+    .frame_lengths = {
+        gfxMillisecondsToTicks(1000), // fade in
+        gfxMillisecondsToTicks(1000), // no op (leds on)
+        gfxMillisecondsToTicks(1000), // fade out
+        gfxMillisecondsToTicks(CROSSFADE_TIME), // crossfade
+        gfxMillisecondsToTicks(GRADIENT_TIME), // left to rigt (outside in)
+        gfxMillisecondsToTicks(CROSSFADE_TIME), // crossfade
+        gfxMillisecondsToTicks(GRADIENT_TIME), // top_to_bottom
+        0,           // mirror leds
+        gfxMillisecondsToTicks(CROSSFADE_TIME), // crossfade
+        gfxMillisecondsToTicks(GRADIENT_TIME), // left_to_right (mirrored, so inside out)
+        gfxMillisecondsToTicks(CROSSFADE_TIME), // crossfade
+        gfxMillisecondsToTicks(GRADIENT_TIME), // top_to_bottom
+        0,           // normal leds
+        gfxMillisecondsToTicks(CROSSFADE_TIME), // crossfade
+
+    },
+    .frame_functions = {
+        led_keyframe_fade_in_all,
+        keyframe_no_operation,
+        led_keyframe_fade_out_all,
+        led_keyframe_crossfade,
+        led_keyframe_left_to_right_gradient,
+        led_keyframe_crossfade,
+        led_keyframe_top_to_bottom_gradient,
+        led_keyframe_mirror_orientation,
+        led_keyframe_crossfade,
+        led_keyframe_left_to_right_gradient,
+        led_keyframe_crossfade,
+        led_keyframe_top_to_bottom_gradient,
+        led_keyframe_normal_orientation,
+        led_keyframe_crossfade,
+    },
+};
+#endif
 
 #endif
index 0c441ff7e9c0dc0550ccecfcac69c1e98de38cd8..6d8b9830d9c96e61dd9da2f3f0423cb07b094f0c 100644 (file)
 
 #include "visualizer.h"
 
+// You can use these default animations, but of course you can also write your own custom ones instead
 extern keyframe_animation_t default_startup_animation;
 extern keyframe_animation_t default_suspend_animation;
 
+// An animation for testing and demonstrating the led support, should probably not be used for real world
+// cases
+extern keyframe_animation_t led_test_animation;
+
 #endif /* KEYBOARDS_ERGODOX_INFINITY_ANIMATIONS_H_ */
diff --git a/quantum/visualizer/led_keyframes.c b/quantum/visualizer/led_keyframes.c
new file mode 100644 (file)
index 0000000..2dacd99
--- /dev/null
@@ -0,0 +1,129 @@
+/*
+The MIT License (MIT)
+
+Copyright (c) 2016 Fred Sundvik
+
+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.
+*/
+#include "gfx.h"
+#include "math.h"
+#include "led_keyframes.h"
+
+static uint8_t fade_led_color(keyframe_animation_t* animation, int from, int to) {
+    int frame_length = animation->frame_lengths[animation->current_frame];
+    int current_pos = frame_length - animation->time_left_in_frame;
+    int delta = to - from;
+    int luma = (delta * current_pos) / frame_length;
+    luma += from;
+    return luma;
+}
+
+static void keyframe_fade_all_leds_from_to(keyframe_animation_t* animation, uint8_t from, uint8_t to) {
+    uint8_t luma = fade_led_color(animation, from, to);
+    color_t color = LUMA2COLOR(luma);
+    gdispGClear(LED_DISPLAY, color);
+}
+
+// TODO: Should be customizable per keyboard
+#define NUM_ROWS 7
+#define NUM_COLS 7
+
+static uint8_t crossfade_start_frame[NUM_ROWS][NUM_COLS];
+static uint8_t crossfade_end_frame[NUM_ROWS][NUM_COLS];
+
+static uint8_t compute_gradient_color(float t, float index, float num) {
+    const float two_pi = M_2_PI;
+    float normalized_index = (1.0f - index / (num - 1.0f)) * two_pi;
+    float x = t * two_pi + normalized_index;
+    float v = 0.5 * (cosf(x) + 1.0f);
+    return (uint8_t)(255.0f * v);
+}
+
+bool led_keyframe_fade_in_all(keyframe_animation_t* animation, visualizer_state_t* state) {
+    (void)state;
+    keyframe_fade_all_leds_from_to(animation, 0, 255);
+    return true;
+}
+
+bool led_keyframe_fade_out_all(keyframe_animation_t* animation, visualizer_state_t* state) {
+    (void)state;
+    keyframe_fade_all_leds_from_to(animation, 255, 0);
+    return true;
+}
+
+bool led_keyframe_left_to_right_gradient(keyframe_animation_t* animation, visualizer_state_t* state) {
+    (void)state;
+    float frame_length = animation->frame_lengths[animation->current_frame];
+    float current_pos = frame_length - animation->time_left_in_frame;
+    float t = current_pos / frame_length;
+    for (int i=0; i< NUM_COLS; i++) {
+        uint8_t color = compute_gradient_color(t, i, NUM_COLS);
+        gdispGDrawLine(LED_DISPLAY, i, 0, i, NUM_ROWS - 1, LUMA2COLOR(color));
+    }
+    return true;
+}
+
+bool led_keyframe_top_to_bottom_gradient(keyframe_animation_t* animation, visualizer_state_t* state) {
+    (void)state;
+    float frame_length = animation->frame_lengths[animation->current_frame];
+    float current_pos = frame_length - animation->time_left_in_frame;
+    float t = current_pos / frame_length;
+    for (int i=0; i< NUM_ROWS; i++) {
+        uint8_t color = compute_gradient_color(t, i, NUM_ROWS);
+        gdispGDrawLine(LED_DISPLAY, 0, i, NUM_COLS - 1, i, LUMA2COLOR(color));
+    }
+    return true;
+}
+
+static void copy_current_led_state(uint8_t* dest) {
+    for (int i=0;i<NUM_ROWS;i++) {
+        for (int j=0;j<NUM_COLS;j++) {
+            dest[i*NUM_COLS + j] = gdispGGetPixelColor(LED_DISPLAY, j, i);
+        }
+    }
+}
+bool led_keyframe_crossfade(keyframe_animation_t* animation, visualizer_state_t* state) {
+    (void)state;
+    if (animation->first_update_of_frame) {
+        copy_current_led_state(&crossfade_start_frame[0][0]);
+        run_next_keyframe(animation, state);
+        copy_current_led_state(&crossfade_end_frame[0][0]);
+    }
+    for (int i=0;i<NUM_ROWS;i++) {
+        for (int j=0;j<NUM_COLS;j++) {
+            color_t color  = LUMA2COLOR(fade_led_color(animation, crossfade_start_frame[i][j], crossfade_end_frame[i][j]));
+            gdispGDrawPixel(LED_DISPLAY, j, i, color);
+        }
+    }
+    return true;
+}
+
+bool led_keyframe_mirror_orientation(keyframe_animation_t* animation, visualizer_state_t* state) {
+    (void)state;
+    (void)animation;
+    gdispGSetOrientation(LED_DISPLAY, GDISP_ROTATE_180);
+    return false;
+}
+
+bool led_keyframe_normal_orientation(keyframe_animation_t* animation, visualizer_state_t* state) {
+    (void)state;
+    (void)animation;
+    gdispGSetOrientation(LED_DISPLAY, GDISP_ROTATE_0);
+    return false;
+}
diff --git a/quantum/visualizer/led_keyframes.h b/quantum/visualizer/led_keyframes.h
new file mode 100644 (file)
index 0000000..a689430
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+The MIT License (MIT)
+
+Copyright (c) 2016 Fred Sundvik
+
+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.
+*/
+
+#ifndef LED_KEYFRAMES_H
+#define LED_KEYFRAMES_H
+
+#include "visualizer.h"
+
+bool led_keyframe_fade_in_all(keyframe_animation_t* animation, visualizer_state_t* state);
+bool led_keyframe_fade_out_all(keyframe_animation_t* animation, visualizer_state_t* state);
+bool led_keyframe_left_to_right_gradient(keyframe_animation_t* animation, visualizer_state_t* state);
+bool led_keyframe_top_to_bottom_gradient(keyframe_animation_t* animation, visualizer_state_t* state);
+bool led_keyframe_crossfade(keyframe_animation_t* animation, visualizer_state_t* state);
+bool led_keyframe_mirror_orientation(keyframe_animation_t* animation, visualizer_state_t* state);
+bool led_keyframe_normal_orientation(keyframe_animation_t* animation, visualizer_state_t* state);
+
+extern keyframe_animation_t led_test_animation;
+
+
+#endif /* LED_KEYFRAMES_H */
diff --git a/quantum/visualizer/led_test.c b/quantum/visualizer/led_test.c
deleted file mode 100644 (file)
index a9abace..0000000
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
-The MIT License (MIT)
-
-Copyright (c) 2016 Fred Sundvik
-
-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.
-*/
-#include "led_test.h"
-#include "gfx.h"
-#include "math.h"
-
-#define CROSSFADE_TIME 1000
-#define GRADIENT_TIME 3000
-
-keyframe_animation_t led_test_animation = {
-    .num_frames = 14,
-    .loop = true,
-    .frame_lengths = {
-        gfxMillisecondsToTicks(1000), // fade in
-        gfxMillisecondsToTicks(1000), // no op (leds on)
-        gfxMillisecondsToTicks(1000), // fade out
-        gfxMillisecondsToTicks(CROSSFADE_TIME), // crossfade
-        gfxMillisecondsToTicks(GRADIENT_TIME), // left to rigt (outside in)
-        gfxMillisecondsToTicks(CROSSFADE_TIME), // crossfade
-        gfxMillisecondsToTicks(GRADIENT_TIME), // top_to_bottom
-        0,           // mirror leds
-        gfxMillisecondsToTicks(CROSSFADE_TIME), // crossfade
-        gfxMillisecondsToTicks(GRADIENT_TIME), // left_to_right (mirrored, so inside out)
-        gfxMillisecondsToTicks(CROSSFADE_TIME), // crossfade
-        gfxMillisecondsToTicks(GRADIENT_TIME), // top_to_bottom
-        0,           // normal leds
-        gfxMillisecondsToTicks(CROSSFADE_TIME), // crossfade
-
-    },
-    .frame_functions = {
-        keyframe_fade_in_all_leds,
-        keyframe_no_operation,
-        keyframe_fade_out_all_leds,
-        keyframe_led_crossfade,
-        keyframe_led_left_to_right_gradient,
-        keyframe_led_crossfade,
-        keyframe_led_top_to_bottom_gradient,
-        keyframe_mirror_led_orientation,
-        keyframe_led_crossfade,
-        keyframe_led_left_to_right_gradient,
-        keyframe_led_crossfade,
-        keyframe_led_top_to_bottom_gradient,
-        keyframe_normal_led_orientation,
-        keyframe_led_crossfade,
-    },
-};
-
-static uint8_t fade_led_color(keyframe_animation_t* animation, int from, int to) {
-    int frame_length = animation->frame_lengths[animation->current_frame];
-    int current_pos = frame_length - animation->time_left_in_frame;
-    int delta = to - from;
-    int luma = (delta * current_pos) / frame_length;
-    luma += from;
-    return luma;
-}
-
-static void keyframe_fade_all_leds_from_to(keyframe_animation_t* animation, uint8_t from, uint8_t to) {
-    uint8_t luma = fade_led_color(animation, from, to);
-    color_t color = LUMA2COLOR(luma);
-    gdispGClear(LED_DISPLAY, color);
-}
-
-// TODO: Should be customizable per keyboard
-#define NUM_ROWS 7
-#define NUM_COLS 7
-
-static uint8_t crossfade_start_frame[NUM_ROWS][NUM_COLS];
-static uint8_t crossfade_end_frame[NUM_ROWS][NUM_COLS];
-
-static uint8_t compute_gradient_color(float t, float index, float num) {
-    const float two_pi = M_2_PI;
-    float normalized_index = (1.0f - index / (num - 1.0f)) * two_pi;
-    float x = t * two_pi + normalized_index;
-    float v = 0.5 * (cosf(x) + 1.0f);
-    return (uint8_t)(255.0f * v);
-}
-
-bool keyframe_fade_in_all_leds(keyframe_animation_t* animation, visualizer_state_t* state) {
-    (void)state;
-    keyframe_fade_all_leds_from_to(animation, 0, 255);
-    return true;
-}
-
-bool keyframe_fade_out_all_leds(keyframe_animation_t* animation, visualizer_state_t* state) {
-    (void)state;
-    keyframe_fade_all_leds_from_to(animation, 255, 0);
-    return true;
-}
-
-bool keyframe_led_left_to_right_gradient(keyframe_animation_t* animation, visualizer_state_t* state) {
-    (void)state;
-    float frame_length = animation->frame_lengths[animation->current_frame];
-    float current_pos = frame_length - animation->time_left_in_frame;
-    float t = current_pos / frame_length;
-    for (int i=0; i< NUM_COLS; i++) {
-        uint8_t color = compute_gradient_color(t, i, NUM_COLS);
-        gdispGDrawLine(LED_DISPLAY, i, 0, i, NUM_ROWS - 1, LUMA2COLOR(color));
-    }
-    return true;
-}
-
-bool keyframe_led_top_to_bottom_gradient(keyframe_animation_t* animation, visualizer_state_t* state) {
-    (void)state;
-    float frame_length = animation->frame_lengths[animation->current_frame];
-    float current_pos = frame_length - animation->time_left_in_frame;
-    float t = current_pos / frame_length;
-    for (int i=0; i< NUM_ROWS; i++) {
-        uint8_t color = compute_gradient_color(t, i, NUM_ROWS);
-        gdispGDrawLine(LED_DISPLAY, 0, i, NUM_COLS - 1, i, LUMA2COLOR(color));
-    }
-    return true;
-}
-
-static void copy_current_led_state(uint8_t* dest) {
-    for (int i=0;i<NUM_ROWS;i++) {
-        for (int j=0;j<NUM_COLS;j++) {
-            dest[i*NUM_COLS + j] = gdispGGetPixelColor(LED_DISPLAY, j, i);
-        }
-    }
-}
-bool keyframe_led_crossfade(keyframe_animation_t* animation, visualizer_state_t* state) {
-    (void)state;
-    if (animation->first_update_of_frame) {
-        copy_current_led_state(&crossfade_start_frame[0][0]);
-        run_next_keyframe(animation, state);
-        copy_current_led_state(&crossfade_end_frame[0][0]);
-    }
-    for (int i=0;i<NUM_ROWS;i++) {
-        for (int j=0;j<NUM_COLS;j++) {
-            color_t color  = LUMA2COLOR(fade_led_color(animation, crossfade_start_frame[i][j], crossfade_end_frame[i][j]));
-            gdispGDrawPixel(LED_DISPLAY, j, i, color);
-        }
-    }
-    return true;
-}
-
-bool keyframe_mirror_led_orientation(keyframe_animation_t* animation, visualizer_state_t* state) {
-    (void)state;
-    (void)animation;
-    gdispGSetOrientation(LED_DISPLAY, GDISP_ROTATE_180);
-    return false;
-}
-
-bool keyframe_normal_led_orientation(keyframe_animation_t* animation, visualizer_state_t* state) {
-    (void)state;
-    (void)animation;
-    gdispGSetOrientation(LED_DISPLAY, GDISP_ROTATE_0);
-    return false;
-}
diff --git a/quantum/visualizer/led_test.h b/quantum/visualizer/led_test.h
deleted file mode 100644 (file)
index 5e23257..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
-The MIT License (MIT)
-
-Copyright (c) 2016 Fred Sundvik
-
-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.
-*/
-
-#ifndef TMK_VISUALIZER_LED_TEST_H_
-#define TMK_VISUALIZER_LED_TEST_H_
-
-#include "visualizer.h"
-
-bool keyframe_fade_in_all_leds(keyframe_animation_t* animation, visualizer_state_t* state);
-bool keyframe_fade_out_all_leds(keyframe_animation_t* animation, visualizer_state_t* state);
-bool keyframe_led_left_to_right_gradient(keyframe_animation_t* animation, visualizer_state_t* state);
-bool keyframe_led_top_to_bottom_gradient(keyframe_animation_t* animation, visualizer_state_t* state);
-bool keyframe_led_crossfade(keyframe_animation_t* animation, visualizer_state_t* state);
-bool keyframe_mirror_led_orientation(keyframe_animation_t* animation, visualizer_state_t* state);
-bool keyframe_normal_led_orientation(keyframe_animation_t* animation, visualizer_state_t* state);
-
-extern keyframe_animation_t led_test_animation;
-
-
-#endif /* TMK_VISUALIZER_LED_TEST_H_ */
index 7c8e98d67bb44fb8b989a00517c38c00baa3cb09..5f710124bc9084c4b667e654bec2dad8c3022447 100644 (file)
@@ -43,7 +43,7 @@ OPT_DEFS += -DLCD_BACKLIGHT_ENABLE
 endif
 
 ifeq ($(strip $(LED_ENABLE)), yes)
-SRC += $(VISUALIZER_DIR)/led_test.c
+SRC += $(VISUALIZER_DIR)/led_keyframes.c
 OPT_DEFS += -DLED_ENABLE
 endif