Пример #1
0
/*
Function: bprTbIntInit
Description: install the interrupt handles function, and only support 14 EINT.
*/
int bprTbIntInit(void) 
{
	  int pinInt;
	  wiringPiSetupPhys();
	 
	  for(pinInt=0; pinInt<14; pinInt++)  //enable the pull up
	  {
	  		pullUpDnControl(ARRAY_INT[pinInt], PUD_UP);
	  }
  
	  wiringPiISR (7, INT_EDGE_FALLING, &myInterrupt1) ;
	  wiringPiISR (8, INT_EDGE_FALLING, &myInterrupt2) ;
	  wiringPiISR (10, INT_EDGE_FALLING, &myInterrupt3) ;
	  wiringPiISR (11, INT_EDGE_FALLING, &myInterrupt4) ;
	  wiringPiISR (13, INT_EDGE_FALLING, &myInterrupt5) ;
	  wiringPiISR (15, INT_EDGE_FALLING, &myInterrupt6) ;
	  wiringPiISR (16, INT_EDGE_FALLING, &myInterrupt7) ;
	  wiringPiISR (18, INT_EDGE_FALLING, &myInterrupt8) ;
	  wiringPiISR (19, INT_EDGE_FALLING, &myInterrupt9) ;
	  wiringPiISR (21, INT_EDGE_FALLING, &myInterrupt10) ;
	  wiringPiISR (22, INT_EDGE_FALLING, &myInterrupt11) ;
	  wiringPiISR (23, INT_EDGE_FALLING, &myInterrupt12) ;
	  wiringPiISR (24, INT_EDGE_FALLING, &myInterrupt13) ;
	  wiringPiISR (26, INT_EDGE_FALLING, &myInterrupt14) ;


}
Пример #2
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
    }
}
Пример #3
0
int wiringSetup ()
{
	int i=0;
	const char *pins_numbering = getenv ("PINS_NUMBERING");
	const char *grovepi = getenv ("GROVE_PI");
	int addr_grovepi = -1;
	if (pins_numbering != NULL && strncmp (pins_numbering, "GPIO", 5)==0)
	{
		wiringPiSetupGpio();
	}
	else
	if (pins_numbering != NULL && strncmp (pins_numbering, "PHYSICAL", 9)==0)
	{
		wiringPiSetupPhys();
	}
	else
	{
		wiringPiSetup ();
	}
	if (grovepi) sscanf (grovepi, "%d", &addr_grovepi);
	if (addr_grovepi > -1)
	{
		grovepiSetup (addr_grovepi, 4);
	}
	for (i=0; i<MAX_SPI_BUSES; i++) spi_buses[i]=-1;
	for (i=0; i<MAX_SERIAL_BUSES; i++) serial_buses[i]=NULL;
	i2c_init ();
}
Пример #4
0
/**
 *
 * @param argc
 * @param argv
 * @return
 */
int main(int argc, char** argv) {
    bool foreground = false;
    
    // TODO: Check for foreground flag
    // TODO: Add other flags
    // Check startup flags
    try {
        po::options_description desc("Allowed options");
        desc.add_options()
            ("help,h", "Display this message")
            ("version,v", "Display version information")
            ("foreground,f", "Run in foreground, logging errors to console")
            ;
        
        po::variables_map vm;
        po::store(po::parse_command_line(argc, argv, desc), vm);
        po::notify(vm);

        // Display help message
        if (vm.count("help")) {
            cout << desc << "\n";
            return 0;
        }
        
        // Display version information
        if (vm.count("version")) {
            printf("[%s] - Version %s\n", argv[0], VERSION);
            return 0;
        }
        
        if (vm.count("fg")) {
            foreground = true;
        }

        
    } catch (exception &e) {
        printf("[%s] Exception caught getting options: %s\n", argv[0], e.what());
        return 1;   
    }

    // Fork to background, if we weren't told not to do it
    if (!foreground) {       
        fork();
    }
    
    // Setup logging
    openlog("tievox", LOG_PERROR | LOG_PID | LOG_CONS, LOG_DAEMON);
    
    // Setup wiringPi, using physical pin numbers.
    wiringPiSetupPhys();
    
    // Run daemon
    Daemon *daemon = new Daemon();
    int result = daemon->Run();
    
    // Cleanup after ourselves
    closelog();
    
    return result;
}
Пример #5
0
/* wiringPiSetupPhys
 *
 * Parameters: None
 * Return Type: int
 */
mrb_value
mrb_Pi_wiringPiSetupPhys(mrb_state* mrb, mrb_value self) {
  /* Invocation */
  int result = wiringPiSetupPhys();

  /* Box the return value */
  mrb_value return_value = mrb_fixnum_value(result);

  return return_value;
}
Пример #6
0
int main()
{
	if(wiringPiSetupPhys() == -1)
	{
		fprintf(stdout, "wiring lib init error:%s", strerror(errno));	
		return 1;
	}
	pinMode(pin,OUTPUT);

	for(;;){
		digitalWrite(pin,HIGH);
		delay(1000);
		digitalWrite(pin,LOW);
		delay(1000);
	}
}
Пример #7
0
int main(int argc, char** argv) {
    float humidity;
    float temperature;
    int error;
    int i;
    
    wiringPiSetupPhys ();
    InitDht();
    
    for (i = 0; i < 500; i++){
        if (0 == (error = ReadDht(&humidity, &temperature)))
            printf("Humidity: %.1f     Temperature: %.1f\n", humidity, temperature);
        else
            printf("Error read from DHT11. Error code: %d\n", error);
        delay(300);
    }
    
    return (EXIT_SUCCESS);
}
Пример #8
0
int main()
{
    int ledStatus = LOW;
    unsigned int t = 0;

    wiringPiSetupPhys();
    pinMode(12, OUTPUT);
    pinMode(11, INPUT);
    digitalWrite(12, ledStatus);

    while(1){
        int switchStatus = digitalRead(11);
        if(switchStatus == HIGH){
            unsigned int temp = millis();
            if(temp - t > 300){
                t = temp;
                ledStatus = ledStatus == HIGH ? LOW : HIGH;
                digitalWrite(12, ledStatus);
            }
        }
    }

    return 0;
}
Пример #9
0
int main(void)
{

	/* reset memory */
	reset();
	/* Call the setup function for wiringPi */
	/* We're going to work with the pins directly */

	printf("initializing...\n");
	wiringPiSetupPhys();

	/* Listen, and write  */  
//	pinMode(KEY_LISTEN, INPUT);
//	pinMode(KEY_SPEAK, OUTPUT);

	/* set pullup for input pin */
//	pullUpDnControl(INPUT,PUD_UP);

	printf("Registering interrupts...\n");
	/* Register inturrupt handler */
	int resR = wiringPiISR(KEY_LISTEN, INT_EDGE_RISING, &startPulse);
	///int resF = wiringPiISR(KEY_LISTEN, INT_EDGE_FALLING, &stopPulse);
	/* Enter kernel loop */
	printf("Entering wait mode...\n");
	int timeout = 0;
	while(1) { 
		char c = '?';
		if ( incData ) {
			timeout = millis();	
			int resB = convertPulse(lastPdiff);
			lastPdiff = 0;
			incData = 0;
			// Add the symbol to the queue or process the char
			if ( resB == 3 ) { // error or we're done 
				c = lookupSequence(preProcessSequence());
				if ( c != 0 ) {
				printf("%c\n",c);}
				reset();
			} else {
				coreBuffer[buffIndex] = resB;
				buffIndex++;
			}  		
		} else {
			// check for timeout
			if (millis() > timeout + SILENCE_TIMEOUT) {
				//printf("timing out - printing\n");
				if ( coreBuffer[0] == 0 ) {
					// Buffer is 0, don't do anything
				} else {
					c = lookupSequence(preProcessSequence());
					if ( c != 0) {
						printf("%c\n",c);
					}
					timeout = millis();
					reset();
				}
			} 
			// do nothing
			//sleep(.1);
		}
		
	}
	printf("broke out of loop?!\n");
	return 1;
}
Пример #10
0
/*
 * Class:     com_pi4j_wiringpi_Gpio
 * Method:    wiringPiSetupPhys
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_com_pi4j_wiringpi_Gpio_wiringPiSetupPhys
  (JNIEnv *env, jclass obj)
{
    wiringpi_init_mode = WPI_MODE_PHYS;
    return wiringPiSetupPhys();
}
Пример #11
0
int main (int argc, char *argv [])
{
    int i ;
    int model, rev, mem, maker, overVolted ;

    if (getenv ("WIRINGPI_DEBUG") != NULL)
    {
        printf ("gpio: wiringPi debug mode enabled\n") ;
        wiringPiDebug = TRUE ;
    }

    if (argc == 1)
    {
        fprintf (stderr, "%s\n", usage) ;
        return 1 ;
    }

    // Help

    if (strcasecmp (argv [1], "-h") == 0)
    {
        printf ("%s: %s\n", argv [0], usage) ;
        return 0 ;
    }

    // Sort of a special:

    if (strcmp (argv [1], "-R") == 0)
    {
        printf ("%d\n", piBoardRev ()) ;
        return 0 ;
    }

    // Version & Warranty

    if (strcmp (argv [1], "-V") == 0)
    {
        printf ("%d\n", piBoardRev ()) ;
        return 0 ;
    }

    if (strcmp (argv [1], "-v") == 0)
    {
        printf ("gpio version: %s\n", VERSION) ;
        printf ("Copyright (c) 2012-2014 Gordon Henderson\n") ;
        printf ("This is free software with ABSOLUTELY NO WARRANTY.\n") ;
        printf ("For details type: %s -warranty\n", argv [0]) ;
        printf ("\n") ;
        piBoardId (&model, &rev, &mem, &maker, &overVolted) ;
        if (model == PI_MODEL_UNKNOWN)
        {
            printf ("Your Raspberry Pi has an unknown model type. Please report this to\n") ;
            printf ("    [email protected]\n") ;
            printf ("with a copy of your /proc/cpuinfo if possible\n") ;
        }
        else
        {
            printf ("Banana Pro Details:\n") ;
            printf ("  Type: %s, Revision: %s, Memory: %dMB, Maker: %s %s\n",
                    piModelNames [model], piRevisionNames [rev], mem, piMakerNames [maker], overVolted ? "[OV]" : "") ;
        }
        return 0 ;
    }

    if (strcasecmp (argv [1], "-warranty") == 0)
    {
        printf ("gpio version: %s\n", VERSION) ;
        printf ("Copyright (c) 2012-2014 Gordon Henderson\n") ;
        printf ("\n") ;
        printf ("    This program is free software; you can redistribute it and/or modify\n") ;
        printf ("    it under the terms of the GNU Leser General Public License as published\n") ;
        printf ("    by the Free Software Foundation, either version 3 of the License, or\n") ;
        printf ("    (at your option) any later version.\n") ;
        printf ("\n") ;
        printf ("    This program is distributed in the hope that it will be useful,\n") ;
        printf ("    but WITHOUT ANY WARRANTY; without even the implied warranty of\n") ;
        printf ("    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n") ;
        printf ("    GNU Lesser General Public License for more details.\n") ;
        printf ("\n") ;
        printf ("    You should have received a copy of the GNU Lesser General Public License\n") ;
        printf ("    along with this program. If not, see <http://www.gnu.org/licenses/>.\n") ;
        printf ("\n") ;
        return 0 ;
    }

    if (geteuid () != 0)
    {
        fprintf (stderr, "%s: Must be root to run. Program should be suid root. This is an error.\n", argv [0]) ;
        return 1 ;
    }

    // Initial test for /sys/class/gpio operations:

    /**/ if (strcasecmp (argv [1], "exports"    ) == 0)
    {
        doExports     (argc, argv) ;
        return 0 ;
    }
    else if (strcasecmp (argv [1], "export"     ) == 0)
    {
        doExport      (argc, argv) ;
        return 0 ;
    }
    else if (strcasecmp (argv [1], "edge"       ) == 0)
    {
        doEdge        (argc, argv) ;
        return 0 ;
    }
    else if (strcasecmp (argv [1], "unexport"   ) == 0)
    {
        doUnexport    (argc, argv) ;
        return 0 ;
    }
    else if (strcasecmp (argv [1], "unexportall") == 0)
    {
        doUnexportall (argv [0]) ;
        return 0 ;
    }

    // Check for load command:

    if (strcasecmp (argv [1], "load" ) == 0)
    {
        doLoad     (argc, argv) ;
        return 0 ;
    }


    // Check for -g argument

    if (strcasecmp (argv [1], "-g") == 0)
    {
        wiringPiSetupGpio () ;

        for (i = 2 ; i < argc ; ++i)
            argv [i - 1] = argv [i] ;
        --argc ;
        wpMode = WPI_MODE_GPIO ;
    }

    // Check for -1 argument

    else if (strcasecmp (argv [1], "-1") == 0)
    {
        wiringPiSetupPhys () ;

        for (i = 2 ; i < argc ; ++i)
            argv [i - 1] = argv [i] ;
        --argc ;
        wpMode = WPI_MODE_PHYS ;
    }

    // Default to wiringPi mode

    else
    {
        wiringPiSetup () ;
        wpMode = WPI_MODE_PINS ;
    }

    // Check for -x argument to load in a new extension

    if (strcasecmp (argv [1], "-x") == 0)
    {
        if (argc < 3)
        {
            fprintf (stderr, "%s: -x missing extension specification.\n", argv [0]) ;
            exit (EXIT_FAILURE) ;
        }

        if (!doExtension (argv [0], argv [2]))	// Prints its own error messages
            exit (EXIT_FAILURE) ;

        for (i = 3 ; i < argc ; ++i)
            argv [i - 2] = argv [i] ;
        argc -= 2 ;
    }

    if (argc <= 1)
    {
        fprintf (stderr, "%s: no command given\n", argv [0]) ;
        exit (EXIT_FAILURE) ;
    }

    // Core wiringPi functions

    /**/ if (strcasecmp (argv [1], "mode"   ) == 0) doMode      (argc, argv) ;
    else if (strcasecmp (argv [1], "read"   ) == 0) doRead      (argc, argv) ;
    else if (strcasecmp (argv [1], "write"  ) == 0) doWrite     (argc, argv) ;
    else if (strcasecmp (argv [1], "pwm"    ) == 0) doPwm       (argc, argv) ;
    else if (strcasecmp (argv [1], "awrite" ) == 0) doAwrite    (argc, argv) ;
    else if (strcasecmp (argv [1], "aread"  ) == 0) doAread     (argc, argv) ;

    // GPIO Nicies

    else if (strcasecmp (argv [1], "toggle" ) == 0) doToggle    (argc, argv) ;

    // Pi Specifics

    else if (strcasecmp (argv [1], "pwm-bal"  ) == 0) doPwmMode    (PWM_MODE_BAL) ;
    else if (strcasecmp (argv [1], "pwm-ms"   ) == 0) doPwmMode    (PWM_MODE_MS) ;
    else if (strcasecmp (argv [1], "pwmr"     ) == 0) doPwmRange   (argc, argv) ;
    else if (strcasecmp (argv [1], "pwmc"     ) == 0) doPwmClock   (argc, argv) ;
    else if (strcasecmp (argv [1], "pwmTone"  ) == 0) doPwmTone    (argc, argv) ;
    else if (strcasecmp (argv [1], "usbp"     ) == 0) doUsbP       (argc, argv) ;
    else if (strcasecmp (argv [1], "readall"  ) == 0) doReadall    () ;
    else if (strcasecmp (argv [1], "nreadall" ) == 0) doReadall    () ;
    else if (strcasecmp (argv [1], "pins"     ) == 0) doPins       () ;
    else if (strcasecmp (argv [1], "i2cdetect") == 0) doI2Cdetect  (argc, argv) ;
    else if (strcasecmp (argv [1], "i2cd"     ) == 0) doI2Cdetect  (argc, argv) ;
    else if (strcasecmp (argv [1], "reset"    ) == 0) doReset      (argv [0]) ;
    else if (strcasecmp (argv [1], "wb"       ) == 0) doWriteByte  (argc, argv) ;
    else
    {
        fprintf (stderr, "%s: Unknown command: %s.\n", argv [0], argv [1]) ;
        exit (EXIT_FAILURE) ;
    }
    return 0 ;
}
Пример #12
0
int main (int argc, char *argv [])
{
  int i ;

  if (getenv ("WIRINGPI_DEBUG") != NULL)
  {
    printf ("gpio: wiringPi debug mode enabled\n") ;
    wiringPiDebug = TRUE ;
  }

  if (argc == 1)
  {
    fprintf (stderr, "%s\n", usage) ;
    return 1 ;
  }

// Help

  if (strcasecmp (argv [1], "-h") == 0)
  {
    printf ("%s: %s\n", argv [0], usage) ;
    return 0 ;
  }

// Sort of a special:

  if (strcmp (argv [1], "-R") == 0)
  {
    printf ("%d\n", piBoardRev ()) ;
    return 0 ;
  }

// Version & Warranty

  if (strcmp (argv [1], "-V") == 0)
  {
    printf ("%d\n", piBoardRev ()) ;
    return 0 ;
  }

  if (strcmp (argv [1], "-v") == 0)
  {
    printf ("gpio version: %s\n", VERSION) ;
    printf ("Copyright (c) 2012-2013 Gordon Henderson\n") ;
    printf ("This is free software with ABSOLUTELY NO WARRANTY.\n") ;
    printf ("For details type: %s -warranty\n", argv [0]) ;
    printf ("\n") ;
    printf ("This Raspberry Pi is a revision %d board.\n", piBoardRev ()) ;
    return 0 ;
  }

  if (strcasecmp (argv [1], "-warranty") == 0)
  {
    printf ("gpio version: %s\n", VERSION) ;
    printf ("Copyright (c) 2012-2013 Gordon Henderson\n") ;
    printf ("\n") ;
    printf ("    This program is free software; you can redistribute it and/or modify\n") ;
    printf ("    it under the terms of the GNU Leser General Public License as published\n") ;
    printf ("    by the Free Software Foundation, either version 3 of the License, or\n") ;
    printf ("    (at your option) any later version.\n") ;
    printf ("\n") ;
    printf ("    This program is distributed in the hope that it will be useful,\n") ;
    printf ("    but WITHOUT ANY WARRANTY; without even the implied warranty of\n") ;
    printf ("    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n") ;
    printf ("    GNU Lesser General Public License for more details.\n") ;
    printf ("\n") ;
    printf ("    You should have received a copy of the GNU Lesser General Public License\n") ;
    printf ("    along with this program. If not, see <http://www.gnu.org/licenses/>.\n") ;
    printf ("\n") ;
    return 0 ;
  }

  if (geteuid () != 0)
  {
    fprintf (stderr, "%s: Must be root to run. Program should be suid root. This is an error.\n", argv [0]) ;
    return 1 ;
  }

// Initial test for /sys/class/gpio operations:

  /**/ if (strcasecmp (argv [1], "exports"    ) == 0)	{ doExports     (argc, argv) ;	return 0 ; }
  else if (strcasecmp (argv [1], "export"     ) == 0)	{ doExport      (argc, argv) ;	return 0 ; }
  else if (strcasecmp (argv [1], "edge"       ) == 0)	{ doEdge        (argc, argv) ;	return 0 ; }
  else if (strcasecmp (argv [1], "unexport"   ) == 0)	{ doUnexport    (argc, argv) ;	return 0 ; }
  else if (strcasecmp (argv [1], "unexportall") == 0)	{ doUnexportall (argv [0]) ;	return 0 ; }

// Check for load command:

  if (strcasecmp (argv [1], "load" ) == 0)	{ doLoad     (argc, argv) ; return 0 ; }

// Gertboard commands

  if (strcasecmp (argv [1], "gbr" ) == 0)	{ doGbr (argc, argv) ; return 0 ; }
  if (strcasecmp (argv [1], "gbw" ) == 0)	{ doGbw (argc, argv) ; return 0 ; }

// Check for -g argument

  /**/ if (strcasecmp (argv [1], "-g") == 0)
  {
    wiringPiSetupGpio () ;

    for (i = 2 ; i < argc ; ++i)
      argv [i - 1] = argv [i] ;
    --argc ;
    wpMode = WPI_MODE_GPIO ;
  }

// Check for -1 argument

  else if (strcasecmp (argv [1], "-1") == 0)
  {
    wiringPiSetupPhys () ;

    for (i = 2 ; i < argc ; ++i)
      argv [i - 1] = argv [i] ;
    --argc ;
    wpMode = WPI_MODE_PHYS ;
  }

// Check for -p argument for PiFace

  else if (strcasecmp (argv [1], "-p") == 0)
  {
    piFaceSetup (200) ;

    for (i = 2 ; i < argc ; ++i)
      argv [i - 1] = argv [i] ;
    --argc ;
    wpMode = WPI_MODE_PIFACE ;
  }

// Default to wiringPi mode

  else
  {
    wiringPiSetup () ;
    wpMode = WPI_MODE_PINS ;
  }

// Check for -x argument to load in a new extension

  if (strcasecmp (argv [1], "-x") == 0)
  {
    if (argc < 3)
    {
      fprintf (stderr, "%s: -x missing extension specification.\n", argv [0]) ;
      exit (EXIT_FAILURE) ;
    }

    if (!doExtension (argv [0], argv [2]))	// Prints its own error messages
      exit (EXIT_FAILURE) ;

    for (i = 3 ; i < argc ; ++i)
      argv [i - 2] = argv [i] ;
    argc -= 2 ;
  }

  if (argc <= 1)
  {
    fprintf (stderr, "%s: no command given\n", argv [0]) ;
    exit (EXIT_FAILURE) ;
  }

// Core wiringPi functions

  /**/ if (strcasecmp (argv [1], "mode"   ) == 0) doMode      (argc, argv) ;
  else if (strcasecmp (argv [1], "read"   ) == 0) doRead      (argc, argv) ;
  else if (strcasecmp (argv [1], "write"  ) == 0) doWrite     (argc, argv) ;
  else if (strcasecmp (argv [1], "pwm"    ) == 0) doPwm       (argc, argv) ;
  else if (strcasecmp (argv [1], "awrite" ) == 0) doAwrite    (argc, argv) ;
  else if (strcasecmp (argv [1], "aread"  ) == 0) doAread     (argc, argv) ;

// GPIO Nicies

  else if (strcasecmp (argv [1], "toggle" ) == 0) doToggle    (argc, argv) ;

// Pi Specifics

  else if (strcasecmp (argv [1], "pwm-bal"  ) == 0) doPwmMode   (PWM_MODE_BAL) ;
  else if (strcasecmp (argv [1], "pwm-ms"   ) == 0) doPwmMode   (PWM_MODE_MS) ;
  else if (strcasecmp (argv [1], "pwmr"     ) == 0) doPwmRange  (argc, argv) ;
  else if (strcasecmp (argv [1], "pwmc"     ) == 0) doPwmClock  (argc, argv) ;
  else if (strcasecmp (argv [1], "drive"    ) == 0) doPadDrive  (argc, argv) ;
  else if (strcasecmp (argv [1], "readall"  ) == 0) doReadall   () ;
  else if (strcasecmp (argv [1], "i2cdetect") == 0) doI2Cdetect (argc, argv) ;
  else if (strcasecmp (argv [1], "i2cd"     ) == 0) doI2Cdetect (argc, argv) ;
  else if (strcasecmp (argv [1], "reset"    ) == 0) doReset     (argv [0]) ;
  else if (strcasecmp (argv [1], "wb"       ) == 0) doWriteByte (argc, argv) ;
  else if (strcasecmp (argv [1], "clock"    ) == 0) doClock     (argc, argv) ;
  else if (strcasecmp (argv [1], "wfi"      ) == 0) doWfi       (argc, argv) ;
  else
  {
    fprintf (stderr, "%s: Unknown command: %s.\n", argv [0], argv [1]) ;
    exit (EXIT_FAILURE) ;
  }
  return 0 ;
}
Пример #13
0
int main(int argc, char **argv)
{
        if(argc  != 2)
        {
        	uSage();
		return FAIL;
        }
	
	if (0 == strcasecmp(argv[1], "int"))
	{
		bprTbIntInit();
		while(1);
	}
	else if (0 == strcasecmp(argv[1], "bcm"))
	{
		wiringPiSetupGpio();
		bprTbAllLedBlink(LOW, BCM); //disable all led
		delay(2000); //delay 2s
		bprTbAllLedBlink(HIGH, BCM); //enable all led
		delay(3000);//delay 3s
		bprTbAllLedBlink(LOW, BCM); //disable all led

		
		bprTbEachLedBlink(500, BCM); //led blink one by one
	}
	else if (0 == strcasecmp(argv[1], "wpi"))
	{
		wiringPiSetup();
		bprTbAllLedBlink(LOW, WPI); //disable all led
		delay(2000); //delay 2s
		bprTbAllLedBlink(HIGH, WPI); //enable all led
		delay(3000);//delay 3s
		bprTbAllLedBlink(LOW, WPI); //disable all led
		
		bprTbEachLedBlink(500, WPI); //led blink one by one
	}
	else if (0 == strcasecmp(argv[1], "phy"))
	{
		wiringPiSetupPhys();
		bprTbAllLedBlink(LOW, PHY); //disable all led
		delay(2000); //delay 2s
		bprTbAllLedBlink(HIGH, PHY); //enable all led
		delay(3000);//delay 3s
		bprTbAllLedBlink(LOW, PHY); //disable all led

		
		bprTbEachLedBlink(500, PHY); //led blink one by one
	}
	else if (0 == strcasecmp(argv[1], "sys")) /*can't control the phy pin27 pin28*/
	{
		bprTbExportAllPin();
		wiringPiSetupSys();
		
		bprTbAllLedBlink(LOW, SYS); //disable all led
		delay(2000); //delay 2s
		bprTbAllLedBlink(HIGH, SYS); //enable all led
		delay(3000);//delay 3s
		bprTbAllLedBlink(LOW, SYS); //disable all led

		
		bprTbEachLedBlink(500, SYS); //led blink one by one		
	}
	else
	{
		uSage();
		return FAIL;
	}
}
Пример #14
-1
int main (void)
{
  printf ("Raspberry Pi wiringPi GPIO speed test program\n") ;
  printf ("=============================================\n") ;

// Start the standard way

  printf ("\nNative wiringPi method: (%8d iterations)\n", FAST_COUNT) ;
  wiringPiSetup () ;
  pinMode (7, OUTPUT) ;
  speedTest (7, FAST_COUNT) ;

// GPIO

  printf ("\nNative GPIO method: (%8d iterations)\n", FAST_COUNT) ;
  wiringPiSetupGpio () ;
  pinMode (7, OUTPUT) ;
  speedTest (7, FAST_COUNT) ;

// Phys

  printf ("\nPhysical pin GPIO method: (%8d iterations)\n", FAST_COUNT) ;
  wiringPiSetupPhys () ;
  pinMode (7, OUTPUT) ;
  speedTest (7, FAST_COUNT) ;

// Switch to SYS mode:

  system ("/usr/bin/gpio export 7 out") ;
  printf ("\n/sys/class/gpio method: (%8d iterations)\n", SLOW_COUNT) ;
  wiringPiSetupSys () ;
  speedTest (7, SLOW_COUNT) ;

  return 0 ;
}