pattern.c
void vCreatePattern( void * pvParameters  )
{
    TickType_t xLastWakeTime;

    /* Initialize the xLastWakeTime variable with the current time. */
    xLastWakeTime = xTaskGetTickCount();

    /* Initialize start time.*/
    uint16_t usStartTime = TIM12->CNT;

    /* Local variable for calculating the pattern. */
#if ( configALL == 1 ) || ( configNO_AUDIO == 1 )
    patterns_t eCurrentPattern = (patterns_t)0;
#elif ( configONLY_AUDIO == 1 )
    patterns_t eCurrentPattern = (patterns_t)(AUDIO_MAGNITUDE_VIS); // ( AUDIO_PATTERNS + 1 );
#endif
    uint32_t ulPatternCount = 0;

    while ( 1 )
    {
        switch ( eCurrentPattern )
        {
        default:
        case RAINBOW_CROSSFADE:
            /* Ramp from one color to the next. */
            vRainbowCrossfade( ulPatternCount );

            /* Check for next pattern. */
            vCheckNextPattern( &ulPatternCount, configRAINBOW_CROSSFADE_TIME_MS, &eCurrentPattern );
            break;

        case AURORA_BOREALIS:
            /* Visualize the northern lights. */
            vAuroraBorealis( ulPatternCount );

            /* Check for next pattern. */
            vCheckNextPattern( &ulPatternCount, configAURORA_BOREALIS_TIME_MS, &eCurrentPattern );
            break;

        case LASER:
            /* Create a wave pattern. */
            vLaser( ulPatternCount );

            /* Check for next pattern. */
            vCheckNextPattern( &ulPatternCount, configLASER_TIME_MS, &eCurrentPattern );
            break;

        case FIRE_SPARKS:
            /* Create a fire with sparks pattern. */
            vFireSparks ( ulPatternCount );

            /* Check for next pattern. */
            vCheckNextPattern( &ulPatternCount, configFIRE_SPARKS_TIME_MS, &eCurrentPattern );
            break;

        case RGB_AUDIO:
            /* Create RGB audio pattern. */
            vRgbAudio ( ulPatternCount );

            /* Check for next pattern. */
            vCheckNextPattern( &ulPatternCount, configRGB_AUDIO_TIME_MS, &eCurrentPattern );
            break;

        case AUDIO_MAGNITUDE_VIS:
            /* Create audio train pattern. */
            vMagVisualization( ulPatternCount );

            /* Check for next pattern. */
            vCheckNextPattern( &ulPatternCount, configAUDIO_MAGNITUDE_VIS_TIME_MS, &eCurrentPattern );
            break;
            
        case SPECTRUM_ANALYZER:
            /* Create spectrum visualizer pattern. */
            vSpectrumAnalyzer( ulPatternCount );
            
            /* Check for next pattern. */
            vCheckNextPattern( &ulPatternCount, configSPECTRUM_ANALYZER_TIME_MS, &eCurrentPattern );
            break;
        }

        /* Check the stack size. */
        xPatternAvailableStack = uxTaskGetStackHighWaterMark( xCreatePatternHandle );

        if ( xPatternAvailableStack <= 20 )
        {
            /* Turn orangle LED on if stack overflow is imminent/detected. */
            STM_EVAL_LEDOn( LED4 );
        }

        /* Update the high water mark for task length. */
        if ( (uint16_t)TIM12->CNT - usStartTime > xDebugStats.usPatternClocks )
        {
            xDebugStats.usPatternClocks = (uint16_t)TIM12->CNT - usStartTime;
        }

        /* Wait for the next cycle. */
        vTaskDelayUntil( &xLastWakeTime, configPATTERN_TASK_TIME_MS );

        /* Initialize the start time. */
        usStartTime = TIM12->CNT;
    }
}
/**
  * @brief  Task chooses pattern and calculates the colors.
  * @note   Executes every 10ms.
        Might increase/decrease the rate depending on CPU usage.
  * @retval None
  */
@brief  Task chooses pattern and calculates the colors.
@note   Executes every 10ms.
Might increase/decrease the rate depending on CPU usage.
@retval None
@brief Task chooses pattern and calculates the colors . @note Executes every 10ms . Might increase / decrease the rate depending on CPU usage . @retval None
void vCreatePattern( void * pvParameters  )
{
    TickType_t xLastWakeTime;
    xLastWakeTime = xTaskGetTickCount();
    uint16_t usStartTime = TIM12->CNT;
#if ( configALL == 1 ) || ( configNO_AUDIO == 1 )
    patterns_t eCurrentPattern = (patterns_t)0;
#elif ( configONLY_AUDIO == 1 )
    patterns_t eCurrentPattern = (patterns_t)(AUDIO_MAGNITUDE_VIS); 
#endif
    uint32_t ulPatternCount = 0;
    while ( 1 )
    {
        switch ( eCurrentPattern )
        {
        default:
        case RAINBOW_CROSSFADE:
            vRainbowCrossfade( ulPatternCount );
            vCheckNextPattern( &ulPatternCount, configRAINBOW_CROSSFADE_TIME_MS, &eCurrentPattern );
            break;
        case AURORA_BOREALIS:
            vAuroraBorealis( ulPatternCount );
            vCheckNextPattern( &ulPatternCount, configAURORA_BOREALIS_TIME_MS, &eCurrentPattern );
            break;
        case LASER:
            vLaser( ulPatternCount );
            vCheckNextPattern( &ulPatternCount, configLASER_TIME_MS, &eCurrentPattern );
            break;
        case FIRE_SPARKS:
            vFireSparks ( ulPatternCount );
            vCheckNextPattern( &ulPatternCount, configFIRE_SPARKS_TIME_MS, &eCurrentPattern );
            break;
        case RGB_AUDIO:
            vRgbAudio ( ulPatternCount );
            vCheckNextPattern( &ulPatternCount, configRGB_AUDIO_TIME_MS, &eCurrentPattern );
            break;
        case AUDIO_MAGNITUDE_VIS:
            vMagVisualization( ulPatternCount );
            vCheckNextPattern( &ulPatternCount, configAUDIO_MAGNITUDE_VIS_TIME_MS, &eCurrentPattern );
            break;
        case SPECTRUM_ANALYZER:
            vSpectrumAnalyzer( ulPatternCount );
            vCheckNextPattern( &ulPatternCount, configSPECTRUM_ANALYZER_TIME_MS, &eCurrentPattern );
            break;
        }
        xPatternAvailableStack = uxTaskGetStackHighWaterMark( xCreatePatternHandle );
        if ( xPatternAvailableStack <= 20 )
        {
            STM_EVAL_LEDOn( LED4 );
        }
        if ( (uint16_t)TIM12->CNT - usStartTime > xDebugStats.usPatternClocks )
        {
            xDebugStats.usPatternClocks = (uint16_t)TIM12->CNT - usStartTime;
        }
        vTaskDelayUntil( &xLastWakeTime, configPATTERN_TASK_TIME_MS );
        usStartTime = TIM12->CNT;
    }
}
void vCreatePattern ( void * pvParameters ) { TickType_t xLastWakeTime ; xLastWakeTime = xTaskGetTickCount ( ) ; uint16_t usStartTime = TIM12 -> CNT ; #if ( configALL == 1 ) || ( configNO_AUDIO == 1 ) patterns_t eCurrentPattern = ( patterns_t ) 0 ; #elif ( configONLY_AUDIO == 1 ) patterns_t eCurrentPattern = ( patterns_t ) ( AUDIO_MAGNITUDE_VIS ) ; #endif uint32_t ulPatternCount = 0 ; while ( 1 ) { switch ( eCurrentPattern ) { default : case RAINBOW_CROSSFADE : vRainbowCrossfade ( ulPatternCount ) ; vCheckNextPattern ( & ulPatternCount , configRAINBOW_CROSSFADE_TIME_MS , & eCurrentPattern ) ; break ; case AURORA_BOREALIS : vAuroraBorealis ( ulPatternCount ) ; vCheckNextPattern ( & ulPatternCount , configAURORA_BOREALIS_TIME_MS , & eCurrentPattern ) ; break ; case LASER : vLaser ( ulPatternCount ) ; vCheckNextPattern ( & ulPatternCount , configLASER_TIME_MS , & eCurrentPattern ) ; break ; case FIRE_SPARKS : vFireSparks ( ulPatternCount ) ; vCheckNextPattern ( & ulPatternCount , configFIRE_SPARKS_TIME_MS , & eCurrentPattern ) ; break ; case RGB_AUDIO : vRgbAudio ( ulPatternCount ) ; vCheckNextPattern ( & ulPatternCount , configRGB_AUDIO_TIME_MS , & eCurrentPattern ) ; break ; case AUDIO_MAGNITUDE_VIS : vMagVisualization ( ulPatternCount ) ; vCheckNextPattern ( & ulPatternCount , configAUDIO_MAGNITUDE_VIS_TIME_MS , & eCurrentPattern ) ; break ; case SPECTRUM_ANALYZER : vSpectrumAnalyzer ( ulPatternCount ) ; vCheckNextPattern ( & ulPatternCount , configSPECTRUM_ANALYZER_TIME_MS , & eCurrentPattern ) ; break ; } xPatternAvailableStack = uxTaskGetStackHighWaterMark ( xCreatePatternHandle ) ; if ( xPatternAvailableStack <= 20 ) { STM_EVAL_LEDOn ( LED4 ) ; } if ( ( uint16_t ) TIM12 -> CNT - usStartTime > xDebugStats . usPatternClocks ) { xDebugStats . usPatternClocks = ( uint16_t ) TIM12 -> CNT - usStartTime ; } vTaskDelayUntil ( & xLastWakeTime , configPATTERN_TASK_TIME_MS ) ; usStartTime = TIM12 -> CNT ; } }
@brief  Task chooses pattern and calculates the colors.
@brief Task chooses pattern and calculates the colors .
/* Initialize the xLastWakeTime variable with the current time. */ /* Initialize start time.*/ /* Local variable for calculating the pattern. */ // ( AUDIO_PATTERNS + 1 ); /* Ramp from one color to the next. */ /* Check for next pattern. */ /* Visualize the northern lights. */ /* Check for next pattern. */ /* Create a wave pattern. */ /* Check for next pattern. */ /* Create a fire with sparks pattern. */ /* Check for next pattern. */ /* Create RGB audio pattern. */ /* Check for next pattern. */ /* Create audio train pattern. */ /* Check for next pattern. */ /* Create spectrum visualizer pattern. */ /* Check for next pattern. */ /* Check the stack size. */ /* Turn orangle LED on if stack overflow is imminent/detected. */ /* Update the high water mark for task length. */ /* Wait for the next cycle. */ /* Initialize the start time. */