예제 #1
0
void hardScroll (int distance) {
	if (abs (distance) >= sceneHeight) {
		blankScreen (0, 0, sceneWidth, sceneHeight);
		return;
	}

	if (! distance) return;

	const GLfloat backdropTexCoords[] = { 
		0.0f, 0.0f,
		backdropTexW, 0.0f,
		0.0f, backdropTexH,
		backdropTexW, backdropTexH
	}; 

	setPixelCoords (true);

	unsigned int xoffset = 0;
	while (xoffset < sceneWidth) {
		int w = (sceneWidth-xoffset < viewportWidth) ? sceneWidth-xoffset : viewportWidth;

		unsigned int yoffset = 0;
		while (yoffset < sceneHeight) {
			int h = (sceneHeight-yoffset < viewportHeight) ? sceneHeight-yoffset : viewportHeight;

			glClear(GL_COLOR_BUFFER_BIT);	// Clear The Screen

			// Render the backdrop
			glBindTexture (GL_TEXTURE_2D, backdropTextureName);
			glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
			glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

			const GLfloat vertices[] = { 
				(GLfloat)-xoffset, (GLfloat)-distance-yoffset, 0., 
				(GLfloat)sceneWidth-xoffset, (GLfloat)-distance-yoffset, 0., 
				(GLfloat)-xoffset, (GLfloat)sceneHeight-distance-yoffset, 0.,
				(GLfloat)sceneWidth-xoffset, (GLfloat)sceneHeight-distance-yoffset, 0. 
			};

			glUseProgram(shader.texture);
			setPMVMatrix(shader.texture);

			drawQuad(shader.texture, vertices, 1, backdropTexCoords);
			glUseProgram(0);

			// Copy Our ViewPort To The Texture
			copyTexSubImage2D(GL_TEXTURE_2D, 0, xoffset, yoffset, viewportOffsetX, viewportOffsetY, w, h, backdropTextureName);
			
			yoffset += viewportHeight;
		}
		xoffset += viewportWidth;
	}
	setPixelCoords (false);
}
예제 #2
0
void main ()
{
	auto int channel;
	auto float current;
	auto int key;
	auto char s[128];

   // Initialize the controller
	brdInit();

   // Configure channel pair 0 & 1 for 4- 20ma mode of operation
   anaInConfig(0, mAMP_MODE);

   // Configure channel pair 2 & 3 for 4- 20ma mode of operation
	anaInConfig(1, mAMP_MODE);

   blankScreen(0, 20);
	DispStr(2, 2, "A/D input current for channels 0 - 3");
	DispStr(2, 3, "------------------------------------");
   DispStr(2, 10, "Press Q or q to exit program.");

   while(1)
   {
		for(channel = 0; channel < 4; channel++)
		{
     		current = anaInmAmps(channel);
         if(current != ADOVERFLOW)
        		sprintf(s, "Channel = %2d Current = %.3f                  ", channel, current);
         else
            sprintf(s, "Channel = %2d Current = Exceeded Range!!!     ", channel);
         DispStr(2,channel + 4, s);
		}
      if(kbhit())
		{
			key = getchar();
			if (key == 'Q' || key == 'q')		// check if it's the q or Q key
			{
				while(kbhit()) getchar();
      		break;
     		}
		}
   }
}	//end main
예제 #3
0
void main ()
{
	auto int channel, keypress;
	auto int key;
	auto int gaincode;
	auto float voltage;
   auto int mode;
   auto char s[128];

   // Initialize the controller
	brdInit();

   // Configure channels 0-7 for Single-Ended unipolar mode of operation.
   // (Max voltage range is 0 - 20v)
	for (channel = 0; channel < BL_ANALOG_IN; ++channel)
   {
   	anaInConfig(channel, SE0_MODE);
   }

	while (1)
	{
     	printrange();
		printf(" Choose gain code (0-%d) =  ", BL_MAX_GAINS - 1);
		do
		{
      	while(!kbhit()); // wait for key hit
			key = getchar() - '0';
		} while (key < 0 || key >= BL_MAX_GAINS);
		gaincode = key;
		printf("%d", gaincode);

      blankScreen();
		DispStr(1, 2,  "A/D input voltage for channels 0 - 7");
		DispStr(1, 3,  "------------------------------------");
   	DispStr(1, 14, "Press key to select another gain option.");

   	while(1)
      {
			for (channel = 0; channel < BL_ANALOG_IN; ++channel)
			{
      		voltage = anaInVolts(channel, gaincode);
            if (voltage > BL_ERRCODESTART)
            {
            	// valid read
         		sprintf(s, "Channel = %2d Voltage = %.3fV              ",
               			channel, voltage);
         	}
            else if (voltage == BL_NOT_CAL)
            {
               sprintf(s, "Channel = %2d Voltage = Not Calibrated     ",
                        channel);
            }
            else
            {
               sprintf(s, "Channel = %2d Voltage = Exceeded Range     ",
                        channel);
            }
            DispStr(1,channel + 4, s);
			}
         if (kbhit())
			{
				getchar();
            blankScreen();
            while (kbhit()) { getchar(); }
            break;
			}
      }
   }
}	//end main
예제 #4
0
void main()
{
	auto int device0, status;
   auto rn_search newdev;
   auto DacCal DacCalTable1;
   auto float volt1, volt2, voltout;
   auto int data1, data2;
   auto int channel, selectChannel, configureDAC;
   auto char tmpbuf[24];
   auto char command;
 	auto int key, done, cal_error;


	brdInit();
   rn_init(RN_PORTS, 1);      //initialize controller RN ports

   //search for device match
	newdev.flags = MATCHFLAG;
	newdev.productid = MATCHPID;
   if ((device0 = rn_find(&newdev)) == -1)
   {
   	printf("\n no device found\n");
      exit(0);
   }


	while(1)
	{
		DispStr(1, 1,"!!!Caution this will overwrite the calibration constants set at the factory.");
		DispStr(1, 2,"Do you want to continue(Y/N)?");

		while(!kbhit());
		key = getchar();
		if(key == 'Y' || key == 'y')
		{
			break;
		}
		else if(key == 'N' || key == 'n')
		{
			exit(0);
		}
	}

   configureDAC = TRUE;
  	selectChannel = TRUE;

 	for(;;)
	{

      if(configureDAC)
      {
      	blankScreen(0, 28);
   		DispStr(2, 1, "DAC Board   CH0&1   CH2-7");
			DispStr(2, 2, "-------------------------");

			DispStr(2, 3, "Config = 0  2.5v    10v");
			DispStr(2, 4, "Config = 1  5.0v    10v");
			DispStr(2, 5, "Config = 2  10v     10v");
			DispStr(2, 6, "Config = 3  5v      20v");
			DispStr(2, 7, "Config = 4  10v     20v");
			DispStr(2, 8, "Config = 5  20v     20v");
			DispStr(2, 9, "Please enter the DAC configuration 0 - 5....");
			do
			{
				command = getchar();
			} while (!((command >= '0') && (command <= '5')));
			printf("Config  = %d", command-=0x30);
      	rn_anaOutConfig(device0, command, 0, 0);
         configureDAC = FALSE;
      }

      if(selectChannel)
      {
      	blankScreen(11, 28);
 			DispStr(2, 11, "DAC0 - DAC7 Calibration Program");
			DispStr(2, 12, "-------------------------------");
			DispStr(2, 13, "Please enter an output channel (0 - 7) = ");
			do
			{
				channel = getchar();
			} while (!((channel >= '0') && (channel <= '7')));
			printf("%d", channel-=0x30);
         selectChannel = FALSE;
      }

      // set two known voltage points using rawdata values, the
		// user will then type in the actual voltage for each point
      rn_anaOut(device0, channel, LOCOUNT, 0);
		DispStr(2, 15, "ENTER the voltage reading from meter(~10% of max voltage) = ");
		volt1 = atof(gets(tmpbuf));

		rn_anaOut(device0, channel, HICOUNT, 0);
		DispStr(2, 16, "ENTER the voltage reading from meter(~90% of max voltage) = ");
		volt2 = atof(gets(tmpbuf));

      cal_error = FALSE;
     	rn_anaOutCalib(channel, LOCOUNT, volt1, HICOUNT, volt2, &DacCalTable1, 0);

      // Store coefficients into eeprom
      rn_anaOutWrCalib(device0, channel, &DacCalTable1, 0);
      memset(&DacCalTable1, 0x00, sizeof(&DacCalTable1));
      rn_anaOutRdCalib(device0, channel, &DacCalTable1, 0);
  		DispStr(2, 17, "Calibration constants has been written to the eeprom");

 		done = FALSE;
		while (!done && !cal_error)
		{
			// display DAC voltage message
			DispStr(2, 20, "Type a desired voltage (in Volts) =  ");

			// get user voltage value for the DAC thats being monitored
			voltout = atof(gets(tmpbuf));

			// send voltage value to DAC for it to output the voltage
     		rn_anaOutVolts(device0, channel,  voltout, &DacCalTable1, 0);
			DispStr(2, 21, "Observe voltage on meter.....");

			// display user options
			DispStr(2, 23, "User Options:");
			DispStr(2, 24, "-------------");
			DispStr(2, 25, "1. Change the voltage on current channel");
			DispStr(2, 26, "2  Calibrate another DAC channel");
			DispStr(2, 27, "3. Change overall DAC output configuration");
         DispStr(2, 28, "4. Exit Program");


			// wait for a key to be pressed
			while(1)
			{
				while(!kbhit());
				key = getchar();
				if(key == '1')
				{
   				// empty the keyboard buffer and clear user options
   				while(kbhit()) getchar();
               blankScreen(19, 28);
 					break;
				}
            if(key == '2')
				{
   				// empty the keyboard buffer and clear user options
   				while(kbhit()) getchar();
               done = TRUE;
               selectChannel = TRUE;
               break;
   			}
            if(key == '3')
				{
   				// empty the keyboard buffer and clear user options
   				while(kbhit()) getchar();
               configureDAC = TRUE;
               selectChannel = TRUE;
               done = TRUE;
               break;
   			}
				if(key == '4')
				{
					// exit sample program
     				exit(0);
   			}
 		}
		}
	}
}
예제 #5
0
void main ()
{
	auto unsigned int rawdata;
	auto int channel, keypress;
	auto int key;
	auto float voltage;
   auto char s[256];

   // The brdInit function is only used to configure the I/O
   // on the prototyping board and is not required for the A/D
   // library which will configure everything required to access
   // the A/D circuit.
	brdInit();

   // Step 5 for MUX control
   // Make sure is low when the line is enabled.
   WrPortI(PDDR,  &PDDRShadow,  (PDDRShadow  & ~0x20));

   // Set Function for I/O opeartion
   WrPortI(PDFR,  &PDFRShadow,  (PDFRShadow  & ~0x20));

   // Make PD5 an output
   WrPortI(PDDDR, &PDDDRShadow, (PDDDRShadow | 0x20));

   // Set PD5 for active high/low operation
   WrPortI(PDDCR, &PDDCRShadow, 0x00);

   // Set Port D to be CLK'd by PCLK/2
   WrPortI(PDCR,  &PDCRShadow,  0x00);
   // End of step

   // Initialize the A/D ramp circuit and low-level driver.
   anaInRampInit();

   // Initialize the core module to read external A/D circuit.
   anaInExternalInit(3, 2, 1);


   // Copy calibration data from ch0 to ch1, since we are simulating the
   // 2nd channel....must be done after executing anaInExternalInit.
   _adcCalib[1][0] = _adcCalib[0][0];
   _adcCalib[1][1] = _adcCalib[0][1];

   mux_conversion_done[0] = FALSE;
   mux_conversion_done[1] = FALSE;
	while (1)
	{
      blankScreen(0, 20);
		DispStr(1, 2,  "External A/D input voltage for channels 0 and 1");
		DispStr(1, 3,  "-----------------------------------------------");
      DispStr(1, 6,  "Press Q or q to exit program.");

    	while(1)
      {
   		// Notes:
      	// 1. The mux_conversion_done flag is predefined and will be set
   		// by the ADC low-level driver.
      	// 2. If the mux_conversion_done flag isn't used, and if you read
      	// the external A/D channel faster than the A/D conversion rate,
      	// then the data will be from the previous A/D conversion until a
      	// new A/D conversion is completed.
      	if(mux_conversion_done[0] && mux_conversion_done[1])
         {
            mux_conversion_done[0] = FALSE;
            mux_conversion_done[1] = FALSE;
            for(channel=0; channel < MAX_ADCHANNELS; channel++)
            {
            	voltage = anaInVolts(channel);
            	if(channel >= MAX_ADCHANNELS)
            		channel = 0;
            	if(voltage != ADOVERFLOW)
         			sprintf(s, "Voltage = %.3f               ", voltage);
            	else
               	sprintf(s, "Voltage = Exceeded Range!!!  ");
            	DispStr(1, channel + 4, s);
         	}
         }
         if(kbhit())
			{
				key = getchar();
				if (key == 'Q' || key == 'q')
				{
            	anaInDisable();
      			exit(0);
     			}
			}
      }
   }
}
예제 #6
0
void main()
{
	auto int device0, status;
	auto char tmpbuf[24];
	auto int done, command;
   auto rn_search newdev;
   auto DacCal DacCalTable1;
   auto float voltout;
   auto int channel, selectChannel;
   auto int key;

	brdInit();		// Required for controllers
   rn_init(RN_PORTS, 1);      //initialize controller RN ports

   //search for device match
	newdev.flags = MATCHFLAG;
	newdev.productid = MATCHPID;
   if ((device0 = rn_find(&newdev)) == -1)
   {
   	printf("\n no device found\n");
      exit(0);
   }

	for(;;)
	{
   	blankScreen(0, 28);

		DispStr(2, 2, "DAC Board   CH0&1   CH2-7 ");
		DispStr(2, 3, "--------------------------");

		DispStr(2, 4, "Config = 0  2.5v    10v");
		DispStr(2, 5, "Config = 1  5.0v    10v");
		DispStr(2, 6, "Config = 2  10v     10v");
		DispStr(2, 7, "Config = 3  5v      20v");
		DispStr(2, 8, "Config = 4  10v     20v");
		DispStr(2, 9, "Config = 5  20v     20v");
		DispStr(2, 10, "Please enter the DAC configuration 0 - 5....");
		do
		{
			command = getchar();
		} while (!((command >= '0') && (command <= '5')));
		printf("Config  = %d", command-=0x30);
      rn_anaOutConfig(device0, command, 1, 0);
      for(channel=0; channel < 8; channel++)
      {
      	rn_anaOutRdCalib(device0, channel, &DacCalTable1, 0);
      }


     	done = FALSE;
      selectChannel = TRUE;
		while (!done)
		{
         if(selectChannel)
         {
         	DispStr(2, 12, "DAC0 - DAC7 Voltage Out Program");
				DispStr(2, 13, "-------------------------------");
				DispStr(2, 14, "Please enter an output channel (0 - 7) = ");
				do
				{
		  			channel = getchar();
				} while (!((channel >= '0') && (channel <= '7')));
				printf("%d", channel-=0x30);
            selectChannel = FALSE;
        	}

         // display DAC voltage message
			DispStr(2, 16, "Type a desired voltage (in Volts) =  ");

			// get user voltage value for the DAC thats being monitored
			voltout = atof(gets(tmpbuf));

 			// send voltage value to DAC for it to output the voltage
     		rn_anaOutVolts(device0, channel,  voltout, &DacCalTable1, 0);

 			// display user options
			DispStr(2, 19, "User Options:");
			DispStr(2, 20, "-------------");
			DispStr(2, 21, "1. Write voltage value to DAC channel (internal register)");
         DispStr(2, 22, "2. Strobe DAC chip, all DAC channels will be updated");
         DispStr(2, 23, "3. Change to another DAC channel");
			DispStr(2, 24, "4. Change overall DAC output configuration");
			DispStr(2, 25, "5. Exit Program");

         DispStr(2, 28, "Note: Must strobe DAC for outputs to be updated!");
         while(1)
			{
				// wait for a key to be pressed
				while(!kbhit());
				key = getchar();
            if(key == '1')
				{
   				// empty the keyboard buffer and clear user options
   				while(kbhit()) getchar();
               blankScreen(16, 28);
   				break;
   			}

            if(key == '2')
				{
   				// empty the keyboard buffer and clear user options
   				while(kbhit()) getchar();
               rn_anaOutStrobe(device0, 0);
               DispStr(2, 27, "DAC outputs have been updated");
               msDelay(1000);
               DispStr(2, 27, "                                ");
   			}

            if(key == '3')
				{
   				// empty the keyboard buffer and clear user options
   				while(kbhit()) getchar();
               blankScreen(12, 28);
               selectChannel = TRUE;
   				break;
   			}

				if(key == '4')
				{
					// exit while loop and clear previous calibration infor
					done = TRUE;
  					blankScreen(15, 28);
					// empty keyboard buffer
					while(kbhit()) getchar();
					break;
				}
				if (key == '5')		// check if it's the q or Q key
				{
					// exit sample program
     				exit(0);
   			}
			}
		}
	}
}
예제 #7
0
void App::Run() {

    DisplayName = DISPLAY;

#ifdef XNEST_DEBUG
    char* p = getenv("DISPLAY");
    if (p && p[0]) {
        DisplayName = p;
        cout << "Using display name " << DisplayName << endl;
    }
#endif

    // Read configuration and theme
    cfg.readConf(CFGFILE);
    string themebase = "";
    string themefile = "";
    string themedir = "";
    string name = "";
    if (testing) {
        name = testtheme;
    } else {
        themebase = string(THEMESDIR) + "/"; 
        name = cfg.getOption("current_theme");
        string::size_type pos;
        if ((pos = name.find(",")) != string::npos) {
            // input is a set
            name = findValidRandomTheme(name);
            if (name == "") {
                name = "default";
            }
        }
    }

    bool loaded = false;
    while (!loaded) {
        themedir =  themebase + name;
        themefile = themedir + THEMESFILE;
        if (!cfg.readConf(themefile)) {
            if (name == "default") {
                cerr << APPNAME << ": Failed to open default theme file "
                     << themefile << endl;
                exit(ERR_EXIT);
            } else {
                cerr << APPNAME << ": Invalid theme in config: "
                     << name << endl;
                name = "default";
            }
        } else {
            loaded = true;
        }
    }

    if (!testing) {
        // Create lock file
        LoginApp->GetLock();

        // Start x-server
        setenv("DISPLAY", DisplayName, 1);
        signal(SIGQUIT, CatchSignal);
        signal(SIGTERM, CatchSignal);
        signal(SIGKILL, CatchSignal);
        signal(SIGINT, CatchSignal);
        signal(SIGHUP, CatchSignal);
        signal(SIGPIPE, CatchSignal);
        signal(SIGUSR1, User1Signal);
        signal(SIGALRM, AlarmSignal);

#ifndef XNEST_DEBUG
        OpenLog();

        // Daemonize
        if (daemonmode) {
            if (daemon(0, 1) == -1) {
                cerr << APPNAME << ": " << strerror(errno) << endl;
                exit(ERR_EXIT);
            }
        }

        StartServer();
        alarm(2);
#endif

    }

    // Open display
    if((Dpy = XOpenDisplay(DisplayName)) == 0) {
        cerr << APPNAME << ": could not open display '"
             << DisplayName << "'" << endl;
        if (!testing) StopServer();
        exit(ERR_EXIT);
    }

    // Get screen and root window
    Scr = DefaultScreen(Dpy);
    Root = RootWindow(Dpy, Scr);


    // for tests we use a standard window
    if (testing) {
        Window RealRoot = RootWindow(Dpy, Scr);
        Root = XCreateSimpleWindow(Dpy, RealRoot, 0, 0, 640, 480, 0, 0, 0);
        XMapWindow(Dpy, Root);
        XFlush(Dpy);
    } else {
        blankScreen();
    }

    HideCursor();

    // Create panel
    LoginPanel = new Panel(Dpy, Scr, Root, &cfg, themedir);

    // Start looping
    XEvent event;
    int panelclosed = 1;
    int Action;
    bool firstloop = true; // 1st time panel is shown (for automatic username)

    while(1) {
        if(panelclosed) {
            // Init root
            setBackground(themedir);

            // Close all clients
            if (!testing) {
                KillAllClients(False);
                KillAllClients(True);
            }

            // Show panel
            LoginPanel->OpenPanel();
        }

        Action = WAIT;
        LoginPanel->GetInput()->Reset();
        if (firstloop && cfg.getOption("default_user") != "") {
            LoginPanel->GetInput()->SetName(cfg.getOption("default_user") );
            firstloop = false;
        }

        while(Action == WAIT) {
            XNextEvent(Dpy, &event);
            Action = LoginPanel->EventHandler(&event);
        }

        if(Action == FAIL) {
            panelclosed = 0;
            LoginPanel->ClearPanel();
            XBell(Dpy, 100);
        } else {
            // for themes test we just quit
            if (testing) {
                Action = EXIT;
            }
            panelclosed = 1;
            LoginPanel->ClosePanel();

            switch(Action) {
                case LOGIN:
                    Login();
                    break;
                case CONSOLE:
                    Console();
                    break;
                case REBOOT:
                    Reboot();
                    break;
                case HALT:
                    Halt();
                    break;
                case EXIT:
                    Exit();
                    break;
            }
        }
    }
}