Advertisement
Guest User

Assetto Corsa

a guest
Apr 14th, 2016
462
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. int _tmain(int argc, _TCHAR* argv[])
  2. {
  3.     initPhysics();
  4.     initGraphics();
  5.     initStatic();
  6.  
  7.     printf("Welcome to the serial test app!\n\n");
  8.  
  9.     Serial* SP = new Serial("COM3");    /* CHANGE COM PORT TO THE ONE THE ARDUINO IS CONNECTED TO*/
  10.  
  11.     if (SP->IsConnected())              /*Check connection to port*/
  12.         printf("We're connected");
  13.     else return 0;
  14.  
  15.     SPageFilePhysics* pf = (SPageFilePhysics*)m_physics.mapFileBuffer;  /*Pointer used to access physics data*/
  16.  
  17.     char Data[256]="";
  18.     int DataLength = 255;
  19.  
  20.     while (true)
  21.     {
  22.         //printf("Speed : %f \n", pf->speedKmh);
  23.  
  24.         snprintf(Data, sizeof(Data), "%3.3f", pf->speedKmh);    /*Float to char conversion, to send it through the serial port*/
  25.  
  26.         SP->WriteData(Data, DataLength);                    /*Write data on Serial Port*/
  27.    
  28.         while (SP->ReadData(inData, sizeof(inData)) != 1);  /*Wait for response*/
  29.  
  30.         printf("Speed KmH : %s\n", Data);
  31.         std::this_thread::sleep_for(std::chrono::milliseconds(1000));   /*Wait 1s to slow things down for testing purposes*/
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement