chiark / gitweb /
gpio Makefile changed to add PREFIX & DESTDIR
authorGordon Henderson <projects@drogon.net>
Sun, 14 Jul 2013 11:28:12 +0000 (12:28 +0100)
committerGordon Henderson <projects@drogon.net>
Sun, 14 Jul 2013 11:28:12 +0000 (12:28 +0100)
mcp3004.c bugfixed. It works now!

gpio/Makefile
wiringPi/mcp3004.c

index 883bfc25da918eacd099955031cc5193677deca2..b4519fafa7fd8ab9eb7a5e5a0bb22de99b72b25d 100644 (file)
 #    along with wiringPi.  If not, see <http://www.gnu.org/licenses/>.
 #################################################################################
 
+DESTDIR=/usr
+PREFIX=/local
 
 #DEBUG = -g -O0
 DEBUG  = -O2
 CC     = gcc
-INCLUDE        = -I/usr/local/include
+INCLUDE        = -I$(DESTDIR)$(PREFIX)/usr/local/include
 CFLAGS = $(DEBUG) -Wall $(INCLUDE) -Winline -pipe
 
-LDFLAGS        = -L/usr/local/lib
+LDFLAGS        = -L$(DESTDIR)$(PREFIX)/lib
 LIBS    = -lwiringPi -lwiringPiDev -lpthread -lm
 
 # May not need to  alter anything below this line
@@ -62,17 +64,17 @@ tags:       $(SRC)
 .PHONEY:       install
 install:
        @echo "[Install]"
-       @cp gpio /usr/local/bin
-       @chown root.root /usr/local/bin/gpio
-       @chmod 4755 /usr/local/bin/gpio
-       @mkdir -p /usr/local/man/man1
-       @cp gpio.1 /usr/local/man/man1
+       @cp gpio                $(DESTDIR)$(PREFIX)/bin
+       @chown root.root        $(DESTDIR)$(PREFIX)/bin/gpio
+       @chmod 4755             $(DESTDIR)$(PREFIX)/bin/gpio
+       @mkdir -p               $(DESTDIR)$(PREFIX)/man/man1
+       @cp gpio.1              $(DESTDIR)$(PREFIX)/man/man1
 
 .PHONEY:       uninstall
 uninstall:
        @echo "[UnInstall]"
-       @rm -f /usr/local/bin/gpio
-       @rm -f /usr/local/man/man1/gpio.1
+       @rm -f $(DESTDIR)$(PREFIX)/bin/gpio
+       @rm -f $(DESTDIR)$(PREFIX)/man/man1/gpio.1
 
 .PHONEY:       depend
 depend:
index 1c9357f237a84b53e6e388df09e620ed627fd5df..82c73dd253165d306c8c2e81db108c11ccbcb53f 100644 (file)
@@ -2,6 +2,8 @@
  * mcp3004.c:
  *     Extend wiringPi with the MCP3004 SPI Analog to Digital convertor
  *     Copyright (c) 2012-2013 Gordon Henderson
+ *
+ *     Thanks also to "ShorTie" on IRC for some remote debugging help!
  ***********************************************************************
  * This file is part of wiringPi:
  *     https://projects.drogon.net/raspberry-pi/wiringpi/
 
 static int myAnalogRead (struct wiringPiNodeStruct *node, int pin)
 {
-  unsigned char spiData [2] ;
+  unsigned char spiData [3] ;
   unsigned char chanBits ;
   int chan = pin - node->pinBase ;
 
-  chanBits = 0b11000000 | (chan << 3) ;
+  chanBits = 0b10000000 | (chan << 4) ;
 
-  spiData [0] = chanBits ;
-  spiData [1] = 0 ;
+  spiData [0] = 1 ;            // Start bit
+  spiData [1] = chanBits ;
+  spiData [2] = 0 ;
 
-  wiringPiSPIDataRW (node->fd, spiData, 2) ;
+  wiringPiSPIDataRW (node->fd, spiData, 3) ;
 
-  return ((spiData [0] << 7) | (spiData [1] >> 1)) & 0x3FF ;
+  return ((spiData [1] << 8) | spiData [2]) & 0x3FF ;
 }