#include <stdint.h>
#include "system.h"
#include "usb_device.h"

void APP_LEDUpdateUSBStatus(void)
{
    static uint16_t ledCount = 0;

    if(USBIsDeviceSuspended() == true)
    {
        LATCbits.LATC1 = 0;
        return;
    }

    switch(USBGetDeviceState())
    {         
        case CONFIGURED_STATE: // slow blinking
            if(ledCount == 1)
            {
                LATCbits.LATC1 = 1;
            }
            else if(ledCount == 50)
            {
                LATCbits.LATC1 = 0;
            }
            else if(ledCount > 950)
            {
                ledCount = 0;
            }
            break;

        default: // fast blinking
            if(ledCount == 1)
            {
                LATCbits.LATC1 = 1;
            }
            else if(ledCount == 75)
            {
                LATCbits.LATC1 = 0;
            }
            else if(ledCount > 150)
            {
                ledCount = 0;
            }
            break;
    }
    ledCount++;
}