コード例 #1
0
ファイル: irq_test.c プロジェクト: ch2i/RadioHead
int main(int argc, char **argv)
{
  // If you call this, it will not actually access the GPIO
  if (!bcm2835_init())
    return 1;
  
  // Set RPI pin to be an input
  bcm2835_gpio_fsel(RF_IRQ_PIN, BCM2835_GPIO_FSEL_INPT);
  //  with a puldown
  bcm2835_gpio_set_pud(RF_IRQ_PIN, BCM2835_GPIO_PUD_DOWN);
  // And a rising edge detect enable
  bcm2835_gpio_ren(RF_IRQ_PIN);
  
  while (1) {
    // we got it ?
    if (bcm2835_gpio_eds(RF_IRQ_PIN)) {
      // Now clear the eds flag by setting it to 1
      bcm2835_gpio_set_eds(RF_IRQ_PIN);
      printf("Rising event detect for pin GPIO%d\n", RF_IRQ_PIN);
    }
    // wait a bit
    bcm2835_delay(5); 
  }
  
  bcm2835_close();
  return 0;
}
コード例 #2
0
ファイル: event.c プロジェクト: VaduvaAlexandru/daisypi
int main(int argc, char **argv)
{
    // If you call this, it will not actually access the GPIO
    // Use for testing
//    bcm2835_set_debug(1);

    if (!bcm2835_init())
	return 1;

    // Set RPI pin P1-15 to be an input
    bcm2835_gpio_fsel(PIN, BCM2835_GPIO_FSEL_INPT);
    //  with a pullup
    bcm2835_gpio_set_pud(PIN, BCM2835_GPIO_PUD_UP);
    // And a low detect enable
    bcm2835_gpio_len(PIN);

    while (1)
    {
	if (bcm2835_gpio_eds(PIN))
	{
	    // Now clear the eds flag by setting it to 1
	    bcm2835_gpio_set_eds(PIN);
	    printf("low event detect for pin 15\n");
	}

	// wait a bit
	delay(500);
    }

    bcm2835_close();
    return 0;
}
コード例 #3
0
/* Initialize the PIR motion detection sensor on a given GPIO pin, 0 on success */
int pirmtn_init(uint8_t pin)
{
    if (!bcm2835_init()) {
        return 1;
    }

    // Set PIN to be an input
    bcm2835_gpio_fsel(pin, BCM2835_GPIO_FSEL_INPT);

    // with a pulldown
    bcm2835_gpio_set_pud(pin, BCM2835_GPIO_PUD_DOWN);

    // And a rising edge detect enable
    bcm2835_gpio_aren(pin);

    // Wait little while for the init jitter on the GPIO
    delay(500);

    // Now clear the eds flag by setting it to 1
    bcm2835_gpio_set_eds(pin);

    // Set the given pin as our static default one
    pirmtn_pin = pin;

    return 0;
}
コード例 #4
0
ファイル: PyBCM2835.c プロジェクト: klobyone/PyBCM2835
static PyObject *
PyBCM2835_gpio_set_eds(PyObject *self, PyObject *args)
{
	uint8_t pin;

	if (!PyArg_ParseTuple(args,"i",&pin)) {
		return NULL;
	}

	bcm2835_gpio_set_eds(pin);

	Py_RETURN_NONE;
}
コード例 #5
0
// this is a simple test program that prints out what it will do rather than 
// actually doing it
int main(int argc, char **argv)
{
    // Be non-destructive
    bcm2835_set_debug(1);

    if (!bcm2835_init())
	return 1;

    // Configure some GPIO pins fo some testing
    // Set RPI pin P1-11 to be an output
    bcm2835_gpio_fsel(RPI_GPIO_P1_11, BCM2835_GPIO_FSEL_OUTP);
    // Set RPI pin P1-15 to be an input
    bcm2835_gpio_fsel(RPI_GPIO_P1_15, BCM2835_GPIO_FSEL_INPT);
    //  with a pullup
    bcm2835_gpio_set_pud(RPI_GPIO_P1_15, BCM2835_GPIO_PUD_UP);
    // And a low detect enable
    bcm2835_gpio_len(RPI_GPIO_P1_15);
    // and input hysteresis disabled on GPIOs 0 to 27
    bcm2835_gpio_set_pad(BCM2835_PAD_GROUP_GPIO_0_27, BCM2835_PAD_SLEW_RATE_UNLIMITED|BCM2835_PAD_DRIVE_8mA);

#if 1
    // Blink
    while (1)
    {
	// Turn it on
	bcm2835_gpio_write(RPI_GPIO_P1_11, HIGH);
	
	// wait a bit
	bcm2835_delay(500);
	
	// turn it off
	bcm2835_gpio_write(RPI_GPIO_P1_11, LOW);
	
	// wait a bit
	bcm2835_delay(500);
    }
#endif

#if 0
    // Read input
    while (1)
    {
	// Read some data
	uint8_t value = bcm2835_gpio_lev(RPI_GPIO_P1_15);
	printf("read from pin 15: %d\n", value);
	
	// wait a bit
	bcm2835_delay(500);
    }
#endif

#if 0
    // Look for a low event detection
    // eds will be set whenever pin 15 goes low
    while (1)
    {
	if (bcm2835_gpio_eds(RPI_GPIO_P1_15))
	{
	    // Now clear the eds flag by setting it to 1
	    bcm2835_gpio_set_eds(RPI_GPIO_P1_15);
	    printf("low event detect for pin 15\n");
	}

	// wait a bit
	bcm2835_delay(500);
    }
#endif

    if (!bcm2835_close())
	return 1;

    return 0;
}
コード例 #6
0
ファイル: multi_server.cpp プロジェクト: ch2i/RadioHead
/* ======================================================================
Function: main
Purpose : not sure ;)
Input   : command line parameters
Output  : -
Comments: -
====================================================================== */
int main (int argc, const char* argv[] )
{
  // LED blink ms timer saving
  unsigned long led_blink[NB_MODULES] = {0,0,0};
  
  // caught CTRL-C to do clean-up
  signal(SIGINT, sig_handler);
  
  // Display app name
  printf( "%s\n", __BASEFILE__);
  for (uint8_t i=0; i<strlen(__BASEFILE__); i++) {
    printf( "=");
  }
  printf("\n");

  // Init GPIO bcm
  if (!bcm2835_init()) {
    fprintf( stderr, "bcm2835_init() Failed\n\n" );
    return 1;
  }

  //save driver instances pointer
  drivers[IDX_MOD1] = &rf95_1;
  drivers[IDX_MOD2] = &rf95_2;
  drivers[IDX_MOD3] = &rf69_3;

  // light onboard LEDs 
  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, HIGH);

  // configure all modules I/O CS pins to 1 before anything else
  // to avoid any problem with SPI sharing
  for (uint8_t i=0 ; i<NB_MODULES; i++) {
    // CS Ping as output and set to 1
    pinMode(CSN_pins[i], OUTPUT);
    digitalWrite(CSN_pins[i], HIGH);
  }

  // configure all modules I/O pins 
  for (uint8_t i=0 ; i<NB_MODULES; i++) {
    // configure all modules
    if (!initRadioModule(i)){
      force_exit = true;
    }
  }

  // All init went fine, continue specific init if any
  if (!force_exit) {
    // Set all modules in receive mode
    rf95_1.setModeRx();
    rf95_2.setModeRx();
    rf69_3.setModeRx();
    printf( "Listening for incoming packets...\n" );
  }

  // Begin the main loop code 
  // ========================
  while (!force_exit) { 
    // Loop thru modules
    for (uint8_t idx=0 ; idx<NB_MODULES ; idx++) {
      // Rising edge fired ?
      if (bcm2835_gpio_eds(IRQ_pins[idx])) {
        // Now clear the eds flag by setting it to 1
        bcm2835_gpio_set_eds(IRQ_pins[idx]);
        //printf("Packet Received, Rising event detect for pin GPIO%d\n", IRQ_pins[idx]);
  
        // Start associated led blink
        led_blink[idx] = millis();
        digitalWrite(LED_pins[idx], HIGH);
        getReceivedData(idx); 
      } // has IRQ

      // A module led blink timer expired ? Light off
      if (led_blink[idx] && millis()-led_blink[idx]>LED_BLINK_MS) {
        led_blink[idx] = 0;
        digitalWrite(LED_pins[idx], LOW);
      } // Led timer expired

      getReceivedData(idx); 

    } // For Modules
    
    // On board led blink (500ms off / 500ms On)
    digitalWrite(LED_PIN, (millis()%1000)<500?LOW:HIGH);

    // Let OS doing other tasks
    // For timed critical appliation receiver, you can reduce or delete
    // this delay, but this will charge CPU usage, take care and monitor
    bcm2835_delay(5);
  }

  // We're here because we need to exit, do it clean
  // Light off on board LED
  digitalWrite(LED_PIN, LOW);
  // All module LEDs off, all modules CS line High
  for (uint8_t i=0 ; i<NB_MODULES; i++) {
    digitalWrite(LED_pins[i], LOW);
    digitalWrite(CSN_pins[i], HIGH);
  }
  printf( "\n%s, done my job!\n", __BASEFILE__ );
  bcm2835_close();
  return 0;
}
コード例 #7
0
/**
 * @brief Checks fro even on given pin. 
 * @param pin Pin to be configured, Available pin definitons are defined in the Utitlies.h
 * @return none
 */
unsigned char CheckPinforEvent(PIN_t pin)
{
	unsigned char event = bcm2835_gpio_eds(pin);		//Check for event detection
	bcm2835_gpio_set_eds(pin);		//Clear even detection interrupt flags
	return event;
}
コード例 #8
0
/* Reset the PIR motion detection sensor */
void pirmtn_reset()
{
    bcm2835_gpio_set_eds(pirmtn_pin);
}