wiringpi-ruby 2.0.0 → 2.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/wiringpi/WiringPi/devLib/ds1302.c +240 -0
- data/ext/wiringpi/WiringPi/devLib/ds1302.h +44 -0
- data/ext/wiringpi/WiringPi/devLib/font.h +2577 -0
- data/ext/wiringpi/WiringPi/devLib/gertboard.c +164 -0
- data/ext/wiringpi/WiringPi/devLib/gertboard.h +45 -0
- data/ext/wiringpi/WiringPi/devLib/lcd.c +495 -0
- data/ext/wiringpi/WiringPi/devLib/lcd.h +52 -0
- data/ext/wiringpi/WiringPi/devLib/lcd128x64.c +673 -0
- data/ext/wiringpi/WiringPi/devLib/lcd128x64.h +39 -0
- data/ext/wiringpi/WiringPi/devLib/maxdetect.c +238 -0
- data/ext/wiringpi/WiringPi/devLib/maxdetect.h +40 -0
- data/ext/wiringpi/WiringPi/devLib/piFace.c +112 -0
- data/ext/wiringpi/WiringPi/devLib/piFace.h +32 -0
- data/ext/wiringpi/WiringPi/devLib/piFaceOld.c +177 -0
- data/ext/wiringpi/WiringPi/devLib/piGlow.c +118 -0
- data/ext/wiringpi/WiringPi/devLib/piGlow.h +45 -0
- data/ext/wiringpi/WiringPi/devLib/piNes.c +113 -0
- data/ext/wiringpi/WiringPi/devLib/piNes.h +45 -0
- data/ext/wiringpi/WiringPi/devLib/scrollPhat.c +430 -0
- data/ext/wiringpi/WiringPi/devLib/scrollPhat.h +39 -0
- data/ext/wiringpi/WiringPi/devLib/scrollPhatFont.h +544 -0
- data/ext/wiringpi/WiringPi/examples/Gertboard/7segments.c +221 -0
- data/ext/wiringpi/WiringPi/examples/Gertboard/buttons.c +83 -0
- data/ext/wiringpi/WiringPi/examples/Gertboard/gertboard.c +96 -0
- data/ext/wiringpi/WiringPi/examples/Gertboard/record.c +60 -0
- data/ext/wiringpi/WiringPi/examples/Gertboard/temperature.c +78 -0
- data/ext/wiringpi/WiringPi/examples/Gertboard/voltmeter.c +73 -0
- data/ext/wiringpi/WiringPi/examples/Gertboard/vumeter.c +152 -0
- data/ext/wiringpi/WiringPi/examples/PiFace/blink.c +59 -0
- data/ext/wiringpi/WiringPi/examples/PiFace/buttons.c +103 -0
- data/ext/wiringpi/WiringPi/examples/PiFace/ladder.c +337 -0
- data/ext/wiringpi/WiringPi/examples/PiFace/metro.c +111 -0
- data/ext/wiringpi/WiringPi/examples/PiFace/motor.c +120 -0
- data/ext/wiringpi/WiringPi/examples/PiFace/reaction.c +194 -0
- data/ext/wiringpi/WiringPi/examples/PiGlow/piGlow0.c +51 -0
- data/ext/wiringpi/WiringPi/examples/PiGlow/piGlow1.c +258 -0
- data/ext/wiringpi/WiringPi/examples/PiGlow/piglow.c +176 -0
- data/ext/wiringpi/WiringPi/examples/blink-thread.c +61 -0
- data/ext/wiringpi/WiringPi/examples/blink.c +48 -0
- data/ext/wiringpi/WiringPi/examples/blink12.c +111 -0
- data/ext/wiringpi/WiringPi/examples/blink12drcs.c +125 -0
- data/ext/wiringpi/WiringPi/examples/blink6drcs.c +115 -0
- data/ext/wiringpi/WiringPi/examples/blink8-drcn.c +61 -0
- data/ext/wiringpi/WiringPi/examples/blink8.c +57 -0
- data/ext/wiringpi/WiringPi/examples/clock.c +201 -0
- data/ext/wiringpi/WiringPi/examples/delayTest.c +102 -0
- data/ext/wiringpi/WiringPi/examples/ds1302.c +238 -0
- data/ext/wiringpi/WiringPi/examples/header.h +23 -0
- data/ext/wiringpi/WiringPi/examples/isr-osc.c +118 -0
- data/ext/wiringpi/WiringPi/examples/isr.c +110 -0
- data/ext/wiringpi/WiringPi/examples/lcd-adafruit.c +347 -0
- data/ext/wiringpi/WiringPi/examples/lcd.c +286 -0
- data/ext/wiringpi/WiringPi/examples/lowPower.c +68 -0
- data/ext/wiringpi/WiringPi/examples/max31855.c +60 -0
- data/ext/wiringpi/WiringPi/examples/nes.c +67 -0
- data/ext/wiringpi/WiringPi/examples/okLed.c +82 -0
- data/ext/wiringpi/WiringPi/examples/pwm.c +58 -0
- data/ext/wiringpi/WiringPi/examples/q2w/binary.c +79 -0
- data/ext/wiringpi/WiringPi/examples/q2w/blink-io.c +61 -0
- data/ext/wiringpi/WiringPi/examples/q2w/blink.c +50 -0
- data/ext/wiringpi/WiringPi/examples/q2w/bright.c +59 -0
- data/ext/wiringpi/WiringPi/examples/q2w/button.c +63 -0
- data/ext/wiringpi/WiringPi/examples/q2w/volts.c +62 -0
- data/ext/wiringpi/WiringPi/examples/rht03.c +86 -0
- data/ext/wiringpi/WiringPi/examples/scrollPhat/scphat.c +230 -0
- data/ext/wiringpi/WiringPi/examples/scrollPhat/test.c +115 -0
- data/ext/wiringpi/WiringPi/examples/serialRead.c +48 -0
- data/ext/wiringpi/WiringPi/examples/serialTest.c +75 -0
- data/ext/wiringpi/WiringPi/examples/servo.c +57 -0
- data/ext/wiringpi/WiringPi/examples/softPwm.c +89 -0
- data/ext/wiringpi/WiringPi/examples/softTone.c +54 -0
- data/ext/wiringpi/WiringPi/examples/speed.c +95 -0
- data/ext/wiringpi/WiringPi/examples/spiSpeed.c +118 -0
- data/ext/wiringpi/WiringPi/examples/wfi.c +161 -0
- data/ext/wiringpi/WiringPi/gpio/gpio.c +1538 -0
- data/ext/wiringpi/WiringPi/gpio/readall.c +403 -0
- data/ext/wiringpi/WiringPi/version.h +3 -0
- data/ext/wiringpi/WiringPi/wiringPi/ads1115.c +293 -0
- data/ext/wiringpi/WiringPi/wiringPi/ads1115.h +55 -0
- data/ext/wiringpi/WiringPi/wiringPi/bmp180.c +237 -0
- data/ext/wiringpi/WiringPi/wiringPi/bmp180.h +34 -0
- data/ext/wiringpi/WiringPi/wiringPi/drcNet.c +405 -0
- data/ext/wiringpi/WiringPi/wiringPi/drcNet.h +42 -0
- data/ext/wiringpi/WiringPi/wiringPi/drcSerial.c +196 -0
- data/ext/wiringpi/WiringPi/wiringPi/drcSerial.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/ds18b20.c +146 -0
- data/ext/wiringpi/WiringPi/wiringPi/ds18b20.h +34 -0
- data/ext/wiringpi/WiringPi/wiringPi/htu21d.c +150 -0
- data/ext/wiringpi/WiringPi/wiringPi/htu21d.h +34 -0
- data/ext/wiringpi/WiringPi/wiringPi/max31855.c +99 -0
- data/ext/wiringpi/WiringPi/wiringPi/max31855.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/max5322.c +84 -0
- data/ext/wiringpi/WiringPi/wiringPi/max5322.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23008.c +149 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23008.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23016.c +164 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23016.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23016reg.h +48 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23017.c +195 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23017.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.c +188 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.c +235 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23x08.h +73 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23x0817.h +87 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp3002.c +76 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp3002.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp3004.c +76 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp3004.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp3422.c +125 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp3422.h +43 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp4802.c +76 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp4802.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/pcf8574.c +126 -0
- data/ext/wiringpi/WiringPi/wiringPi/pcf8574.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/pcf8591.c +90 -0
- data/ext/wiringpi/WiringPi/wiringPi/pcf8591.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/piHiPri.c +51 -0
- data/ext/wiringpi/WiringPi/wiringPi/piThread.c +63 -0
- data/ext/wiringpi/WiringPi/wiringPi/pseudoPins.c +95 -0
- data/ext/wiringpi/WiringPi/wiringPi/pseudoPins.h +26 -0
- data/ext/wiringpi/WiringPi/wiringPi/rht03.c +252 -0
- data/ext/wiringpi/WiringPi/wiringPi/rht03.h +25 -0
- data/ext/wiringpi/WiringPi/wiringPi/sn3218.c +75 -0
- data/ext/wiringpi/WiringPi/wiringPi/sn3218.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/softPwm.c +186 -0
- data/ext/wiringpi/WiringPi/wiringPi/softPwm.h +35 -0
- data/ext/wiringpi/WiringPi/wiringPi/softServo.c +211 -0
- data/ext/wiringpi/WiringPi/wiringPi/softServo.h +35 -0
- data/ext/wiringpi/WiringPi/wiringPi/softTone.c +150 -0
- data/ext/wiringpi/WiringPi/wiringPi/softTone.h +39 -0
- data/ext/wiringpi/WiringPi/wiringPi/sr595.c +109 -0
- data/ext/wiringpi/WiringPi/wiringPi/sr595.h +34 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPi.c +2507 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPi.h +269 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.c +233 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.h +42 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.c +144 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.h +36 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringSerial.c +225 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringSerial.h +38 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringShift.c +83 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringShift.h +41 -0
- data/ext/wiringpi/WiringPi/wiringPi/wpiExtensions.c +928 -0
- data/ext/wiringpi/WiringPi/wiringPi/wpiExtensions.h +26 -0
- data/ext/wiringpi/WiringPi/wiringPiD/daemonise.c +82 -0
- data/ext/wiringpi/WiringPi/wiringPiD/daemonise.h +9 -0
- data/ext/wiringpi/WiringPi/wiringPiD/drcNetCmd.h +43 -0
- data/ext/wiringpi/WiringPi/wiringPiD/network.c +330 -0
- data/ext/wiringpi/WiringPi/wiringPiD/network.h +31 -0
- data/ext/wiringpi/WiringPi/wiringPiD/runRemote.c +126 -0
- data/ext/wiringpi/WiringPi/wiringPiD/runRemote.h +29 -0
- data/ext/wiringpi/WiringPi/wiringPiD/wiringpid.c +382 -0
- data/ext/wiringpi/wiringpi_wrap.c +636 -219
- data/lib/wiringpi.rb +25 -12
- data/lib/wiringpi/gpio.rb +90 -83
- data/lib/wiringpi/i2c.rb +29 -22
- data/lib/wiringpi/modules/mcp23017.rb +15 -0
- data/lib/wiringpi/modules/mcp23s17.rb +16 -0
- data/lib/wiringpi/scrollphat.rb +14 -14
- data/lib/wiringpi/serial.rb +8 -18
- data/lib/wiringpi/spi.rb +14 -11
- data/lib/wiringpi/watch.rb +24 -0
- metadata +160 -4
- data/lib/wiringpi/event.rb +0 -21
- data/lib/wiringpi/mcp23x17.rb +0 -31
@@ -0,0 +1,43 @@
|
|
1
|
+
/*
|
2
|
+
* mcp3422.h:
|
3
|
+
* Extend wiringPi with the MCP3422/3/4 I2C ADC chip
|
4
|
+
***********************************************************************
|
5
|
+
* This file is part of wiringPi:
|
6
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
7
|
+
*
|
8
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
9
|
+
* it under the terms of the GNU Lesser General Public License as
|
10
|
+
* published by the Free Software Foundation, either version 3 of the
|
11
|
+
* License, or (at your option) any later version.
|
12
|
+
*
|
13
|
+
* wiringPi is distributed in the hope that it will be useful,
|
14
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
* GNU Lesser General Public License for more details.
|
17
|
+
*
|
18
|
+
* You should have received a copy of the GNU Lesser General Public
|
19
|
+
* License along with wiringPi.
|
20
|
+
* If not, see <http://www.gnu.org/licenses/>.
|
21
|
+
***********************************************************************
|
22
|
+
*/
|
23
|
+
|
24
|
+
#define MCP3422_SR_240 0
|
25
|
+
#define MCP3422_SR_60 1
|
26
|
+
#define MCP3422_SR_15 2
|
27
|
+
#define MCP3422_SR_3_75 3
|
28
|
+
|
29
|
+
#define MCP3422_GAIN_1 0
|
30
|
+
#define MCP3422_GAIN_2 1
|
31
|
+
#define MCP3422_GAIN_4 2
|
32
|
+
#define MCP3422_GAIN_8 3
|
33
|
+
|
34
|
+
|
35
|
+
#ifdef __cplusplus
|
36
|
+
extern "C" {
|
37
|
+
#endif
|
38
|
+
|
39
|
+
extern int mcp3422Setup (int pinBase, int i2cAddress, int sampleRate, int gain) ;
|
40
|
+
|
41
|
+
#ifdef __cplusplus
|
42
|
+
}
|
43
|
+
#endif
|
@@ -0,0 +1,76 @@
|
|
1
|
+
/*
|
2
|
+
* mcp4802.c:
|
3
|
+
* Extend wiringPi with the MCP4802 SPI Digital to Analog convertor
|
4
|
+
* Copyright (c) 2012-2013 Gordon Henderson
|
5
|
+
***********************************************************************
|
6
|
+
* This file is part of wiringPi:
|
7
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
8
|
+
*
|
9
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
10
|
+
* it under the terms of the GNU Lesser General Public License as
|
11
|
+
* published by the Free Software Foundation, either version 3 of the
|
12
|
+
* License, or (at your option) any later version.
|
13
|
+
*
|
14
|
+
* wiringPi is distributed in the hope that it will be useful,
|
15
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
+
* GNU Lesser General Public License for more details.
|
18
|
+
*
|
19
|
+
* You should have received a copy of the GNU Lesser General Public
|
20
|
+
* License along with wiringPi.
|
21
|
+
* If not, see <http://www.gnu.org/licenses/>.
|
22
|
+
***********************************************************************
|
23
|
+
*/
|
24
|
+
|
25
|
+
#include <wiringPi.h>
|
26
|
+
#include <wiringPiSPI.h>
|
27
|
+
|
28
|
+
#include "mcp4802.h"
|
29
|
+
|
30
|
+
/*
|
31
|
+
* myAnalogWrite:
|
32
|
+
* Write analog value on the given pin
|
33
|
+
*********************************************************************************
|
34
|
+
*/
|
35
|
+
|
36
|
+
static void myAnalogWrite (struct wiringPiNodeStruct *node, int pin, int value)
|
37
|
+
{
|
38
|
+
unsigned char spiData [2] ;
|
39
|
+
unsigned char chanBits, dataBits ;
|
40
|
+
int chan = pin - node->pinBase ;
|
41
|
+
|
42
|
+
if (chan == 0)
|
43
|
+
chanBits = 0x30 ;
|
44
|
+
else
|
45
|
+
chanBits = 0xB0 ;
|
46
|
+
|
47
|
+
chanBits |= ((value >> 4) & 0x0F) ;
|
48
|
+
dataBits = ((value << 4) & 0xF0) ;
|
49
|
+
|
50
|
+
spiData [0] = chanBits ;
|
51
|
+
spiData [1] = dataBits ;
|
52
|
+
|
53
|
+
wiringPiSPIDataRW (node->fd, spiData, 2) ;
|
54
|
+
}
|
55
|
+
|
56
|
+
/*
|
57
|
+
* mcp4802Setup:
|
58
|
+
* Create a new wiringPi device node for an mcp4802 on the Pi's
|
59
|
+
* SPI interface.
|
60
|
+
*********************************************************************************
|
61
|
+
*/
|
62
|
+
|
63
|
+
int mcp4802Setup (const int pinBase, int spiChannel)
|
64
|
+
{
|
65
|
+
struct wiringPiNodeStruct *node ;
|
66
|
+
|
67
|
+
if (wiringPiSPISetup (spiChannel, 1000000) < 0)
|
68
|
+
return FALSE ;
|
69
|
+
|
70
|
+
node = wiringPiNewNode (pinBase, 2) ;
|
71
|
+
|
72
|
+
node->fd = spiChannel ;
|
73
|
+
node->analogWrite = myAnalogWrite ;
|
74
|
+
|
75
|
+
return TRUE ;
|
76
|
+
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
/*
|
2
|
+
* mcp4802.c:
|
3
|
+
* Extend wiringPi with the MCP4802 SPI Digital to Analog convertor
|
4
|
+
* Copyright (c) 2012-2013 Gordon Henderson
|
5
|
+
***********************************************************************
|
6
|
+
* This file is part of wiringPi:
|
7
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
8
|
+
*
|
9
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
10
|
+
* it under the terms of the GNU Lesser General Public License as
|
11
|
+
* published by the Free Software Foundation, either version 3 of the
|
12
|
+
* License, or (at your option) any later version.
|
13
|
+
*
|
14
|
+
* wiringPi is distributed in the hope that it will be useful,
|
15
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
+
* GNU Lesser General Public License for more details.
|
18
|
+
*
|
19
|
+
* You should have received a copy of the GNU Lesser General Public
|
20
|
+
* License along with wiringPi.
|
21
|
+
* If not, see <http://www.gnu.org/licenses/>.
|
22
|
+
***********************************************************************
|
23
|
+
*/
|
24
|
+
|
25
|
+
#ifdef __cplusplus
|
26
|
+
extern "C" {
|
27
|
+
#endif
|
28
|
+
|
29
|
+
extern int mcp4802Setup (int pinBase, int spiChannel) ;
|
30
|
+
|
31
|
+
#ifdef __cplusplus
|
32
|
+
}
|
33
|
+
#endif
|
@@ -0,0 +1,126 @@
|
|
1
|
+
/*
|
2
|
+
* pcf8574.c:
|
3
|
+
* Extend wiringPi with the PCF8574 I2C GPIO expander chip
|
4
|
+
* Copyright (c) 2013 Gordon Henderson
|
5
|
+
***********************************************************************
|
6
|
+
* This file is part of wiringPi:
|
7
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
8
|
+
*
|
9
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
10
|
+
* it under the terms of the GNU Lesser General Public License as
|
11
|
+
* published by the Free Software Foundation, either version 3 of the
|
12
|
+
* License, or (at your option) any later version.
|
13
|
+
*
|
14
|
+
* wiringPi is distributed in the hope that it will be useful,
|
15
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
+
* GNU Lesser General Public License for more details.
|
18
|
+
*
|
19
|
+
* You should have received a copy of the GNU Lesser General Public
|
20
|
+
* License along with wiringPi.
|
21
|
+
* If not, see <http://www.gnu.org/licenses/>.
|
22
|
+
***********************************************************************
|
23
|
+
*/
|
24
|
+
|
25
|
+
#include <stdio.h>
|
26
|
+
#include <pthread.h>
|
27
|
+
|
28
|
+
#include "wiringPi.h"
|
29
|
+
#include "wiringPiI2C.h"
|
30
|
+
|
31
|
+
#include "pcf8574.h"
|
32
|
+
|
33
|
+
|
34
|
+
/*
|
35
|
+
* myPinMode:
|
36
|
+
* The PCF8574 is an odd chip - the pins are effectively bi-directional,
|
37
|
+
* however the pins should be drven high when used as an input pin...
|
38
|
+
* So, we're effectively copying digitalWrite...
|
39
|
+
*********************************************************************************
|
40
|
+
*/
|
41
|
+
|
42
|
+
static void myPinMode (struct wiringPiNodeStruct *node, int pin, int mode)
|
43
|
+
{
|
44
|
+
int bit, old ;
|
45
|
+
|
46
|
+
bit = 1 << ((pin - node->pinBase) & 7) ;
|
47
|
+
|
48
|
+
old = node->data2 ;
|
49
|
+
if (mode == OUTPUT)
|
50
|
+
old &= (~bit) ; // Write bit to 0
|
51
|
+
else
|
52
|
+
old |= bit ; // Write bit to 1
|
53
|
+
|
54
|
+
wiringPiI2CWrite (node->fd, old) ;
|
55
|
+
node->data2 = old ;
|
56
|
+
}
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
/*
|
61
|
+
* myDigitalWrite:
|
62
|
+
*********************************************************************************
|
63
|
+
*/
|
64
|
+
|
65
|
+
static void myDigitalWrite (struct wiringPiNodeStruct *node, int pin, int value)
|
66
|
+
{
|
67
|
+
int bit, old ;
|
68
|
+
|
69
|
+
bit = 1 << ((pin - node->pinBase) & 7) ;
|
70
|
+
|
71
|
+
old = node->data2 ;
|
72
|
+
if (value == LOW)
|
73
|
+
old &= (~bit) ;
|
74
|
+
else
|
75
|
+
old |= bit ;
|
76
|
+
|
77
|
+
wiringPiI2CWrite (node->fd, old) ;
|
78
|
+
node->data2 = old ;
|
79
|
+
}
|
80
|
+
|
81
|
+
|
82
|
+
/*
|
83
|
+
* myDigitalRead:
|
84
|
+
*********************************************************************************
|
85
|
+
*/
|
86
|
+
|
87
|
+
static int myDigitalRead (struct wiringPiNodeStruct *node, int pin)
|
88
|
+
{
|
89
|
+
int mask, value ;
|
90
|
+
|
91
|
+
mask = 1 << ((pin - node->pinBase) & 7) ;
|
92
|
+
value = wiringPiI2CRead (node->fd) ;
|
93
|
+
|
94
|
+
if ((value & mask) == 0)
|
95
|
+
return LOW ;
|
96
|
+
else
|
97
|
+
return HIGH ;
|
98
|
+
}
|
99
|
+
|
100
|
+
|
101
|
+
/*
|
102
|
+
* pcf8574Setup:
|
103
|
+
* Create a new instance of a PCF8574 I2C GPIO interface. We know it
|
104
|
+
* has 8 pins, so all we need to know here is the I2C address and the
|
105
|
+
* user-defined pin base.
|
106
|
+
*********************************************************************************
|
107
|
+
*/
|
108
|
+
|
109
|
+
int pcf8574Setup (const int pinBase, const int i2cAddress)
|
110
|
+
{
|
111
|
+
int fd ;
|
112
|
+
struct wiringPiNodeStruct *node ;
|
113
|
+
|
114
|
+
if ((fd = wiringPiI2CSetup (i2cAddress)) < 0)
|
115
|
+
return FALSE ;
|
116
|
+
|
117
|
+
node = wiringPiNewNode (pinBase, 8) ;
|
118
|
+
|
119
|
+
node->fd = fd ;
|
120
|
+
node->pinMode = myPinMode ;
|
121
|
+
node->digitalRead = myDigitalRead ;
|
122
|
+
node->digitalWrite = myDigitalWrite ;
|
123
|
+
node->data2 = wiringPiI2CRead (fd) ;
|
124
|
+
|
125
|
+
return TRUE ;
|
126
|
+
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
/*
|
2
|
+
* pcf8574.h:
|
3
|
+
* Extend wiringPi with the PCF8574 I2C GPIO expander chip
|
4
|
+
* Copyright (c) 2013 Gordon Henderson
|
5
|
+
***********************************************************************
|
6
|
+
* This file is part of wiringPi:
|
7
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
8
|
+
*
|
9
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
10
|
+
* it under the terms of the GNU Lesser General Public License as
|
11
|
+
* published by the Free Software Foundation, either version 3 of the
|
12
|
+
* License, or (at your option) any later version.
|
13
|
+
*
|
14
|
+
* wiringPi is distributed in the hope that it will be useful,
|
15
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
+
* GNU Lesser General Public License for more details.
|
18
|
+
*
|
19
|
+
* You should have received a copy of the GNU Lesser General Public
|
20
|
+
* License along with wiringPi.
|
21
|
+
* If not, see <http://www.gnu.org/licenses/>.
|
22
|
+
***********************************************************************
|
23
|
+
*/
|
24
|
+
|
25
|
+
#ifdef __cplusplus
|
26
|
+
extern "C" {
|
27
|
+
#endif
|
28
|
+
|
29
|
+
extern int pcf8574Setup (const int pinBase, const int i2cAddress) ;
|
30
|
+
|
31
|
+
#ifdef __cplusplus
|
32
|
+
}
|
33
|
+
#endif
|
@@ -0,0 +1,90 @@
|
|
1
|
+
/*
|
2
|
+
* pcf8591.c:
|
3
|
+
* Extend wiringPi with the PCF8591 I2C GPIO Analog expander chip
|
4
|
+
* The chip has 1 8-bit DAC and 4 x 8-bit ADCs
|
5
|
+
* Copyright (c) 2013 Gordon Henderson
|
6
|
+
***********************************************************************
|
7
|
+
* This file is part of wiringPi:
|
8
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
9
|
+
*
|
10
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
11
|
+
* it under the terms of the GNU Lesser General Public License as
|
12
|
+
* published by the Free Software Foundation, either version 3 of the
|
13
|
+
* License, or (at your option) any later version.
|
14
|
+
*
|
15
|
+
* wiringPi is distributed in the hope that it will be useful,
|
16
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18
|
+
* GNU Lesser General Public License for more details.
|
19
|
+
*
|
20
|
+
* You should have received a copy of the GNU Lesser General Public
|
21
|
+
* License along with wiringPi.
|
22
|
+
* If not, see <http://www.gnu.org/licenses/>.
|
23
|
+
***********************************************************************
|
24
|
+
*/
|
25
|
+
|
26
|
+
#include <unistd.h>
|
27
|
+
|
28
|
+
#include "wiringPi.h"
|
29
|
+
#include "wiringPiI2C.h"
|
30
|
+
|
31
|
+
#include "pcf8591.h"
|
32
|
+
|
33
|
+
|
34
|
+
/*
|
35
|
+
* myAnalogWrite:
|
36
|
+
*********************************************************************************
|
37
|
+
*/
|
38
|
+
|
39
|
+
static void myAnalogWrite (struct wiringPiNodeStruct *node, UNU int pin, int value)
|
40
|
+
{
|
41
|
+
unsigned char b [2] ;
|
42
|
+
b [0] = 0x40 ;
|
43
|
+
b [1] = value & 0xFF ;
|
44
|
+
write (node->fd, b, 2) ;
|
45
|
+
}
|
46
|
+
|
47
|
+
|
48
|
+
/*
|
49
|
+
* myAnalogRead:
|
50
|
+
*********************************************************************************
|
51
|
+
*/
|
52
|
+
|
53
|
+
static int myAnalogRead (struct wiringPiNodeStruct *node, int pin)
|
54
|
+
{
|
55
|
+
int x ;
|
56
|
+
|
57
|
+
wiringPiI2CWrite (node->fd, 0x40 | ((pin - node->pinBase) & 3)) ;
|
58
|
+
|
59
|
+
x = wiringPiI2CRead (node->fd) ; // Throw away the first read
|
60
|
+
x = wiringPiI2CRead (node->fd) ;
|
61
|
+
|
62
|
+
return x ;
|
63
|
+
}
|
64
|
+
|
65
|
+
|
66
|
+
/*
|
67
|
+
* pcf8591Setup:
|
68
|
+
* Create a new instance of a PCF8591 I2C GPIO interface. We know it
|
69
|
+
* has 4 pins, (4 analog inputs and 1 analog output which we'll shadow
|
70
|
+
* input 0) so all we need to know here is the I2C address and the
|
71
|
+
* user-defined pin base.
|
72
|
+
*********************************************************************************
|
73
|
+
*/
|
74
|
+
|
75
|
+
int pcf8591Setup (const int pinBase, const int i2cAddress)
|
76
|
+
{
|
77
|
+
int fd ;
|
78
|
+
struct wiringPiNodeStruct *node ;
|
79
|
+
|
80
|
+
if ((fd = wiringPiI2CSetup (i2cAddress)) < 0)
|
81
|
+
return FALSE ;
|
82
|
+
|
83
|
+
node = wiringPiNewNode (pinBase, 4) ;
|
84
|
+
|
85
|
+
node->fd = fd ;
|
86
|
+
node->analogRead = myAnalogRead ;
|
87
|
+
node->analogWrite = myAnalogWrite ;
|
88
|
+
|
89
|
+
return TRUE ;
|
90
|
+
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
/*
|
2
|
+
* pcf8591.h:
|
3
|
+
* Extend wiringPi with the PCF8591 I2C GPIO Analog expander chip
|
4
|
+
* Copyright (c) 2013 Gordon Henderson
|
5
|
+
***********************************************************************
|
6
|
+
* This file is part of wiringPi:
|
7
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
8
|
+
*
|
9
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
10
|
+
* it under the terms of the GNU Lesser General Public License as
|
11
|
+
* published by the Free Software Foundation, either version 3 of the
|
12
|
+
* License, or (at your option) any later version.
|
13
|
+
*
|
14
|
+
* wiringPi is distributed in the hope that it will be useful,
|
15
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
+
* GNU Lesser General Public License for more details.
|
18
|
+
*
|
19
|
+
* You should have received a copy of the GNU Lesser General Public
|
20
|
+
* License along with wiringPi.
|
21
|
+
* If not, see <http://www.gnu.org/licenses/>.
|
22
|
+
***********************************************************************
|
23
|
+
*/
|
24
|
+
|
25
|
+
#ifdef __cplusplus
|
26
|
+
extern "C" {
|
27
|
+
#endif
|
28
|
+
|
29
|
+
extern int pcf8591Setup (const int pinBase, const int i2cAddress) ;
|
30
|
+
|
31
|
+
#ifdef __cplusplus
|
32
|
+
}
|
33
|
+
#endif
|
@@ -0,0 +1,51 @@
|
|
1
|
+
/*
|
2
|
+
* piHiPri:
|
3
|
+
* Simple way to get your program running at high priority
|
4
|
+
* with realtime schedulling.
|
5
|
+
*
|
6
|
+
* Copyright (c) 2012 Gordon Henderson
|
7
|
+
***********************************************************************
|
8
|
+
* This file is part of wiringPi:
|
9
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
10
|
+
*
|
11
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
12
|
+
* it under the terms of the GNU Lesser General Public License as
|
13
|
+
* published by the Free Software Foundation, either version 3 of the
|
14
|
+
* License, or (at your option) any later version.
|
15
|
+
*
|
16
|
+
* wiringPi is distributed in the hope that it will be useful,
|
17
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19
|
+
* GNU Lesser General Public License for more details.
|
20
|
+
*
|
21
|
+
* You should have received a copy of the GNU Lesser General Public
|
22
|
+
* License along with wiringPi.
|
23
|
+
* If not, see <http://www.gnu.org/licenses/>.
|
24
|
+
***********************************************************************
|
25
|
+
*/
|
26
|
+
|
27
|
+
#include <sched.h>
|
28
|
+
#include <string.h>
|
29
|
+
|
30
|
+
#include "wiringPi.h"
|
31
|
+
|
32
|
+
|
33
|
+
/*
|
34
|
+
* piHiPri:
|
35
|
+
* Attempt to set a high priority schedulling for the running program
|
36
|
+
*********************************************************************************
|
37
|
+
*/
|
38
|
+
|
39
|
+
int piHiPri (const int pri)
|
40
|
+
{
|
41
|
+
struct sched_param sched ;
|
42
|
+
|
43
|
+
memset (&sched, 0, sizeof(sched)) ;
|
44
|
+
|
45
|
+
if (pri > sched_get_priority_max (SCHED_RR))
|
46
|
+
sched.sched_priority = sched_get_priority_max (SCHED_RR) ;
|
47
|
+
else
|
48
|
+
sched.sched_priority = pri ;
|
49
|
+
|
50
|
+
return sched_setscheduler (0, SCHED_RR, &sched) ;
|
51
|
+
}
|