#include "app.h"
#include "system_definitions.h"

extern APP_DATA appData;

// *****************************************************************************
// *****************************************************************************
// Section: System Interrupt Vector Functions
// *****************************************************************************
// *****************************************************************************

void __ISR(_ADC_VECTOR, ipl3AUTO) _IntHandlerDrvAdc(void)
{
    /* The ADC uses persistent interrupts. Persistent interrupts prevent you
       from clearing the interrupt flag until the issue causing the interrupt is 
       cleared. Read the ADC results before clearing the interrupt flag. */

    /* Potentiometer is connected to pin AN8. If the conversion is complete, copy
       new sample to potValue, and set dataReady flag. */
    if(true == DRV_ADC_SamplesAvailable(8))
    {
        appData.potValue = DRV_ADC_SamplesRead(8);
        appData.dataReady = true;
    }

    /* Clear ADC Interrupt Flag */
    PLIB_INT_SourceFlagClear(INT_ID_0, INT_SOURCE_ADC_1);
}