Beispiel #1
0
/**
 * This class runs an OpenGL probe.  It MUST be a singleton (only one instance).
 */
GLDisplay::GLDisplay(int * argc, char * argv[], HyPerLayer * layer, int numRows, int numCols)
{
   initLayerProbe(NULL, layer);
   parent = layer->getParent();
   parent->setDelegate(this);

   rank = parent->icCommunicator()->commRank();

   this->numRows = numRows;
   this->numCols = numCols;
   this->numDisplays = 0;

   // start with time before start for initial display refresh
   lastUpdateTime = parent->simulationTime() - parent->getDeltaTime();

   glProbe = this;
   g_msecs = 0.0f;    // glut timer delay

   time     = 0.0;
   stopTime = 0.0;

   image = NULL;

   const int maxDisplays = numRows * numCols;

   displays = (LayerDataInterface **) calloc(maxDisplays, sizeof(LayerDataInterface *));
   textureIds = (int *) calloc(maxDisplays, sizeof(int));

   assert(displays != NULL);
   assert(textureIds != NULL);

   if (rank == 0) {
      glut_init(argc, argv, glwWidth, glwHeight);
   }
}
/**
 * \brief This function start GLUT never ending loop
 */
void display_loop(struct CTX *_ctx, int argc, char *argv[])
{
	ctx = _ctx;

	glut_init(argc, argv);

	if(ctx != NULL) {
		glutMainLoop();
	}
}
Beispiel #3
0
int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitWindowSize(800, 600);
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
    glutCreateWindow("Engine");

    glut_init();
    tw_init();
    init_color();

    init_game();
    pause = false;
    glutMainLoop();
}
Beispiel #4
0
int main(int argc, char **argv)
{
	// setup window
	glut_init(argc,argv);

	///
	// init radio
	///
	int device_count = rtlsdr_get_device_count();
	if (!device_count)
	{
		fprintf(stderr, "No supported devices found.\n");
		exit(1);
	}

	fprintf(stderr, "Found %d device(s):\n", device_count);

	uint32_t dev_index = 0;
	fprintf(stderr, "Using device %d: %s\n", dev_index, rtlsdr_get_device_name(dev_index));

	int r = rtlsdr_open(&dev, dev_index);
	if (r < 0)
	{
		fprintf(stderr, "Failed to open rtlsdr device #%d.\n", dev_index);
		exit(1);
	}
	
	/* Set the sample rate */
	uint32_t samp_rate = DEFAULT_SAMPLE_RATE;
	r = rtlsdr_set_sample_rate(dev, samp_rate);
	if (r < 0) fprintf(stderr, "WARNING: Failed to set sample rate.\n");

	/* Set the frequency */
	frequency = 100000000;
	if(argv[1]) frequency = (uint32_t)atof(argv[1]) * (uint32_t)1e6;
	if(frequency < 1e6)
	{
		fprintf(stderr, "WARNING: Center frequency should be in range, setting to 100MHz\n");
		frequency = 100000000;
	}
	r = rtlsdr_set_center_freq(dev, frequency);
	if (r < 0) fprintf(stderr, "WARNING: Failed to set center freq.\n");
	else fprintf(stderr, "Tuned to %f MHz.\n", frequency/1e6);
	sprintf(strFreq,"%4.0f",frequency/1e6);

	/* Set the gain */
	int gain = 0;
	if(argv[2]) gain = atoi(argv[2]);
	if (!gain)
	{
		 /* Enable automatic gain */
		r = rtlsdr_set_tuner_gain_mode(dev, 0);
		if (r < 0) fprintf(stderr, "WARNING: Failed to enable automatic gain.\n");
	}
	else
	{
		/* Enable manual gain */
		r = rtlsdr_set_tuner_gain_mode(dev, 1);
		if (r < 0) fprintf(stderr, "WARNING: Failed to enable manual gain.\n");

		/* Set the tuner gain */
		r = rtlsdr_set_tuner_gain(dev, gain);
		if (r < 0)
		{
			fprintf(stderr, "WARNING: Failed to set tuner gain.\n");
			fprintf(stderr, "Valid values for e4000 are: -10, 15, 40, 65, 90, 115, 140, 165, 190, 215, 240, 290, 340, 420, 430, 450, 470, 490\n");
			fprintf(stderr, "Valid values for r820t are: 9, 14, 27, 37, 77, 87, 125, 144, 157, 166, 197, 207, 229, 254, 280, 297,\n\t328, 338, 364, 372, 386, 402, 421, 434, 439, 445, 480, 496\n");
			fprintf(stderr, "Gain values are in tenths of dB, e.g. 115 means 11.5 dB.\n");
		}
		else fprintf(stderr, "Tuner gain set to %f dB.\n", gain/10.0);
	}
	
	/* Reset endpoint before we start reading from it (mandatory) */
	r = rtlsdr_reset_buffer(dev);
	if (r < 0) fprintf(stderr, "WARNING: Failed to reset buffers.\n");

	
	///
	// setup fftw
	///
	uint32_t out_block_size = DEFAULT_BUF_LENGTH;
	buffer = malloc(out_block_size * sizeof(uint8_t));
	fftw_in = fftw_malloc ( sizeof ( fftw_complex ) * out_block_size/2 );
	fftw_out = fftw_malloc ( sizeof ( fftw_complex ) * out_block_size/2 );
	
	// put the plan on FFTW_MEASURE to calculate the optimal fft plan (takes a few seconds).
	// If performance of FFTW_ESTIMATE is good enough use that one
	//fftw_p = fftw_plan_dft_1d ( out_block_size/2, fftw_in, fftw_out, FFTW_FORWARD, FFTW_MEASURE );
	fftw_p = fftw_plan_dft_1d ( out_block_size/2, fftw_in, fftw_out, FFTW_FORWARD, FFTW_ESTIMATE );

	
	/* start reading samples */
	fprintf(stderr, "Update frequency is %.2fHz.\n",((double)DEFAULT_SAMPLE_RATE / (double)DEFAULT_BUF_LENGTH));
	fprintf(stderr, "Press [q,w] to change frequency, [a,z] to adjust waterfall color sensitivity, ESC to quit.\n");
	pwr_max = 0.0f;
	pwr_diff = 1.0f;
	glutTimerFunc(0,readData,0);
	glutMainLoop();
	
	return 0;
}