Exemplo n.º 1
0
//=============================================================================
//	eWxJoystick::OnEvent
//-----------------------------------------------------------------------------
void eWxJoystick::OnEvent(wxJoystickEvent& event)
{
#if wxUSE_JOYSTICK
	if(event.GetEventType() == wxEVT_JOY_BUTTON_DOWN || event.GetEventType() == wxEVT_JOY_BUTTON_UP)
	{
		ProcessButton(JB_FIRE, event.ButtonIsDown(), 'f');
	}
	else if(event.GetEventType() == wxEVT_JOY_MOVE)
	{
		int range_x = joy->GetXMax() - joy->GetXMin();
		int range_y = joy->GetYMax() - joy->GetYMin();
		ProcessButton(JB_UP,	event.GetPosition().y < joy->GetYMin() + range_y/4, 'u');
		ProcessButton(JB_DOWN,	event.GetPosition().y > joy->GetYMax() - range_y/4, 'd');
		ProcessButton(JB_LEFT,	event.GetPosition().x < joy->GetXMin() + range_x/4, 'l');
		ProcessButton(JB_RIGHT,	event.GetPosition().x > joy->GetXMax() - range_x/4, 'r');
	}
#endif//wxUSE_JOYSTICK
}
Exemplo n.º 2
0
void CheckButtons(void){
  byte now_state[NUMBUTTONS];
  digitalWrite(ALERT_LAMP,(boolean)NowMenu);
  if ((lasttime + DEBOUNCE) > millis()) {
    return; // not enough time has passed to debounce
  }
  // ok we have waited DEBOUNCE milliseconds, lets reset the timer
  lasttime = millis();
  for (byte i=0; i<NUMBUTTONS;i++){
    now_state[i]=digitalRead(buttons[i]);   // read the button
    if (now_state[i] != last_state[i]) {
      if (now_state[i] == LOW) {
        //process button
    	  ProcessButton(i);
      }
    last_state[i] = now_state[i];   // keep a running tally of the buttons
    }
  }
};
Exemplo n.º 3
0
//=============================================================================
int main(int argc, char *argv[])
{
	printf("INFO: Monster Outrage v %d\n", VERSION);

	try
	{
		InitSDL();
		LoadMedia();
		InitGame();

		bool quit = false;
		uint ticks = SDL_GetTicks();

		while(!quit)
		{
			// handle events
			SDL_Event e;
			while(SDL_PollEvent(&e) != 0)
			{
				if(e.type == SDL_QUIT)
					quit = true;
				else if(e.type == SDL_KEYDOWN)
				{
					if(e.key.state == SDL_PRESSED)
						ProcessKey(e.key.keysym.scancode, true);
				}
				else if(e.type == SDL_KEYUP)
				{
					if(e.key.state == SDL_RELEASED)
						ProcessKey(e.key.keysym.scancode, false);
				}
				else if(e.type == SDL_MOUSEMOTION || e.type == SDL_MOUSEBUTTONDOWN || e.type == SDL_MOUSEBUTTONUP)
				{
					SDL_GetMouseState(&cursor_pos.x, &cursor_pos.y);
					if(e.type == SDL_MOUSEBUTTONDOWN)
					{
						if(e.button.state == SDL_PRESSED && e.button.button < MAX_BUTTON)
							ProcessButton(e.button.button, true);
					}
					else if(e.type == SDL_MOUSEBUTTONUP)
					{
						if(e.button.state == SDL_RELEASED && e.button.button < MAX_BUTTON)
							ProcessButton(e.button.button, false);
					}
				}
			}

			// calculate dt
			uint new_ticks = SDL_GetTicks();
			float dt = float(new_ticks - ticks)/1000.f;
			ticks = new_ticks;

			Draw();
			Update(dt);
			UpdateInput();
		}

		CleanGame();
		CleanMedia();
		CleanSDL();
	}
	catch(cstring err)
	{
		printf("%s\nERROR: Read error and press any key to exit.\n", err);
		_getch();
		return 1;
	}

	return 0;
}
Exemplo n.º 4
0
/*-----------------------------------------------------------------------------
*  program start
*/
int main(void) {                      

    int     sioHandle;
    uint8_t i;
    uint8_t u8;

    MCUSR = 0;
    wdt_disable();

    /* get module address from EEPROM */
    sMyAddr = eeprom_read_byte((const uint8_t *)MODUL_ADDRESS);
    for (i = 0; i < NUM_BUTTON_EVENT_ADDRESSES; i++) {
        sMySwitchAddr[i] = eeprom_read_byte((const uint8_t *)(BUTTON_EVENT_ADRESS_BASE + i));
    }
   
    PortInit();
    TimerInit();
    SioInit();
    SioRandSeed(MY_ADDR);
    sioHandle = SioOpen("USART0", eSioBaud9600, eSioDataBits8, eSioParityNo, 
                        eSioStopBits1, eSioModeHalfDuplex);
    SioSetIdleFunc(sioHandle, IdleSio);
    SioSetTransceiverPowerDownFunc(sioHandle, BusTransceiverPowerDown);

    BusTransceiverPowerDown(true);
   
    BusInit(sioHandle);
    spRxBusMsg = BusMsgBufGet();

    /* enable global interrupts */
    ENABLE_INT;  
    i2c_slave(SLAVE_ADRESSE);

    button_register = 0;

    init_BJ(SLAVE_ADRESSE);

    for (i = 0; i < NR_OF_LEDS; i++) {
        u8 = eeprom_read_byte((const uint8_t *)(COLOR_LED_BASE + i));
        set_LED(i, u8);
        sNewLedData[i / 2] |= (u8 & 0x0f) << ((i % 2) ? 4 : 0);
    }

    i2c_slave(SLAVE_ADRESSE);

    SendStartupMsg();
   
    while (1) { 
        Idle();
        if (send_startup == 1) {
            init_BJ(SLAVE_ADRESSE);
            for (i = 0; i < NR_OF_LEDS; i++) {
                set_LED(i, eeprom_read_byte((const uint8_t *)(COLOR_LED_BASE + i)));
            }
        }
        sInputState = button_register; 
        ProcessButton(sInputState);

        ProcessBus();

        for (i = 0; i < BUS_SW16_LED_SIZE_SET_VALUE; i++) {
            if ((sNewLedData[i] & 0x0f) != (sLedData[i] & 0x0f) ) { // linke LED
                set_LED(i * 2, sNewLedData[i] & 0x0f);
                i2c_slave(SLAVE_ADRESSE);
            }
            if ((sNewLedData[i] & 0xf0) != (sLedData[i] & 0xf0) ) { // rechte LED
                set_LED(i * 2 + 1, (sNewLedData[i] & 0xf0) >> 4);
                i2c_slave(SLAVE_ADRESSE);
            }
            sLedData[i] = sNewLedData[i];
        }
    }
Exemplo n.º 5
0
/*-----------------------------------------------------------------------------
*  program start
*/
int main(void) {                      

   int     sioHandle;
   uint8_t inputState;

   MCUSR = 0;
   wdt_disable();

   /* get module address from EEPROM */
   sMyAddr = eeprom_read_byte((const uint8_t *)MODUL_ADDRESS);

   sInputType = eeprom_read_byte((const uint8_t *)INPUT_TYPE);
   if (sInputType > INPUT_TYPE_MOTION_DETECTOR) {
      sInputType = INPUT_TYPE_DUAL_BUTTON;
   }
   PortInit();
   TimerInit();
   SioInit();
   SioRandSeed(sMyAddr);
   sioHandle = SioOpen("USART0", eSioBaud9600, eSioDataBits8, eSioParityNo, 
                       eSioStopBits1, eSioModeHalfDuplex);
   SioSetIdleFunc(sioHandle, IdleSio);
   SioSetTransceiverPowerDownFunc(sioHandle, BusTransceiverPowerDown);

   BusTransceiverPowerDown(true);
   
   BusInit(sioHandle);
   spRxBusMsg = BusMsgBufGet();

   /* enable global interrupts */
   ENABLE_INT;  

   SendStartupMsg();
   
   if ((sInputType == INPUT_TYPE_DUAL_SWITCH) ||
       (sInputType == INPUT_TYPE_MOTION_DETECTOR)) {
      /* wait for controller startup delay for sending first state telegram */
      DELAY_S(STARTUP_DELAY);
   }

   if ((sInputType == INPUT_TYPE_DUAL_SWITCH) ||
       (sInputType == INPUT_TYPE_MOTION_DETECTOR)) {
      inputState = GetInputState();
      sSwitchStateOld = ~inputState;
      ProcessSwitch(inputState);
   }

   while (1) { 
      Idle();
   
      inputState = GetInputState(); 
      if ((sInputType == INPUT_TYPE_DUAL_SWITCH) ||
          (sInputType == INPUT_TYPE_MOTION_DETECTOR)) {
         ProcessSwitch(inputState);
      } else if (sInputType == INPUT_TYPE_DUAL_BUTTON) {
         ProcessButton(inputState);
      }

      ProcessBus();
   }
   return 0;  /* never reached */
}