//Predefined implementation by UGUI_LIB:
//Enable the option "UGUI_SD_CARD_LIB_ENABLE" in UGUI_Conf.c
//See UGUI_Conf.c, section UGUI_SD_CARD_LIB_ENABLE for more details.

/* Implementation Example (main.c):
 * Required Apps: USBD_VCOM (1x), FATFS (1x, SD-Card, you may import 'AppConfiguration_FATFS.xml' when on the XMC4800), 1ms Timer-Interrupt (e.g.: PWM_CCU4 + INTERRUPT)
 * Required UGUI-Options: UGUI_STREAMING_ENABLE, UGUI_SD_CARD_LIB_ENABLE
 * XMC4700/4800 Relax Kit
 *
*/

#include <DAVE.h>
#include "UGUI_Lib/UGUI_LIB.h"

void SD_CARD_ConnectionStateChanged_Handler(UGUI_Handle_t* ConnectedHandle, bool Connected);

UGUI_Handle_t UGUI_0;

//float dummy1 = 0.0f;

int main(void)
{
    DAVE_Init();

    UGUI_Init_USBD_VCOM_Simple(&UGUI_0, true);
    UGUI_Bind_SD_CARD_Lib(&UGUI_0, 30000, 128, NULL, SD_CARD_ConnectionStateChanged_Handler, true);

//  uint16_t cmd=1;
//  UGUI_RegisterProperty_RW_Float(&UGUI_0, cmd++, 1000, &dummy1, 0.0f, 1.0f, "dummy");

    XMC_GPIO_SetMode(XMC_GPIO_PORT5, 8, XMC_GPIO_MODE_OUTPUT_PUSH_PULL);
    INTERRUPT_Enable(&INTERRUPT_TIMER_1MS); //Timer_1ms_ISR

    while (1U)
    {
        UGUI_Maintain(&UGUI_0);
    }
}
void Timer_1ms_ISR()
{
    UGUI_TimeoutTick(&UGUI_0);
}
void SD_CARD_ConnectionStateChanged_Handler(UGUI_Handle_t* ConnectedHandle, bool Connected)
{
    if(Connected)
        XMC_GPIO_SetOutputHigh(XMC_GPIO_PORT5, 8);
    else
        XMC_GPIO_SetOutputLow(XMC_GPIO_PORT5, 8);
}
