/* MAIN LOOP */
void keyboardScript::doMainLoop()
{
	static int lastCapsState = -1;
	static int lastNumState = -1;
	static int lastScrollState = -1;

	this->fireEvent("onCreate");

	uint32_t lastLoopFireTime = 0;
	while (!this->inErrorState)
	{
		auto startTime = timeGetHighResTime();
		auto nowTime = startTime;

		this->fireEvent("onTimer", startTime, lastLoopFireTime);
		lastLoopFireTime = startTime;

		startTime = timeGetHighResTime();

		
		/* check for events for the next 200 MS */
		do
		{
			/* check indicator states */
			int capsState = ((GetKeyState(VK_CAPITAL) & 0x0001) != 0) ? INDICATOR_STATE_ON : INDICATOR_STATE_OFF;
			int numState = ((GetKeyState(VK_NUMLOCK) & 0x0001) != 0) ? INDICATOR_STATE_ON : INDICATOR_STATE_OFF;
			int scrollState = ((GetKeyState(VK_SCROLL) & 0x0001) != 0) ? INDICATOR_STATE_ON : INDICATOR_STATE_OFF;

			if (capsState != lastCapsState)
				this->fireEvent("onIndicatorStateChange", INDICATOR_CAPSLOCK, capsState);
			if (numState != lastNumState)
				this->fireEvent("onIndicatorStateChange", INDICATOR_NUMLOCK, numState);
			if (scrollState != lastScrollState)
				this->fireEvent("onIndicatorStateChange", INDICATOR_SCROLLOCK, scrollState);

			lastCapsState = capsState;
			lastNumState = numState;
			lastScrollState = scrollState;

			/* something else might go here */

			/* wait a tiny bit before repeating */
			Sleep(10);


			nowTime = timeGetHighResTime();
		} while (nowTime - startTime < 100);
	}
}
Beispiel #2
0
Uint32		convGetPosition()
{
	Uint32 pos;
	Uint32 deltaTimeMs;	
	Uint32 speed;
	Uint32 offset;
	
	pos = convObject.unNumTotalTriggerSignals * CONV_MILLIMETERS_PER_TRIGGER;
	
	// if standing, the conveyor's position is right before the next
	// trigger point.
	if ( convObject.bStanding )
	{
		pos += CONV_MILLIMETERS_PER_TRIGGER;
		return pos;
	}
	
	
	// determine current delta time since last trigger signal
	// conveyor position is at speed * deltatime + last trigger's
	// position.
	deltaTimeMs = timeToMs( timeGetHighResTime() - convObject.unLastTicks );
	speed = convGetMeasuredSpeed();
	offset = ( speed * deltaTimeMs) >> DRVCONV_FRACTIONAL_BITS;
	
	//dbgLog("pos %d: deltaMs: %d, speed: %d, pos+:%d", pos, deltaTimeMs, speed, offset );
	
	pos += offset;
	
	return pos;	
}
Beispiel #3
0
Uint32		convGetMeasuredSpeed()
{
	Uint32 	unDeltaMs;
	Uint32	unTempDeltaTicks;
	Uint32	unTempDeltaMs;
	Uint32	fpTriggersPerSecond;
	Uint32	fpLastSpeed;
	
		
	// Calculate the last interval in ms.
	unDeltaMs = timeToMs( convObject.unLastDeltaTicks );
	if ( unDeltaMs == 0 )
		return 0;	
	
	// And convert to speed (note: speed is Q.16 format and m/s).
	fpTriggersPerSecond = (1 << DRVCONV_FRACTIONAL_BITS) * 1000  / unDeltaMs;
	fpLastSpeed = fpTriggersPerSecond * convObject.unMillimetersPerTrigger / 1000;	
	
	// If standing, the speed is 0.
	if ( convObject.bStanding )
		return 0;

	// Determine delta time since last trigger.
	unTempDeltaTicks = timeGetHighResTime() - convObject.unLastTicks;
	
	// If delta is too big, the conveyor is declared to be standing and thus its speed
	// is 0 as well.
	if ( timeToMs(unTempDeltaTicks) > convHal.unTimeout )
	{
		//dbgLog("Set to standing because toMs(%ud)=%d > %d", unTempDeltaTicks, timeToMs(unTempDeltaTicks), convHal.unTimeout );
		//dbgLog(" unLastTicks = %ud, curTime= %ud", convObject.unLastTicks, timeGetHighResTime() );
		convObject.bStanding = TRUE;
		return 1;
	}
	
	/*
	// If speed*tempDelta is greater than the distance between two triggers,
	// reduce speed so that speed = distance / curDeltaTime.
	unTempDeltaMs = timeToMs(unTempDeltaTicks);
	
	if ( ( (unTempDeltaMs * fpLastSpeed)>> DRVCONV_FRACTIONAL_BITS ) > CONV_MILLIMETERS_PER_TRIGGER)
	{		
		dbgLog("Time: %ud, deltaMs: %u", timeGetHighResTime(), unTempDeltaMs );
		dbgLog("Reduced speed because %d > %d. From %f to %f",
			(unTempDeltaMs * fpLastSpeed) >> DRVCONV_FRACTIONAL_BITS, 
			CONV_MILLIMETERS_PER_TRIGGER,
			(float)fpLastSpeed / 65536.0,
			(float)(((1<< DRVCONV_FRACTIONAL_BITS ) * CONV_MILLIMETERS_PER_TRIGGER) / unTempDeltaMs) / 65536.0 );
			
		if ( unTempDeltaMs == 0 )
			return 1;
			
		fpLastSpeed = ((1<< DRVCONV_FRACTIONAL_BITS ) * CONV_MILLIMETERS_PER_TRIGGER) / unTempDeltaMs;
	}
	*/	
	
	return fpLastSpeed;
}
Beispiel #4
0
void CClassification::GetStats( ClassificationStats * stats, Bool bReset )
{
#ifndef _WINDOWS // ------- Don't compile on windows -----

	// First, disable all SWI, so that we're not be disturbed here. There shouldn't
	// be any critical task running at the moment, since this function will mainly be
	// called from the control task.
	
//	SWI_disable();
	
	// copy all fields
	if ( stats != NULL )
	{
		stats->unElapsedTime = timeToMs( timeGetHighResTime() - m_sClassificationStats.unElapsedTime );
		stats->unNumProcessed = m_sClassificationStats.unNumProcessed;
		stats->unNumPossible = m_sClassificationStats.unNumPossible;
		stats->fp16ConveyorSpeed = convGetMeasuredSpeed();
		stats->unNumRejectedTotal = m_sClassificationStats.unNumRejectedTotal;
		stats->unNumRejectedSplit = m_sClassificationStats.unNumRejectedSplit;
		stats->unNumRejectedColor = m_sClassificationStats.unNumRejectedColor;
		stats->unNumRejectedGreen = m_sClassificationStats.unNumRejectedGreen;
		stats->unNumRejectedShape = m_sClassificationStats.unNumRejectedShape;
	}
	
	
	if ( bReset )
	{
		m_sClassificationStats.unElapsedTime = timeGetHighResTime();
		m_sClassificationStats.unNumProcessed = 0;
		m_sClassificationStats.unNumPossible = 0;
		m_sClassificationStats.unNumRejectedTotal = 0;
		m_sClassificationStats.unNumRejectedSplit = 0;
		m_sClassificationStats.unNumRejectedColor = 0;
		m_sClassificationStats.unNumRejectedGreen = 0;
		m_sClassificationStats.unNumRejectedShape = 0;
	}

	//	SWI_enable();

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

}
Beispiel #5
0
void 		HWI_ConveyorTrigger_funct( void )
{
	Uint32 unCurrentTicks;
	
	// Note: We do all needed stuff directly in th HWI because:
	//		 - It's not that much (SEM_post is the most expensive operation,
	//		   needing about 182 cycles)
	//		 - Starting an SWI would result in more overhead ( SWI_post is
	//		   almost as expensive as SEM_post, using 118 cycles without
	//		   switching and even more when the switch is performed).
	//		 - The rest is neglectable.
	
	// Increment the stats
	gStats.unConvNumTriggers++;	

	// First, measure the interval...
	unCurrentTicks = timeGetHighResTime();
	convObject.unNumTotalTriggerSignals++;
			
	// If the conveyor was standing before, this is a special case.
	if ( convObject.bStanding == TRUE )
	{
		// We set the delta ticks to a very high value, so that the speed will also
		// be nearly 0.
		convObject.unLastDeltaTicks = 0x3FFFFFFF;
		
		// But, the conveyor is not standing anymore.
		convObject.bStanding = FALSE;
	}
	else
	{
		convObject.unLastDeltaTicks = unCurrentTicks - convObject.unLastTicks;
	}	
	
	convObject.unLastTicks = unCurrentTicks;
	
	// Finally trigger the registered semaphore, if there is one
	*(convObject.bTrigger) = TRUE;
	if ( convObject.semTrigger != NULL )
		SEM_ipost( convObject.semTrigger );
}
Beispiel #6
0
void CClassification::ServiceGenJetCheckCommands( )
{
	
#ifndef _WINDOWS // ------- Don't compile on windows -----

	JetCommand 	cmd;
	Uint32		unTime;
	
	unTime = timeGetHighResTime() + timeFromMs( 50 );
	
	for ( Int i=0; i<MAX_LANES; i++ )
	{
		// clear the command
		for ( Int i=0; i<JetCommand::MAX_JETS; i++)
			cmd.aryJetState[i] = FALSE;
			
		// activate only one jet
		cmd.aryJetState[i] = TRUE;
		cmd.unCmdTime = unTime;
		
		// and add the command
		CJetControl::Instance()->AddCommand( &cmd );
		
		// increase time
		unTime += timeFromMs( 200 );		
	}
	
	// send a clear all command
	for ( Int i=0; i<JetCommand::MAX_JETS; i++)
		cmd.aryJetState[i] = FALSE;
	cmd.unCmdTime = unTime;
	CJetControl::Instance()->AddCommand( &cmd );

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

}
void CVisDemoSorterClassifier::DoProcessing()
{
	Uint32 i;
	
	m_nNumObjectsClassifier_last = 0;
	
	if ( m_pModel == NULL )
		return;

	FastLabelObject *	objLabels = (FastLabelObject*)m_iportLabelData.GetBuffer();
	ColorObject *		objColors = (ColorObject*)m_iportColorData.GetBuffer();

	// Get extents of valid area
	CVisFixpoint fLeft, fRight, fTop, fBottom;
	m_pModel->GetValidArea( fLeft, fRight, fTop, fBottom );
	
				
	for ( i=1; i<objLabels[0].unNumObjects; i++)
	{	
		// Clear the object's flags.
		objLabels[i].unFlags = 0;
		
		// See if the object is valid (i.e. it is in a valid position and has sensibel
		// sizes.
		if ( IsObjectValid( objLabels[i] ) )
		{			
			// The object is valid.
			m_nNumObjectsClassified++;
			m_nNumObjectsClassifier_last++;
			m_nNumFramesWithoutObjects = 0;
			
			// Classify the object.
			Int nClass = ClassifiyColor( objColors[i].Color.unHue, objColors[i].Color.unSat, objColors[i].Color.unLum );
			
			// Increment count for that class.
			if ( nClass != -1 )
				m_aryColorClasses[nClass].nCount++;
				
			// Mark the object as due for ejection if the class is valid and scheduled for ejection.
			if ( (nClass != -1) && ( m_aryColorClasses[nClass].nEject != 0 ) )			
				objLabels[i].unFlags |= FLF_EJECT;
			else
				objLabels[i].unFlags &= ~FLF_EJECT;
				
		} // if object valid

	} // for all objects
	
	// Resolve critical ejections
	//ResolveCriticalEjections( objLabels );
	
	// Generate ejection commands
	for ( i=1; i<objLabels[0].unNumObjects; i++)
	{
		if ( (objLabels[i].unFlags & FLF_EJECT) != 0 )
			EjectObject( objLabels[i] );
	}	
	
#ifndef _WINDOWS
	// See if we've seen no objects for a while and turn of the jets if that's the case
	Uint32 unTime = timeGetHighResTime() + timeFromMs( 10 );
	if ( m_nNumFramesWithoutObjects > 25 )
	{	
		for ( int i=0; i<m_pModel->GetNumJets(); i++ )
			COutputDispatcher::Instance()->Channel( i ).AddCommand( unTime , false );
	}
#endif
}