wiringpi-ruby 2.0.0 → 2.0.1

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.
Files changed (156) hide show
  1. checksums.yaml +4 -4
  2. data/ext/wiringpi/WiringPi/devLib/ds1302.c +240 -0
  3. data/ext/wiringpi/WiringPi/devLib/ds1302.h +44 -0
  4. data/ext/wiringpi/WiringPi/devLib/font.h +2577 -0
  5. data/ext/wiringpi/WiringPi/devLib/gertboard.c +164 -0
  6. data/ext/wiringpi/WiringPi/devLib/gertboard.h +45 -0
  7. data/ext/wiringpi/WiringPi/devLib/lcd.c +495 -0
  8. data/ext/wiringpi/WiringPi/devLib/lcd.h +52 -0
  9. data/ext/wiringpi/WiringPi/devLib/lcd128x64.c +673 -0
  10. data/ext/wiringpi/WiringPi/devLib/lcd128x64.h +39 -0
  11. data/ext/wiringpi/WiringPi/devLib/maxdetect.c +238 -0
  12. data/ext/wiringpi/WiringPi/devLib/maxdetect.h +40 -0
  13. data/ext/wiringpi/WiringPi/devLib/piFace.c +112 -0
  14. data/ext/wiringpi/WiringPi/devLib/piFace.h +32 -0
  15. data/ext/wiringpi/WiringPi/devLib/piFaceOld.c +177 -0
  16. data/ext/wiringpi/WiringPi/devLib/piGlow.c +118 -0
  17. data/ext/wiringpi/WiringPi/devLib/piGlow.h +45 -0
  18. data/ext/wiringpi/WiringPi/devLib/piNes.c +113 -0
  19. data/ext/wiringpi/WiringPi/devLib/piNes.h +45 -0
  20. data/ext/wiringpi/WiringPi/devLib/scrollPhat.c +430 -0
  21. data/ext/wiringpi/WiringPi/devLib/scrollPhat.h +39 -0
  22. data/ext/wiringpi/WiringPi/devLib/scrollPhatFont.h +544 -0
  23. data/ext/wiringpi/WiringPi/examples/Gertboard/7segments.c +221 -0
  24. data/ext/wiringpi/WiringPi/examples/Gertboard/buttons.c +83 -0
  25. data/ext/wiringpi/WiringPi/examples/Gertboard/gertboard.c +96 -0
  26. data/ext/wiringpi/WiringPi/examples/Gertboard/record.c +60 -0
  27. data/ext/wiringpi/WiringPi/examples/Gertboard/temperature.c +78 -0
  28. data/ext/wiringpi/WiringPi/examples/Gertboard/voltmeter.c +73 -0
  29. data/ext/wiringpi/WiringPi/examples/Gertboard/vumeter.c +152 -0
  30. data/ext/wiringpi/WiringPi/examples/PiFace/blink.c +59 -0
  31. data/ext/wiringpi/WiringPi/examples/PiFace/buttons.c +103 -0
  32. data/ext/wiringpi/WiringPi/examples/PiFace/ladder.c +337 -0
  33. data/ext/wiringpi/WiringPi/examples/PiFace/metro.c +111 -0
  34. data/ext/wiringpi/WiringPi/examples/PiFace/motor.c +120 -0
  35. data/ext/wiringpi/WiringPi/examples/PiFace/reaction.c +194 -0
  36. data/ext/wiringpi/WiringPi/examples/PiGlow/piGlow0.c +51 -0
  37. data/ext/wiringpi/WiringPi/examples/PiGlow/piGlow1.c +258 -0
  38. data/ext/wiringpi/WiringPi/examples/PiGlow/piglow.c +176 -0
  39. data/ext/wiringpi/WiringPi/examples/blink-thread.c +61 -0
  40. data/ext/wiringpi/WiringPi/examples/blink.c +48 -0
  41. data/ext/wiringpi/WiringPi/examples/blink12.c +111 -0
  42. data/ext/wiringpi/WiringPi/examples/blink12drcs.c +125 -0
  43. data/ext/wiringpi/WiringPi/examples/blink6drcs.c +115 -0
  44. data/ext/wiringpi/WiringPi/examples/blink8-drcn.c +61 -0
  45. data/ext/wiringpi/WiringPi/examples/blink8.c +57 -0
  46. data/ext/wiringpi/WiringPi/examples/clock.c +201 -0
  47. data/ext/wiringpi/WiringPi/examples/delayTest.c +102 -0
  48. data/ext/wiringpi/WiringPi/examples/ds1302.c +238 -0
  49. data/ext/wiringpi/WiringPi/examples/header.h +23 -0
  50. data/ext/wiringpi/WiringPi/examples/isr-osc.c +118 -0
  51. data/ext/wiringpi/WiringPi/examples/isr.c +110 -0
  52. data/ext/wiringpi/WiringPi/examples/lcd-adafruit.c +347 -0
  53. data/ext/wiringpi/WiringPi/examples/lcd.c +286 -0
  54. data/ext/wiringpi/WiringPi/examples/lowPower.c +68 -0
  55. data/ext/wiringpi/WiringPi/examples/max31855.c +60 -0
  56. data/ext/wiringpi/WiringPi/examples/nes.c +67 -0
  57. data/ext/wiringpi/WiringPi/examples/okLed.c +82 -0
  58. data/ext/wiringpi/WiringPi/examples/pwm.c +58 -0
  59. data/ext/wiringpi/WiringPi/examples/q2w/binary.c +79 -0
  60. data/ext/wiringpi/WiringPi/examples/q2w/blink-io.c +61 -0
  61. data/ext/wiringpi/WiringPi/examples/q2w/blink.c +50 -0
  62. data/ext/wiringpi/WiringPi/examples/q2w/bright.c +59 -0
  63. data/ext/wiringpi/WiringPi/examples/q2w/button.c +63 -0
  64. data/ext/wiringpi/WiringPi/examples/q2w/volts.c +62 -0
  65. data/ext/wiringpi/WiringPi/examples/rht03.c +86 -0
  66. data/ext/wiringpi/WiringPi/examples/scrollPhat/scphat.c +230 -0
  67. data/ext/wiringpi/WiringPi/examples/scrollPhat/test.c +115 -0
  68. data/ext/wiringpi/WiringPi/examples/serialRead.c +48 -0
  69. data/ext/wiringpi/WiringPi/examples/serialTest.c +75 -0
  70. data/ext/wiringpi/WiringPi/examples/servo.c +57 -0
  71. data/ext/wiringpi/WiringPi/examples/softPwm.c +89 -0
  72. data/ext/wiringpi/WiringPi/examples/softTone.c +54 -0
  73. data/ext/wiringpi/WiringPi/examples/speed.c +95 -0
  74. data/ext/wiringpi/WiringPi/examples/spiSpeed.c +118 -0
  75. data/ext/wiringpi/WiringPi/examples/wfi.c +161 -0
  76. data/ext/wiringpi/WiringPi/gpio/gpio.c +1538 -0
  77. data/ext/wiringpi/WiringPi/gpio/readall.c +403 -0
  78. data/ext/wiringpi/WiringPi/version.h +3 -0
  79. data/ext/wiringpi/WiringPi/wiringPi/ads1115.c +293 -0
  80. data/ext/wiringpi/WiringPi/wiringPi/ads1115.h +55 -0
  81. data/ext/wiringpi/WiringPi/wiringPi/bmp180.c +237 -0
  82. data/ext/wiringpi/WiringPi/wiringPi/bmp180.h +34 -0
  83. data/ext/wiringpi/WiringPi/wiringPi/drcNet.c +405 -0
  84. data/ext/wiringpi/WiringPi/wiringPi/drcNet.h +42 -0
  85. data/ext/wiringpi/WiringPi/wiringPi/drcSerial.c +196 -0
  86. data/ext/wiringpi/WiringPi/wiringPi/drcSerial.h +33 -0
  87. data/ext/wiringpi/WiringPi/wiringPi/ds18b20.c +146 -0
  88. data/ext/wiringpi/WiringPi/wiringPi/ds18b20.h +34 -0
  89. data/ext/wiringpi/WiringPi/wiringPi/htu21d.c +150 -0
  90. data/ext/wiringpi/WiringPi/wiringPi/htu21d.h +34 -0
  91. data/ext/wiringpi/WiringPi/wiringPi/max31855.c +99 -0
  92. data/ext/wiringpi/WiringPi/wiringPi/max31855.h +33 -0
  93. data/ext/wiringpi/WiringPi/wiringPi/max5322.c +84 -0
  94. data/ext/wiringpi/WiringPi/wiringPi/max5322.h +33 -0
  95. data/ext/wiringpi/WiringPi/wiringPi/mcp23008.c +149 -0
  96. data/ext/wiringpi/WiringPi/wiringPi/mcp23008.h +33 -0
  97. data/ext/wiringpi/WiringPi/wiringPi/mcp23016.c +164 -0
  98. data/ext/wiringpi/WiringPi/wiringPi/mcp23016.h +33 -0
  99. data/ext/wiringpi/WiringPi/wiringPi/mcp23016reg.h +48 -0
  100. data/ext/wiringpi/WiringPi/wiringPi/mcp23017.c +195 -0
  101. data/ext/wiringpi/WiringPi/wiringPi/mcp23017.h +33 -0
  102. data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.c +188 -0
  103. data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.h +33 -0
  104. data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.c +235 -0
  105. data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.h +33 -0
  106. data/ext/wiringpi/WiringPi/wiringPi/mcp23x08.h +73 -0
  107. data/ext/wiringpi/WiringPi/wiringPi/mcp23x0817.h +87 -0
  108. data/ext/wiringpi/WiringPi/wiringPi/mcp3002.c +76 -0
  109. data/ext/wiringpi/WiringPi/wiringPi/mcp3002.h +33 -0
  110. data/ext/wiringpi/WiringPi/wiringPi/mcp3004.c +76 -0
  111. data/ext/wiringpi/WiringPi/wiringPi/mcp3004.h +33 -0
  112. data/ext/wiringpi/WiringPi/wiringPi/mcp3422.c +125 -0
  113. data/ext/wiringpi/WiringPi/wiringPi/mcp3422.h +43 -0
  114. data/ext/wiringpi/WiringPi/wiringPi/mcp4802.c +76 -0
  115. data/ext/wiringpi/WiringPi/wiringPi/mcp4802.h +33 -0
  116. data/ext/wiringpi/WiringPi/wiringPi/pcf8574.c +126 -0
  117. data/ext/wiringpi/WiringPi/wiringPi/pcf8574.h +33 -0
  118. data/ext/wiringpi/WiringPi/wiringPi/pcf8591.c +90 -0
  119. data/ext/wiringpi/WiringPi/wiringPi/pcf8591.h +33 -0
  120. data/ext/wiringpi/WiringPi/wiringPi/piHiPri.c +51 -0
  121. data/ext/wiringpi/WiringPi/wiringPi/piThread.c +63 -0
  122. data/ext/wiringpi/WiringPi/wiringPi/pseudoPins.c +95 -0
  123. data/ext/wiringpi/WiringPi/wiringPi/pseudoPins.h +26 -0
  124. data/ext/wiringpi/WiringPi/wiringPi/rht03.c +252 -0
  125. data/ext/wiringpi/WiringPi/wiringPi/rht03.h +25 -0
  126. data/ext/wiringpi/WiringPi/wiringPi/sn3218.c +75 -0
  127. data/ext/wiringpi/WiringPi/wiringPi/sn3218.h +33 -0
  128. data/ext/wiringpi/WiringPi/wiringPi/softPwm.c +186 -0
  129. data/ext/wiringpi/WiringPi/wiringPi/softPwm.h +35 -0
  130. data/ext/wiringpi/WiringPi/wiringPi/softServo.c +211 -0
  131. data/ext/wiringpi/WiringPi/wiringPi/softServo.h +35 -0
  132. data/ext/wiringpi/WiringPi/wiringPi/softTone.c +150 -0
  133. data/ext/wiringpi/WiringPi/wiringPi/softTone.h +39 -0
  134. data/ext/wiringpi/WiringPi/wiringPi/sr595.c +109 -0
  135. data/ext/wiringpi/WiringPi/wiringPi/sr595.h +34 -0
  136. data/ext/wiringpi/WiringPi/wiringPi/wiringPi.c +2507 -0
  137. data/ext/wiringpi/WiringPi/wiringPi/wiringPi.h +269 -0
  138. data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.c +233 -0
  139. data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.h +42 -0
  140. data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.c +144 -0
  141. data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.h +36 -0
  142. data/ext/wiringpi/WiringPi/wiringPi/wiringSerial.c +225 -0
  143. data/ext/wiringpi/WiringPi/wiringPi/wiringSerial.h +38 -0
  144. data/ext/wiringpi/WiringPi/wiringPi/wiringShift.c +83 -0
  145. data/ext/wiringpi/WiringPi/wiringPi/wiringShift.h +41 -0
  146. data/ext/wiringpi/WiringPi/wiringPi/wpiExtensions.c +928 -0
  147. data/ext/wiringpi/WiringPi/wiringPi/wpiExtensions.h +26 -0
  148. data/ext/wiringpi/WiringPi/wiringPiD/daemonise.c +82 -0
  149. data/ext/wiringpi/WiringPi/wiringPiD/daemonise.h +9 -0
  150. data/ext/wiringpi/WiringPi/wiringPiD/drcNetCmd.h +43 -0
  151. data/ext/wiringpi/WiringPi/wiringPiD/network.c +330 -0
  152. data/ext/wiringpi/WiringPi/wiringPiD/network.h +31 -0
  153. data/ext/wiringpi/WiringPi/wiringPiD/runRemote.c +126 -0
  154. data/ext/wiringpi/WiringPi/wiringPiD/runRemote.h +29 -0
  155. data/ext/wiringpi/WiringPi/wiringPiD/wiringpid.c +382 -0
  156. metadata +155 -1
@@ -0,0 +1,55 @@
1
+ /*
2
+ * ads1115.c:
3
+ * Extend wiringPi with the ADS1115 I2C 16-bit ADC
4
+ * Copyright (c) 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
+ // Constants for some of the internal functions
26
+
27
+ // Gain
28
+
29
+ #define ADS1115_GAIN_6 0
30
+ #define ADS1115_GAIN_4 1
31
+ #define ADS1115_GAIN_2 2
32
+ #define ADS1115_GAIN_1 3
33
+ #define ADS1115_GAIN_HALF 4
34
+ #define ADS1115_GAIN_QUARTER 5
35
+
36
+ // Data rate
37
+
38
+ #define ADS1115_DR_8 0
39
+ #define ADS1115_DR_16 1
40
+ #define ADS1115_DR_32 2
41
+ #define ADS1115_DR_64 3
42
+ #define ADS1115_DR_128 4
43
+ #define ADS1115_DR_250 5
44
+ #define ADS1115_DR_475 6
45
+ #define ADS1115_DR_860 7
46
+
47
+ #ifdef __cplusplus
48
+ extern "C" {
49
+ #endif
50
+
51
+ extern int ads1115Setup (int pinBase, int i2cAddress) ;
52
+
53
+ #ifdef __cplusplus
54
+ }
55
+ #endif
@@ -0,0 +1,237 @@
1
+ /*
2
+ * bmp180.c:
3
+ * Extend wiringPi with the BMP180 I2C Pressure and Temperature
4
+ * sensor. This is used in the Pi Weather Station
5
+ * Copyright (c) 2016 Gordon Henderson
6
+ *
7
+ * Information from the document held at:
8
+ * http://wmrx00.sourceforge.net/Arduino/BMP085-Calcs.pdf
9
+ * was very useful when building this code.
10
+ *
11
+ ***********************************************************************
12
+ * This file is part of wiringPi:
13
+ * https://projects.drogon.net/raspberry-pi/wiringpi/
14
+ *
15
+ * wiringPi is free software: you can redistribute it and/or modify
16
+ * it under the terms of the GNU Lesser General Public License as
17
+ * published by the Free Software Foundation, either version 3 of the
18
+ * License, or (at your option) any later version.
19
+ *
20
+ * wiringPi is distributed in the hope that it will be useful,
21
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ * GNU Lesser General Public License for more details.
24
+ *
25
+ * You should have received a copy of the GNU Lesser General Public
26
+ * License along with wiringPi.
27
+ * If not, see <http://www.gnu.org/licenses/>.
28
+ ***********************************************************************
29
+ */
30
+
31
+ #include <unistd.h>
32
+ #include <stdint.h>
33
+ #include <stdio.h>
34
+ #include <math.h>
35
+
36
+ #include "wiringPi.h"
37
+ #include "wiringPiI2C.h"
38
+
39
+ #include "bmp180.h"
40
+
41
+ #undef DEBUG
42
+
43
+ #define I2C_ADDRESS 0x77
44
+ #define BMP180_OSS 0
45
+
46
+
47
+ // Static calibration data
48
+ // The down-side of this is that there can only be one BMP180 in
49
+ // a system - which is practice isn't an issue as it's I2C
50
+ // address is fixed.
51
+
52
+ static int16_t AC1, AC2, AC3 ;
53
+ static uint16_t AC4, AC5, AC6 ;
54
+ static int16_t VB1, VB2 ;
55
+ static int16_t MB, MC, MD ;
56
+
57
+ static double c5, c6, mc, md, x0, x1, x2, yy0, yy1, yy2, p0, p1, p2 ;
58
+
59
+ // Pressure & Temp variables
60
+
61
+ uint32_t cPress, cTemp ;
62
+
63
+ static int altitude ;
64
+
65
+ /*
66
+ * read16:
67
+ * Quick hack to read the 16-bit data with the correct endian
68
+ *********************************************************************************
69
+ */
70
+
71
+ uint16_t read16 (int fd, int reg)
72
+ {
73
+ return (wiringPiI2CReadReg8 (fd, reg) << 8) | wiringPiI2CReadReg8 (fd, reg + 1) ;
74
+
75
+ }
76
+
77
+
78
+ /*
79
+ * bmp180ReadTempPress:
80
+ * Does the hard work of reading the sensor
81
+ *********************************************************************************
82
+ */
83
+
84
+ static void bmp180ReadTempPress (int fd)
85
+ {
86
+ double fTemp, fPress ;
87
+ double tu, a ;
88
+ double pu, s, x, y, z ;
89
+
90
+ uint8_t data [4] ;
91
+
92
+ // Start a temperature sensor reading
93
+
94
+ wiringPiI2CWriteReg8 (fd, 0xF4, 0x2E) ;
95
+ delay (5) ;
96
+
97
+ // Read the raw data
98
+
99
+ data [0] = wiringPiI2CReadReg8 (fd, 0xF6) ;
100
+ data [1] = wiringPiI2CReadReg8 (fd, 0xF7) ;
101
+
102
+ // And calculate...
103
+
104
+ tu = (data [0] * 256.0) + data [1] ;
105
+
106
+ a = c5 * (tu - c6) ;
107
+ fTemp = a + (mc / (a + md)) ;
108
+ cTemp = (int)rint (((100.0 * fTemp) + 0.5) / 10.0) ;
109
+
110
+ #ifdef DEBUG
111
+ printf ("fTemp: %f, cTemp: %6d\n", fTemp, cTemp) ;
112
+ #endif
113
+
114
+ // Start a pressure snsor reading
115
+
116
+ wiringPiI2CWriteReg8 (fd, 0xF4, 0x34 | (BMP180_OSS << 6)) ;
117
+ delay (5) ;
118
+
119
+ // Read the raw data
120
+
121
+ data [0] = wiringPiI2CReadReg8 (fd, 0xF6) ;
122
+ data [1] = wiringPiI2CReadReg8 (fd, 0xF7) ;
123
+ data [2] = wiringPiI2CReadReg8 (fd, 0xF8) ;
124
+
125
+ // And calculate...
126
+
127
+ pu = ((double)data [0] * 256.0) + (double)data [1] + ((double)data [2] / 256.0) ;
128
+ s = fTemp - 25.0 ;
129
+ x = (x2 * pow (s, 2.0)) + (x1 * s) + x0 ;
130
+ y = (yy2 * pow (s, 2.0)) + (yy1 * s) + yy0 ;
131
+ z = (pu - x) / y ;
132
+ fPress = (p2 * pow (z, 2.0)) + (p1 * z) + p0 ;
133
+ cPress = (int)rint (((100.0 * fPress) + 0.5) / 10.0) ;
134
+
135
+ #ifdef DEBUG
136
+ printf ("fPress: %f, cPress: %6d\n", fPress, cPress) ;
137
+ #endif
138
+ }
139
+
140
+
141
+ /*
142
+ * myAnalogWrite:
143
+ * Write to a fake register to represent the height above sea level
144
+ * so that the peudo millibar register can read the pressure in mB
145
+ *********************************************************************************
146
+ */
147
+
148
+ static void myAnalogWrite (struct wiringPiNodeStruct *node, int pin, int value)
149
+ {
150
+ int chan = pin - node->pinBase ;
151
+
152
+ if (chan == 0)
153
+ altitude = value ;
154
+ }
155
+
156
+ /*
157
+ * myAnalogRead:
158
+ *********************************************************************************
159
+ */
160
+
161
+ static int myAnalogRead (struct wiringPiNodeStruct *node, int pin)
162
+ {
163
+ int chan = pin - node->pinBase ;
164
+
165
+ bmp180ReadTempPress (node->fd) ;
166
+
167
+ /**/ if (chan == 0) // Read Temperature
168
+ return cTemp ;
169
+ else if (chan == 1) // Pressure
170
+ return cPress ;
171
+ else if (chan == 2) // Pressure in mB
172
+ return cPress / pow (1 - ((double)altitude / 44330.0), 5.255) ;
173
+ else
174
+ return -9999 ;
175
+
176
+ }
177
+
178
+
179
+ /*
180
+ * bmp180Setup:
181
+ * Create a new instance of a PCF8591 I2C GPIO interface. We know it
182
+ * has 4 pins, (4 analog inputs and 1 analog output which we'll shadow
183
+ * input 0) so all we need to know here is the I2C address and the
184
+ * user-defined pin base.
185
+ *********************************************************************************
186
+ */
187
+
188
+ int bmp180Setup (const int pinBase)
189
+ {
190
+ double c3, c4, b1 ;
191
+ int fd ;
192
+ struct wiringPiNodeStruct *node ;
193
+
194
+ if ((fd = wiringPiI2CSetup (I2C_ADDRESS)) < 0)
195
+ return FALSE ;
196
+
197
+ node = wiringPiNewNode (pinBase, 4) ;
198
+
199
+ node->fd = fd ;
200
+ node->analogRead = myAnalogRead ;
201
+ node->analogWrite = myAnalogWrite ;
202
+
203
+ // Read calibration data
204
+
205
+ AC1 = read16 (fd, 0xAA) ;
206
+ AC2 = read16 (fd, 0xAC) ;
207
+ AC3 = read16 (fd, 0xAE) ;
208
+ AC4 = read16 (fd, 0xB0) ;
209
+ AC5 = read16 (fd, 0xB2) ;
210
+ AC6 = read16 (fd, 0xB4) ;
211
+ VB1 = read16 (fd, 0xB6) ;
212
+ VB2 = read16 (fd, 0xB8) ;
213
+ MB = read16 (fd, 0xBA) ;
214
+ MC = read16 (fd, 0xBC) ;
215
+ MD = read16 (fd, 0xBE) ;
216
+
217
+ // Calculate coefficients
218
+
219
+ c3 = 160.0 * pow (2.0, -15.0) * AC3 ;
220
+ c4 = pow (10.0, -3.0) * pow(2.0,-15.0) * AC4 ;
221
+ b1 = pow (160.0, 2.0) * pow(2.0,-30.0) * VB1 ;
222
+ c5 = (pow (2.0, -15.0) / 160.0) * AC5 ;
223
+ c6 = AC6 ;
224
+ mc = (pow (2.0, 11.0) / pow(160.0,2.0)) * MC ;
225
+ md = MD / 160.0 ;
226
+ x0 = AC1 ;
227
+ x1 = 160.0 * pow (2.0, -13.0) * AC2 ;
228
+ x2 = pow (160.0, 2.0) * pow(2.0,-25.0) * VB2 ;
229
+ yy0 = c4 * pow (2.0, 15.0) ;
230
+ yy1 = c4 * c3 ;
231
+ yy2 = c4 * b1 ;
232
+ p0 = (3791.0 - 8.0) / 1600.0 ;
233
+ p1 = 1.0 - 7357.0 * pow (2.0, -20.0) ;
234
+ p2 = 3038.0 * 100.0 * pow (2.0, -36.0) ;
235
+
236
+ return TRUE ;
237
+ }
@@ -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 bmp180Setup (const int pinBase) ;
31
+
32
+ #ifdef __cplusplus
33
+ }
34
+ #endif
@@ -0,0 +1,405 @@
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
+ #include <stdio.h>
26
+ #include <stdint.h>
27
+ #include <unistd.h>
28
+ #include <sys/types.h>
29
+ #include <sys/socket.h>
30
+ #include <arpa/inet.h>
31
+ #include <netdb.h>
32
+ #include <string.h>
33
+ #include <errno.h>
34
+ #include <crypt.h>
35
+
36
+
37
+ #include "wiringPi.h"
38
+ #include "drcNet.h"
39
+ #include "../wiringPiD/drcNetCmd.h"
40
+
41
+
42
+ /*
43
+ * remoteReadline:
44
+ * Read in a line of data from the remote server, ending with a newline
45
+ * character which is not stored. Returns the length or < 0 on
46
+ * any sort of failure.
47
+ *********************************************************************************
48
+ */
49
+
50
+ static int remoteReadline (int fd, char *buf, int max)
51
+ {
52
+ int len = 0 ;
53
+ char c ;
54
+
55
+ for (;;)
56
+ {
57
+ if (read (fd, &c, 1) < 1)
58
+ return -1 ;
59
+
60
+ if (c == '\n')
61
+ return len ;
62
+
63
+ *buf++ = c ;
64
+ if (++len == max)
65
+ return len ;
66
+ }
67
+ }
68
+
69
+
70
+ /*
71
+ * getChallenge:
72
+ * Read in lines from the remote site until we get one identified
73
+ * as the challenge. This line contains the password salt.
74
+ *********************************************************************************
75
+ */
76
+
77
+ static char *getChallenge (int fd)
78
+ {
79
+ static char buf [1024] ;
80
+ int num ;
81
+
82
+ for (;;)
83
+ {
84
+ if ((num = remoteReadline (fd, buf, 1023)) < 0)
85
+ return NULL ;
86
+ buf [num] = 0 ;
87
+
88
+ if (strncmp (buf, "Challenge ", 10) == 0)
89
+ return &buf [10] ;
90
+ }
91
+ }
92
+
93
+
94
+ /*
95
+ * authenticate:
96
+ * Read in the challenge from the server, use it to encrypt our password
97
+ * and send it back to the server. Wait for a reply back from the server
98
+ * to say that we're good to go.
99
+ * The server will simply disconnect on a bad response. No 3 chances here.
100
+ *********************************************************************************
101
+ */
102
+
103
+ static int authenticate (int fd, const char *pass)
104
+ {
105
+ char *challenge ;
106
+ char *encrypted ;
107
+ char salted [1024] ;
108
+
109
+ if ((challenge = getChallenge (fd)) == NULL)
110
+ return -1 ;
111
+
112
+ sprintf (salted, "$6$%s$", challenge) ;
113
+ encrypted = crypt (pass, salted) ;
114
+
115
+ // This is an assertion, or sanity check on my part...
116
+ // The '20' comes from the $6$ then the 16 characters of the salt,
117
+ // then the terminating $.
118
+
119
+ if (strncmp (encrypted, salted, 20) != 0)
120
+ {
121
+ errno = EBADE ;
122
+ return -1 ;
123
+ }
124
+
125
+ // 86 characters is the length of the SHA-256 hash
126
+
127
+ if (write (fd, encrypted + 20, 86) == 86)
128
+ return 0 ;
129
+ else
130
+ return -1 ;
131
+ }
132
+
133
+
134
+ /*
135
+ * _drcSetupNet:
136
+ * Do the hard work of establishing a network connection and authenticating
137
+ * the password.
138
+ *********************************************************************************
139
+ */
140
+
141
+ int _drcSetupNet (const char *ipAddress, const char *port, const char *password)
142
+ {
143
+ struct addrinfo hints;
144
+ struct addrinfo *result, *rp ;
145
+ struct in6_addr serveraddr ;
146
+ int remoteFd ;
147
+
148
+ // Start by seeing if we've been given a (textual) numeric IP address
149
+ // which will save lookups in getaddrinfo()
150
+
151
+ memset (&hints, 0, sizeof (hints)) ;
152
+ hints.ai_flags = AI_NUMERICSERV ;
153
+ hints.ai_family = AF_UNSPEC ;
154
+ hints.ai_socktype = SOCK_STREAM ;
155
+ hints.ai_protocol = 0 ;
156
+
157
+ if (inet_pton (AF_INET, ipAddress, &serveraddr) == 1) // Valid IPv4
158
+ {
159
+ hints.ai_family = AF_INET ;
160
+ hints.ai_flags |= AI_NUMERICHOST ;
161
+ }
162
+ else
163
+ {
164
+ if (inet_pton (AF_INET6, ipAddress, &serveraddr) == 1) // Valid IPv6
165
+ {
166
+ hints.ai_family = AF_INET6 ;
167
+ hints.ai_flags |= AI_NUMERICHOST ;
168
+ }
169
+ }
170
+
171
+ // Now use getaddrinfo() with the newly supplied hints
172
+
173
+ if (getaddrinfo (ipAddress, port, &hints, &result) != 0)
174
+ return -1 ;
175
+
176
+ // Now try each address in-turn until we get one that connects...
177
+
178
+ for (rp = result; rp != NULL; rp = rp->ai_next)
179
+ {
180
+ if ((remoteFd = socket (rp->ai_family, rp->ai_socktype, rp->ai_protocol)) < 0)
181
+ continue ;
182
+
183
+ if (connect (remoteFd, rp->ai_addr, rp->ai_addrlen) < 0)
184
+ continue ;
185
+
186
+ if (authenticate (remoteFd, password) < 0)
187
+ {
188
+ close (remoteFd) ;
189
+ errno = EACCES ; // Permission denied
190
+ return -1 ;
191
+ }
192
+ else
193
+ return remoteFd ;
194
+ }
195
+
196
+ errno = EHOSTUNREACH ; // Host unreachable - may not be right, but good enough
197
+ return -1 ; // Nothing connected
198
+ }
199
+
200
+
201
+ /*
202
+ * myPinMode:
203
+ * Change the pin mode on the remote DRC device
204
+ *********************************************************************************
205
+ */
206
+
207
+ static void myPinMode (struct wiringPiNodeStruct *node, int pin, int mode)
208
+ {
209
+ struct drcNetComStruct cmd ;
210
+
211
+ cmd.pin = pin - node->pinBase ;
212
+ cmd.cmd = DRCN_PIN_MODE ;
213
+ cmd.data = mode ;
214
+
215
+ (void)send (node->fd, &cmd, sizeof (cmd), 0) ;
216
+ (void)recv (node->fd, &cmd, sizeof (cmd), 0) ;
217
+ }
218
+
219
+
220
+ /*
221
+ * myPullUpDnControl:
222
+ *********************************************************************************
223
+ */
224
+
225
+ static void myPullUpDnControl (struct wiringPiNodeStruct *node, int pin, int mode)
226
+ {
227
+ struct drcNetComStruct cmd ;
228
+
229
+ cmd.pin = pin - node->pinBase ;
230
+ cmd.cmd = DRCN_PULL_UP_DN ;
231
+ cmd.data = mode ;
232
+
233
+ (void)send (node->fd, &cmd, sizeof (cmd), 0) ;
234
+ (void)recv (node->fd, &cmd, sizeof (cmd), 0) ;
235
+ }
236
+
237
+
238
+ /*
239
+ * myDigitalWrite:
240
+ *********************************************************************************
241
+ */
242
+
243
+ static void myDigitalWrite (struct wiringPiNodeStruct *node, int pin, int value)
244
+ {
245
+ struct drcNetComStruct cmd ;
246
+
247
+ cmd.pin = pin - node->pinBase ;
248
+ cmd.cmd = DRCN_DIGITAL_WRITE ;
249
+ cmd.data = value ;
250
+
251
+ (void)send (node->fd, &cmd, sizeof (cmd), 0) ;
252
+ (void)recv (node->fd, &cmd, sizeof (cmd), 0) ;
253
+ }
254
+
255
+
256
+ /*
257
+ * myDigitalWrite8:
258
+ *********************************************************************************
259
+
260
+ static void myDigitalWrite8 (struct wiringPiNodeStruct *node, int pin, int value)
261
+ {
262
+ struct drcNetComStruct cmd ;
263
+
264
+ cmd.pin = pin - node->pinBase ;
265
+ cmd.cmd = DRCN_DIGITAL_WRITE8 ;
266
+ cmd.data = value ;
267
+
268
+ (void)send (node->fd, &cmd, sizeof (cmd), 0) ;
269
+ (void)recv (node->fd, &cmd, sizeof (cmd), 0) ;
270
+ }
271
+ */
272
+
273
+
274
+ /*
275
+ * myAnalogWrite:
276
+ *********************************************************************************
277
+ */
278
+
279
+ static void myAnalogWrite (struct wiringPiNodeStruct *node, int pin, int value)
280
+ {
281
+ struct drcNetComStruct cmd ;
282
+
283
+ cmd.pin = pin - node->pinBase ;
284
+ cmd.cmd = DRCN_ANALOG_WRITE ;
285
+ cmd.data = value ;
286
+
287
+ (void)send (node->fd, &cmd, sizeof (cmd), 0) ;
288
+ (void)recv (node->fd, &cmd, sizeof (cmd), 0) ;
289
+ }
290
+
291
+
292
+ /*
293
+ * myPwmWrite:
294
+ *********************************************************************************
295
+ */
296
+
297
+ static void myPwmWrite (struct wiringPiNodeStruct *node, int pin, int value)
298
+ {
299
+ struct drcNetComStruct cmd ;
300
+
301
+ cmd.pin = pin - node->pinBase ;
302
+ cmd.cmd = DRCN_PWM_WRITE ;
303
+ cmd.data = value ;
304
+
305
+ (void)send (node->fd, &cmd, sizeof (cmd), 0) ;
306
+ (void)recv (node->fd, &cmd, sizeof (cmd), 0) ;
307
+ }
308
+
309
+
310
+ /*
311
+ * myAnalogRead:
312
+ *********************************************************************************
313
+ */
314
+
315
+ static int myAnalogRead (struct wiringPiNodeStruct *node, int pin)
316
+ {
317
+ struct drcNetComStruct cmd ;
318
+
319
+ cmd.pin = pin - node->pinBase ;
320
+ cmd.cmd = DRCN_ANALOG_READ ;
321
+ cmd.data = 0 ;
322
+
323
+ (void)send (node->fd, &cmd, sizeof (cmd), 0) ;
324
+ (void)recv (node->fd, &cmd, sizeof (cmd), 0) ;
325
+
326
+ return cmd.data ;
327
+ }
328
+
329
+
330
+ /*
331
+ * myDigitalRead:
332
+ *********************************************************************************
333
+ */
334
+
335
+ static int myDigitalRead (struct wiringPiNodeStruct *node, int pin)
336
+ {
337
+ struct drcNetComStruct cmd ;
338
+
339
+ cmd.pin = pin - node->pinBase ;
340
+ cmd.cmd = DRCN_DIGITAL_READ ;
341
+ cmd.data = 0 ;
342
+
343
+ (void)send (node->fd, &cmd, sizeof (cmd), 0) ;
344
+ (void)recv (node->fd, &cmd, sizeof (cmd), 0) ;
345
+
346
+ return cmd.data ;
347
+ }
348
+
349
+
350
+ /*
351
+ * myDigitalRead8:
352
+ *********************************************************************************
353
+
354
+ static unsigned int myDigitalRead8 (struct wiringPiNodeStruct *node, int pin)
355
+ {
356
+ struct drcNetComStruct cmd ;
357
+
358
+ cmd.pin = pin - node->pinBase ;
359
+ cmd.cmd = DRCN_DIGITAL_READ8 ;
360
+ cmd.data = 0 ;
361
+
362
+ (void)send (node->fd, &cmd, sizeof (cmd), 0) ;
363
+ (void)recv (node->fd, &cmd, sizeof (cmd), 0) ;
364
+
365
+ return cmd.data ;
366
+ }
367
+ */
368
+
369
+
370
+ /*
371
+ * drcNet:
372
+ * Create a new instance of an DRC GPIO interface.
373
+ * Could be a variable nunber of pins here - we might not know in advance.
374
+ *********************************************************************************
375
+ */
376
+
377
+ int drcSetupNet (const int pinBase, const int numPins, const char *ipAddress, const char *port, const char *password)
378
+ {
379
+ int fd, len ;
380
+ struct wiringPiNodeStruct *node ;
381
+
382
+ if ((fd = _drcSetupNet (ipAddress, port, password)) < 0)
383
+ return FALSE ;
384
+
385
+ len = sizeof (struct drcNetComStruct) ;
386
+
387
+ if (setsockopt (fd, SOL_SOCKET, SO_RCVLOWAT, (void *)&len, sizeof (len)) < 0)
388
+ return FALSE ;
389
+
390
+ node = wiringPiNewNode (pinBase, numPins) ;
391
+
392
+ node->fd = fd ;
393
+ node->pinMode = myPinMode ;
394
+ node->pullUpDnControl = myPullUpDnControl ;
395
+ node->analogRead = myAnalogRead ;
396
+ node->analogRead = myAnalogRead ;
397
+ node->analogWrite = myAnalogWrite ;
398
+ node->digitalRead = myDigitalRead ;
399
+ node->digitalWrite = myDigitalWrite ;
400
+ //node->digitalRead8 = myDigitalRead8 ;
401
+ //node->digitalWrite8 = myDigitalWrite8 ;
402
+ node->pwmWrite = myPwmWrite ;
403
+
404
+ return TRUE ;
405
+ }