wiring_lmk 2.0.0
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 +7 -0
- data/ext/wiringpi/WiringPi/devLib/ds1302.c +254 -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 +507 -0
- data/ext/wiringpi/WiringPi/devLib/lcd.h +52 -0
- data/ext/wiringpi/WiringPi/devLib/lcd128x64.c +684 -0
- data/ext/wiringpi/WiringPi/devLib/lcd128x64.h +39 -0
- data/ext/wiringpi/WiringPi/devLib/maxdetect.c +167 -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 +178 -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 +117 -0
- data/ext/wiringpi/WiringPi/devLib/piNes.h +45 -0
- data/ext/wiringpi/WiringPi/gpio/extensions.c +700 -0
- data/ext/wiringpi/WiringPi/gpio/extensions.h +26 -0
- data/ext/wiringpi/WiringPi/gpio/gpio.c +1280 -0
- data/ext/wiringpi/WiringPi/gpio/pins.c +33 -0
- data/ext/wiringpi/WiringPi/gpio/readall.c +337 -0
- data/ext/wiringpi/WiringPi/wiringPi/drcSerial.c +201 -0
- data/ext/wiringpi/WiringPi/wiringPi/drcSerial.h +33 -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 +189 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.c +234 -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 +113 -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 +92 -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/sn3218.c +75 -0
- data/ext/wiringpi/WiringPi/wiringPi/sn3218.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/softPwm.c +168 -0
- data/ext/wiringpi/WiringPi/wiringPi/softPwm.h +35 -0
- data/ext/wiringpi/WiringPi/wiringPi/softServo.c +247 -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 +113 -0
- data/ext/wiringpi/WiringPi/wiringPi/sr595.h +34 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPi.c +3688 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPi.h +229 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.c +236 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.h +42 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.c +121 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.h +35 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringSerial.c +253 -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/extconf.rb +8 -0
- data/ext/wiringpi/wiringpi_wrap.c +4396 -0
- data/lib/wiring_lmk.rb +42 -0
- data/lib/wiring_lmk/event.rb +21 -0
- data/lib/wiring_lmk/gpio.rb +139 -0
- data/lib/wiring_lmk/i2c.rb +26 -0
- data/lib/wiring_lmk/mcp23x17.rb +31 -0
- data/lib/wiring_lmk/serial.rb +49 -0
- data/lib/wiring_lmk/spi.rb +15 -0
- metadata +136 -0
|
@@ -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,121 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* wiringPiSPI.c:
|
|
3
|
+
* Simplified SPI access routines
|
|
4
|
+
* Copyright (c) 2012 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 spiMode = 0 ;
|
|
44
|
+
const static uint8_t spiBPW = 8 ;
|
|
45
|
+
const static uint16_t spiDelay = 0 ;
|
|
46
|
+
|
|
47
|
+
static uint32_t spiSpeeds [2] ;
|
|
48
|
+
static int spiFds [2] ;
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
/*
|
|
52
|
+
* wiringPiSPIGetFd:
|
|
53
|
+
* Return the file-descriptor for the given channel
|
|
54
|
+
*********************************************************************************
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
int wiringPiSPIGetFd (int channel)
|
|
58
|
+
{
|
|
59
|
+
return spiFds [channel & 1] ;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
/*
|
|
64
|
+
* wiringPiSPIDataRW:
|
|
65
|
+
* Write and Read a block of data over the SPI bus.
|
|
66
|
+
* Note the data ia being read into the transmit buffer, so will
|
|
67
|
+
* overwrite it!
|
|
68
|
+
* This is also a full-duplex operation.
|
|
69
|
+
*********************************************************************************
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
int wiringPiSPIDataRW (int channel, unsigned char *data, int len)
|
|
73
|
+
{
|
|
74
|
+
struct spi_ioc_transfer spi ;
|
|
75
|
+
|
|
76
|
+
channel &= 1 ;
|
|
77
|
+
|
|
78
|
+
spi.tx_buf = (unsigned long)data ;
|
|
79
|
+
spi.rx_buf = (unsigned long)data ;
|
|
80
|
+
spi.len = len ;
|
|
81
|
+
spi.delay_usecs = spiDelay ;
|
|
82
|
+
spi.speed_hz = spiSpeeds [channel] ;
|
|
83
|
+
spi.bits_per_word = spiBPW ;
|
|
84
|
+
|
|
85
|
+
return ioctl (spiFds [channel], SPI_IOC_MESSAGE(1), &spi) ;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
/*
|
|
90
|
+
* wiringPiSPISetup:
|
|
91
|
+
* Open the SPI device, and set it up, etc.
|
|
92
|
+
*********************************************************************************
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
int wiringPiSPISetup (int channel, int speed)
|
|
96
|
+
{
|
|
97
|
+
int fd ;
|
|
98
|
+
|
|
99
|
+
channel &= 1 ;
|
|
100
|
+
|
|
101
|
+
if ((fd = open (channel == 0 ? spiDev0 : spiDev1, O_RDWR)) < 0)
|
|
102
|
+
return wiringPiFailure (WPI_ALMOST, "Unable to open SPI device: %s\n", strerror (errno)) ;
|
|
103
|
+
|
|
104
|
+
spiSpeeds [channel] = speed ;
|
|
105
|
+
spiFds [channel] = fd ;
|
|
106
|
+
|
|
107
|
+
// Set SPI parameters.
|
|
108
|
+
// Why are we reading it afterwriting it? I've no idea, but for now I'm blindly
|
|
109
|
+
// copying example code I've seen online...
|
|
110
|
+
|
|
111
|
+
if (ioctl (fd, SPI_IOC_WR_MODE, &spiMode) < 0)
|
|
112
|
+
return wiringPiFailure (WPI_ALMOST, "SPI Mode Change failure: %s\n", strerror (errno)) ;
|
|
113
|
+
|
|
114
|
+
if (ioctl (fd, SPI_IOC_WR_BITS_PER_WORD, &spiBPW) < 0)
|
|
115
|
+
return wiringPiFailure (WPI_ALMOST, "SPI BPW Change failure: %s\n", strerror (errno)) ;
|
|
116
|
+
|
|
117
|
+
if (ioctl (fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed) < 0)
|
|
118
|
+
return wiringPiFailure (WPI_ALMOST, "SPI Speed Change failure: %s\n", strerror (errno)) ;
|
|
119
|
+
|
|
120
|
+
return fd ;
|
|
121
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* wiringPiSPI.h:
|
|
3
|
+
* Simplified SPI access routines
|
|
4
|
+
* Copyright (c) 2012 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 wiringPiSPISetup (int channel, int speed) ;
|
|
32
|
+
|
|
33
|
+
#ifdef __cplusplus
|
|
34
|
+
}
|
|
35
|
+
#endif
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* wiringSerial.c:
|
|
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
|
+
#include <stdio.h>
|
|
24
|
+
#include <stdlib.h>
|
|
25
|
+
#include <stdint.h>
|
|
26
|
+
#include <stdarg.h>
|
|
27
|
+
#include <string.h>
|
|
28
|
+
#include <termios.h>
|
|
29
|
+
#include <unistd.h>
|
|
30
|
+
#include <fcntl.h>
|
|
31
|
+
#include <sys/ioctl.h>
|
|
32
|
+
#include <sys/types.h>
|
|
33
|
+
#include <sys/stat.h>
|
|
34
|
+
|
|
35
|
+
#include "wiringSerial.h"
|
|
36
|
+
|
|
37
|
+
/*
|
|
38
|
+
* serialOpen:
|
|
39
|
+
* Open and initialise the serial port, setting all the right
|
|
40
|
+
* port parameters - or as many as are required - hopefully!
|
|
41
|
+
*********************************************************************************
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
int serialOpen (const char *device, const int baud)
|
|
45
|
+
{
|
|
46
|
+
struct termios options ;
|
|
47
|
+
speed_t myBaud ;
|
|
48
|
+
int status, fd ;
|
|
49
|
+
|
|
50
|
+
switch (baud)
|
|
51
|
+
{
|
|
52
|
+
case 50:
|
|
53
|
+
myBaud = B50 ;
|
|
54
|
+
break ;
|
|
55
|
+
case 75:
|
|
56
|
+
myBaud = B75 ;
|
|
57
|
+
break ;
|
|
58
|
+
case 110:
|
|
59
|
+
myBaud = B110 ;
|
|
60
|
+
break ;
|
|
61
|
+
case 134:
|
|
62
|
+
myBaud = B134 ;
|
|
63
|
+
break ;
|
|
64
|
+
case 150:
|
|
65
|
+
myBaud = B150 ;
|
|
66
|
+
break ;
|
|
67
|
+
case 200:
|
|
68
|
+
myBaud = B200 ;
|
|
69
|
+
break ;
|
|
70
|
+
case 300:
|
|
71
|
+
myBaud = B300 ;
|
|
72
|
+
break ;
|
|
73
|
+
case 600:
|
|
74
|
+
myBaud = B600 ;
|
|
75
|
+
break ;
|
|
76
|
+
case 1200:
|
|
77
|
+
myBaud = B1200 ;
|
|
78
|
+
break ;
|
|
79
|
+
case 1800:
|
|
80
|
+
myBaud = B1800 ;
|
|
81
|
+
break ;
|
|
82
|
+
case 2400:
|
|
83
|
+
myBaud = B2400 ;
|
|
84
|
+
break ;
|
|
85
|
+
case 4800:
|
|
86
|
+
myBaud = B4800 ;
|
|
87
|
+
break ;
|
|
88
|
+
case 9600:
|
|
89
|
+
myBaud = B9600 ;
|
|
90
|
+
break ;
|
|
91
|
+
case 19200:
|
|
92
|
+
myBaud = B19200 ;
|
|
93
|
+
break ;
|
|
94
|
+
case 38400:
|
|
95
|
+
myBaud = B38400 ;
|
|
96
|
+
break ;
|
|
97
|
+
case 57600:
|
|
98
|
+
myBaud = B57600 ;
|
|
99
|
+
break ;
|
|
100
|
+
case 115200:
|
|
101
|
+
myBaud = B115200 ;
|
|
102
|
+
break ;
|
|
103
|
+
case 230400:
|
|
104
|
+
myBaud = B230400 ;
|
|
105
|
+
break ;
|
|
106
|
+
|
|
107
|
+
default:
|
|
108
|
+
return -2 ;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if ((fd = open (device, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK)) == -1)
|
|
112
|
+
return -1 ;
|
|
113
|
+
|
|
114
|
+
fcntl (fd, F_SETFL, O_RDWR) ;
|
|
115
|
+
|
|
116
|
+
// Get and modify current options:
|
|
117
|
+
|
|
118
|
+
tcgetattr (fd, &options) ;
|
|
119
|
+
|
|
120
|
+
cfmakeraw (&options) ;
|
|
121
|
+
cfsetispeed (&options, myBaud) ;
|
|
122
|
+
cfsetospeed (&options, myBaud) ;
|
|
123
|
+
|
|
124
|
+
options.c_cflag |= (CLOCAL | CREAD) ;
|
|
125
|
+
options.c_cflag &= ~PARENB ;
|
|
126
|
+
options.c_cflag &= ~CSTOPB ;
|
|
127
|
+
options.c_cflag &= ~CSIZE ;
|
|
128
|
+
options.c_cflag |= CS8 ;
|
|
129
|
+
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG) ;
|
|
130
|
+
options.c_oflag &= ~OPOST ;
|
|
131
|
+
|
|
132
|
+
options.c_cc [VMIN] = 0 ;
|
|
133
|
+
options.c_cc [VTIME] = 100 ; // Ten seconds (100 deciseconds)
|
|
134
|
+
|
|
135
|
+
tcsetattr (fd, TCSANOW | TCSAFLUSH, &options) ;
|
|
136
|
+
|
|
137
|
+
ioctl (fd, TIOCMGET, &status);
|
|
138
|
+
|
|
139
|
+
status |= TIOCM_DTR ;
|
|
140
|
+
status |= TIOCM_RTS ;
|
|
141
|
+
|
|
142
|
+
ioctl (fd, TIOCMSET, &status);
|
|
143
|
+
|
|
144
|
+
usleep (10000) ; // 10mS
|
|
145
|
+
|
|
146
|
+
return fd ;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
/*
|
|
151
|
+
* serialFlush:
|
|
152
|
+
* Flush the serial buffers (both tx & rx)
|
|
153
|
+
*********************************************************************************
|
|
154
|
+
*/
|
|
155
|
+
|
|
156
|
+
void serialFlush (const int fd)
|
|
157
|
+
{
|
|
158
|
+
tcflush (fd, TCIOFLUSH) ;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
/*
|
|
163
|
+
* serialClose:
|
|
164
|
+
* Release the serial port
|
|
165
|
+
*********************************************************************************
|
|
166
|
+
*/
|
|
167
|
+
|
|
168
|
+
void serialClose (const int fd)
|
|
169
|
+
{
|
|
170
|
+
close (fd) ;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
/*
|
|
175
|
+
* serialPutchar:
|
|
176
|
+
* Send a single character to the serial port
|
|
177
|
+
*********************************************************************************
|
|
178
|
+
*/
|
|
179
|
+
|
|
180
|
+
void serialPutchar (const int fd, const unsigned char c)
|
|
181
|
+
{
|
|
182
|
+
int ret = -1;
|
|
183
|
+
ret = write (fd, &c, 1) ;
|
|
184
|
+
ret = ret;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
/*
|
|
189
|
+
* serialPuts:
|
|
190
|
+
* Send a string to the serial port
|
|
191
|
+
*********************************************************************************
|
|
192
|
+
*/
|
|
193
|
+
|
|
194
|
+
void serialPuts (const int fd, const char *s)
|
|
195
|
+
{
|
|
196
|
+
int ret = -1;
|
|
197
|
+
ret = write (fd, s, strlen (s)) ;
|
|
198
|
+
ret = ret;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/*
|
|
202
|
+
* serialPrintf:
|
|
203
|
+
* Printf over Serial
|
|
204
|
+
*********************************************************************************
|
|
205
|
+
*/
|
|
206
|
+
|
|
207
|
+
void serialPrintf (const int fd, const char *message, ...)
|
|
208
|
+
{
|
|
209
|
+
va_list argp ;
|
|
210
|
+
char buffer [1024] ;
|
|
211
|
+
|
|
212
|
+
va_start (argp, message) ;
|
|
213
|
+
vsnprintf (buffer, 1023, message, argp) ;
|
|
214
|
+
va_end (argp) ;
|
|
215
|
+
|
|
216
|
+
serialPuts (fd, buffer) ;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
/*
|
|
221
|
+
* serialDataAvail:
|
|
222
|
+
* Return the number of bytes of data avalable to be read in the serial port
|
|
223
|
+
*********************************************************************************
|
|
224
|
+
*/
|
|
225
|
+
|
|
226
|
+
int serialDataAvail (const int fd)
|
|
227
|
+
{
|
|
228
|
+
int result ;
|
|
229
|
+
|
|
230
|
+
if (ioctl (fd, FIONREAD, &result) == -1)
|
|
231
|
+
return -1 ;
|
|
232
|
+
|
|
233
|
+
return result ;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
/*
|
|
238
|
+
* serialGetchar:
|
|
239
|
+
* Get a single character from the serial device.
|
|
240
|
+
* Note: Zero is a valid character and this function will time-out after
|
|
241
|
+
* 10 seconds.
|
|
242
|
+
*********************************************************************************
|
|
243
|
+
*/
|
|
244
|
+
|
|
245
|
+
int serialGetchar (const int fd)
|
|
246
|
+
{
|
|
247
|
+
uint8_t x ;
|
|
248
|
+
|
|
249
|
+
if (read (fd, &x, 1) != 1)
|
|
250
|
+
return -1 ;
|
|
251
|
+
|
|
252
|
+
return ((int)x) & 0xFF ;
|
|
253
|
+
}
|