/** * Main. * * @param int argc * @param char** argv * * @return int */ int main(int argc, char **argv) { bcm2835_set_debug(0); if (!bcm2835_init()) { return 1; } // Set each of the pins as input or output bcm2835_gpio_fsel(NES_LATCH,BCM2835_GPIO_FSEL_OUTP); bcm2835_gpio_fsel(NES_CLOCK,BCM2835_GPIO_FSEL_OUTP); bcm2835_gpio_fsel(NES_DATA,BCM2835_GPIO_FSEL_INPT); // Initialize clock and latch bcm2835_gpio_write(NES_LATCH,LOW); bcm2835_gpio_write(NES_CLOCK,LOW); while(1) { uint8_t pressed = read_buttons(); if ((pressed & BTN_A) == BTN_A) printf("A"); if ((pressed & BTN_B) == BTN_B) printf("B"); if ((pressed & BTN_SELECT) == BTN_SELECT) printf("SELECT"); if ((pressed & BTN_START) == BTN_START) printf("START"); if ((pressed & BTN_UP) == BTN_UP) printf("UP"); if ((pressed & BTN_DOWN) == BTN_DOWN) printf("DOWN"); if ((pressed & BTN_LEFT) == BTN_LEFT) printf("LEFT"); if ((pressed & BTN_RIGHT) == BTN_RIGHT) printf("RIGHT"); if (pressed) { printf("\n"); } // Delay approximately 60Hz delay(((1 / 60) * 1000)); } bcm2835_close(); return 0; }
int main(int argc, char **argv) { PiSwitchConfig config; if(!TryGetPiSwitchConfig(CONFIG_FILE, argc, argv, &config)) { fprintf(stderr, "Configuration error\n"); return -1; } // Open the log file openlog(LOG_IDENTITY, LOG_PID, config.RunAsDaemon ? LOG_DAEMON : LOG_USER); syslog(LOG_INFO, "Listening on gpio: %u, Writing to gpio: %u, Poll frequency: %u", config.GpioIn, config.GpioOut, config.PollFrequency); bcm2835_set_debug((uint8_t) config.DebugEnabled); running = true; TryStartDaemon(&config); SetupSignals(); SetupGpio(config.GpioIn, config.GpioOut); bool powerOff = false; while (running) { if(bcm2835_gpio_lev(config.GpioIn) == HIGH) { // Check it again! bcm2835_delay(500); if(bcm2835_gpio_lev(config.GpioIn) == HIGH) { powerOff = true; break; } } bcm2835_delay(config.PollFrequency); } if(powerOff) { syslog(LOG_INFO, "gpio %u set to HIGH, shutting system down", config.GpioIn); } else { syslog(LOG_INFO, "signal reveived, stopping"); } closelog(); bcm2835_close(); if(powerOff) { system("poweroff"); } TryStopDaemon(&config); return EXIT_SUCCESS; }
static PyObject * PyBCM2835_set_debug(PyObject *self, PyObject *args) { int i; if (!PyArg_ParseTuple(args,"i",&i)) { return NULL; } bcm2835_set_debug(i); Py_RETURN_NONE; }
void main(int argc, char* argv) { /* Pour le debugging 1 == Print sur la console les operations des fonctions 0 == Comportement normal du programme */ bcm2835_set_debug(0); /* Initialisation de la librairie */ if(bcm2835_close()) { /* code d'initialisation bcm */ printf("Version de la librairie : %d", bcm2835_version()); if(bcm2835_spi_begin()) { /* Initialisation de la SPI Voir header pour valeurs */ bcm2835_spi_setClockDivider(CLK_SPEED); bcm2835_spi_setDataMode(PI_MODE); bcm2835_spi_setBitOrder(BIT_ORDER); /* Selecte un CS pour le transfert de donnees */ bcm2835_spi_chipSelect(CS_SLAVE); /* Test de transfert avec retour */ uint8_t ret; ret = bcm2835_spi_transfer(5); printf("Retour de l'Arduino : %d", ret); /* Test de transfert sans retour */ bcm2835_spi_transfern("A", 1); bcm2835_spi_end(); } else { printf("Erreur de l'init de SPI\n"); } bcm2835_close(void); /* Libere la memoire et ferme la librairie */ } else { printf("Echec de l'ouverture de la librairie\n"); } }
// 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; }
//void bcm2835_set_debug(uint8_t d); /// Call bcm2835_set_debug() /// \par Refer /// \par Modify /// \return done:0, time_over:-1 void ope_set_debug(void) { get_byte_code(); bcm2835_set_debug( *((uint8_t *)(buff+1)) ); }