示例#1
0
IOEventFlags jshPinWatch(Pin pin, bool shouldWatch) {
  if (jshIsPinValid(pin)) {
    IOEventFlags exti = getNewEVEXTI();
    if (shouldWatch) {
      if (exti) {
        gpioEventFlags[pin] = exti;
        jshPinSetState(pin, JSHPINSTATE_GPIO_IN);
#ifdef SYSFS_GPIO_DIR
        gpioShouldWatch[pin] = true;
        gpioLastState[pin] = jshPinGetValue(pin);
#endif
#ifdef USE_WIRINGPI
        wiringPiISR(pin, INT_EDGE_BOTH, irqEXTIs[exti-EV_EXTI0]);
#endif
      } else 
        jsError("You can only have a maximum of 16 watches!");
    }
    if (!shouldWatch || !exti) {
      gpioEventFlags[pin] = 0;
#ifdef SYSFS_GPIO_DIR
      gpioShouldWatch[pin] = false;
#endif
#ifdef USE_WIRINGPI
      wiringPiISR(pin, INT_EDGE_BOTH, irqEXTIDoNothing);
#endif

    }
    return shouldWatch ? exti : EV_NONE;
  } else jsError("Invalid pin!");
  return EV_NONE;
}
struct encoder *setupencoder(int pin_a, int pin_b, int pin_switch = -1)
{
   if (numberofencoders > max_encoders)
   {
      printf("Maximum number of encodered exceded: %i\n", max_encoders);
      return NULL;
   }

   struct encoder *newencoder = encoders + numberofencoders++;
   newencoder->pin_a = pin_a;
   newencoder->pin_b = pin_b;
   newencoder->pin_switch = pin_switch;
   newencoder->value = 0;
   newencoder->lastEncoded = 0;
   newencoder->switchpresscount = 0;
   newencoder->lasttime = 0;

   pinMode(pin_a, INPUT);
   pinMode(pin_b, INPUT);
   pullUpDnControl(pin_a, PUD_UP);
   pullUpDnControl(pin_b, PUD_UP);
   wiringPiISR(pin_a, INT_EDGE_BOTH, updateEncoders);
   wiringPiISR(pin_b, INT_EDGE_BOTH, updateEncoders);
   if (pin_switch != -1)
   {
      pinMode(pin_switch, INPUT);
      pullUpDnControl(pin_switch, PUD_UP);
      wiringPiISR(pin_switch, INT_EDGE_FALLING, updateSwitch);
   }

   return newencoder;
}
示例#3
0
struct zyncoder_st *setup_zyncoder(uint8_t i, uint8_t pin_a, uint8_t pin_b, uint8_t midi_chan, uint8_t midi_ctrl, char *osc_path, unsigned int value, unsigned int max_value, unsigned int step) {
	if (i > MAX_NUM_ZYNCODERS) {
		printf("Zyncoder: Maximum number of zyncoders exceded: %d\n", MAX_NUM_ZYNCODERS);
		return NULL;
	}

	struct zyncoder_st *zyncoder = zyncoders + i;
	if (midi_chan>15) midi_chan=0;
	if (midi_ctrl>127) midi_ctrl=1;
	if (value>max_value) value=max_value;
	zyncoder->midi_chan = midi_chan;
	zyncoder->midi_ctrl = midi_ctrl;

	//printf("OSC PATH: %s\n",osc_path);
	if (osc_path) {
		char *osc_port_str=strtok(osc_path,":");
		zyncoder->osc_port=atoi(osc_port_str);
		if (zyncoder->osc_port>0) {
			zyncoder->osc_lo_addr=lo_address_new(NULL,osc_port_str);
			strcpy(zyncoder->osc_path,strtok(NULL,":"));
		}
		else zyncoder->osc_path[0]=0;
	} else zyncoder->osc_path[0]=0;

	zyncoder->step = step;
	if (step>0) {
		zyncoder->value = value;
		zyncoder->subvalue = 0;
		zyncoder->max_value = max_value;
	} else {
		zyncoder->value = value;
		zyncoder->subvalue = ZYNCODER_TICKS_PER_RETENT*value;
		zyncoder->max_value = ZYNCODER_TICKS_PER_RETENT*max_value;
	}

	if (zyncoder->enabled==0 || zyncoder->pin_a!=pin_a || zyncoder->pin_b!=pin_b) {
		zyncoder->enabled = 1;
		zyncoder->pin_a = pin_a;
		zyncoder->pin_b = pin_b;
		zyncoder->last_encoded = 0;
		zyncoder->tsus = 0;

		if (zyncoder->pin_a!=zyncoder->pin_b) {
			pinMode(pin_a, INPUT);
			pinMode(pin_b, INPUT);
			pullUpDnControl(pin_a, PUD_UP);
			pullUpDnControl(pin_b, PUD_UP);
#ifndef MCP23017_ENCODERS
			wiringPiISR(pin_a,INT_EDGE_BOTH, update_zyncoder_funcs[i]);
			wiringPiISR(pin_b,INT_EDGE_BOTH, update_zyncoder_funcs[i]);
#else
			// this is a bit brute force, but update all the banks
			mcp23017_bank_ISR(0);
			mcp23017_bank_ISR(1);
#endif
		}
	}

	return zyncoder;
}
示例#4
0
cRCreceiver::cRCreceiver()
{
	wiringPiISR(RC_RHS_LEFTRIGHT_PIN, INT_EDGE_BOTH, &startStopR_LRTimer);
	wiringPiISR(RC_RHS_UPDOWN_PIN, 	  INT_EDGE_BOTH, &startStopR_UDTimer);
	wiringPiISR(RC_LHS_LEFTRIGHT_PIN, INT_EDGE_BOTH, &startStopL_LRTimer);
	wiringPiISR(RC_LHS_UPDOWN_PIN, 	  INT_EDGE_BOTH, &startStopL_UDTimer);
}
示例#5
0
文件: gpio.c 项目: SonnyJim/pisound
static int init_gpio (void)
{
    //Init the input and output queues
    queue_init (&gpio_input_q);
    queue_init (&gpio_output_q);
    
    wiringPiSetup ();
    pinMode (WPC_RST, INPUT);
    pinMode (IN_IRQ, INPUT);
    pinMode (WPC_RST, INPUT);

    pinMode (STATUS_LED, OUTPUT);
    pinMode (OUT_CLK, OUTPUT);
    pinMode (IC6_DIR, OUTPUT);
    pinMode (IC3_CE, OUTPUT);
    
    wiringPiISR (IN_IRQ, INT_EDGE_FALLING, &irq_recv);
    wiringPiISR (WPC_RST, INT_EDGE_FALLING, &rst_recv);
 
    
    set_gpio_input ();

    digitalWrite (STATUS_LED, 1);
    return 0;
}
示例#6
0
int main(int argc, char* argv[]) {
    wiringPiSetupGpio(); // Initialize wiringPi -- using Broadcom pin numbers

    pinMode(BCM_FIRST_GATE, INPUT);
    pinMode(LED_FIRST_GATE, OUTPUT);
    pinMode(BCM_SECOND_GATE, INPUT);
    pinMode(LED_SECOND_GATE, OUTPUT);
    pinMode(BCM_ULTRASONIC_ECHO, INPUT);
    pinMode(BCM_ULTRASONIC_TRIGGER, OUTPUT);
    
    if (wiringPiISR(BCM_FIRST_GATE, INT_EDGE_BOTH, &FIRST_GATE_PASS)  < 0) {
        printf("Unable to setup ISR (FIRST_GATE) for GPIO %d (%s)\n\n", BCM_FIRST_GATE, strerror(errno));
        exit(1);
    }
    if (wiringPiISR(BCM_SECOND_GATE, INT_EDGE_BOTH, &SECOND_GATE_PASS)  < 0) {
        printf("Unable to setup ISR (SECOND_GATE) for GPIO %d (%s)\n\n", BCM_SECOND_GATE, strerror(errno));
        exit(1);
    }
    if (wiringPiISR(BCM_ULTRASONIC_ECHO, INT_EDGE_BOTH, &ISR_ECHO)  < 0) {
        printf("Unable to setup ISR (ULTRASONIC) for GPIO %d (%s)\n\n", BCM_ULTRASONIC_ECHO, strerror(errno));
        exit(1);
    }
	
    while (true) {
            usleep(100);
    }
    return 0;
}
示例#7
0
int main(int argc, char **argv)
{
    wiringPiSetupPhys();

    pullUpDnControl(16, 1);
    wiringPiISR (16, INT_EDGE_FALLING, &myInterrupt1) ;

    pullUpDnControl(18, 1);
    wiringPiISR (18, INT_EDGE_FALLING, &myInterrupt2) ;

    pullUpDnControl(8, 1);
    wiringPiISR (8, INT_EDGE_FALLING, &myInterrupt3) ;

    pullUpDnControl(10, 1);
    wiringPiISR (10, INT_EDGE_FALLING, &myInterrupt4) ;

    /*pullUpDnControl(3, 1);
    wiringPiISR (3, INT_EDGE_FALLING, &myInterrupt5) ;

    pullUpDnControl(5, 1);
    wiringPiISR (5, INT_EDGE_FALLING, &myInterrupt6) ;*/


    while(1)
    {
        delay (100) ;		// mS
    }
}
示例#8
0
struct encoder *setupencoder(int pin_a, int pin_b, int pin_btn) {
    if (N_ENCODERS > MAX_ENCODERS) {
        printf("Maximum number of encodered exceded: %i\n", MAX_ENCODERS);
        return NULL;
    }

    struct encoder *newencoder = encoders + N_ENCODERS++;
    newencoder->pin_a = pin_a;
    newencoder->pin_b = pin_b;
    newencoder->pin_btn = pin_btn;
    newencoder->value = 0;
    newencoder->lastEncoded = 0;
    newencoder->button_was_pressed = false;
    newencoder->button_was_released = false;

    pinMode(pin_a, INPUT);
    pinMode(pin_b, INPUT);
    pinMode(pin_btn, INPUT);

    pullUpDnControl(pin_a, PUD_UP);
    pullUpDnControl(pin_b, PUD_UP);
    pullUpDnControl(pin_btn, PUD_UP);

    wiringPiISR(pin_a,INT_EDGE_BOTH, updateEncoders);
    wiringPiISR(pin_b,INT_EDGE_BOTH, updateEncoders);
    wiringPiISR(pin_btn,INT_EDGE_BOTH, updateButton);

    return newencoder;
}
示例#9
0
int wiegandInit(int d0pin, int d1pin) {
    // Setup wiringPi
    wiringPiSetup() ;
    pinMode(d0pin, INPUT);
    pinMode(d1pin, INPUT);

    wiringPiISR(d0pin, INT_EDGE_FALLING, data0Pulse);
    wiringPiISR(d1pin, INT_EDGE_FALLING, data1Pulse);
}
示例#10
0
文件: prox.cpp 项目: bmhuggett/D4
prox::prox(void)
{
    pinMode(PROX_TRIGGER_PIN,OUTPUT);//seting the output pin to the proximity sensor
    if(wiringPiISR(ISR_START_PIN,INT_EDGE_RISING,&proxStartTimer)<0)
    {
        std::cout<<"Stra Time ISR Setup Failed"<<std::endl;
    }
    if(wiringPiISR(ISR_STOP_PIN,INT_EDGE_RISING,&proxStopTimer)<0)
    {
        std::cout<<"STop Time ISR Setup Failed"<<std::endl;
    }
}
示例#11
0
// -------------------------------------------------------------------------
// main
int main(void) {
  // sets up the wiringPi library
  if (wiringPiSetup () < 0) {
      fprintf (stderr, "Unable to setup wiringPi: %s\n", strerror (errno));
      return 1;
  }

  // set Pin 17/0 generate an interrupt on high-to-low transitions
  // and attach myInterrupt() to the interrupt
  if ( wiringPiISR (SIA, INT_EDGE_BOTH, &myInterrupt0) < 0 ) {
      fprintf (stderr, "Unable to setup ISR: %s\n", strerror (errno));
      return 1;
  }
 if ( wiringPiISR (SIB, INT_EDGE_BOTH, &myInterrupt1) < 0 ) {
      fprintf (stderr, "Unable to setup ISR: %s\n", strerror (errno));
      return 1;
  }
  if ( wiringPiISR (SW, INT_EDGE_FALLING, &myInterrupt2) < 0 ) {
      fprintf (stderr, "Unable to setup ISR: %s\n", strerror (errno));
      return 1;
  }
  
 /* 
    pinMode (dot,OUTPUT);

    digitalWrite(dot ,0);
    delay(500);
    digitalWrite(dot ,1);
    delay(500);
    digitalWrite(dot ,0);
*/
  	while (1)
   { 
		if(turn_flag)
		{
			switch(turn_flag)
			{
				case 1:	printf("Turn right!\r\n");break;
				case 2:	printf("Turn left!\r\n");break;
				case 3:	printf("Turn down!\r\n");break;
				default:break;
			}
			delay(500);
			turn_flag=0;
		}
	 }
	
  return 0;
}
示例#12
0
struct zynswitch_st *setup_zynswitch(uint8_t i, uint8_t pin) {
	if (i >= MAX_NUM_ZYNSWITCHES) {
		printf("Zyncoder: Maximum number of zynswitches exceeded: %d\n", MAX_NUM_ZYNSWITCHES);
		return NULL;
	}
	
	struct zynswitch_st *zynswitch = zynswitches + i;
	zynswitch->enabled = 1;
	zynswitch->pin = pin;
	zynswitch->tsus = 0;
	zynswitch->dtus = 0;
	zynswitch->status = 0;

	if (pin>0) {
		pinMode(pin, INPUT);
		pullUpDnControl(pin, PUD_UP);
#ifndef MCP23017_ENCODERS
		if (pin<MCP23008_BASE_PIN) {
			wiringPiISR(pin,INT_EDGE_BOTH, update_zynswitch_funcs[i]);
			update_zynswitch(i);
		}
#else
		// this is a bit brute force, but update all the banks
		mcp23017_bank_ISR(0);
		mcp23017_bank_ISR(1);
#endif
	}

	return zynswitch;
}
示例#13
0
int main()
{

	//init the wiringPi
	wiringPiSetup();

	piHiPri(99);
	
	//set up pin directions
	pinMode(US_TRIGGER_PIN, OUTPUT);
	pinMode(US_ECHO_PIN, INPUT);
	digitalWrite(US_TRIGGER_PIN, 0);
	
	//set up pin pullups
	pullUpDnControl(US_TRIGGER_PIN, PUD_OFF);
	pullUpDnControl(US_ECHO_PIN, PUD_OFF);
	
	printf("\nGPIO config done.\r\n\r\n");
	
	printf("\nULTRASONIC MEASURE.\r\n\r\n");
	
	wiringPiISR (US_ECHO_PIN,INT_EDGE_RISING ,  echoArrived);
	
	doTrigger();
	gettimeofday(&t1, NULL);
	waitEcho();
	gettimeofday(&t2, NULL);
	
	  elapsedTime = (double)(t2.tv_usec - t1.tv_usec);
	 printf("\nULTRASONIC MEASURE DONE.\r\n\r\n");
	printf("\nTIME %f us\r\n", elapsedTime);
	
	return 0;
}
示例#14
0
void doWfi (int argc, char *argv [])
{
  int pin, mode ;

  if (argc != 4)
  {
    fprintf (stderr, "Usage: %s wfi pin mode\n", argv [0]) ;
    exit (1) ;
  }

  pin  = atoi (argv [2]) ;

  /**/ if (strcasecmp (argv [3], "rising")  == 0) mode = INT_EDGE_RISING ;
  else if (strcasecmp (argv [3], "falling") == 0) mode = INT_EDGE_FALLING ;
  else if (strcasecmp (argv [3], "both")    == 0) mode = INT_EDGE_BOTH ;
  else
  {
    fprintf (stderr, "%s: wfi: Invalid mode: %s. Should be rising, falling or both\n", argv [1], argv [3]) ;
    exit (1) ;
  }

  if (wiringPiISR (pin, mode, &wfi) < 0)
  {
    fprintf (stderr, "%s: wfi: Unable to setup ISR: %s\n", argv [1], strerror (errno)) ;
    exit (1) ;
  }

  for (;;)
    delay (9999) ;
}
示例#15
0
int main (void)
{
  int myCounter = 0 ;

  if (wiringPiSetup () < 0)
  {
    fprintf (stderr, "Unable to setup wiringPi: %s\n", strerror (errno)) ;
    return 1 ;
  }

  if (wiringPiISR (BUTTON_PIN, INT_EDGE_FALLING, &myInterrupt) < 0)
  {
    fprintf (stderr, "Unable to setup ISR: %s\n", strerror (errno)) ;
    return 1 ;
  }


  for (;;)
  {
    printf ("Waiting ... ") ; fflush (stdout) ;

    while (myCounter == globalCounter)
      delay (100) ;

    printf (" Done. counter: %5d\n", globalCounter) ;
    myCounter = globalCounter ;
  }

  return 0 ;
}
示例#16
0
文件: wind.c 项目: mgrennan/oswabox
int main(void)
{
    // sets up the wiringPi library
    if (wiringPiSetup () < 0) {
        fprintf (stderr, "Unable to setup wiringPi: %s\n", strerror (errno));
        return 1;
    }

    // set Pin 17/0 generate an interrupt on high-to-low transitions
    // and attach myInterrupt() to the interrupt
    if ( wiringPiISR (WIND_PIN, INT_EDGE_FALLING, &myInterrupt) < 0 ) {
        fprintf (stderr, "Unable to setup ISR: %s\n", strerror (errno));
        return 1;
    }

    // display counter value every second.
    while ( 1 ) {
        /* Wind is 1.492 mph per event */
        printf("     Wind Speed: % 4.2f\n", eventCounter * 1.492 );
        printf(" Wind Direction: % 4.2f\n", get_wind_direction() );
        eventCounter = 0;
        delay( 1000 );                                      // wait 1 second
    }

    return 0;
}
示例#17
0
文件: dice.c 项目: RAS20152015/rpi
int main(void)
{
	int i, num;

	if(wiringPiSetup() == -1){ //when initialize wiring failed,print messageto screen
		printf("setup wiringPi failed !");
		return 1; 
	}

	init();
	
	if(wiringPiISR(TouchPin, INT_EDGE_FALLING, &randomISR)){
		fprintf(stderr, "Unable to setup ISR : %s\n", strerror(errno));	
		return 1;
	}

	srand(time(NULL));
	
	while(1){
		if(flag == 1){
			num = rand() % 7;
			hc595_shift(SegCode[num]);
			delay(2000);
			flag = 0;
		}

		for(i=0;i<6;i++){	
			num = rand() % 7;
			hc595_shift(SegCode[num]);
			delay(60);
		}
	}

	return 0;
}
示例#18
0
int
main (int argc, char** argv)
{

   int status = wiringPiSetupGpio();
   if (status < 0)
   {
      printf ("Fail to setup wiringPi. Are you root?");
      exit(1);
   }

   pinMode (24,INPUT);

   wiringPiISR(24, INT_EDGE_FALLING, irq_handler);

   status = wiringPiSPISetup(0,500000);
   if (status < 0)
   {
      printf("Failed to configure SPI");
      exit (1);
   }   
   
   unsigned char buf [256];
   pause();
   while (1)
   {
      buf[0] = 0x07;
      buf[1] = 0xff;
      wiringPiSPIDataRW(0, buf, 2);
      printf ("Output %d \n",buf[1]);
      delay (1000);
      
   }
}
示例#19
0
int main(int argc, char **argv)
{
  ros::init(argc, argv, "sonar_test");
  ros::NodeHandle n;
  ros::Publisher chatter_pub = n.advertise<sonar::Sonar>("sonar_data_raw", 1000);
  ros::Rate loop_rate(10);
  float distance0 = 0;
  
  wiringPiSetup();
  pinMode(1, OUTPUT);
  digitalWrite(1, LOW);
  wiringPiISR(0,INT_EDGE_BOTH,&Interrupt0);

  while (ros::ok())
  {
    sonar::Sonar msg;
    
    if(sonar0_stop_time > sonar0_start_time)
    {
      sonar0_time = sonar0_stop_time - sonar0_start_time;
    }
    distance0 = sonar0_time/58;
    msg.sonar_1 = distance0;

    ROS_INFO("%f", distance0);
   
    chatter_pub.publish(msg);
  
    ros:: spinOnce();
    loop_rate.sleep();
  }
  return 0;
}
示例#20
0
/**
 * \brief Setup resources for SPI transactions
 *
 * Called Once to setup buffers, locks, and GPIO
 * \returns
 * If Setup has been called recently, 1 is returned as a warning. \n
 * If GPIO can't be loaded, the entire system is stopped with EXIT_FAILURE. \n
 * Otherwise, 0 is returned.
 */
int spiSetup(void) {
	// Setup resources for SPI transactions
	FILE *FPTR;
	FPTR = popen("gpio load spi", "r");
	fclose(FPTR);
	// FIXME: use SLAVE_INT_PIN here
	FPTR = popen("gpio export 2 in", "r");
	fclose(FPTR);
	//syslog(LOG_DEBUG, "Using pin %i", SLAVE_INT_PIN);
	if (wiringPiSetupSys() == -1) {
		syslog(LOG_ERR, "Couldn't setup wiringPi system!");
		exit(EXIT_FAILURE);
	}
	if (wiringPiISR(SLAVE_INT_PIN, INT_EDGE_FALLING, &sgSerialSlaveSending) < 0) {
		syslog(LOG_ERR, "Couldn't setup interrupt on pin!");
		exit(EXIT_FAILURE);
	}
	pthread_mutex_init(&transfer_lock, NULL);
	if (tx_buffer == NULL) {
		tx_buffer = queueInit(100);
	} else {
		syslog(LOG_WARNING, "spiSetup has already been called!");
		return 1;
	}
	return 0;
}
示例#21
0
int main(int argc, char **argv) {
    int gpio = 2;

    if (setuid(0)) {
        perror("setuid");
        return -1;
    }

    if (wiringPiSetup() == -1) {
        fprintf(stderr, "Wiring Pi not installed");
        return -1;
    }

    verbose = 1;

    piHiPri (99);
    pinMode(gpio, INPUT);
    wiringPiISR (gpio, INT_EDGE_BOTH, handle_interrupt);

    while(1) {
        sleep(1);
    }

    return 0;
}
int main (int argc,char* argv[])
{
  if (argc < 3) {
    printf("Usage example: ./%s button_gpio_port led_gpio_port\n", argv[0]);
    return 1;
  }
  int buttonGpioPort = atoi(argv[1]);
  ledGpioPort = atoi(argv[2]);

  wiringPiSetup();

  // register the function to deal with the button events
  wiringPiISR(buttonGpioPort, INT_EDGE_FALLING, &interrupt2DoSth);
  
  // set mode to output, which will be used to turn on/off the LED
  pinMode(ledGpioPort, OUTPUT);

  recordMillisecond = getMillisecond();

  int currentLevel = 0;
  while(true) {
    if (currentLevel != level) {
      printf("Caught an interrupt\n");
      currentLevel = level;
    }
  }

  return 0;
}
示例#23
0
/** ________________________________________________________________________________________________________________________________________________________ 
 * Enable receiving data
 */
void RCSwitch::enableReceive(int interrupt) 
{
	this->nReceiverInterrupt = interrupt;
	RCSwitch::nReceivedValue = 0;
	RCSwitch::nReceivedBitlength = 0;
	wiringPiISR(this->nReceiverInterrupt, INT_EDGE_BOTH, &handleInterrupt);
}
示例#24
0
int main(void)
{
    if(wiringPiSetup() < 0) {
        fprintf(stderr, "Unable to setup wiringPi:%s\n",strerror(errno));
        return 1;
    }

    pinMode(SWPin, INPUT);
    pinMode(RoAPin, INPUT);
    pinMode(RoBPin, INPUT);

    pullUpDnControl(SWPin, PUD_UP);

    if(wiringPiISR(SWPin, INT_EDGE_FALLING, &btnISR) < 0) {
        fprintf(stderr, "Unable to init ISR\n",strerror(errno));
        return 1;
    }

    while(1) {
        rotaryDeal();
        printf("%d\n", globalCounter);
        //printf("%d\n",globalCounter);
    }

    return 0;
}
示例#25
0
void RCSwitch::enableReceive() {
    if (this->nReceiverInterrupt != -1) {
        RCSwitch::nReceivedValue = NULL;
        RCSwitch::nReceivedBitlength = NULL;
        wiringPiISR(this->nReceiverInterrupt, INT_EDGE_BOTH, &handleInterrupt);
    }
}
示例#26
0
void RFM70::Register_IRQ(void (*func)(void))
{
#if 1
	if (wiringPiISR (_irq, INT_EDGE_FALLING, func) < 0) {
		fprintf (stderr, "Unable to setup ISR: %s\n", strerror (errno)) ;
	}
#endif
}
示例#27
0
int main (int argc, char *argv[])
{
  unsigned long myCounter   = 0 ;
  unsigned long lastCounter = 0 ;

//  fprintf (stderr, "argc=%d\n" , argc);
  if (argc != 2)
  {
    fprintf (stderr, "Usage: %s filename\n", argv[0]);
    return 1 ;
  }

  if (wiringPiSetup () < 0)
  {
    fprintf (stderr, "Unable to setup wiringPi: %s\n", strerror (errno)) ;
    return 1 ;
  }
 
  globalCounter = readFile(argv[1]);

  pinMode (OUT_PIN, OUTPUT) ;
  pinMode (IN_PIN,  INPUT) ;
  pullUpDnControl(IN_PIN,  PUD_UP) ;

  if (wiringPiISR (IN_PIN, INT_EDGE_FALLING, &myInterrupt) < 0)
  {
    fprintf (stderr, "Unable to setup ISR: %s\n", strerror (errno)) ;
    return 1 ;
  }

  if (updateFile(argv[1], 0) != 0 )
  {
    return 1 ;
  }

  for (;;)
  {
    printf ("Waiting ... ") ; fflush (stdout) ;

    while (myCounter == globalCounter)
      delay (100) ;

    if ( lastCounter != 0 ) {
        printf (" Done. counter: %lu: %lu\n",
		globalCounter, myCounter - lastCounter) ;
    }
    lastCounter = myCounter ;
    myCounter   = globalCounter ;
    if ( lastCounter != 0 ) {
        updateFile(argv[1], myCounter);
    }
    digitalWrite (OUT_PIN, globalCounter & 0x1 ) ;
  }

  return 0 ;
}
示例#28
0
int main (void)
{
    printf("Raspberry Pi My Stepper motor LED test\n");

    if (wiringPiSetup() == -1)
        return 1;


    if (wiringPiISR (pin1, INT_EDGE_FALLING, &myInterrupt1) < 0)
    {
        fprintf (stderr, "Unable to setup ISR: %s\n", strerror (errno)) ;
        return 1 ;
    }

    if (wiringPiISR (pin2, INT_EDGE_FALLING, &myInterrupt2) < 0)
    {
        fprintf (stderr, "Unable to setup ISR: %s\n", strerror (errno)) ;
        return 1 ;
    }

    if (wiringPiISR (pin3, INT_EDGE_FALLING, &myInterrupt3) < 0)
    {
        fprintf (stderr, "Unable to setup ISR: %s\n", strerror (errno)) ;
        return 1 ;
    }

    if (wiringPiISR (pin4, INT_EDGE_FALLING, &myInterrupt4) < 0)
    {
        fprintf (stderr, "Unable to setup ISR: %s\n", strerror (errno)) ;
        return 1 ;
    }

    pinMode(pin1, OUTPUT);
    pinMode(pin2, OUTPUT);
    pinMode(pin3, OUTPUT);
    pinMode(pin4, OUTPUT);

    Start_Led_Cycle(pin1);

    while(1) {}

    return 0;
}
示例#29
0
int main(void){
  int setup = 0;
  printf("Start!!\n");
  setup = wiringPiSetupSys();
  wiringPiISR( READ_PIN, INT_EDGE_RISING,  signal);
  while(setup != -1){
    sleep(10000);
  }
  return 0;
}
示例#30
-1
int main()
{
	wiringPiSetup();
	pinMode(0,OUTPUT);
	pinMode(2,INPUT);
	pinMode(3,INPUT);
	softPwmCreate(0,0,100);
	wiringPiISR(2,INT_EDGE_BOTH,updateEncoder);
	wiringPiISR(3,INT_EDGE_BOTH,updateEncoder);
	softPwmWrite(0,100);
	delay(2000);
	isr=0;
	pomiar1=millis();
	softPwmWrite(0,100);
	delay(12000);
	pomiar2=millis();
	softPwmWrite(0,0);
	softPwmWrite(0,100);
	delay(3000);
	wynik=pomiar2-pomiar1;
	printf("Pomiar czasu: %i\n",wynik);
	delay(1000);
	predkosc=(isr*0.000119047)*(60000/wynik);
	printf("Predkosc: %f\n",predkosc);
	return;
}