Example #1
0
extern "C" int main()
{
    pinMode(LED_BUILTIN, OUTPUT);
    leds.begin();

    // Announce firmware version
    serial_begin(BAUD2DIV(115200));
    serial_print("Fadecandy v" DEVICE_VER_STRING "\r\n");

    // Application main loop
    while (usb_dfu_state == DFU_appIDLE) {
        watchdog_refresh();

        // Select a different drawing loop based on our firmware config flags
        switch (buffers.flags & (CFLAG_NO_INTERPOLATION | CFLAG_NO_DITHERING)) {
            case 0:
            default:
                updateDrawBuffer_I1_D1(calculateInterpCoefficient());
                break;
            case CFLAG_NO_INTERPOLATION:
                updateDrawBuffer_I0_D1(0x10000);
                break;
            case CFLAG_NO_DITHERING:
                updateDrawBuffer_I1_D0(calculateInterpCoefficient());
                break;
            case CFLAG_NO_INTERPOLATION | CFLAG_NO_DITHERING:
                updateDrawBuffer_I0_D0(0x10000);
                break;
        }

        // Start sending the next frame over DMA
        leds.show();

        // We can switch to the next frame's buffer now.
        buffers.finalizeFrame();

        // Performance counter, for monitoring frame rate externally
        perf_frameCounter++;
    }

    // Reboot into DFU bootloader
    dfu_reboot();
}
Example #2
0
extern "C" int main()
{
    uint32_t last = systick_millis_count;
    uint32_t lastRender = 0;
    uint16_t i = 0;
    uint16_t j = 0;
    uint8_t index = 0;
    uint8_t startIndex = 0;
    pinMode(LED_BUILTIN, OUTPUT);
    for (i = 0; i < LUT_TOTAL_SIZE; i++)
    {
      buffers.lutCurrent.entries[i] = defaultLUT[i] >> 1;// (i % LUT_CH_SIZE) << 7;
    }

#ifdef RAINBOW_LANTERNS
    int16_t numSteps = 64;
#endif

    leds.begin();

    rainbow10[0] = rainbow7[0] = color(0xFF, 0, 0);
    rainbow10[1] = rainbow7[1] = color(0xFF, 0xA5, 0);
    rainbow10[2] = rainbow7[2] = color(0xFF, 0xFF, 0);
    rainbow10[3] = rainbow7[3] = color(0, 0x80, 0);
    rainbow10[4] = color(0, 0xFF, 0);
    rainbow10[5] = color(0, 0xA5, 0x80);
    rainbow10[6] = rainbow7[4] = color(0, 0, 0xFF);
    rainbow10[7] = rainbow7[5] = color(0x4B, 0, 0x82);
    rainbow10[8] = rainbow7[6] = color(0xFF, 0, 0xFF);
    rainbow10[9] = color(0xEE, 0x82, 0xEE);

    buffers.flags = CFLAG_NO_ACTIVITY_LED;
    //buffers.flags |= CFLAG_LED_CONTROL;

    // Announce firmware version
    serial_begin(BAUD2DIV(115200));
    serial_print("Fadecandy v" DEVICE_VER_STRING "\r\n");

    //usb_serial_printf("test\n");

    // Application main loop
    while (usb_dfu_state == DFU_appIDLE) {
        watchdog_refresh();

        // Select a different drawing loop based on our firmware config flags
        switch (buffers.flags & (CFLAG_NO_INTERPOLATION | CFLAG_NO_DITHERING)) {
            case 0:
            default:
                updateDrawBuffer_I1_D1(calculateInterpCoefficient());
                break;
            case CFLAG_NO_INTERPOLATION:
                updateDrawBuffer_I0_D1(0x10000);
                break;
            case CFLAG_NO_DITHERING:
                updateDrawBuffer_I1_D0(calculateInterpCoefficient());
                break;
            case CFLAG_NO_INTERPOLATION | CFLAG_NO_DITHERING:
                updateDrawBuffer_I0_D0(0x10000);
                break;
        }

        //buffers.flags |= CFLAG_NO_ACTIVITY_LED;
        // Start sending the next frame over DMA
        leds.show();

        if ((systick_millis_count - last) > 500)
        {
            //buffers.flags ^= CFLAG_LED_CONTROL;

            last = systick_millis_count;
        }

        #ifdef RAINBOW_CIRCLE
        if ((systick_millis_count - lastRender) > 500)
        {
          buffers.flags ^= CFLAG_LED_CONTROL;
          lastRender = systick_millis_count;
          index = startIndex;

          for (i = 0; i < 52/*32*/; i++)
          {
            uint8_t* pixel = buffers.fbNew->pixel(LEDS_PER_STRIP * 7 + i);
            uint32_t color = rainbow7[index];

            pixel[0] = RED(color);
            pixel[1] = GREEN(color);
            pixel[2] = BLUE(color);

            index = (index + 1) % 7;
          }

          for (i = 0; i < 20; i++)
          {
            uint8_t* pixel = buffers.fbNew->pixel(LEDS_PER_STRIP * 6 + i);
            uint32_t color = rainbow7[index];

            pixel[0] = RED(color);
            pixel[1] = GREEN(color);
            pixel[2] = BLUE(color);

            index = (index + 1) % 7;
          }

          startIndex = (startIndex + 1) % 7;

          buffers.finalizeFramebuffer();
        }
        #endif

#ifdef RAINBOW_TOPHAT
        (void)j;
        if ((systick_millis_count - lastRender) > 500)
        {
          buffers.flags ^= CFLAG_LED_CONTROL;
          lastRender = systick_millis_count;
          index = startIndex;

          for (i = 0; i < 52/*32*/; i++)
          {
            uint8_t* pixel = buffers.fbNew->pixel(LEDS_PER_STRIP * 7 + i);
            uint32_t color = rainbow7[index];

            pixel[0] = RED(color);
            pixel[1] = GREEN(color);
            pixel[2] = BLUE(color);
            if (i>0 && i % 5 == 0)
            {
              index = (index + 1) % 7;
            }
          }

          for (i = 0; i < 20; i++)
          {
            uint8_t* pixel = buffers.fbNew->pixel(LEDS_PER_STRIP * 6 + i);
            uint32_t color = rainbow7[index];

            pixel[0] = RED(color);
            pixel[1] = GREEN(color);
            pixel[2] = BLUE(color);

            index = (index + 1) % 7;
          }

          startIndex = (startIndex + 1) % 7;

          buffers.finalizeFramebuffer();
        }
#endif

#ifdef RAINBOW_LANTERNS
        /*(void)j;
        (void)index;
        (void)startIndex;
        if ((systick_millis_count - lastRender) > 500)
        {
          buffers.flags ^= CFLAG_LED_CONTROL;
          lastRender = systick_millis_count;

          for (i = 0; i < 20; i++)
          {
            uint8_t* pixel = buffers.fbNew->pixel(LEDS_PER_STRIP * 7 + i);
            int16_t direction = directions[i] < 0 ? -1 : 1;
            uint32_t color1 = rainbow7[indexes[i]];
            int16_t index2 = indexes[i] + direction;
            if (index2 < 0)
            {
              index2 = 6;
            }
            else if (index2 >= 7)
            {
              index2 = 0;
            }
            uint32_t color2 = rainbow7[index2];

            int32_t reddiff = RED(color2) - RED(color1);
            int32_t bluediff = BLUE(color2) - BLUE(color1);
            int32_t greendiff = GREEN(color2) - BLUE(color1);

            reddiff *= steps[i];
            reddiff /= numSteps;
            bluediff *= steps[i];
            bluediff /= numSteps;
            greendiff *= steps[i];
            greendiff /= numSteps;

            pixel[0] = RED(color1) + reddiff;
            pixel[1] = GREEN(color1) + greendiff;
            pixel[2] = BLUE(color1) + bluediff;

            steps[i] += abs(directions[i]);

            if (steps[i] >= numSteps)
            {
              steps[i] = 0;
              indexes[i] = index2;
            }
          }

          buffers.finalizeFramebuffer();
        }*/
        (void)j;
        (void)numSteps;
        if ((systick_millis_count - lastRender) > 5000)
        {
          buffers.flags ^= CFLAG_LED_CONTROL;
          lastRender = systick_millis_count;
          index = startIndex;

          for (i = 0; i < 20/*32*/; i++)
          {
            uint8_t* pixel = buffers.fbNew->pixel(LEDS_PER_STRIP * 7 + i);
            uint32_t color = rainbow7[index];

            pixel[0] = RED(color);
            pixel[1] = GREEN(color);
            pixel[2] = BLUE(color);
            if (i>0 && i % 2 == 0)
            {
              index = (index + 1) % 7;
            }
          }

          for (i = 0; i < 20; i++)
          {
            uint8_t* pixel = buffers.fbNew->pixel(LEDS_PER_STRIP * 6 + i);
            uint32_t color = rainbow7[index];

            pixel[0] = RED(color);
            pixel[1] = GREEN(color);
            pixel[2] = BLUE(color);

            index = (index + 1) % 7;
          }

          startIndex = (startIndex + 1) % 7;

          buffers.finalizeFramebuffer();
        }
#endif

#ifdef PARASOL
        if ((systick_millis_count - lastRender) > 500)
        {
          buffers.flags ^= CFLAG_LED_CONTROL;
          lastRender = systick_millis_count;
          index = startIndex;

          for (i = 0; i < 8; i++)
          {
            for (j = 0; j < 3; j++)
            {
              uint8_t* pixel = buffers.fbNew->pixel(LEDS_PER_STRIP * i + j);
              uint32_t color = rainbow7[index];

              pixel[0] = RED(color);
              pixel[1] = GREEN(color);
              pixel[2] = BLUE(color);
            }

            index = (index + 1) % 7;
          }

          startIndex = (startIndex + 1) % 7;

          buffers.finalizeFramebuffer();
        }
#endif

        #ifdef SMOOTH_RAINBOW
        (void)startIndex;
        (void)j;
        if ((systick_millis_count - lastRender) > 30)
        {
          lastRender = systick_millis_count;
          uint32_t ledIndex = 0;

          if (index >= 16)
          {
            buffers.flags ^= CFLAG_LED_CONTROL;
            index = 0;
          }

          index++;

          float color1[3];
          float color2[3];
          
          for (i = 0; i < 32; i++)
          {
            uint8_t* pixel = buffers.fbNew->pixel(LEDS_PER_STRIP * 7 + i);

            pixel[0] = 0xFF;
            pixel[1] = 0;
            pixel[2] = 0;
            float scaled = ledIndex / 44.0f;
            //fix16_t noise = 32768; (void)scaled;
            float noise = .5f + noise2(scaled, time);
            //float noise = .5f + fbm_noise3(scaled, time, .5f, 4, .25f, 2.0f);
            noise = fmax(fmin(1, noise), 0);
            float mult = 9 * noise;

            float index1 = floor(mult);
            float index2 = ceil(mult);
            float percent = mult - index1;
            uint32_t color = rainbow10[(int)index1];
            color1[0] = RED(color);
            color1[1] = GREEN(color);
            color1[2] = BLUE(color);

            color = rainbow10[(int)index2];
            color2[0] = RED(color);
            color2[1] = GREEN(color);
            color2[2] = BLUE(color);

            pixel[0] = (uint8_t)((int)(color1[0] + ((color2[0] - color1[0]) * percent)) & 0xFF);
            pixel[1] = (uint8_t)((int)(color1[1] + ((color2[1] - color1[1]) * percent)) & 0xFF);
            pixel[2] = (uint8_t)((int)(color1[2] + ((color2[2] - color1[2]) * percent)) & 0xFF);

            ledIndex++;
          }
          /*
          for (i = 0; i < 12; i++)
          {
            uint8_t* pixel = buffers.fbNew->pixel(LEDS_PER_STRIP * 6 + i);

            pixel[0] = 0xFF;
            pixel[1] = 0;
            pixel[2] = 0;
            float scaled = ledIndex / 44.0f;
            (void)scaled;
            float noise = 32768;
              //noise2(scaled, time);
            //fix16_t noise = 32768 + noise2(scaled, time);
            //fix16_t noise = 32768 + fbm_noise3(scaled, time, 0, 4, 16384, 131072);
            noise = fmax(fmin(noise, 1), 0);
            float mult = 9 * noise;
            float index1 = floor(mult);
            float index2 = ceil(mult);
            float percent = mult - index1;
            (void)index2;
            (void)percent;
            uint32_t color = rainbow10[1];// fix16_to_int(index1)];
            color1[0] = RED(color);
            color1[1] = GREEN(color);
            color1[2] = BLUE(color);

            color = rainbow10[2];// fix16_to_int(index2)];
            color2[0] = RED(color);
            color2[1] = GREEN(color);
            color2[2] = BLUE(color);

            pixel[0] = (uint8_t)((int)(color1[0] + ((color2[0] - color1[0]) * percent)) & 0xFF);
            pixel[1] = (uint8_t)((int)(color1[1] + ((color2[1] - color1[1]) * percent)) & 0xFF);
            pixel[2] = (uint8_t)((int)(color1[2] + ((color2[2] - color1[2]) * percent)) & 0xFF);

            ledIndex++;
          } */

          time = (time + timestep);

          buffers.finalizeFramebuffer();
        }
        #endif

        // We can switch to the next frame's buffer now.
        buffers.finalizeFrame();

        // Performance counter, for monitoring frame rate externally
        perf_frameCounter++;
    }

    // Reboot into DFU bootloader
    dfu_reboot();
}