extern int wiringPiDebug ;
+// External functions I can't be bothered creating a separate .h file for:
+
extern void doReadall (void) ;
extern void doReadallOld (void) ;
+extern void doPins (void) ;
+
#ifndef TRUE
# define TRUE (1==1)
# define FALSE (1==2)
#endif
-#define VERSION "2.11"
+#define VERSION "2.18"
#define I2CDETECT "/usr/sbin/i2cdetect"
int wpMode ;
" gpio gbw <channel> <value>" ; // No trailing newline needed here.
+#ifdef NOT_FOR_NOW
+/*
+ * decodePin:
+ * Decode a pin "number" which can actually be a pin name to represent
+ * one of the Pi's on-board pins.
+ *********************************************************************************
+ */
+
+static int decodePin (const char *str)
+{
+
+// The first case - see if it's a number:
+
+ if (isdigit (str [0]))
+ return atoi (str) ;
+
+ return 0 ;
+}
+#endif
+
+
/*
* changeOwner:
* Change the ownership of the file to the real userId of the calling
mode = argv [3] ;
- /**/ if (strcasecmp (mode, "in") == 0) pinMode (pin, INPUT) ;
- else if (strcasecmp (mode, "input") == 0) pinMode (pin, INPUT) ;
- else if (strcasecmp (mode, "out") == 0) pinMode (pin, OUTPUT) ;
- else if (strcasecmp (mode, "output") == 0) pinMode (pin, OUTPUT) ;
- else if (strcasecmp (mode, "pwm") == 0) pinMode (pin, PWM_OUTPUT) ;
- else if (strcasecmp (mode, "clock") == 0) pinMode (pin, GPIO_CLOCK) ;
- else if (strcasecmp (mode, "up") == 0) pullUpDnControl (pin, PUD_UP) ;
- else if (strcasecmp (mode, "down") == 0) pullUpDnControl (pin, PUD_DOWN) ;
- else if (strcasecmp (mode, "tri") == 0) pullUpDnControl (pin, PUD_OFF) ;
- else if (strcasecmp (mode, "off") == 0) pullUpDnControl (pin, PUD_OFF) ;
+ /**/ if (strcasecmp (mode, "in") == 0) pinMode (pin, INPUT) ;
+ else if (strcasecmp (mode, "input") == 0) pinMode (pin, INPUT) ;
+ else if (strcasecmp (mode, "out") == 0) pinMode (pin, OUTPUT) ;
+ else if (strcasecmp (mode, "output") == 0) pinMode (pin, OUTPUT) ;
+ else if (strcasecmp (mode, "pwm") == 0) pinMode (pin, PWM_OUTPUT) ;
+ else if (strcasecmp (mode, "pwmTone") == 0) pinMode (pin, PWM_TONE_OUTPUT) ;
+ else if (strcasecmp (mode, "clock") == 0) pinMode (pin, GPIO_CLOCK) ;
+ else if (strcasecmp (mode, "up") == 0) pullUpDnControl (pin, PUD_UP) ;
+ else if (strcasecmp (mode, "down") == 0) pullUpDnControl (pin, PUD_DOWN) ;
+ else if (strcasecmp (mode, "tri") == 0) pullUpDnControl (pin, PUD_OFF) ;
+ else if (strcasecmp (mode, "off") == 0) pullUpDnControl (pin, PUD_OFF) ;
+
+// Undocumented
+
+ else if (strcasecmp (mode, "alt0") == 0) pinModeAlt (pin, 0b100) ;
+ else if (strcasecmp (mode, "alt1") == 0) pinModeAlt (pin, 0b101) ;
+ else if (strcasecmp (mode, "alt2") == 0) pinModeAlt (pin, 0b110) ;
+ else if (strcasecmp (mode, "alt3") == 0) pinModeAlt (pin, 0b111) ;
+ else if (strcasecmp (mode, "alt4") == 0) pinModeAlt (pin, 0b011) ;
+ else if (strcasecmp (mode, "alt5") == 0) pinModeAlt (pin, 0b010) ;
else
{
fprintf (stderr, "%s: Invalid mode: %s. Should be in/out/pwm/clock/up/down/tri\n", argv [1], mode) ;
exit (1) ;
}
- if ((value < 0) || (value > 1023))
+ if ((value < 0) || (value > 255))
{
fprintf (stderr, "%s: gbw: Value must be from 0 to 255\n", argv [0]) ;
exit (1) ;
digitalWrite (pin, !digitalRead (pin)) ;
}
+
+/*
+ * doPwmTone:
+ * Output a tone in a PWM pin
+ *********************************************************************************
+ */
+
+void doPwmTone (int argc, char *argv [])
+{
+ int pin, freq ;
+
+ if (argc != 4)
+ {
+ fprintf (stderr, "Usage: %s pwmTone <pin> <freq>\n", argv [0]) ;
+ exit (1) ;
+ }
+
+ pin = atoi (argv [2]) ;
+ freq = atoi (argv [3]) ;
+
+ pwmToneWrite (pin, freq) ;
+}
+
+
/*
* doClock:
* Output a clock on a pin
int main (int argc, char *argv [])
{
int i ;
+ int model, rev, mem ;
+ char *maker ;
if (getenv ("WIRINGPI_DEBUG") != NULL)
{
if (strcmp (argv [1], "-v") == 0)
{
printf ("gpio version: %s\n", VERSION) ;
- printf ("Copyright (c) 2012-2013 Gordon Henderson\n") ;
+ 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") ;
- printf ("This Raspberry Pi is a revision %d board.\n", piBoardRev ()) ;
+ piBoardId (&model, &rev, &mem, &maker) ;
+ printf ("Raspberry Pi Details:\n") ;
+ printf (" Type: %s, Revision: %s, Memory: %dMB, Maker: %s\n",
+ piModelNames [model], piRevisionNames [rev], mem, maker) ;
return 0 ;
}
if (strcasecmp (argv [1], "-warranty") == 0)
{
printf ("gpio version: %s\n", VERSION) ;
- printf ("Copyright (c) 2012-2013 Gordon Henderson\n") ;
+ 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") ;
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], "readall" ) == 0) doReadallOld () ;
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]) ;