Exemplo n.º 1
0
/* ... the usual ... */
int
main(void)
{
  presses    = 0;
  firstpress = 0;
  lastpress  = 0;
  lockdown   = LOCKED_BY_DEFAULT;
  strobo     = STROBE_BY_DEFAULT;

  /* initialize hardware */
  init();

  utx('I');

  /* main loop */
  while(1) {
    int event = waitevent();

    switch(event) {

    case EVENT_RING:
      utx('R');
      if(!lockdown) {
	/* if this is the first press, remember the time and enable signals */
	if(!presses) {
	  firstpress = gettick();
	}

        /* blink the led */
	ledoff();
	waitticks(BLINKTIME);
        ledon();

	/* if the number of presses reaches the limit, open the door */
	presses++;

        /* record time of last keypress */
        lastpress = gettick();

	/* if pressed often enough */
	if(presses >= PRESSES) {
          strobooff();
	  opendoor();
	  presses    = 0;
	  firstpress = 0;
          lastpress  = 0;
	}
      }
      break;

    case EVENT_TIMEOUT:
      utx('T');

      strobooff();

      /* reset the sequence detector */
      presses    = 0;
      firstpress = 0;
      lastpress  = 0;
      break;

    case EVENT_STROBE:
      if(strobo)
        stroboon();
      break;

    case EVENT_CMD_OPEN:
      opendoor();
      break;

    case EVENT_CMD_LOCK:
      utx('L');
      lockdown = TRUE;
      break;

    case EVENT_CMD_UNLOCK:
      utx('U');
      lockdown = FALSE;
      break;

    case EVENT_CMD_STROBO_ENABLE:
      utx('S');
      strobo = TRUE;
      break;

    case EVENT_CMD_STROBO_DISABLE:
      utx('s');
      strobooff();
      strobo = FALSE;
      break;
    }
  }
}
Exemplo n.º 2
0
/* deal with a new player command in dungeon or city mode*/
void p_process(void)
{
    static int searchval=0;

    if (Player.status[BERSERK])
        if (goberserk()) {
            setgamestatus(SKIP_PLAYER);
            drawvision(Player.x,Player.y);
        }
    if (! gamestatusp(SKIP_PLAYER)) {
        if (searchval > 0) {
            searchval--;
            if (searchval == 0) resetgamestatus(FAST_MOVE);
        }
        drawvision(Player.x,Player.y);
        if (! gamestatusp(FAST_MOVE)) {
            searchval = 0;
            Cmd = mgetc();
            clear_if_necessary();
        }
        Command_Duration = 0;
        switch (Cmd) {
        case ' ':
        case 13:
            setgamestatus(SKIP_MONSTERS);
            break; /*no op on space or return*/
        case 6:
            abortshadowform();
            break; /* ^f */
        case 7:
            wizard();
            break; /* ^g */
        case 4:
            player_dump();
            break; /* ^d */
        case 9:
            display_pack();
            morewait();
            xredraw();
            break; /* ^i */
        case 11:
            if (gamestatusp(CHEATED)) frobgamestatus();
            break;
        case 12:
            xredraw();
            setgamestatus(SKIP_MONSTERS);
            break; /* ^l */
#if !defined(WIN32)
        case 16:
            bufferprint();
            setgamestatus(SKIP_MONSTERS);
            break; /* ^p */
#else
        case 15:
            bufferprint();
            setgamestatus(SKIP_MONSTERS);
            break; /* ^o */
#endif
        case 18:
            redraw();
            setgamestatus(SKIP_MONSTERS);
            break; /* ^r */
        case 23:
            if (gamestatusp(CHEATED)) drawscreen();
            break; /* ^w */
        case 24: /* ^x */
            if (gamestatusp(CHEATED) ||
                    Player.rank[ADEPT])
                wish(1);
            Command_Duration = 5;
            break;
        case 'a':
            zapwand();
            Command_Duration = Player.speed*8/5;
            break;
        case 'c':
            closedoor();
            Command_Duration = Player.speed*2/5;
            break;
        case 'd':
            drop();
            Command_Duration = Player.speed*5/5;
            break;
        case 'e':
            eat();
            Command_Duration = 30;
            break;
        case 'f':
            fire();
            Command_Duration = Player.speed*5/5;
            break;
        case 'g':
            pickup();
            Command_Duration = Player.speed*10/5;
            break;
        case 'i':
            do_inventory_control();
            break;
        case 'm':
            magic();
            Command_Duration = 12;
            break;
        case 'o':
            opendoor();
            Command_Duration = Player.speed*5/5;
            break;
        case 'p':
            pickpocket();
            Command_Duration = Player.speed*20/5;
            break;
        case 'q':
            quaff();
            Command_Duration = 10;
            break;
        case 'r':
            peruse();
            Command_Duration = 20;
            break;
        case 's':
            search(&searchval);
            Command_Duration = 20;
            break;
        case 't':
            talk();
            Command_Duration = 10;
            break;
        case 'v':
            vault();
            Command_Duration = Player.speed*10/5;
            break;
        case 'x':
            examine();
            Command_Duration = 1;
            break;
        case 'z':
            bash_location();
            Command_Duration = Player.speed*10/5;
            break;
        case 'A':
            activate();
            Command_Duration = 10;
            break;
        case 'C':
            callitem();
            break;
        case 'D':
            disarm();
            Command_Duration = 30;
            break;
        case 'E':
            dismount_steed();
            Command_Duration = Player.speed*10/5;
            break;
        case 'F':
            tacoptions();
            break;
        case 'G':
            give();
            Command_Duration = 10;
            break;
        case 'I':
            if (! optionp(TOPINV)) top_inventory_control();
            else {
                display_possessions();
                inventory_control();
            }
            break;
        case 'M':
            city_move();
            Command_Duration = 10;
            break;
        case 'O':
            setoptions();
#if defined(WIN32)
            show_screen();
            xredraw();
#endif
            break;
        case 'P':
            show_license();
            break; /* actually show_license is in file.c */
        case 'Q':
            quit();
            break;
        case 'R':
            rename_player();
            break;
        case 'S':
            save(FALSE);
            break;
        case 'T':
            tunnel();
            Command_Duration =  Player.speed*30/5;
            break;
        case 'V':
            version();
            break;
        case 'Z':
            bash_item();
            Command_Duration = Player.speed*10/5;
            break;
        case '.':
            rest();
            Command_Duration = 10;
            break;
        case ',':
            Command_Duration = 10;
            nap();
            break;
        case '>':
            downstairs();
            break;
        case '<':
            upstairs();
            break;
        case '@':
            p_movefunction(Level->site[Player.x][Player.y].p_locf);
            Command_Duration = 5;
            break;
        case '#':
            if (gamestatusp(CHEATED)) editstats();
            break; /* RAC - char editor */
        case '/':
            charid();
            setgamestatus(SKIP_MONSTERS);
            break;
        case '?':
            help();
            setgamestatus(SKIP_MONSTERS);
            break;
        case '4':
        case 'h':
            moveplayer(-1,0);
            Command_Duration = Player.speed*5/5;
            break;
        case '2':
        case 'j':
            moveplayer(0,1);
            Command_Duration = Player.speed*5/5;
            break;
        case '8':
        case 'k':
            moveplayer(0,-1);
            Command_Duration = Player.speed*5/5;
            break;
        case '6':
        case 'l':
            moveplayer(1,0);
            Command_Duration = Player.speed*5/5;
            break;
        case '1':
        case 'b':
            moveplayer(-1,1);
            Command_Duration = Player.speed*5/5;
            break;
        case '3':
        case 'n':
            moveplayer(1,1);
            Command_Duration = Player.speed*5/5;
            break;
        case '7':
        case 'y':
            moveplayer(-1,-1);
            Command_Duration = Player.speed*5/5;
            break;
        case '9':
        case 'u':
            moveplayer(1,-1);
            Command_Duration = Player.speed*5/5;
            break;
        case '5':
            setgamestatus(SKIP_MONSTERS); /* don't do anything; a dummy turn */
            Cmd = mgetc();
            while ((Cmd != ESCAPE) &&
                    ((Cmd < '1') || (Cmd > '9') || (Cmd=='5'))) {
                print3("Run in keypad direction [ESCAPE to abort]: ");
                Cmd = mgetc();
            }
            if (Cmd != ESCAPE) 
                setgamestatus(FAST_MOVE);
            else
                clearmsg3();
            break;
        case 'H':
            setgamestatus(FAST_MOVE);
            Cmd = 'h';
            moveplayer(-1,0);
            Command_Duration = Player.speed*4/5;
            break;
        case 'J':
            setgamestatus(FAST_MOVE);
            Cmd = 'j';
            moveplayer(0,1);
            Command_Duration = Player.speed*4/5;
            break;
        case 'K':
            setgamestatus(FAST_MOVE);
            Cmd = 'k';
            moveplayer(0,-1);
            Command_Duration = Player.speed*4/5;
            break;
        case 'L':
            setgamestatus(FAST_MOVE);
            Cmd = 'l';
            moveplayer(1,0);
            Command_Duration = Player.speed*4/5;
            break;
        case 'B':
            setgamestatus(FAST_MOVE);
            Cmd = 'b';
            moveplayer(-1,1);
            Command_Duration = Player.speed*4/5;
            break;
        case 'N':
            setgamestatus(FAST_MOVE);
            Cmd = 'n';
            moveplayer(1,1);
            Command_Duration = Player.speed*4/5;
            break;
        case 'Y':
            setgamestatus(FAST_MOVE);
            Cmd = 'y';
            moveplayer(-1,-1);
            Command_Duration = Player.speed*4/5;
            break;
        case 'U':
            setgamestatus(FAST_MOVE);
            Cmd = 'u';
            moveplayer(1,-1);
            Command_Duration = Player.speed*4/5;
            break;
        default:
            commanderror();
            setgamestatus(SKIP_MONSTERS);
            break;
        }
    }
    if (Current_Environment != E_COUNTRYSIDE) roomcheck();
    screencheck(Player.x,Player.y);
}
Exemplo n.º 3
0
int main(void)
{		
//	u8 x=0;
	unsigned char status;
	u8 Data[16];
	u8 i;
	u8 k=0;//读写错误重试次数
	u8 j;
	
  
	USART1_Config();
	//printf("USART1_Config success\n");
	SysTick_Init();
	
	//printf("SysTick_Init success\n");
	SPI_FLASH_Init();
	//printf("SPI_FLASH_Init success\n");
	InitRc522();				
	//printf("InitRc522 success\n");
	TIM3_PWM_Init();
	//printf("TIM3_PWM_Init success\n");
	GPIO_OUT_Init();
	//NVIC_Configuration();
	EXTI_PB1_Config();
	EXTI_PB2_Config();
	BEEP_Init();
	beep_ok();
	
  	while(1) 
{	
		
			status = PcdRequest(PICC_REQIDL,CT);/*扫描卡*/
			status = PcdAnticoll(SN);/*防冲撞*/
			//printf("%d",status);
			if (status==MI_OK)
			{
				k=0;
				sn=((SN[0]<<24)|(SN[1]<<16)|(SN[2]<<8)|(SN[3]));
				//printf("MI_OK\n");
				//printf("%x\n",sn);
				
				if((sn==YANGCHENGUANG)||(sn==LIUZHIYU)||(sn==CHENDUYU)||(sn==WUPENG)||(sn==BLUECARD))
				{
					//printf("OPEN DOOR\n");
					beep_ok();
					opendoor();
				}
				
			}
			else
			{
				k++;
				if((k++)>20)
				{
					SPI_FLASH_Init();
					//printf("SPI_FLASH_Init success\n");
					Reset_RC522();
					//printf("InitRc522 success\n");
					k=0;
				}
			}
			delay_ms(100);
	}
}