#include "mcc_generated_files/mcc.h"

void processButtonTouch(enum mtouch_button_names button)
{
    switch(button)
    {
        case Button0: LED0_SetLow();break;
        case Button1: LED1_SetLow();break;
        default: break;
    }
}

void processButtonRelease(enum mtouch_button_names button)
{
    switch(button)
    {
        case Button0: LED0_SetHigh();break;
        case Button1: LED1_SetHigh();break;
        default: break;
    }
}

void processSliderPressed(enum mtouch_slider_names slider)
{
    uint16_t position = MTOUCH_Slider_Position_Get(slider);

    if (position < 42)
        LED2_SetLow();
    else if (position < 85)
        LED3_SetLow();
    else if (position < 128)
        LED4_SetLow();
    else if (position < 171)
        LED5_SetLow();
    else if (position < 214)
        LED6_SetLow();
    else
        LED7_SetLow();
}

void processSliderRelease()
{
    LED2_SetHigh();
    LED3_SetHigh();
    LED4_SetHigh();
    LED5_SetHigh();
    LED6_SetHigh();
    LED7_SetHigh();    
}

void processSliderPositionChange(enum mtouch_slider_names slider)
{    
    processSliderRelease();
    processSliderPressed(slider);
}

/*
                         Main application
 */
void main(void)
{
    // initialize the device
    SYSTEM_Initialize();

    // When using interrupts, you need to set the Global and Peripheral Interrupt Enable bits
    // Use the following macros to:

    // Enable the Global Interrupts
    INTERRUPT_GlobalInterruptEnable();

    // Enable the Peripheral Interrupts
    INTERRUPT_PeripheralInterruptEnable();

    // Disable the Global Interrupts
    //INTERRUPT_GlobalInterruptDisable();

    // Disable the Peripheral Interrupts
    //INTERRUPT_PeripheralInterruptDisable();

    MTOUCH_Button_SetPressedCallback(processButtonTouch);
    MTOUCH_Button_SetNotPressedCallback(processButtonRelease);
    MTOUCH_Slider_SetPressedCallback(processSliderPressed);
    MTOUCH_Slider_SetPositionChangedCallback(processSliderPositionChange);
    MTOUCH_Slider_SetReleasedCallback(processSliderRelease);

    while (1)
    {
        // Add your application code
        MTOUCH_Service_Mainloop();
    }
}