Exemplo n.º 1
0
bool Monster::CheckIfAlive(const float dt)
{
	if (TimerCheck(lifeTimer, dt, MONSTER_LIFE_TIME))
		return false;
	else
		return true;
} // End of CheckIfAlive function.
Exemplo n.º 2
0
int Ssl_Rxd( char *psRxdData, ulong uiExpLen,  ulong *puiOutLen, ushort UiTimeOutSec)
{
	int iRet;
	
	TimerSet(TIMER_TEMPORARY, (ushort)(UiTimeOutSec*10));
	iRet = 0;

	while (1)
	{
		if( TimerCheck(TIMER_TEMPORARY)==0 )	// 检查定时器
		{
			if( iRet>0 )	// 已经读取到数据
			{
				*puiOutLen = iRet;
				return 0;
			}
			return 0xff;
		}

		iRet = SslRecv( iSSLSocket, psRxdData, uiExpLen );
		if (iRet > 0)
		{
			*puiOutLen = iRet;
			return 0;
		}
	}

}
Exemplo n.º 3
0
Arquivo: main.c Projeto: x-lugoo/pos
// Modified by Kim_LinHB 2014-7-8
int CheckInitTerminal(void)
{
	uchar	szCurTime[16+1], szLastTime[16+1];
	uchar	ucKey;
	uchar	szBuff[50];
	
	if( !(glSysParam.ucTermStatus & INIT_MODE) )
	{
		return 0;
	}
	
	TimerSet(0, 0);
	memset(szCurTime,  0, sizeof(szCurTime));
	memset(szLastTime, 0, sizeof(szLastTime));
	while( glSysParam.ucTermStatus & INIT_MODE )
	{
	    Gui_UpdateKey(XUI_KEYFUNC, _T("FUNC"), NULL, NULL);
	    Gui_SetVirtualButton(1, 0);
		if( TimerCheck(0)==0 )
		{
			TimerSet(0, 10);
			GetEngTime(szCurTime);
			if (strcmp(szCurTime, szLastTime)!=0)
			{
				Gui_ClearScr();
				sprintf(szBuff, "%s\n[%.14s]", _T("PLEASE INIT"), AppInfo.AppName);
				Gui_UpdateTitle(szCurTime, gl_stTitleAttr);
				Gui_DrawText(szBuff, gl_stCenterAttr, 0, 50);
				memcpy(szLastTime, szCurTime, sizeof(szLastTime));
			}
		}

		ucKey = PubWaitKey(10);
		if(
			(ucKey==KEYF1 && ChkTermEx(_TERMINAL_D200_)) || (ucKey==KEYFN && !ChkTermEx(_TERMINAL_D200_))
			)
		{
			InitTransInfo();
			FunctionInit();
			TimerSet(0, 0);
			memset(szLastTime, 0, sizeof(szLastTime));
		}
	}

	return 0;
}
Exemplo n.º 4
0
main()
{
   printf("Testing OS abstraction layer\n");
   printf("============================\n");
   
   // System init
   TEST_OK("os_init", os_init());
   
   AllocatorCheck();
   
   TimerCheck();
   
   ThreadCheck();       
   
   EventCheck();

   EventCheck2();
}
Exemplo n.º 5
0
void Monster::ProcessTurn(const float dt, const D3DXVECTOR2 playerPosition, const X3DAUDIO_LISTENER* playerListener)
{
	// Check if the monster is still alive.
	if (CheckIfAlive(dt))
	{
		UpdateEmitterPosition();
		ApplySoundEffects(playerListener);

		// If time to move
		if (TimerCheck(movementTimer, dt, MOVEMENT_TIME_DELAY))
			ProcessMovement(playerPosition);
	}
	else
	{
		// The monster is dead, set alive value to false and play death sound.
		alive = false;
		deathSound->Play();
	}
} // End of ProcessTurn function.
Exemplo n.º 6
0
//接收数据
int WifiNetTcpRxd( uchar * RxData,ulong ExpLen,ulong * RxLen,ushort ms)
{
	int ret;

#ifdef DEBUG_USE
	return 0;
#endif

/*	ret = Netioctl(wnet_socket_id, CMD_TO_SET, ms*1000);//设置超时
	if(ret < 0)
		return ret;
	*/
	TimerSet(TIMER_TEMPORARY, (ushort)(ms*10));
	ret = 0;
	
	while(1)
	{
		if( TimerCheck(TIMER_TEMPORARY)==0 )	// 检查定时器
		{
			if( ret>0 )	// 已经读取到数据
			{
				break;
			}
			return 0xff;
		}
		
		ret = NetRecv(wnet_socket_id, RxData,  ExpLen, 0);
		if(ret > 0)
		{
			*RxLen = ret;
			return 0;    
		}
	//else
	//{
		/*	DxxScrClrLine(4, 18);
			
			switch (ret)
			{
				case NET_ERR_MEM:
					strcpy(sBuff,("MEM ERROR"));
					break;
				case NET_ERR_BUF:
					strcpy(sBuff,("BUF ERROR"));
					break;
				case NET_ERR_CLSD:
					strcpy(sBuff,("CONNE CLOSED"));
					break;
				case NET_ERR_CONN:
					strcpy(sBuff,("CONNE NOT EST"));
					break;
				case NET_ERR_LINKDOWN:
					strcpy(sBuff,("LINK DOWN"));
					break;
				case NET_ERR_TIMEOUT:
					strcpy(sBuff,("TIMEOUT"));
					break;
				case NET_ERR_VAL:
					strcpy(sBuff,("VARIABLE ERR"));
					break;
				case NET_ERR_ARG:
					strcpy(sBuff,("PARA ERROR"));
					break;

				default:
					sprintf(sBuff,"ret_rcv=%d",ret);
					ret = 0xff;
					break;
			}

			DxxScrClrLine(4,18);
			PubDispString(sBuff,4|DISP_LINE_CENTER);
			PubWaitKey(5);
	*/
		//if(ret == 0) ret = 0xff;
		//return ret;   
	//}
		}
	return 0;
}
Exemplo n.º 7
0
Arquivo: main.c Projeto: sndae/b3r1
/*****************************************************************************
 *	Balance -
 *****************************************************************************/
void balance(void)
{
    unsigned long TimerMsWork;

    long int g_bias = 0;
    double x_offset = 532;		//offset value 2.56V * 1024 / 4.93V = 4254
    double q_m = 0.0;
    double int_angle = 0.0;
    double x = 0.0;
    double tilt = 0.0;

    int pwm;

    InitADC();
    init_pwm();

    // initialize the UART (serial port)
    uartInit();

    // set the baud rate of the UART for our debug/reporting output
    uartSetBaudRate(115200);

    // initialize rprintf system
    rprintfInit(uartSendByte);

    // initialize vt100 library
    vt100Init();

    // clear the terminal screen
    vt100ClearScreen();

    TimerMsWork = TimerMsCur();

    DDRB |= (1 << PB0);	// Make B0 an output for LED


    /* as a 1st step, a reference measurement of the angular rate sensor is
     * done. This value is used as offset compensation */

    for (int i=1 ; i<=200; i++) // determine initial value for bias of gyro
    {
        g_bias = g_bias + GetADC(gyro_sensor);
    }

    g_bias = g_bias / 200;


    while (!(getkey() == 1))
    {
        /* insure loop runs at specified Hz */
        while (!TimerCheck(TimerMsWork, (dt_PARAM * 1000) -1))
            ;
        TimerMsWork = TimerMsCur();

        // toggle pin B0 for oscilloscope timings.
        PORTB = PINB ^ (1 << PB0);

        // get rate gyro reading and convert to deg/sec
//		q_m = (GetADC(gyro_sensor) - g_bias) / -3.072;	// -3.07bits/deg/sec (neg. because forward is CCW)
        q_m = (GetADC(gyro_sensor) - g_bias) * -0.3255;	// each bit = 0.3255 /deg/sec (neg. because forward is CCW)
        state_update(q_m);


        // get Accelerometer reading and convert to units of gravity.
//		x = (GetADC(accel_sensor) - x_offset) / 204.9;	// (205 bits/G)
        x = (GetADC(accel_sensor) - x_offset) * 0.00488;	// each bit = 0.00488/G

        // x is measured in multiples of earth gravitation g
        // therefore x = sin (tilt) or tilt = arcsin(x)
        // for small angles in rad (not deg): arcsin(x)=x
        // Calculation of deg from rad: 1 deg = 180/pi = 57.29577951
        tilt = 57.29577951 * (x);
        kalman_update(tilt);

        int_angle += angle * dt_PARAM;

        rprintf("  x:");
        rprintfFloat(8, x);
        rprintf("  angle:");
        rprintfFloat(8, angle);
        rprintf("  rate:");
        rprintfFloat(8, rate);

        // Balance.  The most important line in the entire program.
        //	balance_torque = Kp * (current_angle - neutral) + Kd * current_rate;
        //	rprintf("bal_torq: ");
        //	rprintfFloat(8, balance_torque);
        //	rprintfCRLF();

        //steer_knob = 0;

        // change from current angle to something proportional to speed
        // should this be the abs val of the cur speed or just curr speed?
        //double steer_cmd = (1.0 / (1.0 + Ksteer2 * fabs(current_angle))) * (Ksteer * steer_knob);
        //double steer_cmd = 0.0;

        // Get current rate of turn
        //double current_turn = left_speed - right_speed; //<-- is this correct
        //double turn_accel = current_turn - prev_turn;
        //prev_turn = current_turn;

        // Closed-loop turn rate PID
        //double steer_cmd = KpTurn * (current_turn - steer_desired)
        //					+ KdTurn * turn_accel;
        //					//+ KiTurn * turn_integrated;

        // Possibly optional
        //turn_integrated += current_turn - steer_cmd;

        //	Differential steering
        //left_motor_torque	= balance_torque + steer_cmd; //+ cur_speed + steer_cmd;
        //right_motor_torque	= balance_torque - steer_cmd; //+ cur_speed - steer_cmd;


        // Limit extents of torque demand
        //left_motor_torque = flim(left_motor_torque, -MAX_TORQUE, MAX_TORQUE);
//		if (left_motor_torque < -MAX_TORQUE) left_motor_torque = -MAX_TORQUE;
//		if (left_motor_torque > MAX_TORQUE)  left_motor_torque =  MAX_TORQUE;

        //right_motor_torque = flim(right_motor_torque, -MAX_TORQUE, MAX_TORQUE);
//		if (right_motor_torque < -MAX_TORQUE) right_motor_torque = -MAX_TORQUE;
//		if (right_motor_torque > MAX_TORQUE)  right_motor_torque =  MAX_TORQUE;

        pwm = (int) ((angle -3.5) * Kp) + (rate * Kd); // + (int_angle * Ki);

        rprintf("  pwm:%d\r\n", pwm);

        // Set PWM values for both motors
        SetLeftMotorPWM(pwm);
        SetRightMotorPWM(pwm);
    }
    SetLeftMotorPWM(0);
    SetRightMotorPWM(0);
}
Exemplo n.º 8
0
Arquivo: main.c Projeto: x-lugoo/pos
// 检查空闲计时,看是否已经流过了指定的分钟数
// check if the timer counted the specific time(uint:minute)
uchar ChkIdleTimer(int iSeconds)
{
	int	iCnt = TIMERCNT_MAX-TimerCheck(TIMER_TEMPORARY);
	PubASSERT(TIMERCNT_MAX > iSeconds*10);	//	ScrPrint(0,7,ASCII,"%d  ", iCnt/10);
	return (iCnt >= iSeconds*10);
}