wiringpi 1.1.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. checksums.yaml +7 -0
  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 +165 -0
  12. data/ext/wiringpi/{serial.h → WiringPi/devLib/maxdetect.h} +14 -15
  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 +178 -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/examples/Gertboard/7segments.c +221 -0
  21. data/ext/wiringpi/WiringPi/examples/Gertboard/buttons.c +83 -0
  22. data/ext/wiringpi/WiringPi/examples/Gertboard/gertboard.c +96 -0
  23. data/ext/wiringpi/WiringPi/examples/Gertboard/record.c +60 -0
  24. data/ext/wiringpi/WiringPi/examples/Gertboard/temperature.c +78 -0
  25. data/ext/wiringpi/WiringPi/examples/Gertboard/voltmeter.c +73 -0
  26. data/ext/wiringpi/WiringPi/examples/Gertboard/vumeter.c +152 -0
  27. data/ext/wiringpi/WiringPi/examples/PiFace/blink.c +59 -0
  28. data/ext/wiringpi/WiringPi/examples/PiFace/buttons.c +103 -0
  29. data/ext/wiringpi/WiringPi/examples/PiFace/ladder.c +337 -0
  30. data/ext/wiringpi/WiringPi/examples/PiFace/metro.c +111 -0
  31. data/ext/wiringpi/WiringPi/examples/PiFace/motor.c +120 -0
  32. data/ext/wiringpi/WiringPi/examples/PiFace/reaction.c +194 -0
  33. data/ext/wiringpi/WiringPi/examples/PiGlow/piGlow0.c +51 -0
  34. data/ext/wiringpi/WiringPi/examples/PiGlow/piGlow1.c +258 -0
  35. data/ext/wiringpi/WiringPi/examples/PiGlow/piglow.c +176 -0
  36. data/ext/wiringpi/WiringPi/examples/blink.c +48 -0
  37. data/ext/wiringpi/WiringPi/examples/blink12.c +111 -0
  38. data/ext/wiringpi/WiringPi/examples/blink12drcs.c +125 -0
  39. data/ext/wiringpi/WiringPi/examples/blink6drcs.c +115 -0
  40. data/ext/wiringpi/WiringPi/examples/blink8.c +57 -0
  41. data/ext/wiringpi/WiringPi/examples/clock.c +201 -0
  42. data/ext/wiringpi/WiringPi/examples/delayTest.c +107 -0
  43. data/ext/wiringpi/WiringPi/examples/ds1302.c +238 -0
  44. data/ext/wiringpi/WiringPi/examples/header.h +23 -0
  45. data/ext/wiringpi/WiringPi/examples/isr-osc.c +118 -0
  46. data/ext/wiringpi/WiringPi/examples/isr.c +110 -0
  47. data/ext/wiringpi/WiringPi/examples/lcd-adafruit.c +347 -0
  48. data/ext/wiringpi/WiringPi/examples/lcd.c +286 -0
  49. data/ext/wiringpi/WiringPi/examples/lowPower.c +68 -0
  50. data/ext/wiringpi/WiringPi/examples/nes.c +67 -0
  51. data/ext/wiringpi/WiringPi/examples/okLed.c +82 -0
  52. data/ext/wiringpi/WiringPi/examples/pwm.c +58 -0
  53. data/ext/wiringpi/WiringPi/examples/q2w/binary.c +79 -0
  54. data/ext/wiringpi/WiringPi/examples/q2w/blink-io.c +61 -0
  55. data/ext/wiringpi/WiringPi/examples/q2w/blink.c +50 -0
  56. data/ext/wiringpi/WiringPi/examples/q2w/bright.c +59 -0
  57. data/ext/wiringpi/WiringPi/examples/q2w/button.c +63 -0
  58. data/ext/wiringpi/WiringPi/examples/q2w/volts.c +62 -0
  59. data/ext/wiringpi/WiringPi/examples/rht03.c +69 -0
  60. data/ext/wiringpi/WiringPi/examples/serialRead.c +48 -0
  61. data/ext/wiringpi/WiringPi/examples/serialTest.c +75 -0
  62. data/ext/wiringpi/WiringPi/examples/servo.c +57 -0
  63. data/ext/wiringpi/WiringPi/examples/softPwm.c +89 -0
  64. data/ext/wiringpi/WiringPi/examples/softTone.c +54 -0
  65. data/ext/wiringpi/WiringPi/examples/speed.c +95 -0
  66. data/ext/wiringpi/WiringPi/examples/spiSpeed.c +118 -0
  67. data/ext/wiringpi/WiringPi/examples/wfi.c +161 -0
  68. data/ext/wiringpi/WiringPi/gpio/gpio.c +1351 -0
  69. data/ext/wiringpi/WiringPi/gpio/pins.c +33 -0
  70. data/ext/wiringpi/WiringPi/gpio/readall.c +334 -0
  71. data/ext/wiringpi/WiringPi/gpio/version.h +1 -0
  72. data/ext/wiringpi/WiringPi/wiringPi/drcSerial.c +201 -0
  73. data/ext/wiringpi/WiringPi/wiringPi/drcSerial.h +33 -0
  74. data/ext/wiringpi/WiringPi/wiringPi/max31855.c +81 -0
  75. data/ext/wiringpi/WiringPi/wiringPi/max31855.h +33 -0
  76. data/ext/wiringpi/WiringPi/wiringPi/max5322.c +84 -0
  77. data/ext/wiringpi/WiringPi/wiringPi/max5322.h +33 -0
  78. data/ext/wiringpi/WiringPi/wiringPi/mcp23008.c +149 -0
  79. data/ext/wiringpi/WiringPi/wiringPi/mcp23008.h +33 -0
  80. data/ext/wiringpi/WiringPi/wiringPi/mcp23016.c +164 -0
  81. data/ext/wiringpi/WiringPi/wiringPi/mcp23016.h +33 -0
  82. data/ext/wiringpi/WiringPi/wiringPi/mcp23016reg.h +48 -0
  83. data/ext/wiringpi/WiringPi/wiringPi/mcp23017.c +195 -0
  84. data/ext/wiringpi/WiringPi/wiringPi/mcp23017.h +33 -0
  85. data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.c +189 -0
  86. data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.h +33 -0
  87. data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.c +236 -0
  88. data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.h +33 -0
  89. data/ext/wiringpi/WiringPi/wiringPi/mcp23x08.h +73 -0
  90. data/ext/wiringpi/WiringPi/wiringPi/mcp23x0817.h +87 -0
  91. data/ext/wiringpi/WiringPi/wiringPi/mcp3002.c +76 -0
  92. data/ext/wiringpi/WiringPi/wiringPi/mcp3002.h +33 -0
  93. data/ext/wiringpi/WiringPi/wiringPi/mcp3004.c +76 -0
  94. data/ext/wiringpi/WiringPi/wiringPi/mcp3004.h +33 -0
  95. data/ext/wiringpi/WiringPi/wiringPi/mcp3422.c +110 -0
  96. data/ext/wiringpi/WiringPi/wiringPi/mcp3422.h +43 -0
  97. data/ext/wiringpi/WiringPi/wiringPi/mcp4802.c +76 -0
  98. data/ext/wiringpi/WiringPi/wiringPi/mcp4802.h +33 -0
  99. data/ext/wiringpi/WiringPi/wiringPi/pcf8574.c +126 -0
  100. data/ext/wiringpi/WiringPi/wiringPi/pcf8574.h +33 -0
  101. data/ext/wiringpi/WiringPi/wiringPi/pcf8591.c +90 -0
  102. data/ext/wiringpi/WiringPi/wiringPi/pcf8591.h +33 -0
  103. data/ext/wiringpi/WiringPi/wiringPi/piHiPri.c +51 -0
  104. data/ext/wiringpi/WiringPi/wiringPi/piThread.c +63 -0
  105. data/ext/wiringpi/WiringPi/wiringPi/sn3218.c +75 -0
  106. data/ext/wiringpi/WiringPi/wiringPi/sn3218.h +33 -0
  107. data/ext/wiringpi/WiringPi/wiringPi/softPwm.c +166 -0
  108. data/ext/wiringpi/WiringPi/wiringPi/softPwm.h +35 -0
  109. data/ext/wiringpi/WiringPi/wiringPi/softServo.c +211 -0
  110. data/ext/wiringpi/WiringPi/wiringPi/softServo.h +35 -0
  111. data/ext/wiringpi/WiringPi/wiringPi/softTone.c +150 -0
  112. data/ext/wiringpi/WiringPi/wiringPi/softTone.h +39 -0
  113. data/ext/wiringpi/WiringPi/wiringPi/sr595.c +109 -0
  114. data/ext/wiringpi/WiringPi/wiringPi/sr595.h +34 -0
  115. data/ext/wiringpi/WiringPi/wiringPi/wiringPi.c +2007 -0
  116. data/ext/wiringpi/WiringPi/wiringPi/wiringPi.h +224 -0
  117. data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.c +232 -0
  118. data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.h +42 -0
  119. data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.c +136 -0
  120. data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.h +36 -0
  121. data/ext/wiringpi/{serial.c → WiringPi/wiringPi/wiringSerial.c} +38 -29
  122. data/ext/wiringpi/WiringPi/wiringPi/wiringSerial.h +38 -0
  123. data/ext/wiringpi/{wiringShift.c → WiringPi/wiringPi/wiringShift.c} +3 -4
  124. data/ext/wiringpi/{wiringShift.h → WiringPi/wiringPi/wiringShift.h} +5 -5
  125. data/ext/wiringpi/WiringPi/wiringPi/wpiExtensions.c +731 -0
  126. data/ext/wiringpi/WiringPi/wiringPi/wpiExtensions.h +26 -0
  127. data/ext/wiringpi/extconf.rb +7 -1
  128. data/ext/wiringpi/wiringpi_wrap.c +1741 -218
  129. data/lib/wiringpi.rb +24 -222
  130. data/lib/wiringpi/event.rb +21 -0
  131. data/lib/wiringpi/gpio.rb +139 -0
  132. data/lib/wiringpi/i2c.rb +26 -0
  133. data/lib/wiringpi/mcp23x17.rb +31 -0
  134. data/lib/wiringpi/serial.rb +49 -0
  135. data/lib/wiringpi/spi.rb +15 -0
  136. metadata +146 -22
  137. data/ext/wiringpi/wiringPi.c +0 -729
  138. data/ext/wiringpi/wiringPi.h +0 -69
@@ -0,0 +1,42 @@
1
+ /*
2
+ * wiringPiI2C.h:
3
+ * Simplified I2C access routines
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 wiringPiI2CRead (int fd) ;
30
+ extern int wiringPiI2CReadReg8 (int fd, int reg) ;
31
+ extern int wiringPiI2CReadReg16 (int fd, int reg) ;
32
+
33
+ extern int wiringPiI2CWrite (int fd, int data) ;
34
+ extern int wiringPiI2CWriteReg8 (int fd, int reg, int data) ;
35
+ extern int wiringPiI2CWriteReg16 (int fd, int reg, int data) ;
36
+
37
+ extern int wiringPiI2CSetupInterface (const char *device, int devId) ;
38
+ extern int wiringPiI2CSetup (const int devId) ;
39
+
40
+ #ifdef __cplusplus
41
+ }
42
+ #endif
@@ -0,0 +1,136 @@
1
+ /*
2
+ * wiringPiSPI.c:
3
+ * Simplified SPI access routines
4
+ * Copyright (c) 2012-2015 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
+ #include <stdint.h>
27
+ #include <fcntl.h>
28
+ #include <errno.h>
29
+ #include <string.h>
30
+ #include <sys/ioctl.h>
31
+ #include <linux/spi/spidev.h>
32
+
33
+ #include "wiringPi.h"
34
+
35
+ #include "wiringPiSPI.h"
36
+
37
+
38
+ // The SPI bus parameters
39
+ // Variables as they need to be passed as pointers later on
40
+
41
+ const static char *spiDev0 = "/dev/spidev0.0" ;
42
+ const static char *spiDev1 = "/dev/spidev0.1" ;
43
+ const static uint8_t spiBPW = 8 ;
44
+ const static uint16_t spiDelay = 0 ;
45
+
46
+ static uint32_t spiSpeeds [2] ;
47
+ static int spiFds [2] ;
48
+
49
+
50
+ /*
51
+ * wiringPiSPIGetFd:
52
+ * Return the file-descriptor for the given channel
53
+ *********************************************************************************
54
+ */
55
+
56
+ int wiringPiSPIGetFd (int channel)
57
+ {
58
+ return spiFds [channel & 1] ;
59
+ }
60
+
61
+
62
+ /*
63
+ * wiringPiSPIDataRW:
64
+ * Write and Read a block of data over the SPI bus.
65
+ * Note the data ia being read into the transmit buffer, so will
66
+ * overwrite it!
67
+ * This is also a full-duplex operation.
68
+ *********************************************************************************
69
+ */
70
+
71
+ int wiringPiSPIDataRW (int channel, unsigned char *data, int len)
72
+ {
73
+ struct spi_ioc_transfer spi ;
74
+
75
+ channel &= 1 ;
76
+
77
+ // Mentioned in spidev.h but not used in the original kernel documentation
78
+ // test program )-:
79
+
80
+ memset (&spi, 0, sizeof (spi)) ;
81
+
82
+ spi.tx_buf = (unsigned long)data ;
83
+ spi.rx_buf = (unsigned long)data ;
84
+ spi.len = len ;
85
+ spi.delay_usecs = spiDelay ;
86
+ spi.speed_hz = spiSpeeds [channel] ;
87
+ spi.bits_per_word = spiBPW ;
88
+
89
+ return ioctl (spiFds [channel], SPI_IOC_MESSAGE(1), &spi) ;
90
+ }
91
+
92
+
93
+ /*
94
+ * wiringPiSPISetupMode:
95
+ * Open the SPI device, and set it up, with the mode, etc.
96
+ *********************************************************************************
97
+ */
98
+
99
+ int wiringPiSPISetupMode (int channel, int speed, int mode)
100
+ {
101
+ int fd ;
102
+
103
+ mode &= 3 ; // Mode is 0, 1, 2 or 3
104
+ channel &= 1 ; // Channel is 0 or 1
105
+
106
+ if ((fd = open (channel == 0 ? spiDev0 : spiDev1, O_RDWR)) < 0)
107
+ return wiringPiFailure (WPI_ALMOST, "Unable to open SPI device: %s\n", strerror (errno)) ;
108
+
109
+ spiSpeeds [channel] = speed ;
110
+ spiFds [channel] = fd ;
111
+
112
+ // Set SPI parameters.
113
+
114
+ if (ioctl (fd, SPI_IOC_WR_MODE, &mode) < 0)
115
+ return wiringPiFailure (WPI_ALMOST, "SPI Mode Change failure: %s\n", strerror (errno)) ;
116
+
117
+ if (ioctl (fd, SPI_IOC_WR_BITS_PER_WORD, &spiBPW) < 0)
118
+ return wiringPiFailure (WPI_ALMOST, "SPI BPW Change failure: %s\n", strerror (errno)) ;
119
+
120
+ if (ioctl (fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed) < 0)
121
+ return wiringPiFailure (WPI_ALMOST, "SPI Speed Change failure: %s\n", strerror (errno)) ;
122
+
123
+ return fd ;
124
+ }
125
+
126
+
127
+ /*
128
+ * wiringPiSPISetup:
129
+ * Open the SPI device, and set it up, etc. in the default MODE 0
130
+ *********************************************************************************
131
+ */
132
+
133
+ int wiringPiSPISetup (int channel, int speed)
134
+ {
135
+ return wiringPiSPISetupMode (channel, speed, 0) ;
136
+ }
@@ -0,0 +1,36 @@
1
+ /*
2
+ * wiringPiSPI.h:
3
+ * Simplified SPI access routines
4
+ * Copyright (c) 2012-2015 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
+ int wiringPiSPIGetFd (int channel) ;
30
+ int wiringPiSPIDataRW (int channel, unsigned char *data, int len) ;
31
+ int wiringPiSPISetupMode (int channel, int speed, int mode) ;
32
+ int wiringPiSPISetup (int channel, int speed) ;
33
+
34
+ #ifdef __cplusplus
35
+ }
36
+ #endif
@@ -1,21 +1,21 @@
1
1
  /*
2
- * serial.c:
2
+ * wiringSerial.c:
3
3
  * Handle a serial port
4
4
  ***********************************************************************
5
5
  * This file is part of wiringPi:
6
6
  * https://projects.drogon.net/raspberry-pi/wiringpi/
7
7
  *
8
8
  * wiringPi is free software: you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License as published by
9
+ * it under the terms of the GNU Lesser General Public License as published by
10
10
  * the Free Software Foundation, either version 3 of the License, or
11
11
  * (at your option) any later version.
12
12
  *
13
13
  * wiringPi is distributed in the hope that it will be useful,
14
14
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
15
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- * GNU General Public License for more details.
16
+ * GNU Lesser General Public License for more details.
17
17
  *
18
- * You should have received a copy of the GNU General Public License
18
+ * You should have received a copy of the GNU Lesser General Public License
19
19
  * along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
20
20
  ***********************************************************************
21
21
  */
@@ -32,7 +32,7 @@
32
32
  #include <sys/types.h>
33
33
  #include <sys/stat.h>
34
34
 
35
- #include "serial.h"
35
+ #include "wiringSerial.h"
36
36
 
37
37
  /*
38
38
  * serialOpen:
@@ -41,16 +41,12 @@
41
41
  *********************************************************************************
42
42
  */
43
43
 
44
- int serialOpen (char *device, int baud)
44
+ int serialOpen (const char *device, const int baud)
45
45
  {
46
46
  struct termios options ;
47
47
  speed_t myBaud ;
48
48
  int status, fd ;
49
49
 
50
- #ifdef DEBUG
51
- printf ("openSerialPort: <%s> baud: $d\n", device, baud) ;
52
- #endif
53
-
54
50
  switch (baud)
55
51
  {
56
52
  case 50: myBaud = B50 ; break ;
@@ -64,6 +60,7 @@ int serialOpen (char *device, int baud)
64
60
  case 1200: myBaud = B1200 ; break ;
65
61
  case 1800: myBaud = B1800 ; break ;
66
62
  case 2400: myBaud = B2400 ; break ;
63
+ case 4800: myBaud = B4800 ; break ;
67
64
  case 9600: myBaud = B9600 ; break ;
68
65
  case 19200: myBaud = B19200 ; break ;
69
66
  case 38400: myBaud = B38400 ; break ;
@@ -84,22 +81,22 @@ int serialOpen (char *device, int baud)
84
81
 
85
82
  tcgetattr (fd, &options) ;
86
83
 
87
- cfmakeraw (&options) ;
88
- cfsetispeed (&options, myBaud) ;
89
- cfsetospeed (&options, myBaud) ;
84
+ cfmakeraw (&options) ;
85
+ cfsetispeed (&options, myBaud) ;
86
+ cfsetospeed (&options, myBaud) ;
90
87
 
91
- options.c_cflag |= (CLOCAL | CREAD) ;
92
- options.c_cflag &= ~PARENB ;
93
- options.c_cflag &= ~CSTOPB ;
94
- options.c_cflag &= ~CSIZE ;
95
- options.c_cflag |= CS8 ;
96
- options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG) ;
97
- options.c_oflag &= ~OPOST ;
88
+ options.c_cflag |= (CLOCAL | CREAD) ;
89
+ options.c_cflag &= ~PARENB ;
90
+ options.c_cflag &= ~CSTOPB ;
91
+ options.c_cflag &= ~CSIZE ;
92
+ options.c_cflag |= CS8 ;
93
+ options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG) ;
94
+ options.c_oflag &= ~OPOST ;
98
95
 
99
- options.c_cc [VMIN] = 0 ;
100
- options.c_cc [VTIME] = 100 ; // Ten seconds (100 deciseconds)
96
+ options.c_cc [VMIN] = 0 ;
97
+ options.c_cc [VTIME] = 100 ; // Ten seconds (100 deciseconds)
101
98
 
102
- tcsetattr (fd, TCSANOW, &options) ;
99
+ tcsetattr (fd, TCSANOW | TCSAFLUSH, &options) ;
103
100
 
104
101
  ioctl (fd, TIOCMGET, &status);
105
102
 
@@ -114,13 +111,25 @@ int serialOpen (char *device, int baud)
114
111
  }
115
112
 
116
113
 
114
+ /*
115
+ * serialFlush:
116
+ * Flush the serial buffers (both tx & rx)
117
+ *********************************************************************************
118
+ */
119
+
120
+ void serialFlush (const int fd)
121
+ {
122
+ tcflush (fd, TCIOFLUSH) ;
123
+ }
124
+
125
+
117
126
  /*
118
127
  * serialClose:
119
128
  * Release the serial port
120
129
  *********************************************************************************
121
130
  */
122
131
 
123
- void serialClose (int fd)
132
+ void serialClose (const int fd)
124
133
  {
125
134
  close (fd) ;
126
135
  }
@@ -132,7 +141,7 @@ void serialClose (int fd)
132
141
  *********************************************************************************
133
142
  */
134
143
 
135
- void serialPutchar (int fd, uint8_t c)
144
+ void serialPutchar (const int fd, const unsigned char c)
136
145
  {
137
146
  write (fd, &c, 1) ;
138
147
  }
@@ -144,7 +153,7 @@ void serialPutchar (int fd, uint8_t c)
144
153
  *********************************************************************************
145
154
  */
146
155
 
147
- void serialPuts (int fd, char *s)
156
+ void serialPuts (const int fd, const char *s)
148
157
  {
149
158
  write (fd, s, strlen (s)) ;
150
159
  }
@@ -155,7 +164,7 @@ void serialPuts (int fd, char *s)
155
164
  *********************************************************************************
156
165
  */
157
166
 
158
- void serialPrintf (int fd, char *message, ...)
167
+ void serialPrintf (const int fd, const char *message, ...)
159
168
  {
160
169
  va_list argp ;
161
170
  char buffer [1024] ;
@@ -174,7 +183,7 @@ void serialPrintf (int fd, char *message, ...)
174
183
  *********************************************************************************
175
184
  */
176
185
 
177
- int serialDataAvail (int fd)
186
+ int serialDataAvail (const int fd)
178
187
  {
179
188
  int result ;
180
189
 
@@ -193,7 +202,7 @@ int serialDataAvail (int fd)
193
202
  *********************************************************************************
194
203
  */
195
204
 
196
- int serialGetchar (int fd)
205
+ int serialGetchar (const int fd)
197
206
  {
198
207
  uint8_t x ;
199
208
 
@@ -0,0 +1,38 @@
1
+ /*
2
+ * wiringSerial.h:
3
+ * Handle a serial port
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 published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (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 License
19
+ * along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
20
+ ***********************************************************************
21
+ */
22
+
23
+ #ifdef __cplusplus
24
+ extern "C" {
25
+ #endif
26
+
27
+ extern int serialOpen (const char *device, const int baud) ;
28
+ extern void serialClose (const int fd) ;
29
+ extern void serialFlush (const int fd) ;
30
+ extern void serialPutchar (const int fd, const unsigned char c) ;
31
+ extern void serialPuts (const int fd, const char *s) ;
32
+ extern void serialPrintf (const int fd, const char *message, ...) ;
33
+ extern int serialDataAvail (const int fd) ;
34
+ extern int serialGetchar (const int fd) ;
35
+
36
+ #ifdef __cplusplus
37
+ }
38
+ #endif
@@ -8,16 +8,16 @@
8
8
  * https://projects.drogon.net/raspberry-pi/wiringpi/
9
9
  *
10
10
  * wiringPi is free software: you can redistribute it and/or modify
11
- * it under the terms of the GNU General Public License as published by
11
+ * it under the terms of the GNU Lesser General Public License as published by
12
12
  * the Free Software Foundation, either version 3 of the License, or
13
13
  * (at your option) any later version.
14
14
  *
15
15
  * wiringPi is distributed in the hope that it will be useful,
16
16
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
17
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
- * GNU General Public License for more details.
18
+ * GNU Lesser General Public License for more details.
19
19
  *
20
- * You should have received a copy of the GNU General Public License
20
+ * You should have received a copy of the GNU Lesser General Public License
21
21
  * along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
22
22
  ***********************************************************************
23
23
  */
@@ -56,7 +56,6 @@ uint8_t shiftIn (uint8_t dPin, uint8_t cPin, uint8_t order)
56
56
  return value;
57
57
  }
58
58
 
59
-
60
59
  /*
61
60
  * shiftOut:
62
61
  * Shift data out to a clocked source