Esempio n. 1
0
int main(void)
{
    if (pfio_init() < 0)
        exit(-1);

    while (1)
    {
        printf("Input port: 0x%x\n", pfio_read_input());
        sleep(1);
    }

    pfio_deinit();
    return 0;
}
Esempio n. 2
0
File: plotd.c Progetto: am1337/plotd
int main(void)
{
  // init IOs
  signal(SIGINT,sigfunc);
  if (pfio_init() < 0)
    exit(-1);
  
  // init PWM
  if (wiringPiSetup () == -1)
    exit (1);
  pinMode (1, PWM_OUTPUT);
  laserPower = POW_MED;
  
  setZero(JUMP);
  
  printf("plotd: daemon ready\n");
  manualControl();
  
  pfio_write_output(0x00);
  pfio_deinit();
  return 0;
}
void RobotApp(int argc, char *argv[])
{
    pfio_init();

    while (1)
    {
        pfio_digital_write(LIGHT1, RED);
        pfio_digital_write(LIGHT2, RED);
        _delay_ms(SWITCH_TIME);
        pfio_digital_write(LIGHT1, RED);
        pfio_digital_write(LIGHT2, GREEN);
        _delay_ms(CYCLE_TIME);
        pfio_digital_write(LIGHT1, RED);
        pfio_digital_write(LIGHT2, RED);
        _delay_ms(SWITCH_TIME);
        pfio_digital_write(LIGHT1, GREEN);
        pfio_digital_write(LIGHT2, RED);
        _delay_ms(CYCLE_TIME);
    }

    pfio_deinit();
    printf ("Ready.\n");
}
Esempio n. 4
0
void pifaceinitialise()
{
	pfio_init();
	pfd = 1;
}
Esempio n. 5
0
int main(void)
{
    if (pfio_init() < 0) perror("Cannot start PFIO");

    long int code = 0, last = 0;
    int count = 0;
    bool last_d0 = 0, last_d1 = 0;
    
    read_config();
    
    if(signal(SIGHUP, signal_handler) == SIG_ERR) perror("Cannot handle signal SIGHUP.");
    if(signal(SIGUSR1, signal_handler) == SIG_ERR) perror("Cannot handle signal SIGUSR1.");
    if(signal(SIGINT, signal_handler) == SIG_ERR) perror("Cannot handle signal SIGINT.");

		beep(1000);

#if DEBUG
    printf("Ready!\n");
#endif

    while (1)
    {
      int i = pfio_read_input();
			if(i == 0xFF) usleep(1);

			struct timeval tv;
      gettimeofday(&tv, NULL);
      long int now = tv.tv_usec + tv.tv_sec*1000;

      if((now - last > TIMEOUT)||(now<last)) {
#if DEBUG
        printf(" - ");
#endif
        count = 0;
        code = 0;
      }

      bool d0 = (i & MASK_D0)==0;
      bool d1 = (i & MASK_D1)==0;
      bool button = (i & MASK_EXIT)==0;
      bool lockcmd = (i & MASK_LOCK)==0;
      
      if(lockcmd || locked) {
#if DEBUG
	        printf("*** LOCK ***\n");
#endif
      		while(((pfio_read_input() & MASK_LOCK)==0)||locked) {
						pfio_digital_write(PIN_GLED,1);
		        usleep(200000);
						pfio_digital_write(PIN_GLED,0);
		        usleep(200000);
          }
#if DEBUG
	        printf("*** UNLOCK ***\n");
#endif
      }
      
      if(button) {
					#if DEBUG
							printf("Exit button pressed!!!\n");
					#endif
		      open_door_start();
          beep(100);
          while((pfio_read_input() & MASK_EXIT)==0) sleep(1);
					#if DEBUG
							printf("Exit button released!!!\n");
					#endif
          sleep(DOOR_DELAY);
          open_door_stop();
      }
      
			if(d0 && !last_d0) {
#if DEBUG
        printf("0");
#endif
        code = code << 1;
        count++;
      }
			if(d1 && !last_d1) {
#if DEBUG
        printf("1");
#endif
        code = (code << 1) + 1;
        count++;
      }

      if(count==BITSCOUNT) {
#if DEBUG
        printf("[%li]\n",code);
#endif

				struct card * c = cards;
				bool allowed = 0;
				while(c) {
					if(c->code == code) {
						allowed = 1;
						break;
					}
					c = c->next;
				};

        if(allowed) {
            // Accepte
#if DEBUG
          printf("Access authorized!\n");
#endif
          open_door(0);
#if DEBUG
          printf("OK\n");
#endif

        } else {
            // Refuse
#if DEBUG
          printf("Access denied!\n");
#endif
          int n;
          for(n=0; n<3; n++) {
            usleep(200000);
            beep(100);
          }
#if DEBUG
          printf("OK\n");
#endif
        }

        code = 0;
        count = 0;
      }

#if DEBUG
			fflush(stdout);
#endif

			last_d0 = d0;
			last_d1 = d1;
			last = now;
		}

    pfio_deinit();
    return 0;
}