예제 #1
0
/// @brief  Create C Cordic Tables and test the results
/// @return  0
int main (int argc, char *argv[])
{
	Cordic_T x1;
	char str[256];
	char *oname;
	char *p;
	double d;
	int a;
	int i;
	FILE *FO;

	for(i=1; i<argc;++i)
	{
		p = argv[i];
		if(*p != '-')
				continue;
		++p;
		if(*p == 'o')
		{
				oname = argv[++i];
		}
	}
	if(!oname)
	{
		fprintf(stderr,"Usage: %s -o filename [-p]\n",argv[0]);
		fprintf(stderr,"-o filename is CORDIC C table output file\n");
		exit(1);
	}

	FO = fopen(oname,"w");
	if(FO == NULL)
	{
			fprintf(stderr,"Can not open: [%s]\n", oname);
			exit (1);
	}


	fprintf(FO,"#ifndef _CORDIC_INC_H\n");
	fprintf(FO,"#define _CORDIC_INC_H\n");

	fprintf(FO,"/**\n");
	fprintf(FO," @file %s\n", basename(oname));
	fprintf(FO," Generated by:[%s]\n", basename(argv[0]));
	fprintf(FO," On: %s\n", get_date());
	fprintf(FO," By Mike Gore 2015, Cordic C Table\n");
	fprintf(FO,"*/\n");


	dump_tables( FO);

	fprintf(FO,"#else // CORDIC_TABLE\n");
	fprintf(FO,"extern const Cordic_T v_atangrad[];\n");
	fprintf(FO,"#endif // CORDIC_TABLE\n");
	fprintf(FO,"#endif // _CORDIC_INC_H\n");

	printf("// Verify CORDIC table \n");
	for(d=0;d<=1;d+=.1)
	{
		x1 = FP2Cordic(d);
		Circular (Cordic_K, 0L, x1);
		a = (int) 100 * d + 0.000005;	// rounding - 0.1 is not exact
		sprintf(str,"%d Gradians", a);
		PrintXYZ (str);
	}
	printf("// End of CORDIC verify\n");

    return (0);
}
예제 #2
0
//----------------------------------------------
// Display current sensor position
void OnTimer( HWND hDlgWnd ){
  static int iRectIsClean = 0;
  int iFrame;
  double dT_ms;
  tdXYZ atXYZ[N_DISPL_SENSORS];
  int aiDistortion[N_DISPL_SENSORS];
  HWND hPic;
  HDC hDC, hBitmapDC;
  HBITMAP hBitmap;
  RECT recClnt;
  int iSensor;
  int iOffsetX, iOffsetY;
  int iW, iH;
  int nSensors;
  double dSensX, dSensY;
  double dX, dY;
  char szTmp[100];

  ZeroMemory(atXYZ, sizeof(atXYZ));
  hPic = GetDlgItem(hDlgWnd, IDC_PICTURE);
  GetClientRect( hPic, &recClnt );
  if( g_GetLatestCoordinates( N_DISPL_SENSORS, &nSensors, &iFrame, &dT_ms, (double *)atXYZ ) ) {
    if( !iRectIsClean ) {
      // No valid coordinates - not running
      InvalidateRect( hDlgWnd, &recClnt, TRUE );
      // Print timestamp
      SetWindowText(GetDlgItem(hDlgWnd, IDC_LBL_TIME ), "N/A");
      // Print frame
      SetWindowText(GetDlgItem(hDlgWnd, IDC_LBL_IFRAME ), "N/A");
      iRectIsClean = 1;
    }
  }
  else {
    iRectIsClean = 0;
    iW = (recClnt.right - recClnt.left);
    iH = (recClnt.bottom - recClnt.top);
    iOffsetX = (iW - WIN_SIZE_X)/2;
    iOffsetY = (iH - WIN_SIZE_Y)/2;
    hDC = GetDC(hPic);

    // to avoid flicker we draw on the off-screen bitmap and then copy it to the screen
    hBitmapDC = CreateCompatibleDC ( hDC );
    hBitmap = CreateCompatibleBitmap ( hDC, iW, iH );
    SelectObject ( hBitmapDC, hBitmap ); // map DC to the off-screen bitmap
    // Black backgound
    SelectObject( hBitmapDC, GetStockObject( BLACK_BRUSH ));
    Rectangle( hBitmapDC, recClnt.left, recClnt.top, 
                          recClnt.right, recClnt.bottom);
    // White box
    SelectObject( hBitmapDC, GetStockObject( WHITE_PEN ));
    Rectangle( hBitmapDC, iOffsetX, iOffsetY, 
                          WIN_SIZE_X+iOffsetX, WIN_SIZE_Y+iOffsetY );

    for( iSensor = 0; iSensor < nSensors; iSensor++){
      dSensX = atXYZ[iSensor].X;
      dSensY = atXYZ[iSensor].Y;
      // normalize coordinates to 0-1 
      dX = (dSensX - RAW_MIN_X)/ (RAW_MAX_X - RAW_MIN_X);  
      dY = (RAW_MAX_Y - dSensY)/ (RAW_MAX_Y - RAW_MIN_Y);  // make Y axis bottom->top

      // clip coordinates
      if(dX < 0) dX = 0;
      if(dX > 1) dX = 1;
      if(dY < 0) dY = 0;
      if(dY > 1) dY = 1;

      DrawCross( hBitmapDC, x_atMarkerColors[iSensor],
                (int)(dX*WIN_SIZE_X) + iOffsetX,  
                (int)(dY*WIN_SIZE_Y) + iOffsetY  );
    } // for all sensors

    // Draw bitmap
    BitBlt(hDC, recClnt.left, recClnt.top, iW, iH, 
           hBitmapDC, 0, 0, SRCCOPY);

    DeleteObject(hBitmap);
    DeleteDC(hBitmapDC);
    ReleaseDC(hPic, hDC); 

    // Print timestamp
    sprintf(szTmp, "%.2f", dT_ms/1000.0);
    SetWindowText(GetDlgItem(hDlgWnd, IDC_LBL_TIME ), szTmp);
    // Print frame
    sprintf(szTmp, "%d", iFrame);
    SetWindowText(GetDlgItem(hDlgWnd, IDC_LBL_IFRAME ), szTmp);
  }

  // Draw distortion LEDs and print coordinates
  g_GetSignalDistortion( aiDistortion );

  DrawDistortionBox( hDlgWnd, x_atDistortionColors[aiDistortion[0]],  IDC_PIC_SENS1);
  DrawDistortionBox( hDlgWnd, x_atDistortionColors[aiDistortion[1]],  IDC_PIC_SENS2);
  DrawDistortionBox( hDlgWnd, x_atDistortionColors[aiDistortion[2]],  IDC_PIC_SENS3);
  DrawDistortionBox( hDlgWnd, x_atDistortionColors[aiDistortion[3]],  IDC_PIC_SENS4);


  PrintXYZ( hDlgWnd, aiDistortion[0], &atXYZ[0], IDC_LBL_X1, IDC_LBL_Y1, IDC_LBL_Z1 );
  PrintXYZ( hDlgWnd, aiDistortion[1], &atXYZ[1], IDC_LBL_X2, IDC_LBL_Y2, IDC_LBL_Z2 );
  PrintXYZ( hDlgWnd, aiDistortion[2], &atXYZ[2], IDC_LBL_X3, IDC_LBL_Y3, IDC_LBL_Z3 );
  PrintXYZ( hDlgWnd, aiDistortion[3], &atXYZ[3], IDC_LBL_X4, IDC_LBL_Y4, IDC_LBL_Z4 );

/*
  // Print coordinates
  if(aiDistortion[0] < DIST_LEVEL_MAX ){
    PrintCoord(hDlgWnd, atXYZ[0].X, IDC_LBL_X1);
    PrintCoord(hDlgWnd, atXYZ[0].Y, IDC_LBL_Y1);
    PrintCoord(hDlgWnd, atXYZ[0].Z, IDC_LBL_Z1);
  }
  else{
    SetWindowText(GetDlgItem(hDlgWnd, IDC_LBL_X1 ), "N/A");
    SetWindowText(GetDlgItem(hDlgWnd, IDC_LBL_Y1 ), "N/A");
    SetWindowText(GetDlgItem(hDlgWnd, IDC_LBL_Z1 ), "N/A");
  }

  if(aiDistortion[1] < DIST_LEVEL_MAX ){
    PrintCoord(hDlgWnd, atXYZ[1].X, IDC_LBL_X2);
    PrintCoord(hDlgWnd, atXYZ[1].Y, IDC_LBL_Y2);
    PrintCoord(hDlgWnd, atXYZ[1].Z, IDC_LBL_Z2);
  }
  else{
    SetWindowText(GetDlgItem(hDlgWnd, IDC_LBL_X2 ), "N/A");
    SetWindowText(GetDlgItem(hDlgWnd, IDC_LBL_Y2 ), "N/A");
    SetWindowText(GetDlgItem(hDlgWnd, IDC_LBL_Z2 ), "N/A");
  }

  if(aiDistortion[2] < DIST_LEVEL_MAX ){
    PrintCoord(hDlgWnd, atXYZ[2].X, IDC_LBL_X3);
    PrintCoord(hDlgWnd, atXYZ[2].Y, IDC_LBL_Y3);
    PrintCoord(hDlgWnd, atXYZ[2].Z, IDC_LBL_Z3);
  }
  else{
    SetWindowText(GetDlgItem(hDlgWnd, IDC_LBL_X3 ), "N/A");
    SetWindowText(GetDlgItem(hDlgWnd, IDC_LBL_Y3 ), "N/A");
    SetWindowText(GetDlgItem(hDlgWnd, IDC_LBL_Z3 ), "N/A");
  }

  if(aiDistortion[3] < DIST_LEVEL_MAX ){
    PrintCoord(hDlgWnd, atXYZ[3].X, IDC_LBL_X4);
    PrintCoord(hDlgWnd, atXYZ[3].Y, IDC_LBL_Y4);
    PrintCoord(hDlgWnd, atXYZ[3].Z, IDC_LBL_Z4);
  }
  else{
    SetWindowText(GetDlgItem(hDlgWnd, IDC_LBL_X4 ), "N/A");
    SetWindowText(GetDlgItem(hDlgWnd, IDC_LBL_Y4 ), "N/A");
    SetWindowText(GetDlgItem(hDlgWnd, IDC_LBL_Z4 ), "N/A");
  }
*/

}