示例#1
0
    STARTDECL(gl_window) (Value &title, Value &xs, Value &ys)
    {
        if (graphics_initialized)
            g_vm->BuiltinError("cannot call gl_window() twice");

        screensize = int2(xs.ival, ys.ival);
        string err = SDLInit(title.sval->str(), screensize);
        title.DECRT();

        if (err.empty())
        {
            OpenGLInit();

            err = LoadMaterialFile("shaders/default.materials");
        }

        if (!err.empty())
        {
            DebugLog(1, err.c_str());
            return Value(g_vm->NewString(err));
        }

        colorshader = LookupShader("color");
        assert(colorshader);

        meshes   = new IntResourceManagerCompact<Mesh>();

        DebugLog(-1, "graphics fully initialized...");
        graphics_initialized = true;

        return Value(0, V_NIL);
    }
示例#2
0
int main(int argc, char* args[]){
  SDLInit();
  SDL_WM_SetCaption("GTG - maps","GTG");

  GTG gtg; gtg.Construct();
  if(!gtg.Load("res")){
    Popup(gtg.GetLastError(),0xFF0000FF,0x000000FF);
  }else{
    int res = gtg.Run();
    if(res < 0){
      Popup(gtg.GetLastError(),0xFF0000FF,0x000000FF);
    }else if(res == 0){
      Popup("Game finished",0x0000FFFF,0xFFFFFFFF);
    }
  }
  gtg.Destruct();

  SDLExit(); return 0;
}
示例#3
0
	bool Game::OnInit()
	{
		// Init the external dependencies
		//
		bool success = SDLInit() && GlewInit();
		if (!success)
		{
			m_state = GameState::INIT_FAILED;
			return false;
		}

		// Setup the viewport
		//
		SetupViewport();

		// Change game state
		//
		m_state = GameState::INIT_SUCCESSFUL;

		return true;
	}	
示例#4
0
int main(void)
	{

	//*******************************************************************
	Init();
	TMRInit(2);		// Initialize Timer interface with Priority=2
	BLIInit();		// Initialize Signal interface
	//-------------------------------------------------------------------
	BLIAsyncStart(100, 100);
	TMRDelay(5000);			// To avoid false-start at Reset
	BLIAsyncStop();
	BLISignalOFF();
	//*******************************************************************
	// Switch 1 controls the Serial Data Logger (SDL) communication speed
	//-------------------------------------------------------------------
	if (_SW1)
		// Switch 1 is ON - Configuring SDL for PIC-to-PIC
		// high-speed communication at 1 MBaud
		SDLInit(3, BAUD_1M);
	else
		// Switch 1 is OFF - Configuring SDL for ZigBEE
		// wireless communication at 115.2 KBaud
		SDLInit(3, BAUD_115200);
	//*******************************************************************
	// HMC5983 Magnetometer initialization
	//-------------------------------------------------------------------
	byte IL		= 5;	// Interrupt level
	//------------------------------------------------------
	// <editor-fold defaultstate="collapsed" desc="Output Data Rate (ODR">
	//------------------------------------------------------
	// Typical Data Output Rate (Hz) for various ODR values
	//------------------------------------------------------
	//		ODR =	0:		  0.75
	//		ODR =	2:		  1.5
	//		ODR =	2:		  3
	//		ODR =	3:		  7.5
	//		ODR =	4:		 15		(Default)
	//		ODR =	5:		 30
	//		ODR =	6:		 75
	//		ODR =	7:		220		(fastest)
	// </editor-fold>
 	byte ODR	= 7;	// Rate (fastest):	220 Hz
	// <editor-fold defaultstate="collapsed" desc="Low-pass filtering (DLPF)">
	//------------------------------------------------------
	// Low-pass filtering achieved through sample averaging.
	// Averaging does not affect effective ODR, so I assume
	// that wit averaging enabled each successive reported
	// sample is an average of the new measurement with "n"
	// previous measurements - something like a FIR filter.
	//------------------------------------------------------
	// DLPF = 0 => 1-average	
	// DLPF = 1 => 2-average
	// DLPF = 2 => 4-average
	// DLPF = 3 => 8-average
	//------------------------------------------------------
	// </editor-fold>
 	byte DLPF	= 0;
	// <editor-fold defaultstate="collapsed" desc="Sensor Field Range (Gain)">
	//------------------------------------------------------
	// Recommended sensor field range (Ga) for various Gains
	//------------------------------------------------------
	//		Gain =	0:		0.9
	//		Gain =	1:		1.3
	//		Gain =	2:		1.9
	//		Gain =	3:		2.5
	//		Gain =	4:		4.0
	//		Gain =	5:		4.7
	//		Gain =	6:		5.6
	//		Gain =	7:		8.1
	//------------------------------------------------------
	// The magnitude of Earth magnetic field varies over the
	// surface of the Earth in the range 0.3 to 0.6 Gauss.
	//------------------------------------------------------
	// </editor-fold>
 	byte Gain	= 1;	// +/- 1.3 Ga
	//------------------------------------------------------
	HMC_Init(IL, ODR, Gain, DLPF);
	//*******************************************************************
	HMC_RC		RC;
	//----------------------
	ulong		i = 0;
	//-----------------------------------------
	byte		RegA;
	byte		RegB;
	//-------------------------------
	RC = HMC_ReadA(&RegA);
	i++;
	//-------------------------------
	RC = HMC_ReadB(&RegB);
	i++;
	//-------------------------------


	//----------------------
	struct
		{
		HMCData		Sample;
		ulong		Count;
		} SDLData;
		SDLData.Count	= 0;
    //----------------------
	while (1)
		{
		//-------------------------------
		if ( HMC_OK != (RC = HMC_ReadSample(&SDLData.Sample)) )
			BLIDeadStop("SOS", 3);
		SDLData.Count++;
		//-------------------------------
		BLISignalFlip();
		//-------------------------------
		SDLPostIfReady((byte*)&SDLData, sizeof(SDLData));
		//-------------------------------
		}

	//*******************************************************************
	return 0;
	}
示例#5
0
int main(void)
{

    //*******************************************************************
    Init();
    TMRInit(2);        // Initialize Timer interface with Priority=2
    BLIInit();        // Initialize Signal interface
    //*******************************************************************
    // Switch 1 controls the Serial Data Logger (SDL) communication speed
    //-------------------------------------------------------------------
    if (_SW1)
        // Switch 1 is ON - Configuring SDL for PIC-to-PIC
        // high-speed communication at 1 MBaud
        SDLInit(3, BAUD_1M);
    else
        // Switch 1 is OFF - Configuring SDL for ZigBEE
        // wireless communication at 115.2 KBaud
        SDLInit(3, BAUD_115200);
    //*******************************************************************
    I2CInit(5, 1);    // First param: IL = 5 (interrupt request priority
    // Second param: I2C speed
    // 0 - lowest (123 kHz at Fcy = 64MHz)
    // 1 - 200 kHz
    // 2 - 400 kHz
    // 3 - 1 MHz
    //-------------------------------------------------------------------
    uint            RC            = 0;
    ulong            Alarm        = 0;
    //==================================================================
    BLIAsyncStart(100,100);
    TMRDelay(2000);
    BLIAsyncStop();
    //==================================================================
    BLIAsyncStart(50,50);
    if (_SW2)
        // Switch 2 is ON - Configuring MPU fo Alt. sensitivity
        RC = MPUInit(0, 3, MPU_GYRO_1000ds, MPU_ACC_4g);
    // Initialize motion Sensor
    // 1 kHz/(0+1) = 1000 Hz (1ms)
    // DLPF=3 => Bandwidth 44 Hz (delay: 4.9 msec)
    else
        // Switch 2 is OFF - Configuring MPU fo normal sensitivity
        RC = MPUInit(0, 3, MPU_GYRO_2000ds, MPU_ACC_2g);
    // Initialize motion Sensor
    // 1 kHz/(0+1) = 1000 Hz (1ms)
    if (RC)    BLIDeadStop("EG", 2);
    BLIAsyncStop();
    //*******************************************************************
    BLISignalOFF();

    //====================================================
//    byte            mpuID;
//    byte            mpuDLPF;
//    byte            mpuINT;
//    byte            mpuPWRM1;
//    //---------------------------
//    RC = MPUReadID(2, &mpuID);
//    RC = MPUGetPWRM1(2, &mpuPWRM1);
//    RC = MPUGetDLPF(2, &mpuDLPF);
//    RC = MPUGetINT(2, &mpuINT);
    //-----------------------------------------------------

    //====================================================
    // Synchronous interface
    //-----------------------------------------------------
    struct
    {
        MPUData    Sample1;
        MPUData    Sample2;
    } MPU;
    //-----------------------------------------------------
    while (TRUE)
    {
        Alarm = TMRSetAlarm(500);
        //------------------------------------
        if ( (RC = MPUReadSample(1, &MPU.Sample1)) )
            BLIDeadStop("SOS", 3);
        //------------------------
        if ( (RC = MPUReadSample(2, &MPU.Sample2)) )
            BLIDeadStop("SOS", 3);
        //------------------------------------
        BLISignalFlip();
        //-------------------------
        SDLPostIfReady((byte*)&MPU, sizeof(MPU));
        //-------------------------
        TMRWaitAlarm(Alarm);
    }

    //*******************************************************************
    return 0;
}
示例#6
0
void
DisplayThreadCheckParams(chain_t *display_service)
{

  displaythread_info_t *info;
  int first_time=0;
  //int size_change;
  int prev_image_size[2];
  int prev_overlay_size[2];
  info=(displaythread_info_t*)display_service->data;
  
  if (display_service->current_buffer->frame.size[0]==-1)
    fprintf(stderr,"Error: display size: %dx%d\n",
	    display_service->current_buffer->frame.size[0],
	    display_service->current_buffer->frame.size[1]);

  //fprintf(stderr,"check params\n");
  // if some parameters changed, we need to restart the display
  //fprintf(stderr,"Before: [%d %d] After: [%d %d]\n",
  //	  display_service->local_param_copy.frame.size[0],display_service->local_param_copy.frame.size[1],
  //	  display_service->current_buffer->frame.size[0],display_service->current_buffer->frame.size[1]);
  if ((display_service->current_buffer->frame.size[0]!=display_service->local_param_copy.frame.size[0])||
      (display_service->current_buffer->frame.size[1]!=display_service->local_param_copy.frame.size[1])   ) {

    first_time=((display_service->local_param_copy.frame.size[0]==-1)&&(display_service->current_buffer->frame.size[0]!=-1));
    //if (first_time>0)
    //fprintf(stderr,"  first frame...\n");
      
    prev_image_size[0]=display_service->local_param_copy.frame.size[0];
    prev_image_size[1]=display_service->local_param_copy.frame.size[1];

    // alternating between thos two methods may give a clue (don't forget deal with the 'else memcpy' below) ///////////////////////////////////////////
    memcpy(&display_service->local_param_copy,display_service->current_buffer,sizeof(buffer_t));
    //display_service->local_param_copy.frame.size[0]=display_service->current_buffer->frame.size[0];
    //display_service->local_param_copy.frame.size[1]=display_service->current_buffer->frame.size[1];

    // DO SOMETHING
    //fprintf(stderr,"  fs: %d\n",display_service->local_param_copy.frame.size[0]);
    // if the width is not -1, that is if some image has already reached the thread and the size has changed
    if (display_service->local_param_copy.frame.size[0]!=-1) { //&&(size_change!=0)) {
      //fprintf(stderr,"   do something...\n");
      if (first_time) {
	SDLInit(display_service);
      } else {

	//usleep(1000000);

	// note: in order to preserve the previous scaling and ratio, the previous parameters are used to
	// determine the new size of the display area
	prev_overlay_size[0]=info->sdlvideorect.w;
	prev_overlay_size[1]=info->sdlvideorect.h;
	watchthread_info.draw=0;
	//SDLEventStopThread(display_service);
	SDLResizeDisplay(display_service,
			 display_service->current_buffer->frame.size[0]*prev_overlay_size[0]/prev_image_size[0],
			 display_service->current_buffer->frame.size[1]*prev_overlay_size[1]/prev_image_size[1]);
	//SDLEventStartThread(display_service);
      }
    }
    //fprintf(stderr,"SDL updated.\n");
  }

  memcpy(&display_service->local_param_copy,display_service->current_buffer,sizeof(buffer_t));
  display_service->local_param_copy.frame.allocated_image_bytes=0;
}
示例#7
0
int main(void)
	{

	//*******************************************************************
	Init();
	TMRInit(2);		// Initialize Timer interface with Priority=2
	BLIInit();		// Initialize Signal interface
	//*******************************************************************
	// Switch 1 controls the Serial Data Logger (SDL) communication speed
	//-------------------------------------------------------------------
	if (_SW1)
		// Switch 1 is ON - Configuring SDL for PIC-to-PIC
		// high-speed communication at 1 MBaud
		SDLInit(3, BAUD_1M);
	else
		// Switch 1 is OFF - Configuring SDL for ZigBEE
		// wireless communication at 115.2 KBaud
		SDLInit(3, BAUD_115200);
	//*******************************************************************
	I2CInit(5, 2);	// First param: IL = 5 (interrupt request priority
					// Second param: I2C speed
					// 0 - lowest (123 kHz at Fcy = 64MHz)
					// 1 - 200 kHz - MPU-6050 stable
					// 2 - 400 kHz
					// 3 - 1 MHz
	//-------------------------------------------------------------------
	uint			RC			= 0;
	ulong			Alarm		= 0;
	//==================================================================
	BLIAsyncStart(50,50);
	TMRDelay(5000);
	BLIAsyncStop();
	//==================================================================
	if (_SW2)
		// Switch 2 is ON - Configuring MPU fo Alt. sensitivity
		RC = MPUInit(0, 1, MPU_GYRO_1000ds, MPU_ACC_4g);
							// Initialize motion Sensor
							// 1 kHz/(0+1) = 1000 Hz (1ms)
							// DLPF = 3 => Bandwidth 44 Hz (delay: 4.9 msec)
	else
		// Switch 2 is OFF - Configuring MPU fo normal sensitivity
		RC = MPUInit(0, 1, MPU_GYRO_2000ds, MPU_ACC_2g);
							// Initialize motion Sensor
							// 1 kHz/(0+1) = 1000 Hz (1ms)
							// DLPF = 1 => Bandwidth 184 Hz (delay: 2.0 msec)
	if (RC)	BLIDeadStop("EG", 2);
	//*******************************************************************
	struct
		{
		MPUData	Sample1;
		MPUData	Sample2;
		} MPU;
	//=====================================================
	// Initialize Asynchronous mode
	//-----------------------------------------------------
	if ( (RC = MPUAsyncStart(2)) )
		BLIDeadStop("S2", 2);
	//------------------------------
	if ( (RC = MPUAsyncStart(1)) )
		BLIDeadStop("S1", 2);
	//=====================================================
	// Calibrate Gyros
	//-----------------------------------------------------
//	BLIAsyncStart(100,100);
//	//------------------------------
//	if ( (RC = MPUCalibrate(1)) )
//		BLIDeadStop("C1", 2);
//	//------------------------------
//	if ( (RC = MPUCalibrate(2)) )
//		BLIDeadStop("C2", 2);
//	//------------------------------
//	BLIAsyncStop();
	//=====================================================
	// Main Loop
	//-----------------------------------------------------
	BLISignalOFF();
	while (TRUE)
		{
		Alarm = TMRSetAlarm(1000);
		//------------------------------------
		if ( (RC = MPUAsyncReadWhenReady(1, &MPU.Sample1)) )
			BLIDeadStop("SOS", 3);
		//--------------------------
		if ( (RC = MPUAsyncReadWhenReady(2, &MPU.Sample2)) )
			BLIDeadStop("SOS", 3);
		//------------------------
		BLISignalFlip();
		//-------------------------
		SDLPostIfReady((byte*)&MPU, sizeof(MPU));
		//-------------------------
		TMRWaitAlarm(Alarm);
		}

	//*******************************************************************
	return 0;
	}
示例#8
0
int main(void)
    {

    //*******************************************************************
    Init();         // Initialize microprocessor
    TMRInit(2);     // Initialize Timer interface with Priority=2
    BLIInit();      // Initialize Signal interface
    //*******************************************************************
    // Switch 1 controls the Serial Data Logger (SDL) communication speed
    //-------------------------------------------------------------------
    if (_SW1)
        // Switch 1 is ON - Configuring SDL for PIC-to-PIC
        // high-speed communication at 1 MBaud
        SDLInit(3, BAUD_1M);
    else
        // Switch 1 is OFF - Configuring SDL for ZigBEE
        // wireless communication at 115.2 KBaud
        SDLInit(3, BAUD_115200);
    //*******************************************************************
    // Initialize I2C Library
    //-------------------------------------------------------------------
    I2CInit(5, 2);  // First param: IL = 5 (interrupt request priority
                    // Second param: I2C speed
                    // 0 - lowest (123 kHz at Fcy = 64MHz)
                    // 1 - 200 kHz
                    // 2 - 400 kHz
                    // 3 - 1 MHz
    //*******************************************************************
    uint    RC      = 0;
    ulong   Alarm   = 0;
    //==================================================================
    // Initialize MPUs
    //------------------------------------------------------------------
    RC = MPUInit(0, 3, MPU_GYRO_2000ds, MPU_ACC_2g);
                        // Initialize motion Sensor
                        // 1 kHz/(0+1) = 1000 Hz (1msec)
                        // DLPF = 3 => Bandwidth 44 Hz (delay: 4.9 msec)
    if (RC)    BLIDeadStop("EG", 2);
    //==================================================================
    // Initialize MPL3115 Altimeter
    //------------------------------------------------------------------
    // OSR = 0 => No averaging ( 2^0= 1),   update rate about 166.6 Hz
    // OSR = 1 => Average 2^1=   2 samples, update rate about 111.1 Hz
    // OSR = 2 => Average 2^2=   4 samples, update rate about  67.8 Hz
    // OSR = 3 => Average 2^3=   8 samples, update rate about  37.7 Hz
    // OSR = 4 => Average 2^4=  16 samples, update rate about  20.1 Hz
    // OSR = 5 => Average 2^5=  32 samples, update rate about  10.4 Hz
    // OSR = 6 => Average 2^6=  64 samples, update rate about   5.3 Hz
    // OSR = 7 => Average 2^7= 128 samples, update rate about   2.7 Hz
    //------------------------------------------------------------------
    byte    OSR    = 3;
    //------------------------------------------------------------------
    if ( MPL_OK != MPLInit (OSR) )
        BLIDeadStop ("EB", 2);
    //==================================================================
    // Initialize Asynchronous mode
    //-----------------------------------------------------
    if ( (RC = MPUAsyncStart(1)) )
        BLIDeadStop("S1", 2);
    //------------------------------
    if ( (RC = MPUAsyncStart(2)) )
        BLIDeadStop("S2", 2);
    //-----------------------------------------------------
    if ( (RC = MPLAsyncStart()) )
        BLIDeadStop("S3", 2);
    //==================================================================
    // Provide a few second delay prior to calibrating Gyros to make
    // sure that the board is stable after the "turn-on" shake
    //------------------------------------------------------------------
    BLIAsyncStart(50,50);
    TMRDelay(5000);
    BLIAsyncStop();
    //==================================================================
    // Calibrate Gyros
    //------------------------------------------------------------------
    BLIAsyncStart(100,100);
    //------------------------------
    if ( (RC = MPUCalibrateGyro(1)) )
        BLIDeadStop("C1", 2);
    //------------------------------
    if ( (RC = MPUCalibrateGyro(2)) )
        BLIDeadStop("C2", 2);
    //------------------------------
    BLIAsyncStop();
    //==================================================================
    
    //==================================================================
    struct
        {
        MPUData        MPUSample1;
        MPUData        MPUSample2;
        MPLData        MPLSample;
        } SensorData;
    //==================================================================
    // Main Loop
    //------------------------------------------------------------------
    BLISignalOFF();
    while (TRUE)
        {
        Alarm = TMRSetAlarm(1000);
        //-----------------------------------------------------
        if ( (RC = MPUAsyncReadWhenReady(1, &SensorData.MPUSample1)) )
            BLIDeadStop("SOS", 3);
        //--------------------------
        if ( (RC = MPUAsyncReadWhenReady(2, &SensorData.MPUSample2)) )
            BLIDeadStop("SOS", 3);
        if (MPL_OK != MPLAsyncReadWhenReady(&SensorData.MPLSample))
            BLIDeadStop("SOS", 3);
        //-----------------------------------------------------
        BLISignalFlip();
        //-------------------------
        SDLPostIfReady((byte*)&SensorData, sizeof(SensorData));
        //-------------------------
        TMRWaitAlarm(Alarm);
        }

    //*******************************************************************
    return 0;
    }
示例#9
0
文件: main.cpp 项目: CyberMayck/CQML
int main()
{
	int quit=0;
#ifdef USECAIRO
	CairoInit();
#endif
#ifdef USESDL
	SDL_Event sdlEvent;
	SDLInit();
	//SDL_RenderFillRect(SDLRenderer,NULL);
	if(SDLWindow==NULL || SDLRenderer==NULL)
		return 0;
#endif
	InitQML();
	InitSDLDrawer();
	InitSDLResourceManager();
	_QML_Init();
	//mGUI_Element_Draw((GUI_Element*)root);



	/*



	
	SDL_Rect sdlRect;
		sdlRect.x=10;
		sdlRect.y=10;
		sdlRect.w=100;
		sdlRect.h=100;

		SDL_Surface *sText;
		SDL_Color clrFg = {1*255,1*255,0*255,0};
		
		TTF_Font *fnt;
		//fntCourier = TTF_OpenFont( "C64.ttf", 12 );
		printf("TTF_OpenFont: %s\n", TTF_GetError());
		fnt = TTF_OpenFont( "LeagueGothic-CondensedRegular.otf", 100 );
		printf("TTF_OpenFont: %s\n", TTF_GetError());
		const char *text = "200";
		sText = TTF_RenderText_Solid( fnt, text, clrFg );
		printf("TTF_OpenFont: %s\n", TTF_GetError());
		strTex=SDL_CreateTextureFromSurface(SDLRenderer, sText);


		printf("TTF_OpenFont: %s\n", TTF_GetError());
		SDL_FreeSurface(sText);
		SDL_RenderCopy(SDLRenderer, strTex, NULL, &sdlRect);
		SDL_RenderPresent(SDLRenderer);
		while (true)continue;

	return 0;*/

	GUIMainLoop();
#ifdef USESDL
	while(quit==0)
	{
		SDL_WaitEvent(&sdlEvent);
		switch (sdlEvent.type)
		{
		case SDL_QUIT:
			quit=1;
			break;
		case SDL_KEYDOWN:
			printf("pressed %c\n",sdlEvent.key.keysym.sym);
			break;
		case SDL_MOUSEBUTTONDOWN:
			root->MousePressed(sdlEvent.button.x,sdlEvent.button.y,1);
			printf("mouse click %d %d\n",sdlEvent.button.x,sdlEvent.button.y);
			break;
		case SDL_MOUSEBUTTONUP:
			root->MouseReleased(sdlEvent.button.x,sdlEvent.button.y,1);
			printf("mouse click %d %d\n",sdlEvent.button.x,sdlEvent.button.y);
			break;

		}
		SDL_SetRenderDrawColor(SDLRenderer,255,0,0,255);
		SDL_RenderClear(SDLRenderer);
		SDL_SetRenderDrawColor(SDLRenderer,0,0,0,255);
		root->Draw();
		//CQMLGUI::mGUI_Element_Draw((CQMLGUI::Element*)root);
		SDL_RenderPresent(SDLRenderer);
	}
	//SDL_Delay(3000);
	
    SDL_DestroyRenderer(SDLRenderer);
    SDL_DestroyWindow(SDLWindow);

    SDL_Quit();
#endif

#ifdef USECAIRO
	CairoEnd();
#endif


	return 0;
}
示例#10
0
int main(void)
    {

    //*******************************************************************
    Init();
    TMRInit(2);        // Initialize Timer interface with Priority=2
    BLIInit();        // Initialize Signal interface
    //==================================================================
    // Provide a 5 second delay prior to initialization of I2C interface
    // to avoid false-start during programming by PIC Kit 3
    //------------------------------------------------------------------
    BLIAsyncStart(50,200);
    TMRDelay(5000);
    BLIAsyncStop();
    //*******************************************************************
    // Switch 1 controls the Serial Data Logger (SDL) communication speed
    //-------------------------------------------------------------------
    if (_SW1)
        // Switch 1 is ON - Configuring SDL for PIC-to-PIC
        // high-speed communication at 1 MBaud
        SDLInit(3, BAUD_1M);
    else
        // Switch 1 is OFF - Configuring SDL for ZigBEE
        // wireless communication at 115.2 KBaud
        SDLInit(3, BAUD_115200);
    //*******************************************************************
    // Initialize I2C Library
    //-------------------------------------------------------------------
    I2CInit(5, 2);  // First param: IL = 5 (interrupt request priority
                    // Second param: I2C speed
                    // 0 - lowest (123 kHz at Fcy = 64MHz)
                    // 1 - 200 kHz
                    // 2 - 400 kHz
                    // 3 - 1 MHz
    //-------------------------------------------------------------------
    uint    RC      = 0;
    ulong   Alarm   = 0;
    //==================================================================
    // Initialize MPUs
    //------------------------------------------------------------------
    RC = MPUInit(0, 3, MPU_GYRO_2000ds, MPU_ACC_2g);
                        // Initialize motion Sensor
                        // 1 kHz/(0+1) = 1000 Hz (1msec)
                        // DLPF = 3 => Bandwidth 44 Hz (delay: 4.9 msec)
    if (RC)    BLIDeadStop("EG", 2);
    //=====================================================
    // Initialize Asynchronous mode
    //-----------------------------------------------------
    if ( (RC = MPUAsyncStart(2)) )
        BLIDeadStop("S2", 2);
    //------------------------------
    if ( (RC = MPUAsyncStart(1)) )
        BLIDeadStop("S1", 2);
    //==================================================================
    // Provide a few second delay prior to calibrating Gyros to make
    // sure that the board is stable after the "turn-on" shake
    //------------------------------------------------------------------
    BLIAsyncStart(50,50);
    TMRDelay(1000);
    BLIAsyncStop();
    //*******************************************************************
    // Calibrate Gyros
    //-----------------------------------------------------
    //  MPUSetOptions(Rotate, TempComp, CrossAxis)
    MPUSetOptions(TRUE, TRUE, TRUE);
    //-----------------------------------------------------
    BLIAsyncStart(100,100);
    //------------------------------
    if ( (RC = MPUCalibrateGyro(1)) )
        BLIDeadStop("C1", 2);
    //------------------------------
    if ( (RC = MPUCalibrateGyro(2)) )
        BLIDeadStop("C2", 2);
    //------------------------------
    BLIAsyncStop();
    //=====================================================
    struct
        {
        MPUData    Sample1;
        MPUData    Sample2;
        } MPU;
    //=====================================================
    // Main Loop
    //-----------------------------------------------------
    BLISignalOFF();
    while (TRUE)
        {
        Alarm = TMRSetAlarm(20);
        //------------------------------------
        if ( (RC = MPUAsyncReadWhenReady(1, &MPU.Sample1)) )
            BLIDeadStop("SM1", 3);
        //--------------------------
        if ( (RC = MPUAsyncReadWhenReady(2, &MPU.Sample2)) )
            BLIDeadStop("SM2", 3);
        //------------------------
        BLISignalFlip();
        //-------------------------
        SDLPostIfReady((byte*)&MPU, sizeof(MPU));
        //-------------------------
        TMRWaitAlarm(Alarm);
        }

    //*******************************************************************
    return 0;
    }