chiark / gitweb /
Fixed the requirement for -lm
authorGordon Henderson <projects@drogon.net>
Thu, 24 Sep 2015 21:35:31 +0000 (22:35 +0100)
committerGordon Henderson <projects@drogon.net>
Thu, 24 Sep 2015 21:35:31 +0000 (22:35 +0100)
Updated the gpio program to be device tree aware.

VERSION
debian-template/wiringPi/DEBIAN/control
examples/Makefile
examples/PiGlow/Makefile
examples/max31855.c [new file with mode: 0644]
gpio/gpio.1
gpio/gpio.c
gpio/version.h
wiringPi/max31855.c

diff --git a/VERSION b/VERSION
index 7dba3a2df987d22219f287f6c6eca4ae5d0c44d5..410158ac6db4cffce76ff93122ccd007fb6e74a9 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-2.27
+2.28
index 2a65ff514ade5605cefaa6292dd28a461da2029d..9def8c5c955d01f38ae95885e5af9ca03b2c0125 100644 (file)
@@ -1,5 +1,5 @@
 Package: wiringpi
-Version: 2.27
+Version: 2.28
 Section: libraries
 Priority: optional
 Architecture: armhf
index 60659f5b90951331a89928b958c0855a2df63f96..04bcaecacf2832f8e1d5a9575c175e3883121ae1 100644 (file)
@@ -3,7 +3,7 @@
 #      wiringPi - Wiring Compatable library for the Raspberry Pi
 #      https://projects.drogon.net/wiring-pi
 #
-#      Copyright (c) 2012 Gordon Henderson
+#      Copyright (c) 2012-2015 Gordon Henderson
 #################################################################################
 # This file is part of wiringPi:
 #      Wiring Compatable library for the Raspberry Pi
@@ -47,7 +47,8 @@ SRC   =       blink.c blink8.c blink12.c                                      \
                softPwm.c softTone.c                                            \
                delayTest.c serialRead.c serialTest.c okLed.c ds1302.c          \
                lowPower.c                                                      \
-               rht03.c piglow.c
+               max31855.c                                                      \
+               rht03.c
 
 OBJ    =       $(SRC:.c=.o)
 
@@ -148,10 +149,9 @@ ds1302:    ds1302.o
        $Q echo [link]
        $Q $(CC) -o $@ ds1302.o $(LDFLAGS) $(LDLIBS)
 
-piglow:        piglow.o
+max31855:      max31855.o
        $Q echo [link]
-       $Q $(CC) -o $@ piglow.o $(LDFLAGS) $(LDLIBS)
-
+       $Q $(CC) -o $@ max31855.c.o $(LDFLAGS) $(LDLIBS)
 
 .c.o:
        $Q echo [CC] $<
index b7a8595bd7491c13429959729a74f9038208beb8..acd4818fe715d39d3c180dffed14ebd5e7464261 100644 (file)
@@ -3,7 +3,7 @@
 #      wiringPi - Wiring Compatable library for the Raspberry Pi
 #      https://projects.drogon.net/wiring-pi
 #
-#      Copyright (c) 2012-2013 Gordon Henderson
+#      Copyright (c) 2012-2015 Gordon Henderson
 #################################################################################
 # This file is part of wiringPi:
 #      Wiring Compatable library for the Raspberry Pi
diff --git a/examples/max31855.c b/examples/max31855.c
new file mode 100644 (file)
index 0000000..2060a55
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * max31855.c:
+ *     SPI Thermocouple interface chip
+ *
+ * Copyright (c) 2015 Gordon Henderson.
+ ***********************************************************************
+ * This file is part of wiringPi:
+ *     https://projects.drogon.net/raspberry-pi/wiringpi/
+ *
+ *    wiringPi is free software: you can redistribute it and/or modify
+ *    it under the terms of the GNU Lesser General Public License as published by
+ *    the Free Software Foundation, either version 3 of the License, or
+ *    (at your option) any later version.
+ *
+ *    wiringPi is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU Lesser General Public License for more details.
+ *
+ *    You should have received a copy of the GNU Lesser General Public License
+ *    along with wiringPi.  If not, see <http://www.gnu.org/licenses/>.
+ ***********************************************************************
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <time.h>
+
+#include <wiringPi.h>
+#include <max31855.h>
+
+int main (int argc, char *argv [])
+{
+  int i ;
+
+  wiringPiSetup () ;
+  max31855Setup (200, 0) ;
+  max31855Setup (400, 1) ;
+
+  for (;;)
+  {
+    printf ("%6d, %6d, %6d, %6d ::::", analogRead (200), analogRead (201), analogRead (202), analogRead (203)) ;
+    printf ("%6d, %6d, %6d, %6d\n", analogRead (400), analogRead (401), analogRead (402), analogRead (403)) ;
+    delay (500) ;
+  }
+
+}
index 8949442b6e1c99acf2b934e331c3860e8f0134c9..673ebbe2c8db2c2d215fee702db2fd4ec223825f 100644 (file)
@@ -1,4 +1,4 @@
-.TH gpio 1 "January 2015" wiringPi "Command-Line access to Raspberry Pi's GPIO"
+.TH GPIO 1 "September 2015" wiringPi "Command-Line access to Raspberry Pi's GPIO"
 
 .SH NAME
 gpio \- Command-line access to Raspberry Pi's GPIO
@@ -251,12 +251,9 @@ on the associated /dev/ entries so that the current user has access to
 them. Optionally it will set the I2C baudrate to that supplied in Kb/sec
 (or as close as the Pi can manage) The default speed is 100Kb/sec.
 
-Note that on a Pi with a recent 3.18 kernel with the device-tree structure
-enable, the load may fail until you add:
-
-.I dtparam=i2c=on
-
-into \fB/boot/config.txt\fR to allow user use of the I2C bus.
+Note: On recent kernels with the device tree enabled you should use the
+raspi-config program to load/unload the I2C device at boot time.
+(or disable the device tree to continue to use this method)
 
 .TP
 .B load spi
@@ -269,12 +266,9 @@ this has fixed the buffer size. The way to change it now is to edit
 the /boot/cmdline.txt file and add on spdev.bufsiz=8192 to set it to
 e.g. 8192 bytes then reboot.
 
-Note that on a Pi with a recent 3.18 kernel with the device-tree structure
-enable, the load may fail until you add:
-
-.I dtparam=spi=on
-
-into \fB/boot/config.txt\fR to allow user use of the I2C bus.
+Note: On recent kernels with the device tree enabled you should use the
+raspi-config program to load/unload the SPI device at boot time.
+(or disable the device tree to continue to use this method)
 
 .TP
 .B gbr
index a25f45432d94b5f3c1db9d5e6eeba5cc246a1f5d..5c87a7e16ee09545945f2e9615b6d4fd18ae5c7b 100644 (file)
@@ -116,7 +116,7 @@ static void changeOwner (char *cmd, char *file)
   if (chown (file, uid, gid) != 0)
   {
     if (errno == ENOENT)       // Warn that it's not there
-      fprintf (stderr, "%s: Warning (not an error): File not present: %s\n", cmd, file) ;
+      fprintf (stderr, "%s: Warning (not an error, do not report): File not present: %s\n", cmd, file) ;
     else
       fprintf (stderr, "%s: Warning (not an error): Unable to change ownership of %s: %s\n", cmd, file, strerror (errno)) ;
   }
@@ -163,6 +163,22 @@ static int moduleLoaded (char *modName)
  *********************************************************************************
  */
 
+static void checkDevTree (char *argv [])
+{
+  struct stat statBuf ;
+
+  if (stat ("/proc/device-tree", &statBuf) == 0)       // We're on a devtree system ...
+  {
+    fprintf (stderr,
+"%s: Unable to load/unload modules as this Pi has the device tree enabled.\n"
+"  You need to run the raspi-config program (as root) and select the\n"
+"  modules (SPI or I2C) that you wish to load/unload there and reboot.\n"
+"  There is more information here:\n"
+"      https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=97314\n", argv [0]) ;
+    exit (1) ;
+  }
+}
+
 static void _doLoadUsage (char *argv [])
 {
   fprintf (stderr, "Usage: %s load <spi/i2c> [I2C baudrate in Kb/sec]\n", argv [0]) ;
@@ -176,6 +192,8 @@ static void doLoad (int argc, char *argv [])
   char *file1, *file2 ;
   char args1 [32], args2 [32] ;
 
+  checkDevTree (argv) ;
+
   if (argc < 3)
     _doLoadUsage (argv) ;
 
@@ -251,6 +269,8 @@ static void doUnLoad (int argc, char *argv [])
   char *module1, *module2 ;
   char cmd [80] ;
 
+  checkDevTree (argv) ;
+
   if (argc != 3)
     _doUnLoadUsage (argv) ;
 
@@ -1138,6 +1158,8 @@ int main (int argc, char *argv [])
 {
   int i ;
   int model, rev, mem, maker, overVolted ;
+  struct stat statBuf ;
+
 
   if (getenv ("WIRINGPI_DEBUG") != NULL)
   {
@@ -1195,15 +1217,15 @@ int main (int argc, char *argv [])
       printf ("  Type: %s, Revision: %s, Memory: %dMB, Maker: %s %s\n", 
          piModelNames [model], piRevisionNames [rev], mem, piMakerNames [maker], overVolted ? "[OV]" : "") ;
 
-// Quick check for /dev/gpiomem
+// Check for device tree
+
+      if (stat ("/proc/device-tree", &statBuf) == 0)   // We're on a devtree system ...
+       printf ("  Device tree is enabled.\n") ;
 
-      if ((i = open ("/dev/gpiomem", O_RDWR | O_SYNC | O_CLOEXEC) ) >= 0)
-       printf ("  This Raspberry Pi supports user-level GPIO access via /dev/gpiomem.\n") ;
+      if (stat ("/dev/gpiomem", &statBuf) == 0)                // User level GPIO is GO
+       printf ("  This Raspberry Pi supports user-level GPIO access.\n") ;
       else
-      {
-       printf ("  You need to run your programs as root for GPIO access\n") ;
-       printf ("  (Old /dev/mem method - consider upgrading)\n") ;
-      }
+       printf ("  * Root or sudo required for GPIO access.\n") ;
       
     }
     return 0 ;
index ac80bc5a377aa4f77b1181824ed88b4ab299be13..704c10dfbd35e6267bf8e2d1f08e3af4404f724e 100644 (file)
@@ -1 +1 @@
-#define VERSION "2.27"
+#define VERSION "2.28"
index 702d7c03226c95dea85634e3cb10a21308b036d8..ea184d8fd770ab788b9a53d4f5274a6aa2254d08 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * max31855.c:
  *     Extend wiringPi with the max31855 SPI Analog to Digital convertor
- *     Copyright (c) 2012-2013 Gordon Henderson
+ *     Copyright (c) 2012-2015 Gordon Henderson
  ***********************************************************************
  * This file is part of wiringPi:
  *     https://projects.drogon.net/raspberry-pi/wiringpi/
@@ -24,7 +24,6 @@
 
 #include <byteswap.h>
 #include <stdint.h>
-#include <math.h>
 
 #include <wiringPi.h>
 #include <wiringPiSPI.h>
@@ -60,7 +59,7 @@ static int myAnalogRead (struct wiringPiNodeStruct *node, int pin)
       if ((spiData & 0x2000) != 0)     // Negative
         temp = -temp ;
 
-      return (int)rint ((double)temp * 2.5) ;
+      return (int)((((double)temp * 25) + 0.5) / 10.0) ;
 
     case 3:                            // Return temp in F * 10
       spiData >>= 18 ;
@@ -68,7 +67,7 @@ static int myAnalogRead (struct wiringPiNodeStruct *node, int pin)
       if ((spiData & 0x2000) != 0)     // Negative
         temp = -temp ;
 
-      return (int)rint ((((double)temp * 0.25 * 9.0 / 5.0) + 32.0) * 10.0) ;
+      return (int)((((((double)temp * 0.25 * 9.0 / 5.0) + 32.0) * 100.0) + 0.5) / 10.0) ;
 
     default:                           // Who knows...
       return 0 ;