software/videomixer: support additive blending (enable with SW1, status on LED)
authorSebastien Bourdeauducq <sebastien@milkymist.org>
Thu, 16 May 2013 15:44:49 +0000 (17:44 +0200)
committerSebastien Bourdeauducq <sebastien@milkymist.org>
Thu, 16 May 2013 15:44:49 +0000 (17:44 +0200)
software/videomixer/main.c

index 203d69e20758acb74522b618af07365a0b29f3cc..aa92c0f87f283531069bc565eecb378f92214ab5 100644 (file)
@@ -25,20 +25,51 @@ static int scale_pot(int raw, int range)
        return scaled;
 }
 
-static void pots_service(void)
+static void regular_blend(int p0, int p1)
 {
-       static int last_event;
        int blackout;
        int crossfade;
 
+       blackout = scale_pot(p0, 256);
+       crossfade = scale_pot(p1, 255);
+
+       fb_blender_f0_write(crossfade*blackout >> 8);
+       fb_blender_f1_write((255-crossfade)*blackout >> 8);     
+}
+
+static void additive_blend(int p0, int p1)
+{
+       fb_blender_f0_write(scale_pot(p0, 255));
+       fb_blender_f1_write(scale_pot(p1, 255));
+}
+
+static void pots_service(void)
+{
+       static int last_event;
+       static int additive_blend_enabled;
+       static int old_btn;
+       int btn;
+       int p0, p1;
+
        if(elapsed(&last_event, identifier_frequency_read()/32)) {
+               btn = buttons_in_read() & 0x1;
+               if(btn && !old_btn) {
+                       additive_blend_enabled = !additive_blend_enabled;
+                       if(additive_blend_enabled)
+                               leds_out_write(leds_out_read() | 0x1);
+                       else
+                               leds_out_write(leds_out_read() & ~0x1);
+               }
+               old_btn = btn;
+
                pots_start_busy_write(1);
                while(pots_start_busy_read());
-               blackout = scale_pot(pots_res0_read(), 256);
-               crossfade = scale_pot(pots_res1_read(), 255);
-
-               fb_blender_f0_write(crossfade*blackout >> 8);
-               fb_blender_f1_write((255-crossfade)*blackout >> 8);     
+               p0 = pots_res0_read();
+               p1 = pots_res1_read();
+               if(!additive_blend_enabled)
+                       regular_blend(p0, p1);
+               else
+                       additive_blend(p0, p1);
        }
 }