diff --git a/devLib/lcd.c b/devLib/lcd.c index 6c0e474..ba8618b 100644 --- a/devLib/lcd.c +++ b/devLib/lcd.c @@ -32,9 +32,9 @@ #include "lcd.h" -#ifndef TRUE -# define TRUE (1==1) -# define FALSE (1==2) +#ifndef true +# define true (1==1) +# define false (1==2) #endif // HD44780U Commands @@ -483,9 +483,9 @@ int lcdInit (const int rows, const int cols, const int bits, // Rest of the initialisation sequence - lcdDisplay (lcdFd, TRUE) ; - lcdCursor (lcdFd, FALSE) ; - lcdCursorBlink (lcdFd, FALSE) ; + lcdDisplay (lcdFd, true) ; + lcdCursor (lcdFd, false) ; + lcdCursorBlink (lcdFd, false) ; lcdClear (lcdFd) ; putCommand (lcd, LCD_ENTRY | LCD_ENTRY_ID) ; diff --git a/devLib/maxdetect.c b/devLib/maxdetect.c index 74ff70e..7417608 100644 --- a/devLib/maxdetect.c +++ b/devLib/maxdetect.c @@ -31,9 +31,9 @@ #include "maxdetect.h" -#ifndef TRUE -# define TRUE (1==1) -# define FALSE (1==2) +#ifndef true +# define true (1==1) +# define false (1==2) #endif @@ -58,7 +58,7 @@ static int maxDetectLowHighWait (const int pin) { gettimeofday (&now, NULL) ; if (timercmp (&now, &timeUp, >)) - return FALSE ; + return false ; } // Wait for it to go HIGH @@ -72,10 +72,10 @@ static int maxDetectLowHighWait (const int pin) { gettimeofday (&now, NULL) ; if (timercmp (&now, &timeUp, >)) - return FALSE ; + return false ; } - return TRUE ; + return true ; } @@ -110,7 +110,7 @@ static unsigned int maxDetectClockByte (const int pin) /* * maxDetectRead: * Read in and return the 4 data bytes from the MaxDetect sensor. - * Return TRUE/FALSE depending on the checksum validity + * Return true/false depending on the checksum validity ********************************************************************************* */ @@ -136,7 +136,7 @@ int maxDetectRead (const int pin, unsigned char buffer [4]) // Now wait for sensor to pull pin low if (!maxDetectLowHighWait (pin)) - return FALSE ; + return false ; // and read in 5 bytes (40 bits) @@ -165,7 +165,7 @@ int maxDetectRead (const int pin, unsigned char buffer [4]) // reading is probably bogus. if ((took.tv_sec != 0) || (took.tv_usec > 16000)) - return FALSE ; + return false ; return checksum == localBuf [4] ; } @@ -196,7 +196,7 @@ int readRHT03 (const int pin, int *temp, int *rh) { *rh = lastRh ; *temp = lastTemp ; - return TRUE ; + return true ; } // Set timeout for next read @@ -214,7 +214,7 @@ int readRHT03 (const int pin, int *temp, int *rh) result = maxDetectRead (pin, buffer) ; if (!result) - return FALSE ; + return false ; *rh = (buffer [0] * 256 + buffer [1]) ; *temp = (buffer [2] * 256 + buffer [3]) ; @@ -229,10 +229,10 @@ int readRHT03 (const int pin, int *temp, int *rh) // (which does seem to happen - no realtime here) if ((*rh > 999) || (*temp > 800) || (*temp < -400)) - return FALSE ; + return false ; lastRh = *rh ; lastTemp = *temp ; - return TRUE ; + return true ; } diff --git a/examples/Gertboard/vumeter.c b/examples/Gertboard/vumeter.c index 9643ace..1746309 100644 --- a/examples/Gertboard/vumeter.c +++ b/examples/Gertboard/vumeter.c @@ -23,9 +23,9 @@ #include #include -#ifndef TRUE -#define TRUE (1==1) -#define FALSE (!TRUE) +#ifndef true +#define true (1==1) +#define false (!true) #endif #define B_SIZE 1000 diff --git a/examples/PiFace/ladder.c b/examples/PiFace/ladder.c index 4f08a6f..34a601c 100644 --- a/examples/PiFace/ladder.c +++ b/examples/PiFace/ladder.c @@ -13,9 +13,9 @@ #include #include -#ifndef TRUE -# define TRUE (1==1) -# define FALSE (1==2) +#ifndef true +# define true (1==1) +# define false (1==2) #endif #undef DEBUG @@ -244,7 +244,7 @@ void ledOnAction (void) if (digitalRead (PIFACE) == LOW) { chargeCapacitor () ; - ledBargraph (vCap, TRUE) ; + ledBargraph (vCap, true) ; } } @@ -264,7 +264,7 @@ void ledOffAction (void) if (digitalRead (PIFACE) == LOW) { vCap = vCapLast = 0.0 ; - ledBargraph (vCap, FALSE) ; + ledBargraph (vCap, false) ; // Wait until we release the button @@ -300,7 +300,7 @@ int main (void) // LED ON: - (void)ledBargraph (vCap, TRUE) ; + (void)ledBargraph (vCap, true) ; then = millis () + ledOnTime ; while (millis () < then) { @@ -323,7 +323,7 @@ int main (void) // LED OFF: - (void)ledBargraph (vCap, FALSE) ; + (void)ledBargraph (vCap, false) ; then = millis () + ledOffTime ; while (millis () < then) { diff --git a/examples/PiGlow/piGlow1.c b/examples/PiGlow/piGlow1.c index a00b31e..7d3a185 100644 --- a/examples/PiGlow/piGlow1.c +++ b/examples/PiGlow/piGlow1.c @@ -32,9 +32,9 @@ #define PIGLOW_BASE 533 -#ifndef TRUE -# define TRUE (1==1) -# define FALSE (!TRUE) +#ifndef true +# define true (1==1) +# define false (!true) #endif diff --git a/examples/PiGlow/piglow.c b/examples/PiGlow/piglow.c index e6a2db3..cf1dbeb 100644 --- a/examples/PiGlow/piglow.c +++ b/examples/PiGlow/piglow.c @@ -27,9 +27,9 @@ #include #include -#ifndef TRUE -# define TRUE (1==1) -# define FALSE (!TRUE) +#ifndef true +# define true (1==1) +# define false (!true) #endif #include @@ -81,7 +81,7 @@ int main (int argc, char *argv []) // Initialise the piGlow devLib - piGlowSetup (FALSE) ; + piGlowSetup (false) ; if (argc == 1) failUsage () ; diff --git a/examples/clock.c b/examples/clock.c index 9a53210..6a71a23 100644 --- a/examples/clock.c +++ b/examples/clock.c @@ -45,9 +45,9 @@ #include #include -#ifndef TRUE -# define TRUE (1==1) -# define FALSE (1==2) +#ifndef true +# define true (1==1) +# define false (1==2) #endif double clockRadius ; @@ -130,15 +130,15 @@ void drawClockFace (void) double d, px1, py1, px2, py2 ; lcd128x64clear (0) ; - lcd128x64circle (0,0, clockRadius, 1, TRUE) ; - lcd128x64circle (0,0, clockRadius - thickness, 0, TRUE) ; + lcd128x64circle (0,0, clockRadius, 1, true) ; + lcd128x64circle (0,0, clockRadius - thickness, 0, true) ; // The four big indicators for 12,15,30 and 45 - lcd128x64rectangle (- 3, clockRadius - barLen, 3, clockRadius, 1, TRUE) ; // 12 - lcd128x64rectangle (clockRadius - barLen, 3, clockRadius, -3, 1, TRUE) ; // 3 - lcd128x64rectangle (- 3, -clockRadius + barLen, 3, -clockRadius, 1, TRUE) ; // 6 - lcd128x64rectangle (-clockRadius + barLen, 3, -clockRadius, -3, 1, TRUE) ; // 9 + lcd128x64rectangle (- 3, clockRadius - barLen, 3, clockRadius, 1, true) ; // 12 + lcd128x64rectangle (clockRadius - barLen, 3, clockRadius, -3, 1, true) ; // 3 + lcd128x64rectangle (- 3, -clockRadius + barLen, 3, -clockRadius, 1, true) ; // 6 + lcd128x64rectangle (-clockRadius + barLen, 3, -clockRadius, -3, 1, true) ; // 9 // Smaller 5 and 1 minute ticks diff --git a/examples/lcd-adafruit.c b/examples/lcd-adafruit.c index 47c9b9b..e540057 100644 --- a/examples/lcd-adafruit.c +++ b/examples/lcd-adafruit.c @@ -34,9 +34,9 @@ #include #include -#ifndef TRUE -# define TRUE (1==1) -# define FALSE (1==2) +#ifndef true +# define true (1==1) +# define false (1==2) #endif @@ -251,7 +251,7 @@ int main (int argc, char *argv[]) { int colour ; int cols = 16 ; - int waitForRelease = FALSE ; + int waitForRelease = false ; struct tm *t ; time_t tim ; @@ -287,13 +287,13 @@ int main (int argc, char *argv[]) lcdPuts (lcdHandle, "User Char: ") ; lcdPutchar (lcdHandle, 2) ; - lcdCursor (lcdHandle, TRUE) ; - lcdCursorBlink (lcdHandle, TRUE) ; + lcdCursor (lcdHandle, true) ; + lcdCursorBlink (lcdHandle, true) ; waitForEnter () ; - lcdCursor (lcdHandle, FALSE) ; - lcdCursorBlink (lcdHandle, FALSE) ; + lcdCursor (lcdHandle, false) ; + lcdCursorBlink (lcdHandle, false) ; speedTest () ; @@ -320,7 +320,7 @@ int main (int argc, char *argv[]) if ((digitalRead (AF_UP) == LOW) || (digitalRead (AF_DOWN) == LOW)) continue ; else - waitForRelease = FALSE ; + waitForRelease = false ; } if (digitalRead (AF_UP) == LOW) // Pushed @@ -329,7 +329,7 @@ int main (int argc, char *argv[]) if (colour == 8) colour = 0 ; setBacklightColour (colour) ; - waitForRelease = TRUE ; + waitForRelease = true ; } if (digitalRead (AF_DOWN) == LOW) // Pushed @@ -338,7 +338,7 @@ int main (int argc, char *argv[]) if (colour == -1) colour = 7 ; setBacklightColour (colour) ; - waitForRelease = TRUE ; + waitForRelease = true ; } } diff --git a/examples/lcd.c b/examples/lcd.c index 510f562..ebb7225 100644 --- a/examples/lcd.c +++ b/examples/lcd.c @@ -47,9 +47,9 @@ #include #include -#ifndef TRUE -# define TRUE (1==1) -# define FALSE (1==2) +#ifndef true +# define true (1==1) +# define false (1==2) #endif static unsigned char newChar [8] = @@ -247,13 +247,13 @@ int main (int argc, char *argv[]) lcdPuts (lcdHandle, "User Char: ") ; lcdPutchar (lcdHandle, 2) ; - lcdCursor (lcdHandle, TRUE) ; - lcdCursorBlink (lcdHandle, TRUE) ; + lcdCursor (lcdHandle, true) ; + lcdCursorBlink (lcdHandle, true) ; waitForEnter () ; - lcdCursor (lcdHandle, FALSE) ; - lcdCursorBlink (lcdHandle, FALSE) ; + lcdCursor (lcdHandle, false) ; + lcdCursorBlink (lcdHandle, false) ; lcdClear (lcdHandle) ; for (;;) diff --git a/examples/spiSpeed.c b/examples/spiSpeed.c index 0208f0a..64f8262 100644 --- a/examples/spiSpeed.c +++ b/examples/spiSpeed.c @@ -36,8 +36,8 @@ #include #include -#define TRUE (1==1) -#define FALSE (!TRUE) +#define true (1==1) +#define false (!true) #define SPI_CHAN 0 #define NUM_TIMES 100 @@ -78,7 +78,7 @@ int main (void) printf ("| MHz | Size | mS/Trans | TpS | Mb/Sec | Latency mS |\n") ; printf ("+-------+--------+----------+----------+-----------+------------+\n") ; - spiFail = FALSE ; + spiFail = false ; spiSetup (speed * 1000000) ; for (size = 1 ; size <= MAX_SIZE ; size *= 2) { @@ -89,7 +89,7 @@ int main (void) if (wiringPiSPIDataRW (SPI_CHAN, myData, size) == -1) { printf ("SPI failure: %s\n", strerror (errno)) ; - spiFail = TRUE ; + spiFail = true ; break ; } end = millis () ; diff --git a/gpio/Makefile b/gpio/Makefile index 622269e..73672ab 100644 --- a/gpio/Makefile +++ b/gpio/Makefile @@ -53,7 +53,7 @@ CC = arm-linux-gnueabihf-gcc #DEBUG = -g -O0 DEBUG = -O2 INCLUDE = -I/$(LOCAL_INCLUDE_DIR) -CFLAGS = $(DEBUG) -Wall -Wextra $(INCLUDE) -Winline -pipe +CFLAGS = $(DEBUG) -Wall -Wextra -Werror $(INCLUDE) -Winline -pipe LDFLAGS = -L/$(LOCAL_LIB_DIR) LIBS = -lwiringPi -lwiringPiDev -lpthread -lrt -lm -lcrypt diff --git a/gpio/gpio.c b/gpio/gpio.c index 714e790..2fd71ff 100644 --- a/gpio/gpio.c +++ b/gpio/gpio.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -50,9 +51,9 @@ extern void doReadall (void) ; extern void doAllReadall (void) ; extern void doQmode (int argc, char *argv []) ; -#ifndef TRUE -# define TRUE (1==1) -# define FALSE (1==2) +#ifndef true +# define true (1==1) +# define false (1==2) #endif #define PI_USB_POWER_CONTROL 38 @@ -118,33 +119,41 @@ static int decodePin (const char *str) ********************************************************************************* */ -static const char *searchPath [] = -{ - "/sbin", - "/usr/sbin", - "/bin", - "/usr/bin", - NULL, -} ; - static char *findExecutable (const char *progName) { + static const char *searchPath [] = + { + "/sbin", + "/usr/sbin", + "/bin", + "/usr/bin", + NULL, + } ; + static char *path = NULL ; - int len = strlen (progName) ; - int i = 0 ; + size_t len = strlen (progName) ; + unsigned int i = 0 ; struct stat statBuf ; for (i = 0 ; searchPath [i] != NULL ; ++i) { - path = malloc (strlen (searchPath [i]) + len + 2) ; + if( (path = malloc (strlen (searchPath [i]) + len + 2)) == NULL ) + { + error( EXIT_FAILURE, 0, "Insufficient memory\n" ); + } + sprintf (path, "%s/%s", searchPath [i], progName) ; if (stat (path, &statBuf) == 0) - return path ; + { + break; + } + free (path) ; + path = NULL; } - return NULL ; + return path; } @@ -181,7 +190,7 @@ static void changeOwner (char *cmd, char *file) static int moduleLoaded (char *modName) { int len = strlen (modName) ; - int found = FALSE ; + int found = false ; FILE *fd = fopen ("/proc/modules", "r") ; char line [80] ; @@ -196,7 +205,7 @@ static int moduleLoaded (char *modName) if (strncmp (line, modName, len) != 0) continue ; - found = TRUE ; + found = true ; break ; } @@ -234,7 +243,7 @@ static void _doLoadUsage (char *argv []) static void doLoad (int argc, char *argv []) { - char *module1, *module2 ; + char *module1, *module2, *loader_path ; char cmd [80] ; char *file1, *file2 ; char args1 [32], args2 [32] ; @@ -274,19 +283,27 @@ static void doLoad (int argc, char *argv []) else _doLoadUsage (argv) ; - if (findExecutable ("modprobe") == NULL) - printf ("No found\n") ; + if ((loader_path = findExecutable (MODPROBE)) == NULL) + { + error( EXIT_FAILURE, 0, "\"%s\" not found, unable to load module\n", loader_path ); + } if (!moduleLoaded (module1)) { - sprintf (cmd, "%s %s%s", findExecutable (MODPROBE), module1, args1) ; - system (cmd) ; + sprintf (cmd, "%s %s%s", loader_path, module1, args1) ; + if( system(cmd) == -1 ) + { + error( EXIT_FAILURE, 0, "Can't execute %s", cmd); + } } if (!moduleLoaded (module2)) { - sprintf (cmd, "%s %s%s", findExecutable (MODPROBE), module2, args2) ; - system (cmd) ; + sprintf (cmd, "%s %s%s", loader_path, module2, args2) ; + if( system(cmd) == -1 ) + { + error( EXIT_FAILURE, 0, "Can't execute %s", cmd); + } } if (!moduleLoaded (module2)) @@ -295,6 +312,9 @@ static void doLoad (int argc, char *argv []) exit (1) ; } + + free( loader_path ); + sleep (1) ; // To let things get settled changeOwner (argv [0], file1) ; @@ -316,7 +336,7 @@ static void _doUnLoadUsage (char *argv []) static void doUnLoad (int argc, char *argv []) { - char *module1, *module2 ; + char *module1, *module2, *unloader_path ; char cmd [80] ; checkDevTree (argv) ; @@ -335,18 +355,35 @@ static void doUnLoad (int argc, char *argv []) module2 = "i2c_bcm2708" ; } else + { _doUnLoadUsage (argv) ; + } - if (moduleLoaded (module1)) + if ((unloader_path = findExecutable (RMMOD)) == NULL) { - sprintf (cmd, "%s %s", findExecutable (RMMOD), module1) ; - system (cmd) ; + error( 0, 0, "\"%s\" not found, unable to unload modules\n", unloader_path ); } - - if (moduleLoaded (module2)) + else { - sprintf (cmd, "%s %s", findExecutable (RMMOD), module2) ; - system (cmd) ; + if (moduleLoaded (module1)) + { + sprintf (cmd, "%s %s", unloader_path, module1) ; + if( system(cmd) == -1 ) + { + error( 0, 0, "Can't execute %s", cmd); + } + } + + if (moduleLoaded (module2)) + { + sprintf (cmd, "%s %s", unloader_path, module2) ; + if( system(cmd) == -1 ) + { + error( 0, 0, "Can't execute %s", cmd); + } + } + + free( unloader_path ); } } @@ -1287,9 +1324,12 @@ static void doVersion (char *argv []) { if ((fd = fopen ("/proc/device-tree/model", "r")) != NULL) { - fgets (name, 80, fd) ; + if( fgets (name, 80, fd) != NULL ) + { + printf (" *--> %s\n", name) ; + } + fclose (fd) ; - printf (" *--> %s\n", name) ; } } @@ -1313,7 +1353,7 @@ int main (int argc, char *argv []) if (getenv ("WIRINGPI_DEBUG") != NULL) { printf ("gpio: wiringPi debug mode enabled\n") ; - wiringPiDebug = TRUE ; + wiringPiDebug = true ; } if (argc == 1) @@ -1475,7 +1515,7 @@ int main (int argc, char *argv []) exit (EXIT_FAILURE) ; } - if (!loadWPiExtension (argv [0], argv [2], TRUE)) + if (!loadWPiExtension (argv [0], argv [2], true)) { fprintf (stderr, "%s: Extension load failed: %s\n", argv [0], strerror (errno)) ; exit (EXIT_FAILURE) ; @@ -1524,8 +1564,8 @@ int main (int argc, char *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], "rbx" ) == 0) doReadByte (argc, argv, TRUE) ; - else if (strcasecmp (argv [1], "rbd" ) == 0) doReadByte (argc, argv, FALSE) ; + else if (strcasecmp (argv [1], "rbx" ) == 0) doReadByte (argc, argv, true) ; + else if (strcasecmp (argv [1], "rbd" ) == 0) doReadByte (argc, argv, false) ; else if (strcasecmp (argv [1], "clock" ) == 0) doClock (argc, argv) ; else if (strcasecmp (argv [1], "wfi" ) == 0) doWfi (argc, argv) ; else diff --git a/gpio/readall.c b/gpio/readall.c index 9396c6d..7aeb97e 100644 --- a/gpio/readall.c +++ b/gpio/readall.c @@ -37,9 +37,9 @@ extern int wpMode ; -#ifndef TRUE -# define TRUE (1==1) -# define FALSE (1==2) +#ifndef true +# define true (1==1) +# define false (1==2) #endif /* diff --git a/wiringPi/Makefile b/wiringPi/Makefile index 7f4ad64..8404a01 100644 --- a/wiringPi/Makefile +++ b/wiringPi/Makefile @@ -54,7 +54,7 @@ CC = arm-linux-gnueabihf-gcc DEBUG = -O2 INCLUDE = -I. DEFS = -D_GNU_SOURCE -CFLAGS = $(DEBUG) $(DEFS) -Wformat=2 -Wall -Wextra -Winline $(INCLUDE) -pipe -fPIC +CFLAGS = $(DEBUG) $(DEFS) -Wformat=2 -Wall -Wextra -Winline -Werror $(INCLUDE) -pipe -fPIC #CFLAGS = $(DEBUG) $(DEFS) -Wformat=2 -Wall -Wextra -Wconversion -Winline $(INCLUDE) -pipe -fPIC LIBS = -lm -lpthread -lrt -lcrypt diff --git a/wiringPi/ads1115.c b/wiringPi/ads1115.c index 648e612..60fa6d4 100644 --- a/wiringPi/ads1115.c +++ b/wiringPi/ads1115.c @@ -278,7 +278,7 @@ int ads1115Setup (const int pinBase, int i2cAddr) int fd ; if ((fd = wiringPiI2CSetup (i2cAddr)) < 0) - return FALSE ; + return false ; node = wiringPiNewNode (pinBase, 8) ; @@ -289,5 +289,5 @@ int ads1115Setup (const int pinBase, int i2cAddr) node->analogWrite = myAnalogWrite ; node->digitalWrite = myDigitalWrite ; - return TRUE ; + return true ; } diff --git a/wiringPi/bmp180.c b/wiringPi/bmp180.c index bad4bb3..4cbdf10 100644 --- a/wiringPi/bmp180.c +++ b/wiringPi/bmp180.c @@ -192,7 +192,7 @@ int bmp180Setup (const int pinBase) struct wiringPiNodeStruct *node ; if ((fd = wiringPiI2CSetup (I2C_ADDRESS)) < 0) - return FALSE ; + return false ; node = wiringPiNewNode (pinBase, 4) ; @@ -233,5 +233,5 @@ int bmp180Setup (const int pinBase) p1 = 1.0 - 7357.0 * pow (2.0, -20.0) ; p2 = 3038.0 * 100.0 * pow (2.0, -36.0) ; - return TRUE ; + return true ; } diff --git a/wiringPi/drcNet.c b/wiringPi/drcNet.c index 0964ff7..0e8db4a 100644 --- a/wiringPi/drcNet.c +++ b/wiringPi/drcNet.c @@ -32,6 +32,7 @@ #include #include #include +#include #include "wiringPi.h" @@ -103,31 +104,44 @@ static char *getChallenge (int fd) static int authenticate (int fd, const char *pass) { char *challenge ; - char *encrypted ; - char salted [1024] ; - if ((challenge = getChallenge (fd)) == NULL) - return -1 ; + int return_value = -1; - sprintf (salted, "$6$%s$", challenge) ; - encrypted = crypt (pass, salted) ; - -// This is an assertion, or sanity check on my part... -// The '20' comes from the $6$ then the 16 characters of the salt, -// then the terminating $. - if (strncmp (encrypted, salted, 20) != 0) + if ((challenge = getChallenge (fd)) != NULL) { - errno = EBADE ; - return -1 ; - } + char *salted ; -// 86 characters is the length of the SHA-256 hash + if( asprintf(&salted, "$6$%s$", challenge) >=0 ) + { + char *encrypted ; - if (write (fd, encrypted + 20, 86) == 86) - return 0 ; - else - return -1 ; + encrypted = crypt (pass, salted) ; + + // This is an assertion, or sanity check on my part... + // The '20' comes from the $6$ then the 16 characters of the salt, + // then the terminating $. + + if (strncmp (encrypted, salted, 20) == 0) + { + + // 86 characters is the length of the SHA-256 hash + + if (write (fd, encrypted + 20, 86) == 86) + { + return_value = 0 ; + } + } + else + { + errno = EBADE ; + } + + free( salted ); + } + } + + return return_value ; } @@ -380,12 +394,12 @@ int drcSetupNet (const int pinBase, const int numPins, const char *ipAddress, co struct wiringPiNodeStruct *node ; if ((fd = _drcSetupNet (ipAddress, port, password)) < 0) - return FALSE ; + return false ; len = sizeof (struct drcNetComStruct) ; if (setsockopt (fd, SOL_SOCKET, SO_RCVLOWAT, (void *)&len, sizeof (len)) < 0) - return FALSE ; + return false ; node = wiringPiNewNode (pinBase, numPins) ; @@ -401,5 +415,5 @@ int drcSetupNet (const int pinBase, const int numPins, const char *ipAddress, co //node->digitalWrite8 = myDigitalWrite8 ; node->pwmWrite = myPwmWrite ; - return TRUE ; + return true ; } diff --git a/wiringPi/drcSerial.c b/wiringPi/drcSerial.c index db7cc09..810d11b 100644 --- a/wiringPi/drcSerial.c +++ b/wiringPi/drcSerial.c @@ -151,7 +151,7 @@ int drcSetupSerial (const int pinBase, const int numPins, const char *device, co struct wiringPiNodeStruct *node ; if ((fd = serialOpen (device, baud)) < 0) - return FALSE ; + return false ; delay (10) ; // May need longer if it's an Uno that reboots on the open... @@ -160,7 +160,7 @@ int drcSetupSerial (const int pinBase, const int numPins, const char *device, co while (serialDataAvail (fd)) (void)serialGetchar (fd) ; - ok = FALSE ; + ok = false ; for (tries = 1 ; (tries < 5) && (!ok) ; ++tries) { serialPutchar (fd, '@') ; // Ping @@ -170,7 +170,7 @@ int drcSetupSerial (const int pinBase, const int numPins, const char *device, co { if (serialGetchar (fd) == '@') { - ok = TRUE ; + ok = true ; break ; } } @@ -179,7 +179,7 @@ int drcSetupSerial (const int pinBase, const int numPins, const char *device, co if (!ok) { serialClose (fd) ; - return FALSE ; + return false ; } node = wiringPiNewNode (pinBase, numPins) ; @@ -192,5 +192,5 @@ int drcSetupSerial (const int pinBase, const int numPins, const char *device, co node->digitalWrite = myDigitalWrite ; node->pwmWrite = myPwmWrite ; - return TRUE ; + return true ; } diff --git a/wiringPi/ds18b20.c b/wiringPi/ds18b20.c index 533398e..c64b2ad 100644 --- a/wiringPi/ds18b20.c +++ b/wiringPi/ds18b20.c @@ -123,7 +123,7 @@ int ds18b20Setup (const int pinBase, const char *deviceId) // Allocate space for the filename if ((fileName = malloc (strlen (W1_PREFIX) + strlen (W1_POSTFIX) + strlen (deviceId) + 1)) == NULL) - return FALSE ; + return false ; sprintf (fileName, "%s%s%s", W1_PREFIX, deviceId, W1_POSTFIX) ; @@ -132,7 +132,7 @@ int ds18b20Setup (const int pinBase, const char *deviceId) free (fileName) ; if (fd < 0) - return FALSE ; + return false ; // We'll keep the file open, to make access a little faster // although it's very slow reading these things anyway )-: @@ -142,5 +142,5 @@ int ds18b20Setup (const int pinBase, const char *deviceId) node->fd = fd ; node->analogRead = myAnalogRead ; - return TRUE ; + return true ; } diff --git a/wiringPi/htu21d.c b/wiringPi/htu21d.c index 46c0fcb..900521c 100644 --- a/wiringPi/htu21d.c +++ b/wiringPi/htu21d.c @@ -40,7 +40,7 @@ int checksum (UNU uint8_t data [4]) { - return TRUE ; + return true ; } @@ -127,7 +127,7 @@ int htu21dSetup (const int pinBase) int status ; if ((fd = wiringPiI2CSetup (I2C_ADDRESS)) < 0) - return FALSE ; + return false ; node = wiringPiNewNode (pinBase, 2) ; @@ -138,7 +138,7 @@ int htu21dSetup (const int pinBase) data = 0xFE ; if (write (fd, &data, 1) != 1) - return FALSE ; + return false ; delay (15) ; @@ -146,5 +146,5 @@ int htu21dSetup (const int pinBase) status = wiringPiI2CReadReg8 (fd, 0xE7) ; - return (status == 0x02) ? TRUE : FALSE ; + return (status == 0x02) ? true : false ; } diff --git a/wiringPi/max31855.c b/wiringPi/max31855.c index d86cabd..2e68b75 100644 --- a/wiringPi/max31855.c +++ b/wiringPi/max31855.c @@ -88,12 +88,12 @@ int max31855Setup (const int pinBase, int spiChannel) struct wiringPiNodeStruct *node ; if (wiringPiSPISetup (spiChannel, 5000000) < 0) // 5MHz - prob 4 on the Pi - return FALSE ; + return false ; node = wiringPiNewNode (pinBase, 4) ; node->fd = spiChannel ; node->analogRead = myAnalogRead ; - return TRUE ; + return true ; } diff --git a/wiringPi/max5322.c b/wiringPi/max5322.c index e56b085..a38b7a5 100644 --- a/wiringPi/max5322.c +++ b/wiringPi/max5322.c @@ -66,7 +66,7 @@ int max5322Setup (const int pinBase, int spiChannel) unsigned char spiData [2] ; if (wiringPiSPISetup (spiChannel, 8000000) < 0) // 10MHz Max - return FALSE ; + return false ; node = wiringPiNewNode (pinBase, 2) ; @@ -80,5 +80,5 @@ int max5322Setup (const int pinBase, int spiChannel) wiringPiSPIDataRW (node->fd, spiData, 2) ; - return TRUE ; + return true ; } diff --git a/wiringPi/mcp23008.c b/wiringPi/mcp23008.c index 71757a8..e47eb87 100644 --- a/wiringPi/mcp23008.c +++ b/wiringPi/mcp23008.c @@ -132,7 +132,7 @@ int mcp23008Setup (const int pinBase, const int i2cAddress) struct wiringPiNodeStruct *node ; if ((fd = wiringPiI2CSetup (i2cAddress)) < 0) - return FALSE ; + return false ; wiringPiI2CWriteReg8 (fd, MCP23x08_IOCON, IOCON_INIT) ; @@ -145,5 +145,5 @@ int mcp23008Setup (const int pinBase, const int i2cAddress) node->digitalWrite = myDigitalWrite ; node->data2 = wiringPiI2CReadReg8 (fd, MCP23x08_OLAT) ; - return TRUE ; + return true ; } diff --git a/wiringPi/mcp23016.c b/wiringPi/mcp23016.c index 928d9e5..61655d5 100644 --- a/wiringPi/mcp23016.c +++ b/wiringPi/mcp23016.c @@ -146,7 +146,7 @@ int mcp23016Setup (const int pinBase, const int i2cAddress) struct wiringPiNodeStruct *node ; if ((fd = wiringPiI2CSetup (i2cAddress)) < 0) - return FALSE ; + return false ; wiringPiI2CWriteReg8 (fd, MCP23016_IOCON0, IOCON_INIT) ; wiringPiI2CWriteReg8 (fd, MCP23016_IOCON1, IOCON_INIT) ; @@ -160,5 +160,5 @@ int mcp23016Setup (const int pinBase, const int i2cAddress) node->data2 = wiringPiI2CReadReg8 (fd, MCP23016_OLAT0) ; node->data3 = wiringPiI2CReadReg8 (fd, MCP23016_OLAT1) ; - return TRUE ; + return true ; } diff --git a/wiringPi/mcp23017.c b/wiringPi/mcp23017.c index 4c3952d..66d8b6e 100644 --- a/wiringPi/mcp23017.c +++ b/wiringPi/mcp23017.c @@ -177,7 +177,7 @@ int mcp23017Setup (const int pinBase, const int i2cAddress) struct wiringPiNodeStruct *node ; if ((fd = wiringPiI2CSetup (i2cAddress)) < 0) - return FALSE ; + return false ; wiringPiI2CWriteReg8 (fd, MCP23x17_IOCON, IOCON_INIT) ; @@ -191,5 +191,5 @@ int mcp23017Setup (const int pinBase, const int i2cAddress) node->data2 = wiringPiI2CReadReg8 (fd, MCP23x17_OLATA) ; node->data3 = wiringPiI2CReadReg8 (fd, MCP23x17_OLATB) ; - return TRUE ; + return true ; } diff --git a/wiringPi/mcp23s08.c b/wiringPi/mcp23s08.c index f293f3a..6b5eedb 100644 --- a/wiringPi/mcp23s08.c +++ b/wiringPi/mcp23s08.c @@ -170,7 +170,7 @@ int mcp23s08Setup (const int pinBase, const int spiPort, const int devId) struct wiringPiNodeStruct *node ; if (wiringPiSPISetup (spiPort, MCP_SPEED) < 0) - return FALSE ; + return false ; writeByte (spiPort, devId, MCP23x08_IOCON, IOCON_INIT) ; @@ -184,5 +184,5 @@ int mcp23s08Setup (const int pinBase, const int spiPort, const int devId) node->digitalWrite = myDigitalWrite ; node->data2 = readByte (spiPort, devId, MCP23x08_OLAT) ; - return TRUE ; + return true ; } diff --git a/wiringPi/mcp23s17.c b/wiringPi/mcp23s17.c index 42b0358..84adef9 100644 --- a/wiringPi/mcp23s17.c +++ b/wiringPi/mcp23s17.c @@ -215,7 +215,7 @@ int mcp23s17Setup (const int pinBase, const int spiPort, const int devId) struct wiringPiNodeStruct *node ; if (wiringPiSPISetup (spiPort, MCP_SPEED) < 0) - return FALSE ; + return false ; writeByte (spiPort, devId, MCP23x17_IOCON, IOCON_INIT | IOCON_HAEN) ; writeByte (spiPort, devId, MCP23x17_IOCONB, IOCON_INIT | IOCON_HAEN) ; @@ -231,5 +231,5 @@ int mcp23s17Setup (const int pinBase, const int spiPort, const int devId) node->data2 = readByte (spiPort, devId, MCP23x17_OLATA) ; node->data3 = readByte (spiPort, devId, MCP23x17_OLATB) ; - return TRUE ; + return true ; } diff --git a/wiringPi/mcp3002.c b/wiringPi/mcp3002.c index 9ebf3e4..b16a815 100644 --- a/wiringPi/mcp3002.c +++ b/wiringPi/mcp3002.c @@ -65,12 +65,12 @@ int mcp3002Setup (const int pinBase, int spiChannel) struct wiringPiNodeStruct *node ; if (wiringPiSPISetup (spiChannel, 1000000) < 0) - return FALSE ; + return false ; node = wiringPiNewNode (pinBase, 2) ; node->fd = spiChannel ; node->analogRead = myAnalogRead ; - return TRUE ; + return true ; } diff --git a/wiringPi/mcp3004.c b/wiringPi/mcp3004.c index be8383e..723446d 100644 --- a/wiringPi/mcp3004.c +++ b/wiringPi/mcp3004.c @@ -65,12 +65,12 @@ int mcp3004Setup (const int pinBase, int spiChannel) struct wiringPiNodeStruct *node ; if (wiringPiSPISetup (spiChannel, 1000000) < 0) - return FALSE ; + return false ; node = wiringPiNewNode (pinBase, 8) ; node->fd = spiChannel ; node->analogRead = myAnalogRead ; - return TRUE ; + return true ; } diff --git a/wiringPi/mcp3422.c b/wiringPi/mcp3422.c index be14db6..3ecec85 100644 --- a/wiringPi/mcp3422.c +++ b/wiringPi/mcp3422.c @@ -29,10 +29,13 @@ #include #include #include +#include +#include #include #include #include +#include "wiring_private.h" #include "mcp3422.h" @@ -45,12 +48,25 @@ void waitForConversion (int fd, unsigned char *buffer, int n) { - for (;;) + enum { MAX_CONVERSION_WAIT = 400 }; // Slowest conversion @ 3.75 samples/second = 266.7ms, x 1.5 "fudge factor" + + for( uint16_t conversion_time_ms=0; conversion_time_msfd, buffer, 3) ; value = ((buffer [0] & 0x0F) << 8) | buffer [1] ; break ; + + default: + wiringPiFailure( WPI_ALMOST, "mcp3422:myAnalogRead: unhandled sample rate value %u", node->data0 ); + break; } return value ; @@ -112,7 +132,7 @@ int mcp3422Setup (int pinBase, int i2cAddress, int sampleRate, int gain) struct wiringPiNodeStruct *node ; if ((fd = wiringPiI2CSetup (i2cAddress)) < 0) - return FALSE ; + return false ; node = wiringPiNewNode (pinBase, 4) ; @@ -121,5 +141,5 @@ int mcp3422Setup (int pinBase, int i2cAddress, int sampleRate, int gain) node->data1 = gain ; node->analogRead = myAnalogRead ; - return TRUE ; + return true ; } diff --git a/wiringPi/mcp4802.c b/wiringPi/mcp4802.c index ef104ed..43d1173 100644 --- a/wiringPi/mcp4802.c +++ b/wiringPi/mcp4802.c @@ -65,12 +65,12 @@ int mcp4802Setup (const int pinBase, int spiChannel) struct wiringPiNodeStruct *node ; if (wiringPiSPISetup (spiChannel, 1000000) < 0) - return FALSE ; + return false ; node = wiringPiNewNode (pinBase, 2) ; node->fd = spiChannel ; node->analogWrite = myAnalogWrite ; - return TRUE ; + return true ; } diff --git a/wiringPi/pcf8574.c b/wiringPi/pcf8574.c index e0b686a..96cf5e5 100644 --- a/wiringPi/pcf8574.c +++ b/wiringPi/pcf8574.c @@ -112,7 +112,7 @@ int pcf8574Setup (const int pinBase, const int i2cAddress) struct wiringPiNodeStruct *node ; if ((fd = wiringPiI2CSetup (i2cAddress)) < 0) - return FALSE ; + return false ; node = wiringPiNewNode (pinBase, 8) ; @@ -122,5 +122,5 @@ int pcf8574Setup (const int pinBase, const int i2cAddress) node->digitalWrite = myDigitalWrite ; node->data2 = wiringPiI2CRead (fd) ; - return TRUE ; + return true ; } diff --git a/wiringPi/pcf8591.c b/wiringPi/pcf8591.c index 66c6255..b624399 100644 --- a/wiringPi/pcf8591.c +++ b/wiringPi/pcf8591.c @@ -24,9 +24,12 @@ */ #include +#include +#include #include "wiringPi.h" #include "wiringPiI2C.h" +#include "wiring_private.h" #include "pcf8591.h" @@ -38,10 +41,20 @@ static void myAnalogWrite (struct wiringPiNodeStruct *node, UNU int pin, int value) { - unsigned char b [2] ; - b [0] = 0x40 ; - b [1] = value & 0xFF ; - write (node->fd, b, 2) ; + unsigned char b[] = { 0x40, (value & 0xFF) }; + ssize_t num_bytes_to_send = (ssize_t)sizeof( b ); + ssize_t num_bytes_sent; + + num_bytes_sent = TEMP_FAILURE_RETRY( write(node->fd, b, num_bytes_to_send) ); + + if( num_bytes_sent == IO_FAIL ) + { + wiringPiFailure( WPI_ALMOST, "pcf8591:myAnalogWrite: %s\n", strerror(errno) ); + } + else if( num_bytes_sent != num_bytes_to_send ) + { + wiringPiFailure( WPI_ALMOST, "pcf8591:myAnalogWrite: sent %d bytes instead of %d", num_bytes_sent, num_bytes_to_send ); + } } @@ -78,7 +91,7 @@ int pcf8591Setup (const int pinBase, const int i2cAddress) struct wiringPiNodeStruct *node ; if ((fd = wiringPiI2CSetup (i2cAddress)) < 0) - return FALSE ; + return false ; node = wiringPiNewNode (pinBase, 4) ; @@ -86,5 +99,5 @@ int pcf8591Setup (const int pinBase, const int i2cAddress) node->analogRead = myAnalogRead ; node->analogWrite = myAnalogWrite ; - return TRUE ; + return true ; } diff --git a/wiringPi/pseudoPins.c b/wiringPi/pseudoPins.c index c2bf5e0..08c004f 100644 --- a/wiringPi/pseudoPins.c +++ b/wiringPi/pseudoPins.c @@ -79,10 +79,10 @@ int pseudoPinsSetup (const int pinBase) node->fd = shm_open (SHARED_NAME, O_CREAT | O_RDWR, 0666) ; if (node->fd < 0) - return FALSE ; + return false ; if (ftruncate (node->fd, PSEUDO_PINS * sizeof (int)) < 0) - return FALSE ; + return false ; ptr = mmap (NULL, PSEUDO_PINS * sizeof (int), PROT_READ | PROT_WRITE, MAP_SHARED, node->fd, 0) ; @@ -91,5 +91,5 @@ int pseudoPinsSetup (const int pinBase) node->analogRead = myAnalogRead ; node->analogWrite = myAnalogWrite ; - return TRUE ; + return true ; } diff --git a/wiringPi/rht03.c b/wiringPi/rht03.c index 1129cfd..34dc9c2 100644 --- a/wiringPi/rht03.c +++ b/wiringPi/rht03.c @@ -51,7 +51,7 @@ static int maxDetectLowHighWait (const int pin) { gettimeofday (&now, NULL) ; if (timercmp (&now, &timeUp, >)) - return FALSE ; + return false ; } // Wait for it to go HIGH @@ -65,10 +65,10 @@ static int maxDetectLowHighWait (const int pin) { gettimeofday (&now, NULL) ; if (timercmp (&now, &timeUp, >)) - return FALSE ; + return false ; } - return TRUE ; + return true ; } @@ -103,7 +103,7 @@ static unsigned int maxDetectClockByte (const int pin) /* * maxDetectRead: * Read in and return the 4 data bytes from the MaxDetect sensor. - * Return TRUE/FALSE depending on the checksum validity + * Return true/false depending on the checksum validity ********************************************************************************* */ @@ -129,7 +129,7 @@ static int maxDetectRead (const int pin, unsigned char buffer [4]) // Now wait for sensor to pull pin low if (!maxDetectLowHighWait (pin)) - return FALSE ; + return false ; // and read in 5 bytes (40 bits) @@ -158,7 +158,7 @@ static int maxDetectRead (const int pin, unsigned char buffer [4]) // reading is probably bogus. if ((took.tv_sec != 0) || (took.tv_usec > 16000)) - return FALSE ; + return false ; return checksum == localBuf [4] ; } @@ -181,7 +181,7 @@ static int myReadRHT03 (const int pin, int *temp, int *rh) result = maxDetectRead (pin, buffer) ; if (!result) - return FALSE ; + return false ; *rh = (buffer [0] * 256 + buffer [1]) ; *temp = (buffer [2] * 256 + buffer [3]) ; @@ -196,9 +196,9 @@ static int myReadRHT03 (const int pin, int *temp, int *rh) // (which does seem to happen - no realtime here) if ((*rh > 999) || (*temp > 800) || (*temp < -400)) - return FALSE ; + return false ; - return TRUE ; + return true ; } @@ -239,7 +239,7 @@ int rht03Setup (const int pinBase, const int piPin) struct wiringPiNodeStruct *node ; if ((piPin & PI_GPIO_MASK) != 0) // Must be an on-board pin - return FALSE ; + return false ; // 2 pins - temperature and humidity @@ -248,5 +248,5 @@ int rht03Setup (const int pinBase, const int piPin) node->fd = piPin ; node->analogRead = myAnalogRead ; - return TRUE ; + return true ; } diff --git a/wiringPi/sn3218.c b/wiringPi/sn3218.c index d9b9113..d623906 100644 --- a/wiringPi/sn3218.c +++ b/wiringPi/sn3218.c @@ -55,7 +55,7 @@ int sn3218Setup (const int pinBase) struct wiringPiNodeStruct *node ; if ((fd = wiringPiI2CSetup (0x54)) < 0) - return FALSE ; + return false ; // Setup the chip - initialise all 18 LEDs to off @@ -71,5 +71,5 @@ int sn3218Setup (const int pinBase) node->fd = fd ; node->analogWrite = myAnalogWrite ; - return TRUE ; + return true ; } diff --git a/wiringPi/sr595.c b/wiringPi/sr595.c index 8280618..002f233 100644 --- a/wiringPi/sr595.c +++ b/wiringPi/sr595.c @@ -105,5 +105,5 @@ int sr595Setup (const int pinBase, const int numPins, pinMode (clockPin, OUTPUT) ; pinMode (latchPin, OUTPUT) ; - return TRUE ; + return true ; } diff --git a/wiringPi/wiringPi.c b/wiringPi/wiringPi.c index 586b148..650fe80 100644 --- a/wiringPi/wiringPi.c +++ b/wiringPi/wiringPi.c @@ -76,6 +76,8 @@ #include "wiringPi.h" #include "../version.h" +#include "wiring_private.h" + // Environment Variables @@ -139,8 +141,8 @@ static volatile unsigned int GPIO_PWM ; #define PAGE_SIZE (4*1024) #define BLOCK_SIZE (4*1024) -static unsigned int usingGpioMem = FALSE ; -static int wiringPiSetuped = FALSE ; +static unsigned int usingGpioMem = false ; +static int wiringPiSetuped = false ; // PWM // Word offsets into the PWM control region @@ -302,12 +304,12 @@ static pthread_mutex_t pinMutex ; // Debugging & Return codes -int wiringPiDebug = FALSE ; -int wiringPiReturnCodes = FALSE ; +int wiringPiDebug = false ; +int wiringPiReturnCodes = false ; // Use /dev/gpiomem ? -int wiringPiTryGpioMem = FALSE ; +int wiringPiTryGpioMem = false ; // sysFds: // Map a file descriptor from the /sys/class/gpio/gpioX/value @@ -642,13 +644,16 @@ static uint8_t gpioToClkDiv [] = ********************************************************************************* */ -int wiringPiFailure (int fatal, const char *message, ...) +//int wiringPiFailure (int fatal, const char *message, ...) +int wiringPiFailure (wpi_fail_t is_fatal, const char *message, ...) { va_list argp ; char buffer [1024] ; - if (!fatal && wiringPiReturnCodes) + if( (is_fatal != WPI_FATAL) && (wiringPiReturnCodes == true) ) + { return -1 ; + } va_start (argp, message) ; vsnprintf (buffer, 1023, message, argp) ; @@ -1305,14 +1310,19 @@ struct wiringPiNodeStruct *wiringPiFindNode (int pin) static void pinModeDummy (UNU struct wiringPiNodeStruct *node, UNU int pin, UNU int mode) { return ; } static void pullUpDnControlDummy (UNU struct wiringPiNodeStruct *node, UNU int pin, UNU int pud) { return ; } + +#if defined (DUMMY_8) static unsigned int digitalRead8Dummy (UNU struct wiringPiNodeStruct *node, UNU int UNU pin) { return 0 ; } static void digitalWrite8Dummy (UNU struct wiringPiNodeStruct *node, UNU int pin, UNU int value) { return ; } +#endif + static int digitalReadDummy (UNU struct wiringPiNodeStruct *node, UNU int UNU pin) { return LOW ; } static void digitalWriteDummy (UNU struct wiringPiNodeStruct *node, UNU int pin, UNU int value) { return ; } static void pwmWriteDummy (UNU struct wiringPiNodeStruct *node, UNU int pin, UNU int value) { return ; } static int analogReadDummy (UNU struct wiringPiNodeStruct *node, UNU int pin) { return 0 ; } static void analogWriteDummy (UNU struct wiringPiNodeStruct *node, UNU int pin, UNU int value) { return ; } + struct wiringPiNodeStruct *wiringPiNewNode (int pinBase, int numPins) { int pin ; @@ -1338,9 +1348,13 @@ struct wiringPiNodeStruct *wiringPiNewNode (int pinBase, int numPins) node->pinMode = pinModeDummy ; node->pullUpDnControl = pullUpDnControlDummy ; node->digitalRead = digitalReadDummy ; -//node->digitalRead8 = digitalRead8Dummy ; +#if defined (DUMMY_8) + node->digitalRead8 = digitalRead8Dummy ; +#endif node->digitalWrite = digitalWriteDummy ; -//node->digitalWrite8 = digitalWrite8Dummy ; +#if defined (DUMMY_8) + node->digitalWrite8 = digitalWrite8Dummy ; +#endif node->pwmWrite = pwmWriteDummy ; node->analogRead = analogReadDummy ; node->analogWrite = analogWriteDummy ; @@ -1505,7 +1519,7 @@ void pullUpDnControl (int pin, int pud) return ; *(gpio + GPPUD) = pud & 3 ; delayMicroseconds (5) ; - *(gpio + gpioToPUDCLK [pin]) = 1 << (pin & 31) ; delayMicroseconds (5) ; + *(gpio + gpioToPUDCLK [pin]) = GPIO_PIN_N_REGISTER_MASK( pin ) ; delayMicroseconds (5) ; *(gpio + GPPUD) = 0 ; delayMicroseconds (5) ; *(gpio + gpioToPUDCLK [pin]) = 0 ; delayMicroseconds (5) ; @@ -1527,38 +1541,63 @@ void pullUpDnControl (int pin, int pud) int digitalRead (int pin) { - char c ; - struct wiringPiNodeStruct *node = wiringPiNodes ; + int pin_value = LOW; if ((pin & PI_GPIO_MASK) == 0) // On-Board Pin { - /**/ if (wiringPiMode == WPI_MODE_GPIO_SYS) // Sys mode + if( wiringPiMode == WPI_MODE_GPIO_SYS ) // Sys mode { - if (sysFds [pin] == -1) - return LOW ; - - lseek (sysFds [pin], 0L, SEEK_SET) ; - read (sysFds [pin], &c, 1) ; - return (c == '0') ? LOW : HIGH ; + if (sysFds [pin] != -1) + { + uint8_t pin_value_char = '0'; + ssize_t num_bytes_read; + + num_bytes_read = pread( sysFds [pin], &pin_value_char, 1, 0 ); + + if( num_bytes_read == IO_FAIL ) + { + wiringPiFailure( WPI_ALMOST, "digitalRead: %s\n", strerror(errno) ); + } + else if( num_bytes_read > 1 ) + { + wiringPiFailure( WPI_FATAL, "digitalRead: read %d bytes instead of 1", num_bytes_read ); + } + + pin_value = (pin_value_char == '0') ? LOW : HIGH ; + } } - else if (wiringPiMode == WPI_MODE_PINS) - pin = pinToGpio [pin] ; - else if (wiringPiMode == WPI_MODE_PHYS) - pin = physToGpio [pin] ; - else if (wiringPiMode != WPI_MODE_GPIO) - return LOW ; + else if( (wiringPiMode == WPI_MODE_PINS) || (wiringPiMode == WPI_MODE_PHYS) || (wiringPiMode == WPI_MODE_GPIO) ) + { + if( wiringPiMode == WPI_MODE_PINS ) + { + pin = pinToGpio [pin] ; // Translate wiringPi pin number to GPIO pin number + } + else if( wiringPiMode == WPI_MODE_PHYS ) // Translate physical pin number to GPIO number + { + pin = physToGpio [pin] ; + } - if ((*(gpio + gpioToGPLEV [pin]) & (1 << (pin & 31))) != 0) - return HIGH ; - else - return LOW ; + if( (*(gpio + gpioToGPLEV [pin]) & GPIO_PIN_N_REGISTER_MASK(pin)) != 0 ) + { + pin_value = HIGH ; + } + else + { + pin_value = LOW ; + } + } } - else + else // "Off-board" pin { - if ((node = wiringPiFindNode (pin)) == NULL) - return LOW ; - return node->digitalRead (node, pin) ; + struct wiringPiNodeStruct *node = wiringPiNodes ; + + if( (node = wiringPiFindNode (pin)) != NULL ) + { + pin_value = node->digitalRead (node, pin) ; + } } + + return pin_value; } @@ -1599,26 +1638,51 @@ void digitalWrite (int pin, int value) { if (sysFds [pin] != -1) { - if (value == LOW) - write (sysFds [pin], "0\n", 2) ; - else - write (sysFds [pin], "1\n", 2) ; + char *val_string; + + if (value == LOW) + { + val_string = "0\n"; + } + else + { + val_string = "1\n"; + } + + // Write value string to device file, excluding terminating NULL + ssize_t num_bytes_sent; + ssize_t num_bytes_to_send = (ssize_t)(sizeof(val_string) - sizeof(char)); + + num_bytes_sent = TEMP_FAILURE_RETRY( write(sysFds [pin], val_string, num_bytes_to_send) ); + + if( num_bytes_sent == IO_FAIL ) + { + wiringPiFailure( WPI_ALMOST, "digitalWrite: %s\n", strerror(errno) ); + } + else if( num_bytes_sent != num_bytes_to_send ) + { + wiringPiFailure( WPI_ALMOST, "digitalWrite: sent %d bytes instead of %d", num_bytes_sent, num_bytes_to_send ); + } + } + } // end if Sys mode + else if( (wiringPiMode == WPI_MODE_PINS) || (wiringPiMode == WPI_MODE_PHYS) || (wiringPiMode == WPI_MODE_GPIO) ) // On-board, not Sys mode + { + if (wiringPiMode == WPI_MODE_PINS) + { + pin = pinToGpio [pin] ; + } + else if (wiringPiMode == WPI_MODE_PHYS) + { + pin = physToGpio [pin] ; } - return ; - } - else if (wiringPiMode == WPI_MODE_PINS) - pin = pinToGpio [pin] ; - else if (wiringPiMode == WPI_MODE_PHYS) - pin = physToGpio [pin] ; - else if (wiringPiMode != WPI_MODE_GPIO) - return ; - if (value == LOW) - *(gpio + gpioToGPCLR [pin]) = 1 << (pin & 31) ; - else - *(gpio + gpioToGPSET [pin]) = 1 << (pin & 31) ; - } - else + if (value == LOW) + *(gpio + gpioToGPCLR [pin]) = GPIO_PIN_N_REGISTER_MASK( pin ) ; + else + *(gpio + gpioToGPSET [pin]) = GPIO_PIN_N_REGISTER_MASK( pin ) ; + } // end if not Sys mode + } // end if On-board pin + else // "Off-board" pin { if ((node = wiringPiFindNode (pin)) != NULL) node->digitalWrite (node, pin, value) ; @@ -1880,9 +1944,7 @@ unsigned int digitalReadByte2 (void) int waitForInterrupt (int pin, int mS) { - int fd, x ; - uint8_t c ; - struct pollfd polls ; + int fd, x = 0 ; /**/ if (wiringPiMode == WPI_MODE_PINS) pin = pinToGpio [pin] ; @@ -1890,9 +1952,10 @@ int waitForInterrupt (int pin, int mS) pin = physToGpio [pin] ; if ((fd = sysFds [pin]) == -1) - return -2 ; + return PIN_NOT_CONFIGURED ; // Setup poll structure + struct pollfd polls ; polls.fd = fd ; polls.events = POLLPRI | POLLERR ; @@ -1906,8 +1969,12 @@ int waitForInterrupt (int pin, int mS) if (x > 0) { - lseek (fd, 0, SEEK_SET) ; // Rewind - (void)read (fd, &c, 1) ; // Read & clear + uint8_t c ; + + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wunused-result" + pread( fd, &c, sizeof(c), 0 ); // If an error occurs, should result really be ignored? + #pragma GCC diagnostic pop } return x ; @@ -1955,7 +2022,6 @@ int wiringPiISR (int pin, int mode, void (*function)(void)) char pinS [8] ; pid_t pid ; int count, i ; - char c ; int bcmGpioPin ; if ((pin < 0) || (pin > 63)) @@ -2023,7 +2089,14 @@ int wiringPiISR (int pin, int mode, void (*function)(void)) ioctl (sysFds [bcmGpioPin], FIONREAD, &count) ; for (i = 0 ; i < count ; ++i) - read (sysFds [bcmGpioPin], &c, 1) ; + { + uint8_t c ; + + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wunused-result" + pread( sysFds [bcmGpioPin], &c, sizeof(c), 0 ); // If an error occurs, should result really be ignored? + #pragma GCC diagnostic pop + } isrFunctions [pin] = function ; @@ -2220,13 +2293,13 @@ int wiringPiSetup (void) if (wiringPiSetuped) return 0 ; - wiringPiSetuped = TRUE ; + wiringPiSetuped = true ; if (getenv (ENV_DEBUG) != NULL) - wiringPiDebug = TRUE ; + wiringPiDebug = true ; if (getenv (ENV_CODES) != NULL) - wiringPiReturnCodes = TRUE ; + wiringPiReturnCodes = true ; if (wiringPiDebug) printf ("wiringPi: wiringPiSetup called\n") ; @@ -2281,7 +2354,7 @@ int wiringPiSetup (void) if ((fd = open ("/dev/gpiomem", O_RDWR | O_SYNC | O_CLOEXEC) ) >= 0) // We're using gpiomem { piGpioBase = 0 ; - usingGpioMem = TRUE ; + usingGpioMem = true ; } else return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: Unable to open /dev/mem or /dev/gpiomem: %s.\n" @@ -2413,13 +2486,13 @@ int wiringPiSetupSys (void) if (wiringPiSetuped) return 0 ; - wiringPiSetuped = TRUE ; + wiringPiSetuped = true ; if (getenv (ENV_DEBUG) != NULL) - wiringPiDebug = TRUE ; + wiringPiDebug = true ; if (getenv (ENV_CODES) != NULL) - wiringPiReturnCodes = TRUE ; + wiringPiReturnCodes = true ; if (wiringPiDebug) printf ("wiringPi: wiringPiSetupSys called\n") ; diff --git a/wiringPi/wiringPi.h b/wiringPi/wiringPi.h index ae5d647..a8fe121 100644 --- a/wiringPi/wiringPi.h +++ b/wiringPi/wiringPi.h @@ -24,14 +24,18 @@ #ifndef __WIRING_PI_H__ #define __WIRING_PI_H__ +/* // C doesn't have true/false by default and I can never remember which // way round they are, so ... // (and yes, I know about stdbool.h but I like capitals for these and I'm old) -#ifndef TRUE -# define TRUE (1==1) -# define FALSE (!TRUE) -#endif +#ifndef true +# define true (1==1) +# define false (!true) +#endif +*/ +#include // "True today, false tomorrow": C has boolean data types and "true"/"false" as of C11 + // GCC warning suppressor @@ -125,8 +129,14 @@ extern const int piMemorySize [ 8] ; // Failure modes -#define WPI_FATAL (1==1) -#define WPI_ALMOST (1==2) +typedef enum { + WPI_ALMOST = 0, + WPI_FATAL = 1 +} wpi_fail_t; +//#define WPI_FATAL (1==1) +//#define WPI_ALMOST (1==2) + +enum { PIN_NOT_CONFIGURED = -2 }; // wiringPiNodeStruct: @@ -185,7 +195,7 @@ extern "C" { // Internal -extern int wiringPiFailure (int fatal, const char *message, ...) ; +extern int wiringPiFailure (wpi_fail_t fatal, const char *message, ...) ; // Core wiringPi functions diff --git a/wiringPi/wiringSerial.c b/wiringPi/wiringSerial.c index e1587ad..d544d18 100644 --- a/wiringPi/wiringSerial.c +++ b/wiringPi/wiringSerial.c @@ -28,11 +28,15 @@ #include #include #include +#include #include #include #include +#include "wiringPi.h" #include "wiringSerial.h" +#include "wiring_private.h" + /* * serialOpen: @@ -155,7 +159,18 @@ void serialClose (const int fd) void serialPutchar (const int fd, const unsigned char c) { - write (fd, &c, 1) ; + ssize_t num_bytes_sent; + + num_bytes_sent = TEMP_FAILURE_RETRY( write(fd, &c, NUM_BYTES_PER_CHAR) ); + + if( num_bytes_sent == IO_FAIL ) + { + wiringPiFailure( WPI_ALMOST, "serialPutchar: %s\n", strerror(errno) ); + } + else if( num_bytes_sent != NUM_BYTES_PER_CHAR ) + { + wiringPiFailure( WPI_ALMOST, "serialPutchar: sent %d bytes instead of %d", num_bytes_sent, NUM_BYTES_PER_CHAR ); + } } @@ -167,7 +182,19 @@ void serialPutchar (const int fd, const unsigned char c) void serialPuts (const int fd, const char *s) { - write (fd, s, strlen (s)) ; + ssize_t num_char_to_send = (ssize_t)strlen( s ); + ssize_t num_bytes_sent; + + num_bytes_sent = TEMP_FAILURE_RETRY( write(fd, s, num_char_to_send) ); + + if( num_bytes_sent == IO_FAIL ) + { + wiringPiFailure( WPI_ALMOST, "serialPuts: %s\n", strerror(errno) ); + } + else if( num_bytes_sent != num_char_to_send ) + { + wiringPiFailure( WPI_ALMOST, "serialPuts: sent %d bytes instead of %d", num_bytes_sent, num_char_to_send ); + } } /* diff --git a/wiringPi/wpiExtensions.c b/wiringPi/wpiExtensions.c index bef126f..bde801e 100644 --- a/wiringPi/wpiExtensions.c +++ b/wiringPi/wpiExtensions.c @@ -146,7 +146,7 @@ static char *extractInt (char *progName, char *p, int *num) static char *extractStr (char *progName, char *p, char **str) { char *q, *r ; - int quoted = FALSE ; + int quoted = false ; if (*p != ':') { @@ -158,7 +158,7 @@ static char *extractStr (char *progName, char *p, char **str) if (*p == '[') { - quoted = TRUE ; + quoted = true ; ++p ; } @@ -205,17 +205,17 @@ static int doExtensionMcp23008 (char *progName, int pinBase, char *params) int i2c ; if ((params = extractInt (progName, params, &i2c)) == NULL) - return FALSE ; + return false ; if ((i2c < 0x01) || (i2c > 0x77)) { verbError ("%s: i2c address (0x%X) out of range", progName, i2c) ; - return FALSE ; + return false ; } mcp23008Setup (pinBase, i2c) ; - return TRUE ; + return true ; } @@ -231,17 +231,17 @@ static int doExtensionMcp23016 (char *progName, int pinBase, char *params) int i2c ; if ((params = extractInt (progName, params, &i2c)) == NULL) - return FALSE ; + return false ; if ((i2c < 0x03) || (i2c > 0x77)) { verbError ("%s: i2c address (0x%X) out of range", progName, i2c) ; - return FALSE ; + return false ; } mcp23016Setup (pinBase, i2c) ; - return TRUE ; + return true ; } @@ -257,17 +257,17 @@ static int doExtensionMcp23017 (char *progName, int pinBase, char *params) int i2c ; if ((params = extractInt (progName, params, &i2c)) == NULL) - return FALSE ; + return false ; if ((i2c < 0x03) || (i2c > 0x77)) { verbError ("%s: i2c address (0x%X) out of range", progName, i2c) ; - return FALSE ; + return false ; } mcp23017Setup (pinBase, i2c) ; - return TRUE ; + return true ; } @@ -283,26 +283,26 @@ static int doExtensionMcp23s08 (char *progName, int pinBase, char *params) int spi, port ; if ((params = extractInt (progName, params, &spi)) == NULL) - return FALSE ; + return false ; if ((spi < 0) || (spi > 1)) { verbError ("%s: SPI address (%d) out of range", progName, spi) ; - return FALSE ; + return false ; } if ((params = extractInt (progName, params, &port)) == NULL) - return FALSE ; + return false ; if ((port < 0) || (port > 7)) { verbError ("%s: port address (%d) out of range", progName, port) ; - return FALSE ; + return false ; } mcp23s08Setup (pinBase, spi, port) ; - return TRUE ; + return true ; } @@ -318,26 +318,26 @@ static int doExtensionMcp23s17 (char *progName, int pinBase, char *params) int spi, port ; if ((params = extractInt (progName, params, &spi)) == NULL) - return FALSE ; + return false ; if ((spi < 0) || (spi > 1)) { verbError ("%s: SPI address (%d) out of range", progName, spi) ; - return FALSE ; + return false ; } if ((params = extractInt (progName, params, &port)) == NULL) - return FALSE ; + return false ; if ((port < 0) || (port > 7)) { verbError ("%s: port address (%d) out of range", progName, port) ; - return FALSE ; + return false ; } mcp23s17Setup (pinBase, spi, port) ; - return TRUE ; + return true ; } @@ -355,26 +355,26 @@ static int doExtensionSr595 (char *progName, int pinBase, char *params) // Extract pins if ((params = extractInt (progName, params, &pins)) == NULL) - return FALSE ; + return false ; if ((pins < 8) || (pins > 32)) { verbError ("%s: pin count (%d) out of range - 8-32 expected.", progName, pins) ; - return FALSE ; + return false ; } if ((params = extractInt (progName, params, &data)) == NULL) - return FALSE ; + return false ; if ((params = extractInt (progName, params, &clock)) == NULL) - return FALSE ; + return false ; if ((params = extractInt (progName, params, &latch)) == NULL) - return FALSE ; + return false ; sr595Setup (pinBase, pins, data, clock, latch) ; - return TRUE ; + return true ; } @@ -390,17 +390,17 @@ static int doExtensionPcf8574 (char *progName, int pinBase, char *params) int i2c ; if ((params = extractInt (progName, params, &i2c)) == NULL) - return FALSE ; + return false ; if ((i2c < 0x03) || (i2c > 0x77)) { verbError ("%s: i2c address (0x%X) out of range", progName, i2c) ; - return FALSE ; + return false ; } pcf8574Setup (pinBase, i2c) ; - return TRUE ; + return true ; } @@ -416,17 +416,17 @@ static int doExtensionAds1115 (char *progName, int pinBase, char *params) int i2c ; if ((params = extractInt (progName, params, &i2c)) == NULL) - return FALSE ; + return false ; if ((i2c < 0x03) || (i2c > 0x77)) { verbError ("%s: i2c address (0x%X) out of range", progName, i2c) ; - return FALSE ; + return false ; } ads1115Setup (pinBase, i2c) ; - return TRUE ; + return true ; } @@ -442,17 +442,17 @@ static int doExtensionPcf8591 (char *progName, int pinBase, char *params) int i2c ; if ((params = extractInt (progName, params, &i2c)) == NULL) - return FALSE ; + return false ; if ((i2c < 0x03) || (i2c > 0x77)) { verbError ("%s: i2c address (0x%X) out of range", progName, i2c) ; - return FALSE ; + return false ; } pcf8591Setup (pinBase, i2c) ; - return TRUE ; + return true ; } @@ -467,7 +467,7 @@ static int doExtensionPseudoPins (UNU char *progName, int pinBase, UNU char *par { pseudoPinsSetup (pinBase) ; - return TRUE ; + return true ; } @@ -482,7 +482,7 @@ static int doExtensionBmp180 (UNU char *progName, int pinBase, UNU char *params) { bmp180Setup (pinBase) ; - return TRUE ; + return true ; } @@ -497,7 +497,7 @@ static int doExtensionHtu21d (UNU char *progName, int pinBase, UNU char *params) { htu21dSetup (pinBase) ; - return TRUE ; + return true ; } @@ -513,7 +513,7 @@ static int doExtensionDs18b20 (char *progName, int pinBase, char *params) char *serialNum ; if ((params = extractStr (progName, params, &serialNum)) == NULL) - return FALSE ; + return false ; return ds18b20Setup (pinBase, serialNum) ; } @@ -531,7 +531,7 @@ static int doExtensionRht03 (char *progName, int pinBase, char *params) int piPin ; if ((params = extractInt (progName, params, &piPin)) == NULL) - return FALSE ; + return false ; return rht03Setup (pinBase, piPin) ; } @@ -549,17 +549,17 @@ static int doExtensionMax31855 (char *progName, int pinBase, char *params) int spi ; if ((params = extractInt (progName, params, &spi)) == NULL) - return FALSE ; + return false ; if ((spi < 0) || (spi > 1)) { verbError ("%s: SPI channel (%d) out of range", progName, spi) ; - return FALSE ; + return false ; } max31855Setup (pinBase, spi) ; - return TRUE ; + return true ; } @@ -575,17 +575,17 @@ static int doExtensionMcp3002 (char *progName, int pinBase, char *params) int spi ; if ((params = extractInt (progName, params, &spi)) == NULL) - return FALSE ; + return false ; if ((spi < 0) || (spi > 1)) { verbError ("%s: SPI channel (%d) out of range", progName, spi) ; - return FALSE ; + return false ; } mcp3002Setup (pinBase, spi) ; - return TRUE ; + return true ; } @@ -601,17 +601,17 @@ static int doExtensionMcp3004 (char *progName, int pinBase, char *params) int spi ; if ((params = extractInt (progName, params, &spi)) == NULL) - return FALSE ; + return false ; if ((spi < 0) || (spi > 1)) { verbError ("%s: SPI channel (%d) out of range", progName, spi) ; - return FALSE ; + return false ; } mcp3004Setup (pinBase, spi) ; - return TRUE ; + return true ; } @@ -627,17 +627,17 @@ static int doExtensionMax5322 (char *progName, int pinBase, char *params) int spi ; if ((params = extractInt (progName, params, &spi)) == NULL) - return FALSE ; + return false ; if ((spi < 0) || (spi > 1)) { verbError ("%s: SPI channel (%d) out of range", progName, spi) ; - return FALSE ; + return false ; } max5322Setup (pinBase, spi) ; - return TRUE ; + return true ; } @@ -653,17 +653,17 @@ static int doExtensionMcp4802 (char *progName, int pinBase, char *params) int spi ; if ((params = extractInt (progName, params, &spi)) == NULL) - return FALSE ; + return false ; if ((spi < 0) || (spi > 1)) { verbError ("%s: SPI channel (%d) out of range", progName, spi) ; - return FALSE ; + return false ; } mcp4802Setup (pinBase, spi) ; - return TRUE ; + return true ; } @@ -677,7 +677,7 @@ static int doExtensionMcp4802 (char *progName, int pinBase, char *params) static int doExtensionSn3218 (UNU char *progName, int pinBase, UNU char *params) { sn3218Setup (pinBase) ; - return TRUE ; + return true ; } @@ -693,35 +693,35 @@ static int doExtensionMcp3422 (char *progName, int pinBase, char *params) int i2c, sampleRate, gain ; if ((params = extractInt (progName, params, &i2c)) == NULL) - return FALSE ; + return false ; if ((i2c < 0x03) || (i2c > 0x77)) { verbError ("%s: i2c address (0x%X) out of range", progName, i2c) ; - return FALSE ; + return false ; } if ((params = extractInt (progName, params, &sampleRate)) == NULL) - return FALSE ; + return false ; if ((sampleRate < 0) || (sampleRate > 3)) { verbError ("%s: sample rate (%d) out of range", progName, sampleRate) ; - return FALSE ; + return false ; } if ((params = extractInt (progName, params, &gain)) == NULL) - return FALSE ; + return false ; if ((gain < 0) || (gain > 3)) { verbError ("%s: gain (%d) out of range", progName, gain) ; - return FALSE ; + return false ; } mcp3422Setup (pinBase, i2c, sampleRate, gain) ; - return TRUE ; + return true ; } @@ -738,35 +738,35 @@ static int doExtensionDrcS (char *progName, int pinBase, char *params) int pins, baud ; if ((params = extractInt (progName, params, &pins)) == NULL) - return FALSE ; + return false ; if ((pins < 1) || (pins > 1000)) { verbError ("%s: pins (%d) out of range (2-1000)", progName, pins) ; - return FALSE ; + return false ; } if ((params = extractStr (progName, params, &port)) == NULL) - return FALSE ; + return false ; if (strlen (port) == 0) { verbError ("%s: serial port device name required", progName) ; - return FALSE ; + return false ; } if ((params = extractInt (progName, params, &baud)) == NULL) - return FALSE ; + return false ; if ((baud < 1) || (baud > 4000000)) { verbError ("%s: baud rate (%d) out of range", progName, baud) ; - return FALSE ; + return false ; } drcSetupSerial (pinBase, pins, port, baud) ; - return TRUE ; + return true ; } @@ -784,25 +784,25 @@ static int doExtensionDrcNet (char *progName, int pinBase, char *params) char pPort [1024] ; if ((params = extractInt (progName, params, &pins)) == NULL) - return FALSE ; + return false ; if ((pins < 1) || (pins > 1000)) { verbError ("%s: pins (%d) out of range (2-1000)", progName, pins) ; - return FALSE ; + return false ; } if ((params = extractStr (progName, params, &ipAddress)) == NULL) - return FALSE ; + return false ; if (strlen (ipAddress) == 0) { verbError ("%s: ipAddress required", progName) ; - return FALSE ; + return false ; } if ((params = extractStr (progName, params, &port)) == NULL) - return FALSE ; + return false ; if (strlen (port) == 0) { @@ -811,12 +811,12 @@ static int doExtensionDrcNet (char *progName, int pinBase, char *params) } if ((params = extractStr (progName, params, &password)) == NULL) - return FALSE ; + return false ; if (strlen (password) == 0) { verbError ("%s: password required", progName) ; - return FALSE ; + return false ; } return drcSetupNet (pinBase, pins, ipAddress, port, password) ; @@ -883,7 +883,7 @@ int loadWPiExtension (char *progName, char *extensionData, int printErrors) if (!*p) // ran out of characters { verbError ("%s: extension name not terminated by a colon", progName) ; - return FALSE ; + return false ; } ++p ; } @@ -894,7 +894,7 @@ int loadWPiExtension (char *progName, char *extensionData, int printErrors) if (!isdigit (*p)) { verbError ("%s: decimal pinBase number expected after extension name", progName) ; - return FALSE ; + return false ; } while (isdigit (*p)) @@ -902,7 +902,7 @@ int loadWPiExtension (char *progName, char *extensionData, int printErrors) if (pinBase > 2147483647) // 2^31-1 ... Lets be realistic here... { verbError ("%s: pinBase too large", progName) ; - return FALSE ; + return false ; } pinBase = pinBase * 10 + (*p - '0') ; @@ -912,7 +912,7 @@ int loadWPiExtension (char *progName, char *extensionData, int printErrors) if (pinBase < 64) { verbError ("%s: pinBase (%d) too small. Minimum is 64.", progName, pinBase) ; - return FALSE ; + return false ; } // Search for extensions: @@ -924,5 +924,5 @@ int loadWPiExtension (char *progName, char *extensionData, int printErrors) } fprintf (stderr, "%s: extension %s not found", progName, extension) ; - return FALSE ; + return false ; } diff --git a/wiringPiD/network.c b/wiringPiD/network.c index 9f6bb88..1c870e7 100644 --- a/wiringPiD/network.c +++ b/wiringPiD/network.c @@ -36,8 +36,8 @@ #include "network.h" -#define TRUE (1==1) -#define FALSE (!TRUE) +#define true (1==1) +#define false (!true) // Local data diff --git a/wiringPiD/runRemote.c b/wiringPiD/runRemote.c index cd7432b..f225226 100644 --- a/wiringPiD/runRemote.c +++ b/wiringPiD/runRemote.c @@ -40,7 +40,7 @@ -int noLocalPins = FALSE ; +int noLocalPins = false ; void runRemoteCommands (int fd) diff --git a/wiringPiD/wiringpid.c b/wiringPiD/wiringpid.c index 8dde1cd..3df3f28 100644 --- a/wiringPiD/wiringpid.c +++ b/wiringPiD/wiringpid.c @@ -46,7 +46,7 @@ // Globals static const char *usage = "[-h] [-d] [-g | -1 | -z] [[-x extension:pin:params] ...] password" ; -static int doDaemon = FALSE ; +static int doDaemon = false ; // @@ -156,7 +156,7 @@ int main (int argc, char *argv []) exit (EXIT_FAILURE) ; } - doDaemon = TRUE ; + doDaemon = true ; daemonise (PIDFILE) ; for (i = 2 ; i < argc ; ++i) @@ -216,7 +216,7 @@ int main (int argc, char *argv []) for (i = 2 ; i < argc ; ++i) argv [i - 1] = argv [i] ; --argc ; - noLocalPins = TRUE ; + noLocalPins = true ; ++wpiSetup ; continue ; } @@ -263,7 +263,7 @@ int main (int argc, char *argv []) logMsg ("Loading extension: %s", argv [2]) ; - if (!loadWPiExtension (argv [0], argv [2], TRUE)) + if (!loadWPiExtension (argv [0], argv [2], true)) { logMsg ("Extension load failed: %s", strerror (errno)) ; exit (EXIT_FAILURE) ;