/* ========================================
 *
 *
 * ========================================
*/
#include <project.h>
#include <stdlib.h>
#include <animations.h>
#include <BLE_Process.h>
#include <main.h>

/* ========================================*/
/*****************************************************************************
* Function Prototypes
*****************************************************************************/
static void InitializeSystem(void);
void blink(void);

/* Interrupt prototypes */
CY_ISR_PROTO(Time_BLE_Helper_ISR);

/* ========================================*/
uint8 i,j;
uint16 wait = 100; 
CYBLE_LP_MODE_T bleMode;
uint8 interruptStatus;
e_Animation uc_AnimationSelector = 0;
uint16 us_langweiligbeendercounter;

/* ========================================*/
int main()
{
     InitializeSystem();
    // uc_AnimationSelector = Flashanimation2;
    
    // Endless loop to run forever.
    for(;;)
    {  
        // If not connected, perform some Animations
		if(TRUE == showanimation)
        {
            v_Animate_LEDs(uc_AnimationSelector);
        }            
    } 
}

CY_ISR(Time_BLE_Helper_ISR)
{
    isr_1_Disable();

    // bearbeite BLE-Events
    
    RED_Write(0);
    CyBle_ProcessEvents();
    RED_Write(0xFF);
    
    isr_1_ClearPending();
    isr_1_Enable();    
    Timer_Enable();
    
}

/*******************************************************************************
* Function Name: InitializeSystem
********************************************************************************
* Summary:
* Start the components and initialize system.
*
* Parameters:
*  void
*
* Return:
*  void
*
*******************************************************************************/
void InitializeSystem(void)
{
    CyGlobalIntEnable; // enable global interrupts
    
    // Signalize the start of the software
    for(i=0; i<4; i++)
    {
        blink();
    }
    
	/* Start BLE component and register the CustomEventHandler function. This 
	 * function exposes the events from BLE component for application use */
    CyBle_Start(CustomEventHandler);	
    
    Timer_Init(); // config but don't start the timeout counter
	isr_1_StartEx(Time_BLE_Helper_ISR); // setup timer interrupt sub-routine
	
    
    Timer_Enable();
    
    /* Initialize and enable the SPI-Master */
    SPIMASTER_Start();
}

void Set_AnimationSelector(uint8 newanimation)
{
    uc_AnimationSelector = (e_Animation)newanimation;   
}

/***************************
    Just a hello-World at the start of the software
*/
void blink( void )
{
   RED_Write(0);
   CyDelay(wait);
   RED_Write(0xFF);
   CyDelay(wait);
}

/* [] END OF FILE */
