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.
- 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
- metadata +155 -1
@@ -0,0 +1,63 @@
|
|
1
|
+
/*
|
2
|
+
* piThread.c:
|
3
|
+
* Provide a simplified interface to pthreads
|
4
|
+
*
|
5
|
+
* Copyright (c) 2012 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 <pthread.h>
|
27
|
+
#include "wiringPi.h"
|
28
|
+
|
29
|
+
static pthread_mutex_t piMutexes [4] ;
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
/*
|
34
|
+
* piThreadCreate:
|
35
|
+
* Create and start a thread
|
36
|
+
*********************************************************************************
|
37
|
+
*/
|
38
|
+
|
39
|
+
int piThreadCreate (void *(*fn)(void *))
|
40
|
+
{
|
41
|
+
pthread_t myThread ;
|
42
|
+
|
43
|
+
return pthread_create (&myThread, NULL, fn, NULL) ;
|
44
|
+
}
|
45
|
+
|
46
|
+
/*
|
47
|
+
* piLock: piUnlock:
|
48
|
+
* Activate/Deactivate a mutex.
|
49
|
+
* We're keeping things simple here and only tracking 4 mutexes which
|
50
|
+
* is more than enough for out entry-level pthread programming
|
51
|
+
*********************************************************************************
|
52
|
+
*/
|
53
|
+
|
54
|
+
void piLock (int key)
|
55
|
+
{
|
56
|
+
pthread_mutex_lock (&piMutexes [key]) ;
|
57
|
+
}
|
58
|
+
|
59
|
+
void piUnlock (int key)
|
60
|
+
{
|
61
|
+
pthread_mutex_unlock (&piMutexes [key]) ;
|
62
|
+
}
|
63
|
+
|
@@ -0,0 +1,95 @@
|
|
1
|
+
/*
|
2
|
+
* pseudoPins.c:
|
3
|
+
* Extend wiringPi with a number of pseudo pins which can be
|
4
|
+
* digitally or analog written/read.
|
5
|
+
*
|
6
|
+
* Note:
|
7
|
+
* Just one set of pseudo pins can exist per Raspberry Pi.
|
8
|
+
* These pins are shared between all programs running on
|
9
|
+
* that Raspberry Pi. The values are also persistant as
|
10
|
+
* they live in shared RAM. This gives you a means for
|
11
|
+
* temporary variable storing/sharing between programs,
|
12
|
+
* or for other cunning things I've not thought of yet..
|
13
|
+
*
|
14
|
+
* Copyright (c) 2012-2016 Gordon Henderson
|
15
|
+
***********************************************************************
|
16
|
+
* This file is part of wiringPi:
|
17
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
18
|
+
*
|
19
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
20
|
+
* it under the terms of the GNU Lesser General Public License as
|
21
|
+
* published by the Free Software Foundation, either version 3 of the
|
22
|
+
* License, or (at your option) any later version.
|
23
|
+
*
|
24
|
+
* wiringPi is distributed in the hope that it will be useful,
|
25
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
26
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
27
|
+
* GNU Lesser General Public License for more details.
|
28
|
+
*
|
29
|
+
* You should have received a copy of the GNU Lesser General Public
|
30
|
+
* License along with wiringPi.
|
31
|
+
* If not, see <http://www.gnu.org/licenses/>.
|
32
|
+
***********************************************************************
|
33
|
+
*/
|
34
|
+
|
35
|
+
#define SHARED_NAME "wiringPiPseudoPins"
|
36
|
+
#define PSEUDO_PINS 64
|
37
|
+
|
38
|
+
#include <unistd.h>
|
39
|
+
#include <sys/types.h>
|
40
|
+
#include <sys/mman.h>
|
41
|
+
#include <sys/stat.h>
|
42
|
+
#include <fcntl.h>
|
43
|
+
|
44
|
+
#include <wiringPi.h>
|
45
|
+
|
46
|
+
#include "pseudoPins.h"
|
47
|
+
|
48
|
+
static int myAnalogRead (struct wiringPiNodeStruct *node, int pin)
|
49
|
+
{
|
50
|
+
int *ptr = (int *)node->data0 ;
|
51
|
+
int myPin = pin - node->pinBase ;
|
52
|
+
|
53
|
+
return *(ptr + myPin) ;
|
54
|
+
}
|
55
|
+
|
56
|
+
|
57
|
+
static void myAnalogWrite (struct wiringPiNodeStruct *node, int pin, int value)
|
58
|
+
{
|
59
|
+
int *ptr = (int *)node->data0 ;
|
60
|
+
int myPin = pin - node->pinBase ;
|
61
|
+
|
62
|
+
*(ptr + myPin) = value ;
|
63
|
+
}
|
64
|
+
|
65
|
+
|
66
|
+
/*
|
67
|
+
* pseudoPinsSetup:
|
68
|
+
* Create a new wiringPi device node for the pseudoPins driver
|
69
|
+
*********************************************************************************
|
70
|
+
*/
|
71
|
+
|
72
|
+
int pseudoPinsSetup (const int pinBase)
|
73
|
+
{
|
74
|
+
struct wiringPiNodeStruct *node ;
|
75
|
+
void *ptr ;
|
76
|
+
|
77
|
+
node = wiringPiNewNode (pinBase, PSEUDO_PINS) ;
|
78
|
+
|
79
|
+
node->fd = shm_open (SHARED_NAME, O_CREAT | O_RDWR, 0666) ;
|
80
|
+
|
81
|
+
if (node->fd < 0)
|
82
|
+
return FALSE ;
|
83
|
+
|
84
|
+
if (ftruncate (node->fd, PSEUDO_PINS * sizeof (int)) < 0)
|
85
|
+
return FALSE ;
|
86
|
+
|
87
|
+
ptr = mmap (NULL, PSEUDO_PINS * sizeof (int), PROT_READ | PROT_WRITE, MAP_SHARED, node->fd, 0) ;
|
88
|
+
|
89
|
+
node->data0 = (unsigned int)ptr ;
|
90
|
+
|
91
|
+
node->analogRead = myAnalogRead ;
|
92
|
+
node->analogWrite = myAnalogWrite ;
|
93
|
+
|
94
|
+
return TRUE ;
|
95
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
/*
|
2
|
+
* pseudoPins.h:
|
3
|
+
* Extend wiringPi with a number of pseudo pins which can be
|
4
|
+
* digitally or analog written/read.
|
5
|
+
* Copyright (c) 2012-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
|
+
extern int pseudoPinsSetup (const int pinBase) ;
|
@@ -0,0 +1,252 @@
|
|
1
|
+
/*
|
2
|
+
* rht03.c:
|
3
|
+
* Extend wiringPi with the rht03 Maxdetect 1-Wire sensor.
|
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 <sys/time.h>
|
26
|
+
#include <stdio.h>
|
27
|
+
#include <stdio.h>
|
28
|
+
#include <time.h>
|
29
|
+
|
30
|
+
#include "wiringPi.h"
|
31
|
+
#include "rht03.h"
|
32
|
+
|
33
|
+
/*
|
34
|
+
* maxDetectLowHighWait:
|
35
|
+
* Wait for a transition from low to high on the bus
|
36
|
+
*********************************************************************************
|
37
|
+
*/
|
38
|
+
|
39
|
+
static int maxDetectLowHighWait (const int pin)
|
40
|
+
{
|
41
|
+
struct timeval now, timeOut, timeUp ;
|
42
|
+
|
43
|
+
// If already high then wait for pin to go low
|
44
|
+
|
45
|
+
gettimeofday (&now, NULL) ;
|
46
|
+
timerclear (&timeOut) ;
|
47
|
+
timeOut.tv_usec = 1000 ;
|
48
|
+
timeradd (&now, &timeOut, &timeUp) ;
|
49
|
+
|
50
|
+
while (digitalRead (pin) == HIGH)
|
51
|
+
{
|
52
|
+
gettimeofday (&now, NULL) ;
|
53
|
+
if (timercmp (&now, &timeUp, >))
|
54
|
+
return FALSE ;
|
55
|
+
}
|
56
|
+
|
57
|
+
// Wait for it to go HIGH
|
58
|
+
|
59
|
+
gettimeofday (&now, NULL) ;
|
60
|
+
timerclear (&timeOut) ;
|
61
|
+
timeOut.tv_usec = 1000 ;
|
62
|
+
timeradd (&now, &timeOut, &timeUp) ;
|
63
|
+
|
64
|
+
while (digitalRead (pin) == LOW)
|
65
|
+
{
|
66
|
+
gettimeofday (&now, NULL) ;
|
67
|
+
if (timercmp (&now, &timeUp, >))
|
68
|
+
return FALSE ;
|
69
|
+
}
|
70
|
+
|
71
|
+
return TRUE ;
|
72
|
+
}
|
73
|
+
|
74
|
+
|
75
|
+
/*
|
76
|
+
* maxDetectClockByte:
|
77
|
+
* Read in a single byte from the MaxDetect bus
|
78
|
+
*********************************************************************************
|
79
|
+
*/
|
80
|
+
|
81
|
+
static unsigned int maxDetectClockByte (const int pin)
|
82
|
+
{
|
83
|
+
unsigned int byte = 0 ;
|
84
|
+
int bit ;
|
85
|
+
|
86
|
+
for (bit = 0 ; bit < 8 ; ++bit)
|
87
|
+
{
|
88
|
+
if (!maxDetectLowHighWait (pin))
|
89
|
+
return 0 ;
|
90
|
+
|
91
|
+
// bit starting now - we need to time it.
|
92
|
+
|
93
|
+
delayMicroseconds (30) ;
|
94
|
+
byte <<= 1 ;
|
95
|
+
if (digitalRead (pin) == HIGH) // It's a 1
|
96
|
+
byte |= 1 ;
|
97
|
+
}
|
98
|
+
|
99
|
+
return byte ;
|
100
|
+
}
|
101
|
+
|
102
|
+
|
103
|
+
/*
|
104
|
+
* maxDetectRead:
|
105
|
+
* Read in and return the 4 data bytes from the MaxDetect sensor.
|
106
|
+
* Return TRUE/FALSE depending on the checksum validity
|
107
|
+
*********************************************************************************
|
108
|
+
*/
|
109
|
+
|
110
|
+
static int maxDetectRead (const int pin, unsigned char buffer [4])
|
111
|
+
{
|
112
|
+
int i ;
|
113
|
+
unsigned int checksum ;
|
114
|
+
unsigned char localBuf [5] ;
|
115
|
+
struct timeval now, then, took ;
|
116
|
+
|
117
|
+
// See how long we took
|
118
|
+
|
119
|
+
gettimeofday (&then, NULL) ;
|
120
|
+
|
121
|
+
// Wake up the RHT03 by pulling the data line low, then high
|
122
|
+
// Low for 10mS, high for 40uS.
|
123
|
+
|
124
|
+
pinMode (pin, OUTPUT) ;
|
125
|
+
digitalWrite (pin, 0) ; delay (10) ;
|
126
|
+
digitalWrite (pin, 1) ; delayMicroseconds (40) ;
|
127
|
+
pinMode (pin, INPUT) ;
|
128
|
+
|
129
|
+
// Now wait for sensor to pull pin low
|
130
|
+
|
131
|
+
if (!maxDetectLowHighWait (pin))
|
132
|
+
return FALSE ;
|
133
|
+
|
134
|
+
// and read in 5 bytes (40 bits)
|
135
|
+
|
136
|
+
for (i = 0 ; i < 5 ; ++i)
|
137
|
+
localBuf [i] = maxDetectClockByte (pin) ;
|
138
|
+
|
139
|
+
checksum = 0 ;
|
140
|
+
for (i = 0 ; i < 4 ; ++i)
|
141
|
+
{
|
142
|
+
buffer [i] = localBuf [i] ;
|
143
|
+
checksum += localBuf [i] ;
|
144
|
+
}
|
145
|
+
checksum &= 0xFF ;
|
146
|
+
|
147
|
+
// See how long we took
|
148
|
+
|
149
|
+
gettimeofday (&now, NULL) ;
|
150
|
+
timersub (&now, &then, &took) ;
|
151
|
+
|
152
|
+
// Total time to do this should be:
|
153
|
+
// 10mS + 40µS - reset
|
154
|
+
// + 80µS + 80µS - sensor doing its low -> high thing
|
155
|
+
// + 40 * (50µS + 27µS (0) or 70µS (1) )
|
156
|
+
// = 15010µS
|
157
|
+
// so if we take more than that, we've had a scheduling interruption and the
|
158
|
+
// reading is probably bogus.
|
159
|
+
|
160
|
+
if ((took.tv_sec != 0) || (took.tv_usec > 16000))
|
161
|
+
return FALSE ;
|
162
|
+
|
163
|
+
return checksum == localBuf [4] ;
|
164
|
+
}
|
165
|
+
|
166
|
+
|
167
|
+
/*
|
168
|
+
* myReadRHT03:
|
169
|
+
* Read the Temperature & Humidity from an RHT03 sensor
|
170
|
+
* Values returned are *10, so 123 is 12.3.
|
171
|
+
*********************************************************************************
|
172
|
+
*/
|
173
|
+
|
174
|
+
static int myReadRHT03 (const int pin, int *temp, int *rh)
|
175
|
+
{
|
176
|
+
int result ;
|
177
|
+
unsigned char buffer [4] ;
|
178
|
+
|
179
|
+
// Read ...
|
180
|
+
|
181
|
+
result = maxDetectRead (pin, buffer) ;
|
182
|
+
|
183
|
+
if (!result)
|
184
|
+
return FALSE ;
|
185
|
+
|
186
|
+
*rh = (buffer [0] * 256 + buffer [1]) ;
|
187
|
+
*temp = (buffer [2] * 256 + buffer [3]) ;
|
188
|
+
|
189
|
+
if ((*temp & 0x8000) != 0) // Negative
|
190
|
+
{
|
191
|
+
*temp &= 0x7FFF ;
|
192
|
+
*temp = -*temp ;
|
193
|
+
}
|
194
|
+
|
195
|
+
// Discard obviously bogus readings - the checksum can't detect a 2-bit error
|
196
|
+
// (which does seem to happen - no realtime here)
|
197
|
+
|
198
|
+
if ((*rh > 999) || (*temp > 800) || (*temp < -400))
|
199
|
+
return FALSE ;
|
200
|
+
|
201
|
+
return TRUE ;
|
202
|
+
}
|
203
|
+
|
204
|
+
|
205
|
+
/*
|
206
|
+
* myAnalogRead:
|
207
|
+
*********************************************************************************
|
208
|
+
*/
|
209
|
+
|
210
|
+
static int myAnalogRead (struct wiringPiNodeStruct *node, int pin)
|
211
|
+
{
|
212
|
+
int piPin = node->fd ;
|
213
|
+
int chan = pin - node->pinBase ;
|
214
|
+
int temp = -9997 ;
|
215
|
+
int rh = -9997 ;
|
216
|
+
int try ;
|
217
|
+
|
218
|
+
if (chan > 1)
|
219
|
+
return -9999 ; // Bad parameters
|
220
|
+
|
221
|
+
for (try = 0 ; try < 10 ; ++try)
|
222
|
+
{
|
223
|
+
if (myReadRHT03 (piPin, &temp, &rh))
|
224
|
+
return chan == 0 ? temp : rh ;
|
225
|
+
}
|
226
|
+
|
227
|
+
return -9998 ;
|
228
|
+
}
|
229
|
+
|
230
|
+
|
231
|
+
/*
|
232
|
+
* rht03Setup:
|
233
|
+
* Create a new instance of an RHT03 temperature sensor.
|
234
|
+
*********************************************************************************
|
235
|
+
*/
|
236
|
+
|
237
|
+
int rht03Setup (const int pinBase, const int piPin)
|
238
|
+
{
|
239
|
+
struct wiringPiNodeStruct *node ;
|
240
|
+
|
241
|
+
if ((piPin & PI_GPIO_MASK) != 0) // Must be an on-board pin
|
242
|
+
return FALSE ;
|
243
|
+
|
244
|
+
// 2 pins - temperature and humidity
|
245
|
+
|
246
|
+
node = wiringPiNewNode (pinBase, 2) ;
|
247
|
+
|
248
|
+
node->fd = piPin ;
|
249
|
+
node->analogRead = myAnalogRead ;
|
250
|
+
|
251
|
+
return TRUE ;
|
252
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
/*
|
2
|
+
* rht03.h:
|
3
|
+
* Extend wiringPi with the rht03 Maxdetect 1-Wire sensor.
|
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
|
+
extern int rht03Setup (const int pinBase, const int devicePin) ;
|