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,42 @@
|
|
1
|
+
/*
|
2
|
+
* drcNet.h:
|
3
|
+
* Extend wiringPi with the DRC Network protocol (e.g. to another Pi)
|
4
|
+
* Copyright (c) 2016-2017 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
|
+
/*********
|
26
|
+
struct drcNetStruct
|
27
|
+
{
|
28
|
+
uint32_t pin ;
|
29
|
+
uint32_t cmd ;
|
30
|
+
uint32_t data ;
|
31
|
+
} ;
|
32
|
+
**************/
|
33
|
+
|
34
|
+
#ifdef __cplusplus
|
35
|
+
extern "C" {
|
36
|
+
#endif
|
37
|
+
|
38
|
+
extern int drcSetupNet (const int pinBase, const int numPins, const char *ipAddress, const char *port, const char *password) ;
|
39
|
+
|
40
|
+
#ifdef __cplusplus
|
41
|
+
}
|
42
|
+
#endif
|
@@ -0,0 +1,196 @@
|
|
1
|
+
/*
|
2
|
+
* drcSerial.c:
|
3
|
+
* Extend wiringPi with the DRC Serial protocol (e.g. to Arduino)
|
4
|
+
* Copyright (c) 2013-2016 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 <time.h>
|
27
|
+
#include <string.h>
|
28
|
+
#include <errno.h>
|
29
|
+
|
30
|
+
#include "wiringPi.h"
|
31
|
+
#include "wiringSerial.h"
|
32
|
+
|
33
|
+
#include "drcSerial.h"
|
34
|
+
|
35
|
+
|
36
|
+
/*
|
37
|
+
* myPinMode:
|
38
|
+
* Change the pin mode on the remote DRC device
|
39
|
+
*********************************************************************************
|
40
|
+
*/
|
41
|
+
|
42
|
+
static void myPinMode (struct wiringPiNodeStruct *node, int pin, int mode)
|
43
|
+
{
|
44
|
+
/**/ if (mode == OUTPUT)
|
45
|
+
serialPutchar (node->fd, 'o') ; // Input
|
46
|
+
else if (mode == PWM_OUTPUT)
|
47
|
+
serialPutchar (node->fd, 'p') ; // PWM
|
48
|
+
else
|
49
|
+
serialPutchar (node->fd, 'i') ; // Default to input
|
50
|
+
|
51
|
+
serialPutchar (node->fd, pin - node->pinBase) ;
|
52
|
+
}
|
53
|
+
|
54
|
+
|
55
|
+
/*
|
56
|
+
* myPullUpDnControl:
|
57
|
+
* ATmegas only have pull-up's on of off. No pull-downs.
|
58
|
+
*********************************************************************************
|
59
|
+
*/
|
60
|
+
|
61
|
+
static void myPullUpDnControl (struct wiringPiNodeStruct *node, int pin, int mode)
|
62
|
+
{
|
63
|
+
|
64
|
+
// Force pin into input mode
|
65
|
+
|
66
|
+
serialPutchar (node->fd, 'i' ) ;
|
67
|
+
serialPutchar (node->fd, pin - node->pinBase) ;
|
68
|
+
|
69
|
+
/**/ if (mode == PUD_UP)
|
70
|
+
{
|
71
|
+
serialPutchar (node->fd, '1') ;
|
72
|
+
serialPutchar (node->fd, pin - node->pinBase) ;
|
73
|
+
}
|
74
|
+
else if (mode == PUD_OFF)
|
75
|
+
{
|
76
|
+
serialPutchar (node->fd, '0') ;
|
77
|
+
serialPutchar (node->fd, pin - node->pinBase) ;
|
78
|
+
}
|
79
|
+
}
|
80
|
+
|
81
|
+
|
82
|
+
/*
|
83
|
+
* myDigitalWrite:
|
84
|
+
*********************************************************************************
|
85
|
+
*/
|
86
|
+
|
87
|
+
static void myDigitalWrite (struct wiringPiNodeStruct *node, int pin, int value)
|
88
|
+
{
|
89
|
+
serialPutchar (node->fd, value == 0 ? '0' : '1') ;
|
90
|
+
serialPutchar (node->fd, pin - node->pinBase) ;
|
91
|
+
}
|
92
|
+
|
93
|
+
|
94
|
+
/*
|
95
|
+
* myPwmWrite:
|
96
|
+
*********************************************************************************
|
97
|
+
*/
|
98
|
+
|
99
|
+
static void myPwmWrite (struct wiringPiNodeStruct *node, int pin, int value)
|
100
|
+
{
|
101
|
+
serialPutchar (node->fd, 'v') ;
|
102
|
+
serialPutchar (node->fd, pin - node->pinBase) ;
|
103
|
+
serialPutchar (node->fd, value & 0xFF) ;
|
104
|
+
}
|
105
|
+
|
106
|
+
|
107
|
+
/*
|
108
|
+
* myAnalogRead:
|
109
|
+
*********************************************************************************
|
110
|
+
*/
|
111
|
+
|
112
|
+
static int myAnalogRead (struct wiringPiNodeStruct *node, int pin)
|
113
|
+
{
|
114
|
+
int vHi, vLo ;
|
115
|
+
|
116
|
+
serialPutchar (node->fd, 'a') ;
|
117
|
+
serialPutchar (node->fd, pin - node->pinBase) ;
|
118
|
+
vHi = serialGetchar (node->fd) ;
|
119
|
+
vLo = serialGetchar (node->fd) ;
|
120
|
+
|
121
|
+
return (vHi << 8) | vLo ;
|
122
|
+
}
|
123
|
+
|
124
|
+
|
125
|
+
/*
|
126
|
+
* myDigitalRead:
|
127
|
+
*********************************************************************************
|
128
|
+
*/
|
129
|
+
|
130
|
+
static int myDigitalRead (struct wiringPiNodeStruct *node, int pin)
|
131
|
+
{
|
132
|
+
serialPutchar (node->fd, 'r') ; // Send read command
|
133
|
+
serialPutchar (node->fd, pin - node->pinBase) ;
|
134
|
+
return (serialGetchar (node->fd) == '0') ? 0 : 1 ;
|
135
|
+
}
|
136
|
+
|
137
|
+
|
138
|
+
/*
|
139
|
+
* drcSetup:
|
140
|
+
* Create a new instance of an DRC GPIO interface.
|
141
|
+
* Could be a variable nunber of pins here - we might not know in advance
|
142
|
+
* if it's an ATmega with 14 pins, or something with less or more!
|
143
|
+
*********************************************************************************
|
144
|
+
*/
|
145
|
+
|
146
|
+
int drcSetupSerial (const int pinBase, const int numPins, const char *device, const int baud)
|
147
|
+
{
|
148
|
+
int fd ;
|
149
|
+
int ok, tries ;
|
150
|
+
time_t then ;
|
151
|
+
struct wiringPiNodeStruct *node ;
|
152
|
+
|
153
|
+
if ((fd = serialOpen (device, baud)) < 0)
|
154
|
+
return FALSE ;
|
155
|
+
|
156
|
+
delay (10) ; // May need longer if it's an Uno that reboots on the open...
|
157
|
+
|
158
|
+
// Flush any pending input
|
159
|
+
|
160
|
+
while (serialDataAvail (fd))
|
161
|
+
(void)serialGetchar (fd) ;
|
162
|
+
|
163
|
+
ok = FALSE ;
|
164
|
+
for (tries = 1 ; (tries < 5) && (!ok) ; ++tries)
|
165
|
+
{
|
166
|
+
serialPutchar (fd, '@') ; // Ping
|
167
|
+
then = time (NULL) + 2 ;
|
168
|
+
while (time (NULL) < then)
|
169
|
+
if (serialDataAvail (fd))
|
170
|
+
{
|
171
|
+
if (serialGetchar (fd) == '@')
|
172
|
+
{
|
173
|
+
ok = TRUE ;
|
174
|
+
break ;
|
175
|
+
}
|
176
|
+
}
|
177
|
+
}
|
178
|
+
|
179
|
+
if (!ok)
|
180
|
+
{
|
181
|
+
serialClose (fd) ;
|
182
|
+
return FALSE ;
|
183
|
+
}
|
184
|
+
|
185
|
+
node = wiringPiNewNode (pinBase, numPins) ;
|
186
|
+
|
187
|
+
node->fd = fd ;
|
188
|
+
node->pinMode = myPinMode ;
|
189
|
+
node->pullUpDnControl = myPullUpDnControl ;
|
190
|
+
node->analogRead = myAnalogRead ;
|
191
|
+
node->digitalRead = myDigitalRead ;
|
192
|
+
node->digitalWrite = myDigitalWrite ;
|
193
|
+
node->pwmWrite = myPwmWrite ;
|
194
|
+
|
195
|
+
return TRUE ;
|
196
|
+
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
/*
|
2
|
+
* drcSerial.h:
|
3
|
+
* Extend wiringPi with the DRC Serial protocol (e.g. to Arduino)
|
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 drcSetupSerial (const int pinBase, const int numPins, const char *device, const int baud) ;
|
30
|
+
|
31
|
+
#ifdef __cplusplus
|
32
|
+
}
|
33
|
+
#endif
|
@@ -0,0 +1,146 @@
|
|
1
|
+
/*
|
2
|
+
* ds18b20.c:
|
3
|
+
* Extend wiringPi with the DS18B20 1-Wire temperature sensor.
|
4
|
+
* This is used in the Pi Weather Station and many other places.
|
5
|
+
* Copyright (c) 2016 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 <sys/types.h>
|
27
|
+
#include <sys/stat.h>
|
28
|
+
#include <fcntl.h>
|
29
|
+
|
30
|
+
#include <unistd.h>
|
31
|
+
#include <stdint.h>
|
32
|
+
#include <stdio.h>
|
33
|
+
#include <string.h>
|
34
|
+
#include <malloc.h>
|
35
|
+
#include <ctype.h>
|
36
|
+
|
37
|
+
#include "wiringPi.h"
|
38
|
+
|
39
|
+
#include "ds18b20.h"
|
40
|
+
|
41
|
+
#define W1_PREFIX "/sys/bus/w1/devices/28-"
|
42
|
+
#define W1_POSTFIX "/w1_slave"
|
43
|
+
|
44
|
+
|
45
|
+
/*
|
46
|
+
* myAnalogRead:
|
47
|
+
*********************************************************************************
|
48
|
+
*/
|
49
|
+
|
50
|
+
static int myAnalogRead (struct wiringPiNodeStruct *node, int pin)
|
51
|
+
{
|
52
|
+
int chan = pin - node->pinBase ;
|
53
|
+
int fd = node->fd ;
|
54
|
+
char buffer [4096] ;
|
55
|
+
char *p ;
|
56
|
+
int temp, sign ;
|
57
|
+
|
58
|
+
if (chan != 0)
|
59
|
+
return -9999 ;
|
60
|
+
|
61
|
+
// Rewind the file - we're keeping it open to keep things going
|
62
|
+
// smoothly
|
63
|
+
|
64
|
+
lseek (fd, 0, SEEK_SET) ;
|
65
|
+
|
66
|
+
// Read the file - we know it's only a couple of lines, so this ought to be
|
67
|
+
// more than enough
|
68
|
+
|
69
|
+
if (read (fd, buffer, 4096) <= 0) // Read nothing, or it failed in some odd way
|
70
|
+
return -9998 ;
|
71
|
+
|
72
|
+
// Look for YES, then t=
|
73
|
+
|
74
|
+
if (strstr (buffer, "YES") == NULL)
|
75
|
+
return -9997 ;
|
76
|
+
|
77
|
+
if ((p = strstr (buffer, "t=")) == NULL)
|
78
|
+
return -9996 ;
|
79
|
+
|
80
|
+
// p points to the 't', so we skip over it...
|
81
|
+
|
82
|
+
p += 2 ;
|
83
|
+
|
84
|
+
// and extract the number
|
85
|
+
// (without caring about overflow)
|
86
|
+
|
87
|
+
|
88
|
+
if (*p == '-') // Negative number?
|
89
|
+
{
|
90
|
+
sign = -1 ;
|
91
|
+
++p ;
|
92
|
+
}
|
93
|
+
else
|
94
|
+
sign = 1 ;
|
95
|
+
|
96
|
+
temp = 0 ;
|
97
|
+
while (isdigit (*p))
|
98
|
+
{
|
99
|
+
temp = temp * 10 + (*p - '0') ;
|
100
|
+
++p ;
|
101
|
+
}
|
102
|
+
|
103
|
+
// We know it returns temp * 1000, but we only really want temp * 10, so
|
104
|
+
// do a bit of rounding...
|
105
|
+
|
106
|
+
temp = (temp + 50) / 100 ;
|
107
|
+
return temp * sign ;
|
108
|
+
}
|
109
|
+
|
110
|
+
|
111
|
+
/*
|
112
|
+
* ds18b20Setup:
|
113
|
+
* Create a new instance of a DS18B20 temperature sensor.
|
114
|
+
*********************************************************************************
|
115
|
+
*/
|
116
|
+
|
117
|
+
int ds18b20Setup (const int pinBase, const char *deviceId)
|
118
|
+
{
|
119
|
+
int fd ;
|
120
|
+
struct wiringPiNodeStruct *node ;
|
121
|
+
char *fileName ;
|
122
|
+
|
123
|
+
// Allocate space for the filename
|
124
|
+
|
125
|
+
if ((fileName = malloc (strlen (W1_PREFIX) + strlen (W1_POSTFIX) + strlen (deviceId) + 1)) == NULL)
|
126
|
+
return FALSE ;
|
127
|
+
|
128
|
+
sprintf (fileName, "%s%s%s", W1_PREFIX, deviceId, W1_POSTFIX) ;
|
129
|
+
|
130
|
+
fd = open (fileName, O_RDONLY) ;
|
131
|
+
|
132
|
+
free (fileName) ;
|
133
|
+
|
134
|
+
if (fd < 0)
|
135
|
+
return FALSE ;
|
136
|
+
|
137
|
+
// We'll keep the file open, to make access a little faster
|
138
|
+
// although it's very slow reading these things anyway )-:
|
139
|
+
|
140
|
+
node = wiringPiNewNode (pinBase, 1) ;
|
141
|
+
|
142
|
+
node->fd = fd ;
|
143
|
+
node->analogRead = myAnalogRead ;
|
144
|
+
|
145
|
+
return TRUE ;
|
146
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
/*
|
2
|
+
* bmp180.h:
|
3
|
+
* Extend wiringPi with the BMP180 I2C Pressure and Temperature
|
4
|
+
* sensor.
|
5
|
+
* Copyright (c) 2016 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
|
+
#ifdef __cplusplus
|
27
|
+
extern "C" {
|
28
|
+
#endif
|
29
|
+
|
30
|
+
extern int ds18b20Setup (const int pinBase, const char *serialNum) ;
|
31
|
+
|
32
|
+
#ifdef __cplusplus
|
33
|
+
}
|
34
|
+
#endif
|