]> git.donarmstrong.com Git - qmk_firmware.git/commitdiff
Vertical animation support for arm_atsam led_matrix (#4538)
authorIan O'Dea <ianodea@gmail.com>
Thu, 6 Dec 2018 16:58:58 +0000 (10:58 -0600)
committerDrashna Jaelre <drashna@live.com>
Thu, 6 Dec 2018 16:58:58 +0000 (08:58 -0800)
* Add initial support for vertically-oriented animations

* DRY up vertical animation support

* Fix animation code for arm_atsam led_matrix to work in all directions

* Adjust py calculation to base off bottom rather than top

tmk_core/protocol/arm_atsam/led_matrix.c
tmk_core/protocol/arm_atsam/led_matrix.h

index c328fdc4ceaf457604ed70b4cb9b28e522d2958b..729e042a6ed035d3f2935fcda84f61a43ac07c6f 100644 (file)
@@ -226,7 +226,7 @@ void disp_pixel_setup(void)
     while (cur < lede)
     {
         cur->px = (cur->x - disp.left) / disp.width * 100;
-        cur->py = (cur->y - disp.top) / disp.height * 100;
+        cur->py = (cur->y - disp.bottom) / disp.height * 100;
         *cur->rgb.r = 0;
         *cur->rgb.g = 0;
         *cur->rgb.b = 0;
@@ -244,6 +244,7 @@ void led_matrix_prepare(void)
 uint8_t led_enabled;
 float led_animation_speed;
 uint8_t led_animation_direction;
+uint8_t led_animation_orientation;
 uint8_t led_animation_breathing;
 uint8_t led_animation_breathe_cur;
 uint8_t breathe_step;
@@ -263,7 +264,7 @@ void led_matrix_run(void)
     float ro;
     float go;
     float bo;
-    float px;
+    float po;
     uint8_t led_this_run = 0;
     led_setup_t *f = (led_setup_t*)led_setups[led_animation_id];
 
@@ -325,59 +326,68 @@ void led_matrix_run(void)
             //Act on LED
             for (fcur = 0; fcur < fmax; fcur++)
             {
-                px = led_cur->px;
-                float pxmod;
-                pxmod = (float)(disp.frame % (uint32_t)(1000.0f / led_animation_speed)) / 10.0f * led_animation_speed;
+
+                if (led_animation_orientation)
+                {
+                  po = led_cur->py;
+                }
+                else
+                {
+                  po = led_cur->px;
+                }
+
+                float pomod;
+                pomod = (float)(disp.frame % (uint32_t)(1000.0f / led_animation_speed)) / 10.0f * led_animation_speed;
 
                 //Add in any moving effects
                 if ((!led_animation_direction && f[fcur].ef & EF_SCR_R) || (led_animation_direction && (f[fcur].ef & EF_SCR_L)))
                 {
-                    pxmod *= 100.0f;
-                    pxmod = (uint32_t)pxmod % 10000;
-                    pxmod /= 100.0f;
+                    pomod *= 100.0f;
+                    pomod = (uint32_t)pomod % 10000;
+                    pomod /= 100.0f;
 
-                    px -= pxmod;
+                    po -= pomod;
 
-                    if (px > 100) px -= 100;
-                    else if (px < 0) px += 100;
+                    if (po > 100) po -= 100;
+                    else if (po < 0) po += 100;
                 }
                 else if ((!led_animation_direction && f[fcur].ef & EF_SCR_L) || (led_animation_direction && (f[fcur].ef & EF_SCR_R)))
                 {
-                    pxmod *= 100.0f;
-                    pxmod = (uint32_t)pxmod % 10000;
-                    pxmod /= 100.0f;
-                    px += pxmod;
+                    pomod *= 100.0f;
+                    pomod = (uint32_t)pomod % 10000;
+                    pomod /= 100.0f;
+                    po += pomod;
 
-                    if (px > 100) px -= 100;
-                    else if (px < 0) px += 100;
+                    if (po > 100) po -= 100;
+                    else if (po < 0) po += 100;
                 }
 
-                //Check if LED's px is in current frame
-                if (px < f[fcur].hs) continue;
-                if (px > f[fcur].he) continue;
+                //Check if LED's po is in current frame
+                if (po < f[fcur].hs) continue;
+                if (po > f[fcur].he) continue;
                 //note: < 0 or > 100 continue
 
-                //Calculate the px within the start-stop percentage for color blending
-                px = (px - f[fcur].hs) / (f[fcur].he - f[fcur].hs);
+                //Calculate the po within the start-stop percentage for color blending
+                po = (po - f[fcur].hs) / (f[fcur].he - f[fcur].hs);
 
                 //Add in any color effects
                 if (f[fcur].ef & EF_OVER)
                 {
-                    ro = (px * (f[fcur].re - f[fcur].rs)) + f[fcur].rs;// + 0.5;
-                    go = (px * (f[fcur].ge - f[fcur].gs)) + f[fcur].gs;// + 0.5;
-                    bo = (px * (f[fcur].be - f[fcur].bs)) + f[fcur].bs;// + 0.5;
+                    ro = (po * (f[fcur].re - f[fcur].rs)) + f[fcur].rs;// + 0.5;
+                    go = (po * (f[fcur].ge - f[fcur].gs)) + f[fcur].gs;// + 0.5;
+                    bo = (po * (f[fcur].be - f[fcur].bs)) + f[fcur].bs;// + 0.5;
                 }
                 else if (f[fcur].ef & EF_SUBTRACT)
                 {
-                    ro -= (px * (f[fcur].re - f[fcur].rs)) + f[fcur].rs;// + 0.5;
-                    go -= (px * (f[fcur].ge - f[fcur].gs)) + f[fcur].gs;// + 0.5;
-                    bo -= (px * (f[fcur].be - f[fcur].bs)) + f[fcur].bs;// + 0.5;
+                    ro -= (po * (f[fcur].re - f[fcur].rs)) + f[fcur].rs;// + 0.5;
+                    go -= (po * (f[fcur].ge - f[fcur].gs)) + f[fcur].gs;// + 0.5;
+                    bo -= (po * (f[fcur].be - f[fcur].bs)) + f[fcur].bs;// + 0.5;
                 }
                 else
                 {
-                    ro += (px * (f[fcur].re - f[fcur].rs)) + f[fcur].rs;// + 0.5;
-                    go += (px * (f[fcur].ge - f[fcur].gs)) + f[fcur].gs;// + 0.5;
-                    bo += (px * (f[fcur].be - f[fcur].bs)) + f[fcur].bs;// + 0.5;
+                    ro += (po * (f[fcur].re - f[fcur].rs)) + f[fcur].rs;// + 0.5;
+                    go += (po * (f[fcur].ge - f[fcur].gs)) + f[fcur].gs;// + 0.5;
+                    bo += (po * (f[fcur].be - f[fcur].bs)) + f[fcur].bs;// + 0.5;
                 }
             }
         }
@@ -451,6 +461,7 @@ uint8_t led_matrix_init(void)
     led_lighting_mode = LED_MODE_NORMAL;
     led_animation_speed = 4.0f;
     led_animation_direction = 0;
+    led_animation_orientation = 0;
     led_animation_breathing = 0;
     led_animation_breathe_cur = BREATHE_MIN_STEP;
     breathe_step = 1;
index 3f2b9cdb8684d3d3d9e5ca98881e27eb4c7131ce..cedea8a856dcaff2cd5b94c162a33f2cc4ec0d96 100644 (file)
@@ -125,6 +125,7 @@ extern uint8_t led_enabled;
 extern float led_animation_speed;
 extern uint8_t led_lighting_mode;
 extern uint8_t led_animation_direction;
+extern uint8_t led_animation_orientation;
 extern uint8_t led_animation_breathing;
 extern uint8_t led_animation_breathe_cur;
 extern uint8_t breathe_dir;