Ejemplo n.º 1
0
void KeyboardHandler (unsigned char cKey, int iX, int iY) // keyboard input handling function
{
	GLfloat fRadians ;
	switch (cKey)
	{
	case 'p' : // toggle pause
	case 'P' : 
		bPause = !bPause ;
	break ;

	case '/' : // toggle filling
	case '?' :
		ToggleFilling(!bFilling) ;
	break ;

	case '.' : // toggle lighting
	case '>' :
		ToggleLighting(!bLighting) ;
	break ;

	case 'g' :	// toggle fullscreen
	case 'G' :
		ToggleFullscreen(!bFullscreen) ;
	break ;

	case 'i' :  // set initial position and velocity
	case 'I' :
		InitCamera() ;
		ptVelocity = 0.0 ;
	break ;

	case 'f' : // move forward
	case 'F' : 
		ptVelocity = 0.0 ;
		fRadians = fPlaneOrientation[1] * 3.1415 / 180.0 ;
		fCameraX += sin(fRadians) ;
		fCameraZ += cos(fRadians) ;

		fRadians = fPlaneOrientation[0] * 3.1415 / 180.0 ;
		if (fCameraY + sin(fRadians) > 3) fCameraY += sin(fRadians) ;
	break ;

	case 'a' :	// decrease velocity
	case 'A' :
		fPlaneOrientation[2] -= 10.0 ;
	break ;

	case 'd' :	// increase velocity
	case 'D' :
		fPlaneOrientation[2] += 10.0 ;
	break ;

	case 'o' :  // toggle time of day
	case 'O' :
		bTime = !bTime ;
	break ;

	case 'w' :	// increase velocity
	case 'W' :
		ptVelocity.dVal[2] += 2 ;
	break ;

	case 's' :	// decrease velocity
	case 'S' :
		ptVelocity.dVal[2] -= 2 ;
	break ;

	case 'c' :	// toggle cockpit
	case 'C' :
		bCockpit = !bCockpit ;
	break ;

	case 'q' : // quit program
	case 'Q' :
		CleanObjects() ;
		exit(0) ;
	break ;
	}
}
Ejemplo n.º 2
0
void CClassification::EnterTask()
{
#ifndef _WINDOWS // ------- Don't compile on windows -----

	Uint32 unIntervalTicks;
	
	Bool bLed2 = FALSE;
	ledLight( 2, FALSE );
	
	// Initialize the conveyor device driver and register the trigger semaphore.
	convInit( );
	SEM_new( &m_semTrigger, 0 );
	
	convRegisterSemTrigger( &m_semTrigger, &m_bTrigger );	
	
	// Reset statstics
	GetStats( NULL, TRUE );

	// Initialize the high res timer
	timeInit();
	
	// Pre-calculate the maximum wait time for the semaphore.
	unIntervalTicks = hlpMsToTicks( 1000 * MAXWAIT_SECONDS );
	
	// Open the interlink UART channel and configure it.
	m_hPPUSerial = serOpen( INTERLINK_UART_CHAN, sizeof( ClassificationTable ) *4 );
	assertLog( m_hPPUSerial != NULL );
	serConfigChannel( m_hPPUSerial, 115000, FALSE, FALSE, FALSE );	
	
	// Initialize the jet controller
	TSK_sleep( 2000 );
	CJetControl::Instance()->Init();
	
	// Start watchdog and set it to twice the time of our maximum interval.
	m_unWatchId = CWatchdog::Instance()->AddToWatch( "Classification", MAXWAIT_SECONDS * 2 );
	CWatchdog::Instance()->EnableWatch( m_unWatchId, TRUE );
	
	while( 1 )
	{
			
		// Wait for a trigger signal, timeout at some time to reset watchdog
		if ( SEM_pend( &m_semTrigger, unIntervalTicks ) )
		{
			// Succesfully received a trigger
			ledLight( 2, bLed2 );
			bLed2 = !bLed2;			
						
			// Get the trigger time as exact as possible.
			Uint32 unCurTime = convGetLastTriggerTime();
						
			// Increment our trigger counter.
			m_unCurrentTriggerPulse++;
			// dbgLog( "Entering Trigger %d", m_unCurrentTriggerPulse );
			
			// Store that trigger in the stats. This increments the number of possible potatoes by the number
			// of lanes.
			m_sClassificationStats.unNumPossible += m_nNumLanes;
			
			// See if we're in service mode and handle it.
			if ( m_csmServiceMode != CSM_NORMAL )
			{
				if (   (m_csmServiceMode == CSM_ADJUST_SMALL_EJECTION_PARAMS )
					|| (m_csmServiceMode == CSM_ADJUST_MEDIUM_EJECTION_PARAMS )
					|| (m_csmServiceMode == CSM_ADJUST_LARGE_EJECTION_PARAMS ) )
					ServiceGenParamAdjustCommands( unCurTime );
			}
			else
			{		
				// If not in service mode, see if we've got any due ejections to make and generate
				// the commands for it.
				EjectionTable * pTable;
				
				// See if any ejections are due and generate the jetcontrol commands, which are then
				// sent to the jet control.
				pTable = GetDueEjectionTable();
				if ( pTable != NULL )
				{
					// Generate ejection commands, but only if we're in classification mode.
					if ( m_eOperationMode == OP_CLASSIFICATION )
					{
						GenerateEjectionCommands( pTable, unCurTime );
					}
					ReleaseEjectionTable( pTable );
				}
							
				// Now we have to classify the potatoes and create the ejection table for the current
				// line. Only build the table if we've got a reference to the global potato table
				if ( m_pPotatoTable != NULL )
				{												
					// Build the local classification table (i.e. the per-frame classification)
					BuildTable( &m_LocalClassificationTable,  m_pPotatoTable );
					
					// Only exchange tables if we're in classification mode.
					if ( m_eOperationMode == OP_CLASSIFICATION )
					{					
						// Exchange the table with the other DSP
						if ( ExchangeTables( &m_LocalClassificationTable, &m_ForeignClassificationTable ) == TRUE )
						{
							MergeTables( &m_LocalClassificationTable, &m_ForeignClassificationTable );
						}
					}
						
					// Classify the potatoes using a new ejection table. This, we'll
					// have to do even in calibration mode, because of the statistics
					// for the GUI.
					pTable = GetNewEjectionTable( m_nNumTriggerPulsesDelay );
					if ( pTable != NULL )
					{
						ClassifyPotatoes( & m_LocalClassificationTable, &m_ForeignClassificationTable, pTable );
					}	
					
				} // if potatoobject table accessible
				
			} // if not in servicemode
			
		} // if trigger occured
		
		else
		{
			// Clean the objects list from time to time, if we don't receive trigger signals for
			// a long time. This prevents the number of objects from growing to big.
			CleanObjects( m_pPotatoTable );	
			
			// Check for service operation
			if ( m_csmServiceMode == CSM_CHECK_JETS )
				ServiceGenJetCheckCommands();	
						
		}
		
		// See if any of the strictness values changed and apply it to the properties
		if (   m_propSplitStrictness.HasChanged()
			|| m_propShapeStrictness.HasChanged()
			|| m_propGreenStrictness.HasChanged()
			|| m_propColorStrictness.HasChanged() )
		{
			ApplyStrictness();		
		}
		
		// Signal the watchdog.
		CWatchdog::Instance()->SignalAlive( m_unWatchId );	
		
	} // while(1)

#endif // ------------------------------------------------

}