wiringpi 1.1.0 → 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 +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 +165 -0
- data/ext/wiringpi/{serial.h → WiringPi/devLib/maxdetect.h} +14 -15
- 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 +113 -0
- data/ext/wiringpi/WiringPi/devLib/piNes.h +45 -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.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.c +57 -0
- data/ext/wiringpi/WiringPi/examples/clock.c +201 -0
- data/ext/wiringpi/WiringPi/examples/delayTest.c +107 -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/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 +69 -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 +1351 -0
- data/ext/wiringpi/WiringPi/gpio/pins.c +33 -0
- data/ext/wiringpi/WiringPi/gpio/readall.c +334 -0
- data/ext/wiringpi/WiringPi/gpio/version.h +1 -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 +81 -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 +236 -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 +110 -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/sn3218.c +75 -0
- data/ext/wiringpi/WiringPi/wiringPi/sn3218.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/softPwm.c +166 -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 +2007 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPi.h +224 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.c +232 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.h +42 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.c +136 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.h +36 -0
- data/ext/wiringpi/{serial.c → WiringPi/wiringPi/wiringSerial.c} +38 -29
- data/ext/wiringpi/WiringPi/wiringPi/wiringSerial.h +38 -0
- data/ext/wiringpi/{wiringShift.c → WiringPi/wiringPi/wiringShift.c} +3 -4
- data/ext/wiringpi/{wiringShift.h → WiringPi/wiringPi/wiringShift.h} +5 -5
- data/ext/wiringpi/WiringPi/wiringPi/wpiExtensions.c +731 -0
- data/ext/wiringpi/WiringPi/wiringPi/wpiExtensions.h +26 -0
- data/ext/wiringpi/extconf.rb +7 -1
- data/ext/wiringpi/wiringpi_wrap.c +1741 -218
- data/lib/wiringpi.rb +24 -222
- data/lib/wiringpi/event.rb +21 -0
- data/lib/wiringpi/gpio.rb +139 -0
- data/lib/wiringpi/i2c.rb +26 -0
- data/lib/wiringpi/mcp23x17.rb +31 -0
- data/lib/wiringpi/serial.rb +49 -0
- data/lib/wiringpi/spi.rb +15 -0
- metadata +146 -22
- data/ext/wiringpi/wiringPi.c +0 -729
- data/ext/wiringpi/wiringPi.h +0 -69
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* piGlow1.c:
|
|
3
|
+
* Very simple demonstration of the PiGlow board.
|
|
4
|
+
* This uses the piGlow devLib.
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2013 Gordon Henderson.
|
|
7
|
+
***********************************************************************
|
|
8
|
+
* This file is part of wiringPi:
|
|
9
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
|
10
|
+
*
|
|
11
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
|
12
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
|
13
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
14
|
+
* (at your option) any later version.
|
|
15
|
+
*
|
|
16
|
+
* wiringPi is distributed in the hope that it will be useful,
|
|
17
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19
|
+
* GNU Lesser General Public License for more details.
|
|
20
|
+
*
|
|
21
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
22
|
+
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
|
23
|
+
***********************************************************************
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
#include <stdio.h>
|
|
27
|
+
#include <stdlib.h>
|
|
28
|
+
#include <poll.h>
|
|
29
|
+
|
|
30
|
+
#include <wiringPi.h>
|
|
31
|
+
#include <piGlow.h>
|
|
32
|
+
|
|
33
|
+
#define PIGLOW_BASE 533
|
|
34
|
+
|
|
35
|
+
#ifndef TRUE
|
|
36
|
+
# define TRUE (1==1)
|
|
37
|
+
# define FALSE (!TRUE)
|
|
38
|
+
#endif
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
/*
|
|
42
|
+
* keypressed: clearKeypressed:
|
|
43
|
+
* Simple but effective ways to tell if the enter key has been pressed
|
|
44
|
+
*********************************************************************************
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
static int keypressed (void)
|
|
48
|
+
{
|
|
49
|
+
struct pollfd polls ;
|
|
50
|
+
|
|
51
|
+
polls.fd = fileno (stdin) ;
|
|
52
|
+
polls.events = POLLIN ;
|
|
53
|
+
|
|
54
|
+
return poll (&polls, 1, 0) != 0 ;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
static void clearKeypressed (void)
|
|
58
|
+
{
|
|
59
|
+
while (keypressed ())
|
|
60
|
+
(void)getchar () ;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
/*
|
|
65
|
+
* pulseLed:
|
|
66
|
+
* Pulses the LED at position leg, ring from off to a max. value,
|
|
67
|
+
* then off again
|
|
68
|
+
*********************************************************************************
|
|
69
|
+
*/
|
|
70
|
+
|
|
71
|
+
static void pulseLed (int leg, int ring)
|
|
72
|
+
{
|
|
73
|
+
int i ;
|
|
74
|
+
|
|
75
|
+
for (i = 0 ; i < 140 ; ++i)
|
|
76
|
+
{
|
|
77
|
+
piGlow1 (leg, ring, i) ;
|
|
78
|
+
delay (1) ;
|
|
79
|
+
}
|
|
80
|
+
delay (10) ;
|
|
81
|
+
for (i = 140 ; i >= 0 ; --i)
|
|
82
|
+
{
|
|
83
|
+
piGlow1 (leg, ring, i) ;
|
|
84
|
+
delay (1) ;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/*
|
|
89
|
+
* pulseLeg:
|
|
90
|
+
* Same as above, but a whole leg at a time
|
|
91
|
+
*********************************************************************************
|
|
92
|
+
*/
|
|
93
|
+
|
|
94
|
+
static void pulseLeg (int leg)
|
|
95
|
+
{
|
|
96
|
+
int i ;
|
|
97
|
+
|
|
98
|
+
for (i = 0 ; i < 140 ; ++i)
|
|
99
|
+
{
|
|
100
|
+
piGlowLeg (leg, i) ; delay (1) ;
|
|
101
|
+
}
|
|
102
|
+
delay (10) ;
|
|
103
|
+
for (i = 140 ; i >= 0 ; --i)
|
|
104
|
+
{
|
|
105
|
+
piGlowLeg (leg, i) ; delay (1) ;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
/*
|
|
111
|
+
* pulse Ring:
|
|
112
|
+
* Same as above, but a whole ring at a time
|
|
113
|
+
*********************************************************************************
|
|
114
|
+
*/
|
|
115
|
+
|
|
116
|
+
static void pulseRing (int ring)
|
|
117
|
+
{
|
|
118
|
+
int i ;
|
|
119
|
+
|
|
120
|
+
for (i = 0 ; i < 140 ; ++i)
|
|
121
|
+
{
|
|
122
|
+
piGlowRing (ring, i) ; delay (1) ;
|
|
123
|
+
}
|
|
124
|
+
delay (10) ;
|
|
125
|
+
for (i = 140 ; i >= 0 ; --i)
|
|
126
|
+
{
|
|
127
|
+
piGlowRing (ring, i) ; delay (1) ;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
#define LEG_STEPS 3
|
|
132
|
+
|
|
133
|
+
static int legSequence [] =
|
|
134
|
+
{
|
|
135
|
+
4, 12, 99,
|
|
136
|
+
99, 4, 12,
|
|
137
|
+
12, 99, 4,
|
|
138
|
+
} ;
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
#define RING_STEPS 16
|
|
142
|
+
|
|
143
|
+
static int ringSequence [] =
|
|
144
|
+
{
|
|
145
|
+
0, 0, 0, 0, 0, 64,
|
|
146
|
+
0, 0, 0, 0, 64, 64,
|
|
147
|
+
0, 0, 0, 64, 64, 0,
|
|
148
|
+
0, 0, 64, 64, 0, 0,
|
|
149
|
+
0, 64, 64, 0, 0, 0,
|
|
150
|
+
64, 64, 0, 0, 0, 0,
|
|
151
|
+
64, 0, 0, 0, 0, 0,
|
|
152
|
+
0, 0, 0, 0, 0, 0,
|
|
153
|
+
64, 0, 0, 0, 0, 0,
|
|
154
|
+
64, 64, 0, 0, 0, 0,
|
|
155
|
+
0, 64, 64, 0, 0, 0,
|
|
156
|
+
0, 0, 64, 64, 0, 0,
|
|
157
|
+
0, 0, 0, 64, 64, 0,
|
|
158
|
+
0, 0, 0, 0, 64, 64,
|
|
159
|
+
0, 0, 0, 0, 0, 64,
|
|
160
|
+
0, 0, 0, 0, 0, 0,
|
|
161
|
+
} ;
|
|
162
|
+
|
|
163
|
+
/*
|
|
164
|
+
* main:
|
|
165
|
+
* Our little demo prgoram
|
|
166
|
+
*********************************************************************************
|
|
167
|
+
*/
|
|
168
|
+
|
|
169
|
+
int main (void)
|
|
170
|
+
{
|
|
171
|
+
int i ;
|
|
172
|
+
int step, ring, leg ;
|
|
173
|
+
|
|
174
|
+
// Always initialise wiringPi:
|
|
175
|
+
// Use the Sys method if you don't need to run as root
|
|
176
|
+
|
|
177
|
+
wiringPiSetupSys () ;
|
|
178
|
+
|
|
179
|
+
// Initialise the piGlow devLib with our chosen pin base
|
|
180
|
+
|
|
181
|
+
piGlowSetup (1) ;
|
|
182
|
+
|
|
183
|
+
// LEDs, one at a time
|
|
184
|
+
|
|
185
|
+
printf ("LEDs, one at a time\n") ;
|
|
186
|
+
for (; !keypressed () ;)
|
|
187
|
+
for (leg = 0 ; leg < 3 ; ++leg)
|
|
188
|
+
{
|
|
189
|
+
for (ring = 0 ; ring < 6 ; ++ring)
|
|
190
|
+
{
|
|
191
|
+
pulseLed (leg, ring) ;
|
|
192
|
+
if (keypressed ())
|
|
193
|
+
break ;
|
|
194
|
+
}
|
|
195
|
+
if (keypressed ())
|
|
196
|
+
break ;
|
|
197
|
+
}
|
|
198
|
+
clearKeypressed () ;
|
|
199
|
+
|
|
200
|
+
// Rings, one at a time
|
|
201
|
+
|
|
202
|
+
printf ("Rings, one at a time\n") ;
|
|
203
|
+
for (; !keypressed () ;)
|
|
204
|
+
for (ring = 0 ; ring < 6 ; ++ring)
|
|
205
|
+
{
|
|
206
|
+
pulseRing (ring) ;
|
|
207
|
+
if (keypressed ())
|
|
208
|
+
break ;
|
|
209
|
+
}
|
|
210
|
+
clearKeypressed () ;
|
|
211
|
+
|
|
212
|
+
// Legs, one at a time
|
|
213
|
+
|
|
214
|
+
printf ("Legs, one at a time\n") ;
|
|
215
|
+
for (; !keypressed () ;)
|
|
216
|
+
for (leg = 0 ; leg < 3 ; ++leg)
|
|
217
|
+
{
|
|
218
|
+
pulseLeg (leg) ;
|
|
219
|
+
if (keypressed ())
|
|
220
|
+
break ;
|
|
221
|
+
}
|
|
222
|
+
clearKeypressed () ;
|
|
223
|
+
|
|
224
|
+
delay (1000) ;
|
|
225
|
+
|
|
226
|
+
// Sequence - alternating rings, legs and random
|
|
227
|
+
|
|
228
|
+
printf ("Sequence now\n") ;
|
|
229
|
+
for (; !keypressed () ;)
|
|
230
|
+
{
|
|
231
|
+
for (i = 0 ; i < 20 ; ++i)
|
|
232
|
+
for (step = 0 ; step < LEG_STEPS ; ++step)
|
|
233
|
+
{
|
|
234
|
+
for (leg = 0 ; leg < 3 ; ++leg)
|
|
235
|
+
piGlowLeg (leg, legSequence [step * 3 + leg]) ;
|
|
236
|
+
delay (80) ;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
for (i = 0 ; i < 10 ; ++i)
|
|
240
|
+
for (step = 0 ; step < RING_STEPS ; ++step)
|
|
241
|
+
{
|
|
242
|
+
for (ring = 0 ; ring < 6 ; ++ring)
|
|
243
|
+
piGlowRing (ring, ringSequence [step * 6 + ring]) ;
|
|
244
|
+
delay (80) ;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
for (i = 0 ; i < 1000 ; ++i)
|
|
248
|
+
{
|
|
249
|
+
leg = random () % 3 ;
|
|
250
|
+
ring = random () % 6 ;
|
|
251
|
+
piGlow1 (leg, ring, random () % 256) ;
|
|
252
|
+
delay (5) ;
|
|
253
|
+
piGlow1 (leg, ring, 0) ;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return 0 ;
|
|
258
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* piglow.c:
|
|
3
|
+
* Very simple demonstration of the PiGlow board.
|
|
4
|
+
* This uses the piGlow devLib.
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2013 Gordon Henderson.
|
|
7
|
+
***********************************************************************
|
|
8
|
+
* This file is part of wiringPi:
|
|
9
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
|
10
|
+
*
|
|
11
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
|
12
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
|
13
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
14
|
+
* (at your option) any later version.
|
|
15
|
+
*
|
|
16
|
+
* wiringPi is distributed in the hope that it will be useful,
|
|
17
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19
|
+
* GNU Lesser General Public License for more details.
|
|
20
|
+
*
|
|
21
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
22
|
+
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
|
23
|
+
***********************************************************************
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
#include <stdio.h>
|
|
27
|
+
#include <string.h>
|
|
28
|
+
#include <stdlib.h>
|
|
29
|
+
|
|
30
|
+
#ifndef TRUE
|
|
31
|
+
# define TRUE (1==1)
|
|
32
|
+
# define FALSE (!TRUE)
|
|
33
|
+
#endif
|
|
34
|
+
|
|
35
|
+
#include <wiringPi.h>
|
|
36
|
+
#include <piGlow.h>
|
|
37
|
+
|
|
38
|
+
static void failUsage (void)
|
|
39
|
+
{
|
|
40
|
+
fprintf (stderr, "Usage examples:\n") ;
|
|
41
|
+
fprintf (stderr, " piglow off # All off\n") ;
|
|
42
|
+
fprintf (stderr, " piglow red 50 # Light the 3 red LEDs to 50%%\n") ;
|
|
43
|
+
fprintf (stderr, " colours are: red, yellow, orange, green, blue and white\n") ;
|
|
44
|
+
fprintf (stderr, " piglow all 75 # Light all to 75%%\n") ;
|
|
45
|
+
fprintf (stderr, " piglow leg 0 25 # Light leg 0 to 25%%\n") ;
|
|
46
|
+
fprintf (stderr, " piglow ring 3 100 # Light ring 3 to 100%%\n") ;
|
|
47
|
+
fprintf (stderr, " piglow led 2 5 100 # Light the single LED on Leg 2, ring 5 to 100%%\n") ;
|
|
48
|
+
|
|
49
|
+
exit (EXIT_FAILURE) ;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
static int getPercent (char *typed)
|
|
53
|
+
{
|
|
54
|
+
int percent ;
|
|
55
|
+
|
|
56
|
+
percent = atoi (typed) ;
|
|
57
|
+
if ((percent < 0) || (percent > 100))
|
|
58
|
+
{
|
|
59
|
+
fprintf (stderr, "piglow: percent value out of range\n") ;
|
|
60
|
+
exit (EXIT_FAILURE) ;
|
|
61
|
+
}
|
|
62
|
+
return (percent * 255) / 100 ;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
/*
|
|
67
|
+
* main:
|
|
68
|
+
* Our little demo prgoram
|
|
69
|
+
*********************************************************************************
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
int main (int argc, char *argv [])
|
|
73
|
+
{
|
|
74
|
+
int percent ;
|
|
75
|
+
int ring, leg ;
|
|
76
|
+
|
|
77
|
+
// Always initialise wiringPi:
|
|
78
|
+
// Use the Sys method if you don't need to run as root
|
|
79
|
+
|
|
80
|
+
wiringPiSetupSys () ;
|
|
81
|
+
|
|
82
|
+
// Initialise the piGlow devLib
|
|
83
|
+
|
|
84
|
+
piGlowSetup (FALSE) ;
|
|
85
|
+
|
|
86
|
+
if (argc == 1)
|
|
87
|
+
failUsage () ;
|
|
88
|
+
|
|
89
|
+
if ((argc == 2) && (strcasecmp (argv [1], "off") == 0))
|
|
90
|
+
{
|
|
91
|
+
for (leg = 0 ; leg < 3 ; ++leg)
|
|
92
|
+
piGlowLeg (leg, 0) ;
|
|
93
|
+
return 0 ;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (argc == 3)
|
|
97
|
+
{
|
|
98
|
+
percent = getPercent (argv [2]) ;
|
|
99
|
+
|
|
100
|
+
/**/ if (strcasecmp (argv [1], "red") == 0)
|
|
101
|
+
piGlowRing (PIGLOW_RED, percent) ;
|
|
102
|
+
else if (strcasecmp (argv [1], "yellow") == 0)
|
|
103
|
+
piGlowRing (PIGLOW_YELLOW, percent) ;
|
|
104
|
+
else if (strcasecmp (argv [1], "orange") == 0)
|
|
105
|
+
piGlowRing (PIGLOW_ORANGE, percent) ;
|
|
106
|
+
else if (strcasecmp (argv [1], "green") == 0)
|
|
107
|
+
piGlowRing (PIGLOW_GREEN, percent) ;
|
|
108
|
+
else if (strcasecmp (argv [1], "blue") == 0)
|
|
109
|
+
piGlowRing (PIGLOW_BLUE, percent) ;
|
|
110
|
+
else if (strcasecmp (argv [1], "white") == 0)
|
|
111
|
+
piGlowRing (PIGLOW_WHITE, percent) ;
|
|
112
|
+
else if (strcasecmp (argv [1], "all") == 0)
|
|
113
|
+
for (ring = 0 ; ring < 6 ; ++ring)
|
|
114
|
+
piGlowRing (ring, percent) ;
|
|
115
|
+
else
|
|
116
|
+
{
|
|
117
|
+
fprintf (stderr, "piglow: invalid colour\n") ;
|
|
118
|
+
exit (EXIT_FAILURE) ;
|
|
119
|
+
}
|
|
120
|
+
return 0 ;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (argc == 4)
|
|
124
|
+
{
|
|
125
|
+
/**/ if (strcasecmp (argv [1], "leg") == 0)
|
|
126
|
+
{
|
|
127
|
+
leg = atoi (argv [2]) ;
|
|
128
|
+
if ((leg < 0) || (leg > 2))
|
|
129
|
+
{
|
|
130
|
+
fprintf (stderr, "piglow: leg value out of range\n") ;
|
|
131
|
+
exit (EXIT_FAILURE) ;
|
|
132
|
+
}
|
|
133
|
+
percent = getPercent (argv [3]) ;
|
|
134
|
+
piGlowLeg (leg, percent) ;
|
|
135
|
+
}
|
|
136
|
+
else if (strcasecmp (argv [1], "ring") == 0)
|
|
137
|
+
{
|
|
138
|
+
ring = atoi (argv [2]) ;
|
|
139
|
+
if ((ring < 0) || (ring > 5))
|
|
140
|
+
{
|
|
141
|
+
fprintf (stderr, "piglow: ring value out of range\n") ;
|
|
142
|
+
exit (EXIT_FAILURE) ;
|
|
143
|
+
}
|
|
144
|
+
percent = getPercent (argv [3]) ;
|
|
145
|
+
piGlowRing (ring, percent) ;
|
|
146
|
+
}
|
|
147
|
+
return 0 ;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (argc == 5)
|
|
151
|
+
{
|
|
152
|
+
if (strcasecmp (argv [1], "led") != 0)
|
|
153
|
+
failUsage () ;
|
|
154
|
+
|
|
155
|
+
leg = atoi (argv [2]) ;
|
|
156
|
+
if ((leg < 0) || (leg > 2))
|
|
157
|
+
{
|
|
158
|
+
fprintf (stderr, "piglow: leg value out of range\n") ;
|
|
159
|
+
exit (EXIT_FAILURE) ;
|
|
160
|
+
}
|
|
161
|
+
ring = atoi (argv [3]) ;
|
|
162
|
+
if ((ring < 0) || (ring > 5))
|
|
163
|
+
{
|
|
164
|
+
fprintf (stderr, "piglow: ring value out of range\n") ;
|
|
165
|
+
exit (EXIT_FAILURE) ;
|
|
166
|
+
}
|
|
167
|
+
percent = getPercent (argv [4]) ;
|
|
168
|
+
piGlow1 (leg, ring, percent) ;
|
|
169
|
+
return 0 ;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
failUsage () ;
|
|
173
|
+
return 0 ;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* blink.c:
|
|
3
|
+
* Standard "blink" program in wiringPi. Blinks an LED connected
|
|
4
|
+
* to the first GPIO pin.
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
|
7
|
+
***********************************************************************
|
|
8
|
+
* This file is part of wiringPi:
|
|
9
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
|
10
|
+
*
|
|
11
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
|
12
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
|
13
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
14
|
+
* (at your option) any later version.
|
|
15
|
+
*
|
|
16
|
+
* wiringPi is distributed in the hope that it will be useful,
|
|
17
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19
|
+
* GNU Lesser General Public License for more details.
|
|
20
|
+
*
|
|
21
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
22
|
+
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
|
23
|
+
***********************************************************************
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
#include <stdio.h>
|
|
27
|
+
#include <wiringPi.h>
|
|
28
|
+
|
|
29
|
+
// LED Pin - wiringPi pin 0 is BCM_GPIO 17.
|
|
30
|
+
|
|
31
|
+
#define LED 0
|
|
32
|
+
|
|
33
|
+
int main (void)
|
|
34
|
+
{
|
|
35
|
+
printf ("Raspberry Pi blink\n") ;
|
|
36
|
+
|
|
37
|
+
wiringPiSetup () ;
|
|
38
|
+
pinMode (LED, OUTPUT) ;
|
|
39
|
+
|
|
40
|
+
for (;;)
|
|
41
|
+
{
|
|
42
|
+
digitalWrite (LED, HIGH) ; // On
|
|
43
|
+
delay (500) ; // mS
|
|
44
|
+
digitalWrite (LED, LOW) ; // Off
|
|
45
|
+
delay (500) ;
|
|
46
|
+
}
|
|
47
|
+
return 0 ;
|
|
48
|
+
}
|