コード例 #1
0
ファイル: ladder.c プロジェクト: cschirin/computergraphics
void setup (void)
{
  int i ;

  wiringPiSetupSys () ;

  if (piFaceSetup (200) == -1)
    exit (1) ;

// Enable internal pull-ups

  for (i = 0 ; i < 8 ; ++i)
    pullUpDnControl (PIFACE + i, PUD_UP) ;

// Calculate the actual charging voltage - standard calculation of
//	vCharge = r2 / (r1 + r2) * vBatt
//
//
//   -----+--- vBatt
//        |
//        R1
//        |
//        +---+---- vCharge
//        |   |
//        R2  C
//        |   |
//   -----+---+-----

  vCharge = rDischarge / (rCharge + rDischarge) * vBatt ;

// Start with no charge

  vCap    = vCapLast = 0.0 ;
}
コード例 #2
0
ファイル: blink.c プロジェクト: LeMaker/WiringLMK
int main (int argc, char *argv [])
{
    printf ("Raspberry Pi PiFace Blink\n") ;
    printf ("=========================\n") ;

    // Always initialise wiringPi. Use wiringPiSys() if you don't need
    //	(or want) to run as root

    // wiringPiSetupSys () ;
    wiringPiSetup();

    // Setup the PiFace board

    piFaceSetup (PIFACE) ;

    for (;;)
    {
        digitalWrite (LED, HIGH) ;	// On
        delay (500) ;		// mS
        digitalWrite (LED, LOW) ;	// Off
        delay (500) ;
    }

    return 0 ;
}
コード例 #3
0
ファイル: metro.c プロジェクト: sumotoy/wiringPi
int main (int argc, char *argv [])
{
  int bpm, msPerBeat, state = 0 ;
  unsigned int end ;

  printf ("Raspberry Pi PiFace Metronome\n") ;
  printf ("=============================\n") ;

  piHiPri (50) ;

  wiringPiSetupSys () ;	// Needed for timing functions
  piFaceSetup      (PIFACE) ;

  if (argc != 2)
  {
    printf ("Usage: %s <beates per minute>\n", argv [0]) ;
    exit (1) ;
  }

  if (strcmp (argv [1], "a") == 0)
    middleA () ;

  bpm = atoi (argv [1]) ;

  if ((bpm < 40) || (bpm > 208))
  {
    printf ("%s range is 40 through 208 beats per minute\n", argv [0]) ;
    exit (1) ;
  }

  msPerBeat = 60000 / bpm  ;

// Main loop:
//	Put some random LED pairs up for a few seconds, then blank ...

  for (;;)
  {
    end = millis ()  + msPerBeat ;

    digitalWrite (PIFACE + 0, state)  ;
    digitalWrite (PIFACE + 1, state)  ;

    while (millis () < end)
      delayMicroseconds (500) ;

    state ^= 1 ;
  }

  return 0 ;
}
コード例 #4
0
int main (void)
{
  int pin, button ;

  printf ("Banana Pro wiringPi + LNDigital test program\n") ;
  printf ("===========================================\n") ;
  printf ("\n") ;
  printf (
"This program reads the buttons and uses them to toggle the first 4\n"
"outputs. Push a button once to turn an output on, and push it again to\n"
"turn it off again.\n\n") ;

// Always initialise wiringPi. Use wiringPiSys() if you don't need
//	(or want) to run as root

  wiringPiSetupSys () ;

  piFaceSetup (LN_DIGITAL_BASE) ;

// Enable internal pull-ups & start with all off

  for (pin = 0 ; pin < 8 ; ++pin)
  {
    pullUpDnControl (LN_DIGITAL_BASE + pin, PUD_UP) ;
    digitalWrite    (LN_DIGITAL_BASE + pin, 0) ;
  }

// Loop, scanning the buttons

  for (;;)
  {
    for (button = 0 ; button < 4 ; ++button)
      scanButton (button) ;
    delay (5) ;
  }

  return 0 ;
}
コード例 #5
0
ファイル: piface.c プロジェクト: Dzenik/WiringCB-python
int main (void)
{
  int pin, button ;

  printf ("Raspberry Pi wiringPiFace test program\n") ;
  printf ("======================================\n") ;

  if (piFaceSetup (200) == -1)
    exit (1) ;

// Enable internal pull-ups

  for (pin = PIFACE_BASE ; pin < (PIFACE_BASE + 8) ; ++pin)
    pullUpDnControl (pin, PUD_UP) ;

  for (;;)
  {
    for (button = 0 ; button < 4 ; ++button)
      scanButton (button) ;
    delay (1) ;
  }

  return 0 ;
}
コード例 #6
0
ファイル: fppd.c プロジェクト: bagumondigi/fpp
void MainLoop(void)
{
	int            commandSock = 0;
	int            controlSock = 0;
	int            bridgeSock = 0;
	int            prevFPPstatus = FPPstatus;
	int            sleepms = 50000;
	fd_set         active_fd_set;
	fd_set         read_fd_set;
	struct timeval timeout;
	int            selectResult;

	LogDebug(VB_GENERAL, "MainLoop()\n");

	FD_ZERO (&active_fd_set);

	CheckExistanceOfDirectoriesAndFiles();

	piFaceSetup(200); // PiFace inputs 1-8 == wiringPi 200-207

	if (getFPPmode() == BRIDGE_MODE)
	{
		bridgeSock = Bridge_Initialize();
		if (bridgeSock)
			FD_SET (bridgeSock, &active_fd_set);
	}
	else
	{
		InitMediaOutput();
	}

	pluginCallbackManager.init();

	InitializeChannelOutputs();
	sequence->SendBlankingData();

	InitEffects();
	InitializeChannelDataMemoryMap();

	commandSock = Command_Initialize();
	if (commandSock)
		FD_SET (commandSock, &active_fd_set);

#ifdef USEHTTPAPI
	APIServer apiServer;
	apiServer.Init();
#endif

	controlSock = InitControlSocket();
	FD_SET (controlSock, &active_fd_set);

	SetupGPIOInput();

	if (getFPPmode() & PLAYER_MODE)
	{
		if (getFPPmode() == MASTER_MODE)
			InitSyncMaster();

		scheduler->CheckIfShouldBePlayingNow();

		if (getAlwaysTransmit())
			StartChannelOutputThread();
	}

	LogInfo(VB_GENERAL, "Starting main processing loop\n");

	while (runMainFPPDLoop)
	{
		timeout.tv_sec  = 0;
		timeout.tv_usec = sleepms;

		read_fd_set = active_fd_set;


		selectResult = select(FD_SETSIZE, &read_fd_set, NULL, NULL, &timeout);
		if (selectResult < 0)
		{
			if (errno == EINTR)
			{
				// We get interrupted when media players finish
				continue;
			}
			else
			{
				LogErr(VB_GENERAL, "Main select() failed: %s\n",
					strerror(errno));
				runMainFPPDLoop = 0;
				continue;
			}
		}

		if (commandSock && FD_ISSET(commandSock, &read_fd_set))
			CommandProc();

		if (bridgeSock && FD_ISSET(bridgeSock, &read_fd_set))
			Bridge_ReceiveData();

		if (controlSock && FD_ISSET(controlSock, &read_fd_set))
			ProcessControlPacket();

		// Check to see if we need to start up the output thread.
		// FIXME, possibly trigger this via a fpp command to fppd
		if ((!ChannelOutputThreadIsRunning()) &&
			(getFPPmode() != BRIDGE_MODE) &&
			((UsingMemoryMapInput()) ||
			 (channelTester->Testing()) ||
			 (getAlwaysTransmit()))) {
			int E131BridgingInterval = getSettingInt("E131BridgingInterval");
			if (!E131BridgingInterval)
				E131BridgingInterval = 50;
			SetChannelOutputRefreshRate(1000 / E131BridgingInterval);
			StartChannelOutputThread();
		}

		if (getFPPmode() & PLAYER_MODE)
		{
			if ((FPPstatus == FPP_STATUS_PLAYLIST_PLAYING) ||
				(FPPstatus == FPP_STATUS_STOPPING_GRACEFULLY))
			{
				if (prevFPPstatus == FPP_STATUS_IDLE)
				{
					playlist->PlayListPlayingInit();
					sleepms = 10000;
				}

				// Check again here in case PlayListPlayingInit
				// didn't find anything and put us back to IDLE
				if ((FPPstatus == FPP_STATUS_PLAYLIST_PLAYING) ||
					(FPPstatus == FPP_STATUS_STOPPING_GRACEFULLY))
				{
					playlist->PlayListPlayingProcess();
				}
			}

			int reactivated = 0;
			if (FPPstatus == FPP_STATUS_IDLE)
			{
				if ((prevFPPstatus == FPP_STATUS_PLAYLIST_PLAYING) ||
					(prevFPPstatus == FPP_STATUS_STOPPING_GRACEFULLY))
				{
					playlist->PlayListPlayingCleanup();

					if (FPPstatus != FPP_STATUS_IDLE)
						reactivated = 1;
					else
						sleepms = 50000;
				}
			}

			if (reactivated)
				prevFPPstatus = FPP_STATUS_IDLE;
			else
				prevFPPstatus = FPPstatus;

			scheduler->ScheduleProc();
		}
		else if (getFPPmode() == REMOTE_MODE)
		{
			if(mediaOutputStatus.status == MEDIAOUTPUTSTATUS_PLAYING)
			{
				playlist->PlaylistProcessMediaData();
			}
		}

		CheckGPIOInputs();
	}

	StopChannelOutputThread();
	ShutdownControlSocket();

	if (getFPPmode() == BRIDGE_MODE)
		Bridge_Shutdown();

	LogInfo(VB_GENERAL, "Main Loop complete, shutting down.\n");
}
コード例 #7
0
ファイル: gpio.cpp プロジェクト: ASA1976/wiringPi-cpp
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-2015 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 ("Raspberry Pi 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-2015 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 ; }
  if (strcasecmp (argv [1], "unload" ) == 0)	{ doUnLoad (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 (!loadWPiExtension (argv [0], argv [2], TRUE))	// 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], "drive"    ) == 0) doPadDrive   (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 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 ;
}
コード例 #8
0
ファイル: reaction.c プロジェクト: 0x1abin/LinuxLearn
int main (void)
{
  int i, j ;
  int led, button ;
  unsigned int start, stop ;

  printf ("Raspberry Pi PiFace Reaction Timer\n") ;
  printf ("==================================\n") ;

  if (piFaceSetup (PIFACE) == -1)
    exit (1) ;

// Enable internal pull-ups

  for (i = 0 ; i < 8 ; ++i)
    pullUpDnControl (PIFACE + i, PUD_UP) ;


// Main game loop:
//	Put some random LED pairs up for a few seconds, then blank ...

  for (;;)
  {
    printf ("Press any button to start ... \n") ; fflush (stdout) ;

    for (;;)
    {
      led = rand () % 4 ;
      light (led, 1) ;
      delay (10) ;
      light (led, 0) ;

      button = 0 ;
      for (j = 0 ; j < 4 ; ++j)
	button += digitalRead (PIFACE + j) ;

      if (button != 4)
	break ;
    }

    waitForNoButtons () ;

    printf ("Wait for it ... ") ; fflush (stdout) ;

    led = rand () % 4 ;
    delay (rand () % 500 + 1000) ;
    light (led, 1) ;

    start = millis () ;
    for (button = -1 ; button == -1 ; )
    {
      for (j = 0 ; j < 4 ; ++j)
	if (digitalRead (PIFACE + j) == 0)	// Pushed
	{
	  button = j ;
	  break ;
	}
    }
    stop = millis () ;
    button = 3 - button ; // Correct for the buttons/LEDs reversed

    light (led, 0) ;

    waitForNoButtons () ;

    light (led, 1) ;

    if (button == led)
    {
      printf ("You got it in %3d mS\n", stop - start) ;
    }
    else
    {
      printf ("Missed: You pushed %d - LED was %d\n", button, led) ;
      for (;;)
      {
	light (button, 1) ;
	delay (100) ;
	light (button, 0) ;
	delay (100) ;
	i = 0 ;
	for (j = 0 ; j < 4 ; ++j)
	  i += digitalRead (PIFACE + j) ;
	if (i != 4)
	  break ;
      }

      waitForNoButtons () ;
    }
    light (led, 0) ;
    delay (4000) ;
  }

  return 0 ;
}
コード例 #9
0
ファイル: gpio.c プロジェクト: Dzenik/WiringCB-python
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 ;
  }

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

  if (strcasecmp (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 module

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

    if (!doModule (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) ;

// 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], "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
  {
    fprintf (stderr, "%s: Unknown command: %s.\n", argv [0], argv [1]) ;
    exit (EXIT_FAILURE) ;
  }
  return 0 ;
}