/* STATUS: OK */
#include <p33FJ64MC802.h>
#include <stdio.h>
#include <timer.h>
#include "../../../drivers/delay.h"
#include "../../../../drivers/drvI2C.h"
#include "../../../../drivers/drvUART.h"
#include "../driverHMC5883L/drvHMC5883L.h"


//config oscillateur
_FOSCSEL(FNOSC_PRIPLL);					// Choix du oscillateur + PLL
_FOSC(FCKSM_CSDCMD & OSCIOFNC_OFF  & POSCMD_XT);	// Pas de basculement d'horloge
													// pas de OSC2
													// type d'oscillateur XT
_FWDT(FWDTEN_OFF); // watchdog off;



// create global
unsigned char buffTX[50]={'i','u','t','\n','\0'};
unsigned char buffKOI2C[5]={'K','0','\n','\0'};





//HMC5883L magnetometre;






volatile int test;

int main (void)
{
        unsigned char idmagnetometre;
      

        int I2C_OK;
		InitClockNoSwitch() ; // config PLL
        InitPORT_AND_PIN(); // init broche remapable        
        


        InitUART1();
        InitI2C1();
        InitHMC5883L();
		idmagnetometre =GetWhoAmIHMC5883L(); // 
        
		// on suppose la calibration faite
        SetValueMagOffsetXY(56,-57); // valeur x et y obtenu lors de la phase de calibration
       
 

       for(;;)
        {
         I2C_OK=getCompensatedHMC5883LData(&magnetometre);
         test=CalculCap(magnetometre.data[0], magnetometre.data[2]);
         idmagnetometre++;
         sprintf(buffTX,"\r Angle : %d \r\n", test);
         UART_puts(buffTX);
         Delay(Delay_200mS_Cnt);
        }
       



}//fin main(void)
