Esempio n. 1
0
/*
 * Do a special thing (beep, flush, etc)
 */
static errr Term_xtra_emx(int n, int v)
{
	switch (n)
	{
		case TERM_XTRA_SHAPE:
		if (v)
		{
			v_ctype(curs_start, curs_end);
		}
		else
		{
			v_hidecursor();
		}
		return (0);

		case TERM_XTRA_NOISE:
		DosBeep(440, 50);
		return (0);

		case TERM_XTRA_FLUSH:
		while (!CheckEvents(TRUE));
		return 0;

		case TERM_XTRA_EVENT:

		/* Process an event */
		return (CheckEvents(!v));

		/* Success */
		return (0);
	}

	return (1);
}
Esempio n. 2
0
/*
 * Do a special thing (beep, flush, etc)
 */
static errr Term_xtra_emx(int n, int v)
{
	void *instance=((termWindow*)Term)->instance;

	switch (n)
	{
		case TERM_XTRA_SHAPE:
		if (v)
		{
			emx_showcursor(instance);
		}
		else
		{
			emx_hidecursor(instance);
		}
		return (0);

		case TERM_XTRA_NOISE:
		DosBeep(440, 50);
		return (0);

		case TERM_XTRA_FLUSH:
		while (!CheckEvents(TRUE));
		return 0;

		case TERM_XTRA_EVENT:
		return (CheckEvents(!v));

		case TERM_XTRA_DELAY:
		if (v > 0) _sleep2(v);
		return (0);
	}

	return (1);
}
Esempio n. 3
0
/*
 * Low-level graphics routine (assumes valid input)
 * Do a "special thing"
 */
static errr term_xtra_svgalib(int n, int v)
{
	switch (n)
	{
	case TERM_XTRA_EVENT:
		{
			/* Process some pending events */
			if (v) return (CheckEvents (FALSE));
			while (!CheckEvents (TRUE));
			return 0;
		}

	case TERM_XTRA_FLUSH:
		{
			/* Flush all pending events */
			/* Should discard all key presses but unimplemented */
			return 0;
		}

	case TERM_XTRA_CLEAR:
		{
			/* Clear the entire window */
			gl_fillbox (0, 0, 80 * CHAR_W, 25 * CHAR_H, 0);
			return 0;
		}

	case TERM_XTRA_DELAY:
		{
			/* Delay for some milliseconds */
			usleep(1000 * v);
			return 0;
		}
	}
	return 1;
}
Esempio n. 4
0
File: main.c Progetto: DeRampage/Mop
int main(int argc, char**argv)
{
	int errno =  0;
	srand(time(NULL));
	if (errno = PacMan())
	{
		return errno;
	}
	
	/* ToDo: add Timer-Callbacks for Goodies */
	//SDL_TimerID timer = SDL_AddTimer(200, NewGoodie, NULL);
	if(CheckEvents()){
		return 0;
	}
	SDL_TimerID timer = SDL_AddTimer(randomGTime(2000, 7000), NewGoodie, NULL);
	if(timer){
		printf("Timer erfolgreich erstellt!\n");
	}
	thrd_create(NULL, Enemy, NULL);
	
	
	/* Implementation of an enemy *********************************************/
	/* An enemy lives for 25 Steps and walks a bit slower than the player ... */
	/**************************************************************************/
	
	/* ToDo: move enemy into Thread */
	/* Already done */
	
	
	
	/* EventLoop */
	
	return EventLoop();
	
}
Esempio n. 5
0
extern  void    PGBlip(char *name)
/********************************/
{
    int         count;

    CheckEvents();
    if( BlipsOn ) {
        count = 0;
        for( ;; ) {
            if( *name == NULLCHAR ) break;
            if( count >= MAX_FNAME_LEN ) break;
            Blip( count + PGPos, *name );
            ++count;
            ++name;
        }
        while( count < MAX_FNAME_LEN ) {
            Blip( count + PGPos, ' ' );
            ++count;
        }
        count = PGPos;
        while( --count >= BLPos ) {
            Blip( count, ' ' );
        }
        count = 0;
        while( Version[ count ] != NULLCHAR ) {
            Blip( count, Version[ count ] );
            ++count;
        }
    }
}
Esempio n. 6
0
Event* EventQueue::get() {
	CheckEvents();
	Event *e=head;
	head = head? head->next : NULL;
	if (!head)
		tail=NULL;
	return e;
}
Esempio n. 7
0
void    GRBlip( void )
/********************/
{
    CheckEvents();
    if( BlipsOn ) {
        DoBlip( &GRCount, GRPos, 'R' );
    }
}
Esempio n. 8
0
void    LPBlip( void )
/********************/
{
    CheckEvents();
    if( BlipsOn ) {
        DoBlip( &LPCount, LPPos, 'L' );
    }
}
Esempio n. 9
0
void    EXBlip( void )
/********************/
{
    CheckEvents();
    if( BlipsOn ) {
        DoBlip( &EXCount, EXPos, 'E' );
    }
}
Esempio n. 10
0
void    URBlip( void )
/********************/
{
    CheckEvents();
    if( BlipsOn ) {
        DoBlip( &URCount, URPos, 'U' );
    }
}
Esempio n. 11
0
void    SXBlip( void )
/********************/
{
    CheckEvents();
    if( BlipsOn ) {
        DoBlip( &SXCount, SXPos, 'X' );
    }
}
Esempio n. 12
0
void    TGBlip( void )
/********************/
{
    CheckEvents();
    if( BlipsOn ) {
        DoBlip( &TGCount, TGPos, 'T' );
    }
}
Esempio n. 13
0
void    PSBlip( void )
/********************/
{
    CheckEvents();
    if( BlipsOn ) {
        DoBlip( &PSCount, PSPos, 'O' );
    }
}
Esempio n. 14
0
void    SCBlip( void )
/********************/
{
    CheckEvents();
    if( BlipsOn ) {
        DoBlip( &SCCount, SCPos, 'S' );
    }
}
Esempio n. 15
0
void    IMBlip( void )
/********************/
{
    CheckEvents();
    if( BlipsOn ) {
        DoBlip( &IMCount, IMPos, 'M' );
    }
}
Esempio n. 16
0
void    PLBlip( void )
/********************/
{
    CheckEvents();
    if( BlipsOn ) {
        DoBlip( &PLCount, PLPos, 'o' );
    }
}
Esempio n. 17
0
void    DGBlip( void )
/********************/
{
    CheckEvents();
    if( BlipsOn ) {
        DoBlip( &DGCount, DGPos, 'D' );
    }
}
Esempio n. 18
0
File: main.c Progetto: DeRampage/Mop
int EventLoop(void)
{
	while(1)
	{
		if (CheckEvents())
			break;
	}
	return 0;
}
Esempio n. 19
0
bool CBlueZStack::WaitHCICommandStatus()
{
    struct {
        uint8_t event_code, param_length;
        uint8_t status, ncmd;
        uint16_t opcode;
    } __PPACKED__ event;
    while (!CheckEvents()) usleep(10);
    ReadData(&event, sizeof(event));
    return event.event_code == 0x0f && event.status == 0;
}
Esempio n. 20
0
void CAirRide::Init()
{

    Serial.println(F(">AirRide,msg,GMC Air Ride Controller V1.0<"));
    
    pinMode(2, OUTPUT);
    pinMode(12, OUTPUT);
    pinMode(13, OUTPUT);
    CalLED(false); 

    SampleTime = millis();

    SetState(ENTERMANUAL);

    pinMode(PINMODE1, INPUT_PULLUP);
    pinMode(PINMODE2, INPUT_PULLUP);
    pinMode(PINCAL, INPUT_PULLUP);
  
    CornerL.Init(LeftRear); 
    CornerR.Init(RightRear);
    
    EEProm.GetLimits(&LeftLowLimit, &LeftHighLimit, &RightLowLimit, &RightHighLimit);
    
    //debug, force travel height to known value
    //EEProm.SaveLeftTravel(512); 
    //EEProm.SaveRightTravel(512);

    LTravelHeight = EEProm.GetLeftTravel(); //642
    RTravelHeight = EEProm.GetRightTravel(); //698
   
    CornerL.Limits(LeftLowLimit, LeftHighLimit);
    CornerR.Limits(RightLowLimit, RightHighLimit);
    
    Serial.print(F(">AirRide,msg,limts (Lt, Rt, Ll Lh,Rl Rh) "));
    Serial.print(LTravelHeight);
    Serial.print(F(","));
    Serial.print(RTravelHeight);
    Serial.print(F(","));
    Serial.print(LeftLowLimit);
    Serial.print(F(","));
    Serial.print(LeftHighLimit);
    Serial.print(F(","));
    Serial.print(RightLowLimit);
    Serial.print(F(","));
    Serial.print(RightHighLimit);
    Serial.println(F("<"));
    
    CheckEvents();
  
}
Esempio n. 21
0
void main(void) {
  (void)printf("Start of E128 program\r\n");
  InitPorts();
  InitTimer();
  InitMotors();
  InitSide();
  InitBeacons();
  EnableInterrupts;

  StartMasterSM();

  while(1) {		   		     // Repeat State Machine Forever
    (void)RunMasterSM(CheckEvents());
  }
}
Esempio n. 22
0
void EventHandler::EventLoop()
{
	while (!m_quit)
	{
		struct timeval tv;
		if (GetTimeUntilNextEvent(&tv))
		{
			Select(&tv);
			CheckEvents();
		}
		else
		{
			Select();
		}
	}
}
Esempio n. 23
0
static errr Term_xtra_pipe_emx(int n, int v)
{
	termPipe *tp=(termPipe*)Term;

	switch (n)
	{
		case TERM_XTRA_NOISE:
		DosBeep(440, 50);
		return (0);

		case TERM_XTRA_SHAPE:
		return (0);

		case TERM_XTRA_EVENT:
		return (CheckEvents(FALSE));
	}

	return (1);
}
Esempio n. 24
0
void    LNBlip( source_line_number num )
/**************************************/
{
    int         i;
    char        ch;

    CheckEvents();
    if( BlipsOn ) {
        Blip( LNPos+LNSize, ' ' );
        for( i = LNSize; i-- > 0; ) {
            if( num == 0 ) {
                ch = ' ';
            } else {
                ch = num % 10 + '0';
                num /= 10;
            }
            Blip( LNPos + i, ch );
        }
    }
}
Esempio n. 25
0
void    PGBlip( const char *name )
/********************************/
{
    int         count;

    CheckEvents();
    if( BlipsOn ) {
        for( count = 0; *name != NULLCHAR && count < MAX_FNAME_LEN; ++count, ++name) {
            Blip( count + PGPos, *name );
        }
        for( ; count < MAX_FNAME_LEN; ++count ) {
            Blip( count + PGPos, ' ' );
        }
        for( count = PGPos; count-- > BLPos; ) {
            Blip( count, ' ' );
        }
        for( count = 0; Version[count] != NULLCHAR; ++count ) {
            Blip( count, Version[count] );
        }
    }
}
Esempio n. 26
0
void usdxMainLoop()
{
	/* NOTE: These must be floats to use accurate float division instead of inaccurate integer division. */
	const float MillisecondsInSecond = 1000.0f;
	const float MaxFPS = 100.0f;

	bool done = false;
	Uint32 ticksCurrent, ticksBeforeFrame;
	Sint32 delay;
	float mouseX = 0.0f, mouseY = 0.0f;

	// For some reason this seems to be needed with the SDL timer functions.
	CountSkipTime();

	do
	{
		ticksBeforeFrame = SDL_GetTicks();

		// Do we have a joypad?
		// if (Joystick::getSingletonPtr() != NULL)
		//	sJoystick.Update();

		// Check keyboard events
		CheckEvents(mouseX, mouseY);

		// Display
		done = !sDisplay.Draw();
		SwapBuffers();
		
		// FPS limiter
		ticksCurrent = SDL_GetTicks();
		delay = (Sint32)(MillisecondsInSecond / MaxFPS) - (ticksCurrent - ticksBeforeFrame);
		if (delay > 0)
			SDL_Delay(delay); // dynamic, maximum is 100 fps

		CountSkipTime();
	} while (!done);
}
Esempio n. 27
0
/**
 * Main function
 *
 * This function must do a lot of stuff.
 */
int main(int argc, char *argv[])
{
	/* Initialize the machine itself XXX XXX XXX */

	/* Process command line arguments XXX XXX XXX */

	/* Initialize the windows */
	if (init_xxx(argc, argv) != 0) quit("Oops!");

	/* XXX XXX XXX */
	ANGBAND_SYS = "xxx";

	/* Initialize some stuff */
	init_stuff();

	/* Initialize */
	init_angband();

	/* Allow auto-startup XXX XXX XXX */

	/* Event loop forever XXX XXX XXX */
	while (TRUE) CheckEvents(TRUE);
}
Esempio n. 28
0
u32 SPUThread::GetChannelCount(u32 ch)
{
	switch (ch)
	{
	case SPU_WrOutMbox:       return SPU.Out_MBox.GetFreeCount();
	case SPU_WrOutIntrMbox:   return SPU.Out_IntrMBox.GetFreeCount();
	case SPU_RdInMbox:        return SPU.In_MBox.GetCount();
	case MFC_RdTagStat:       return MFC1.TagStatus.GetCount();
	case MFC_RdListStallStat: return StallStat.GetCount();
	case MFC_WrTagUpdate:     return MFC1.TagStatus.GetCount(); // hack
	case SPU_RdSigNotify1:    return SPU.SNR[0].GetCount();
	case SPU_RdSigNotify2:    return SPU.SNR[1].GetCount();
	case MFC_RdAtomicStat:    return MFC1.AtomicStat.GetCount();
	case SPU_RdEventStat:     return CheckEvents() ? 1 : 0;

	default:
	{
		LOG_ERROR(Log::SPU, "%s error: unknown/illegal channel (%d [%s]).",
			__FUNCTION__, ch, spu_ch_name[ch]);
		return 0;
	}
	}
}
Esempio n. 29
0
void SPUThread::ReadChannel(u128& r, u32 ch)
{
	r.clear();
	u32& v = r._u32[3];

	switch (ch)
	{
	case SPU_RdInMbox:
	{
		while (!SPU.In_MBox.Pop(v) && !Emu.IsStopped()) std::this_thread::sleep_for(std::chrono::milliseconds(1));
		break;
	}

	case MFC_RdTagStat:
	{
		while (!MFC1.TagStatus.Pop(v) && !Emu.IsStopped()) std::this_thread::sleep_for(std::chrono::milliseconds(1));
		break;
	}

	case MFC_RdTagMask:
	{
		v = MFC1.QueryMask.GetValue();
		break;
	}

	case SPU_RdSigNotify1:
	{
		while (!SPU.SNR[0].Pop(v) && !Emu.IsStopped()) std::this_thread::sleep_for(std::chrono::milliseconds(1));
		break;
	}

	case SPU_RdSigNotify2:
	{
		while (!SPU.SNR[1].Pop(v) && !Emu.IsStopped()) std::this_thread::sleep_for(std::chrono::milliseconds(1));
		break;
	}

	case MFC_RdAtomicStat:
	{
		while (!MFC1.AtomicStat.Pop(v) && !Emu.IsStopped()) std::this_thread::sleep_for(std::chrono::milliseconds(1));
		break;
	}

	case MFC_RdListStallStat:
	{
		while (!StallStat.Pop(v) && !Emu.IsStopped()) std::this_thread::sleep_for(std::chrono::milliseconds(1));
		break;
	}

	case SPU_RdDec:
	{
		v = m_dec_value - (u32)(get_time() - m_dec_start);
		break;
	}

	case SPU_RdEventMask:
	{
		v = m_event_mask;
		break;
	}

	case SPU_RdEventStat:
	{
		while (!CheckEvents() && !Emu.IsStopped()) std::this_thread::sleep_for(std::chrono::milliseconds(1));
		v = m_events & m_event_mask;
		break;
	}

	case SPU_RdMachStat:
	{
		v = 1; // hack (not isolated, interrupts enabled)
		// TODO: check value
		break;
	}

	default:
	{
		LOG_ERROR(Log::SPU, "%s error: unknown/illegal channel (%d [%s]).", __FUNCTION__, ch, spu_ch_name[ch]);
		break;
	}
	}

	if (Emu.IsStopped()) LOG_WARNING(Log::SPU, "%s(%s) aborted", __FUNCTION__, spu_ch_name[ch]);
}
Esempio n. 30
0
void CAirRide::Run() 
{
    static bool bBlink = false;
    static uint32_t blinktime = millis();
  
    SetPoint = analogRead(PINSETPOINT);
    Tilt = analogRead(PINTILT)-512;
        
    //read the tilt setpoint and adjust heights as needed
    //center of pot means no tilt
    //increasing value (>512) means raise right side, lower left side
    //decreasing value (<512) means raise left side, Lover right side
    
    if(IsTimedOut(250, SampleTime))
    {      
       
        Serial.print(F(">AirRide,SetPoint,"));
        Serial.print(SetPoint);
        Serial.println(F("<"));
        
        Serial.print(F(">AirRide,Tilt,"));
        Serial.print(Tilt);
        Serial.println(F("<"));
               
        SampleTime = millis();
    }

    CheckEvents();
    
    switch(state)
    {
        //Manual leveling
        //need to pass in setpoint as read from set point pot
        case ENTERMANUAL:
            CornerL.SetLongFilter(false);
            CornerR.SetLongFilter(false);
            
            SetState(RUNMANUAL);
            break;
        case RUNMANUAL: 
            CornerL.Run(SetPoint - Tilt);  
            CornerR.Run(SetPoint + Tilt);
            break;
            
        //Run at the calibrated travel height
        //need to pass in travel height as read from EEPROM
        case ENTERTRAVEL:
            CornerL.SetLongFilter(false);
            CornerR.SetLongFilter(false);
            
            //reset the at height flag
            CornerL.AtHeight(false);
            CornerR.AtHeight(false);
            
            SetState(STARTTRAVEL);
            break;
            
        case STARTTRAVEL:
            //Start travel mode in a fast reacting mode
            //until height is reached
            if( CornerL.AtHeight() && CornerR.AtHeight() )
            {
                CornerL.SetLongFilter(true);
                CornerR.SetLongFilter(true);    

                SetState(RUNTRAVEL);
            }
            else
            {
                CornerL.Run(LTravelHeight);  
                CornerR.Run(RTravelHeight);
            }
        case RUNTRAVEL:
            CornerL.Run(LTravelHeight);  
            CornerR.Run(RTravelHeight);  
            break;
            
        //Auto level to the  for camping
        case RUNCAMP:
            //read accel
            CaclulateLevel();
            CornerL.Run(512);  
            CornerR.Run(512);
            break;
            
        //manually level the coach to the horizon
        //then press caibrate to save the acellerometer values
        //to use for autoleveling
        case RUNAUTOCAL:
            CornerL.Run(0);  
            CornerR.Run(0);
            break;
        //raise and lower the coach to find the upper and lower limits of travel 
        //must be in travelmode before pressing cal button
        case CALLIMITS:
          blinktime = millis();
          MoveTimeOut = millis();
          SetState(CALLIMITSRUN);
          break;
        case CALLIMITSRUN:
            CornerL.Run(0);  
            CornerR.Run(0);
          
            //Blink Cal LED fast
            if(IsTimedOut(25, blinktime))
            {
              CalLED(bBlink);
              bBlink = !bBlink;
              blinktime = millis();
            }
            
            if(CornerL.GetHeight() > 200)
            {
                if(CornerL.IsMoving() || CornerR.IsMoving() )
                {
                    MoveTimeOut = millis();
                    
                    SetState(CALLOW);
                }
                else
                {
                    //wait 10 seconds if no movement cancel calibration
                    if(true == IsTimedOut(10000, MoveTimeOut) )
                    {
                        Serial.println(F(">AirRide,msg,Cal failed to Lower<"));
                        MoveTimeOut = millis();
                        
                        SetState(CALDONELED);
                    }
                }
            }
            else //we may be all the way down already
            {
                MoveTimeOut = millis();
                    
                SetState(CALLOW);
            }
            break;
        case CALLOW:
            CornerL.Run(0);  
            CornerR.Run(0);
            
            //blink Cal LEd kinda fast
            if(IsTimedOut(500, blinktime))
            {
              CalLED(bBlink);
              bBlink != bBlink;
              blinktime = millis();
            }
            
            //wait for car to be all the way down
            if(CornerL.IsMoving() || CornerR.IsMoving())
            {
                //keep resetting timeout until both corners stop moving
                MoveTimeOut = millis();
            }
            else
            {
                    //wait 10 seconds to see if we get any more movement
                if(IsTimedOut(10000, MoveTimeOut))
                {
                    Serial.println(F("AirRide,msg,All Down<"));
                    
                    MoveTimeOut = millis();
                    
                    LeftLowLimit = CornerL.GetHeight();
                    RightLowLimit = CornerR.GetHeight();
                    
                    Serial.print(F("AirRide,msg,Left low cal; "));
                    Serial.print(LeftLowLimit);
                    Serial.println(F("<")); 
                    
                    Serial.print(F("AirRide,msg,Right low cal; "));
                    Serial.print(RightLowLimit);
                    Serial.println(F("<"));

                    SetState(CALWAITHIGH);
                }

            }
            break;
        case CALWAITHIGH:
            CornerL.Run(1024);  
            CornerR.Run(1024);
            
            //blink cal led slow
            if(IsTimedOut(1000, blinktime))
            {
              CalLED(bBlink);
              bBlink != bBlink;
              blinktime = millis();
            }
            
            //wait for the car to start rising
            if(CornerL.IsMoving() || CornerR.IsMoving() )   
            {
                MoveTimeOut = millis();
                
                SetState(CALHIGH);
            }
            else
            {
                //wait 10 seconds if no movement cancel calibration
                if(IsTimedOut(20000, MoveTimeOut))
                {
                    Serial.println(F("AirRide,msg,Cal failed to rise<"));
                    MoveTimeOut = millis();
                    
                    SetState(CALDONELED);
                }
            }
            break;
        case CALHIGH:
            CornerL.Run(1024);  
            CornerR.Run(1024);
            
            //Cal LED on
            
            if(CornerL.IsMoving() || CornerR.IsMoving() )
            {
                MoveTimeOut = millis();
            }
            else
            {
                //wait 10 seconds to see if we get any more movement
                if(IsTimedOut(20000, MoveTimeOut) )
                {
                    Serial.println(F("AirRide,msg,All up<"));
     
                    MoveTimeOut = millis();
                    
                    LeftHighLimit = CornerL.GetHeight();
                    RightHighLimit = CornerR.GetHeight();
                    
                    Serial.print(F("AirRide,msg,Left hi cal; "));
                    Serial.print(RightHighLimit);
                    Serial.println(F("<"));
                    
                    Serial.print(F("AirRide,msg,Right hi cal; "));
                    Serial.print(RightLowLimit);
                    Serial.println(F("<"));
                    
                    SetState(CALSAVELIMITS);
                }
            }
            break;
        case CALSAVELIMITS:
            EEProm.SaveLimits(LeftLowLimit, LeftHighLimit, RightLowLimit, RightHighLimit);
           
            CornerL.Limits(LeftLowLimit, LeftHighLimit);
            CornerR.Limits(RightLowLimit, RightHighLimit);
            
            SetState(CALDONELED);
            break;
         //done with cal, show cal LED for 1 sec 
        case CALDONELED:
            CalLED(false);
            SetState(CALDONEOFF);
            MoveTimeOut = millis();
            break;
        case CALDONEOFF:
            if(IsTimedOut(1000, MoveTimeOut))
            {
                CalLED(true);
                SetState(CALDONE);
                MoveTimeOut = millis();
            }
            break;
        case CALDONE:
            if(IsTimedOut(1000, MoveTimeOut))
            {
                CalLED(false);
                SetState(CALCOMPLETE);
            }
            break;
        case CALCOMPLETE:
            break;
            
        case CALTRAVEL:
            //dont adjust height, let the user adjust the height with the remote
            CornerL.DoHeight(CornerL.GetHeight(), 512);
            CornerR.DoHeight(CornerR.GetHeight(), 512);
            break;
        case CALTRAVELDONE:
            //save heights
            //return to where we were
            LTravelHeight = CornerL.GetHeight(); 
            RTravelHeight = CornerR.GetHeight(); 
    
            EEProm.SaveLeftTravel(LTravelHeight); 
            EEProm.SaveRightTravel(RTravelHeight);
                    
            Serial.print(F("AirRide,msg,Left Travel Height; "));
            Serial.print(LTravelHeight);
            Serial.println(F("<"));

            Serial.print(F("AirRide,msg,Right Travel Height; "));
            Serial.print(RTravelHeight);
            Serial.println(F("<"));                    

            break;
        default:
            SetState(RUNMANUAL);
    }
  
}