wiringpi 1.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,110 @@
|
|
1
|
+
/*
|
2
|
+
* isr.c:
|
3
|
+
* Wait for Interrupt test program - ISR method
|
4
|
+
*
|
5
|
+
* How to test:
|
6
|
+
* Use the SoC's pull-up and pull down resistors that are avalable
|
7
|
+
* on input pins. So compile & run this program (via sudo), then
|
8
|
+
* in another terminal:
|
9
|
+
* gpio mode 0 up
|
10
|
+
* gpio mode 0 down
|
11
|
+
* at which point it should trigger an interrupt. Toggle the pin
|
12
|
+
* up/down to generate more interrupts to test.
|
13
|
+
*
|
14
|
+
* Copyright (c) 2013 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 published by
|
21
|
+
* the Free Software Foundation, either version 3 of the License, or
|
22
|
+
* (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 License
|
30
|
+
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
31
|
+
***********************************************************************
|
32
|
+
*/
|
33
|
+
|
34
|
+
#include <stdio.h>
|
35
|
+
#include <string.h>
|
36
|
+
#include <errno.h>
|
37
|
+
#include <stdlib.h>
|
38
|
+
#include <wiringPi.h>
|
39
|
+
|
40
|
+
|
41
|
+
// globalCounter:
|
42
|
+
// Global variable to count interrupts
|
43
|
+
// Should be declared volatile to make sure the compiler doesn't cache it.
|
44
|
+
|
45
|
+
static volatile int globalCounter [8] ;
|
46
|
+
|
47
|
+
|
48
|
+
/*
|
49
|
+
* myInterrupt:
|
50
|
+
*********************************************************************************
|
51
|
+
*/
|
52
|
+
|
53
|
+
void myInterrupt0 (void) { ++globalCounter [0] ; }
|
54
|
+
void myInterrupt1 (void) { ++globalCounter [1] ; }
|
55
|
+
void myInterrupt2 (void) { ++globalCounter [2] ; }
|
56
|
+
void myInterrupt3 (void) { ++globalCounter [3] ; }
|
57
|
+
void myInterrupt4 (void) { ++globalCounter [4] ; }
|
58
|
+
void myInterrupt5 (void) { ++globalCounter [5] ; }
|
59
|
+
void myInterrupt6 (void) { ++globalCounter [6] ; }
|
60
|
+
void myInterrupt7 (void) { ++globalCounter [7] ; }
|
61
|
+
|
62
|
+
|
63
|
+
/*
|
64
|
+
*********************************************************************************
|
65
|
+
* main
|
66
|
+
*********************************************************************************
|
67
|
+
*/
|
68
|
+
|
69
|
+
int main (void)
|
70
|
+
{
|
71
|
+
int gotOne, pin ;
|
72
|
+
int myCounter [8] ;
|
73
|
+
|
74
|
+
for (pin = 0 ; pin < 8 ; ++pin)
|
75
|
+
globalCounter [pin] = myCounter [pin] = 0 ;
|
76
|
+
|
77
|
+
wiringPiSetup () ;
|
78
|
+
|
79
|
+
wiringPiISR (0, INT_EDGE_FALLING, &myInterrupt0) ;
|
80
|
+
wiringPiISR (1, INT_EDGE_FALLING, &myInterrupt1) ;
|
81
|
+
wiringPiISR (2, INT_EDGE_FALLING, &myInterrupt2) ;
|
82
|
+
wiringPiISR (3, INT_EDGE_FALLING, &myInterrupt3) ;
|
83
|
+
wiringPiISR (4, INT_EDGE_FALLING, &myInterrupt4) ;
|
84
|
+
wiringPiISR (5, INT_EDGE_FALLING, &myInterrupt5) ;
|
85
|
+
wiringPiISR (6, INT_EDGE_FALLING, &myInterrupt6) ;
|
86
|
+
wiringPiISR (7, INT_EDGE_FALLING, &myInterrupt7) ;
|
87
|
+
|
88
|
+
for (;;)
|
89
|
+
{
|
90
|
+
gotOne = 0 ;
|
91
|
+
printf ("Waiting ... ") ; fflush (stdout) ;
|
92
|
+
|
93
|
+
for (;;)
|
94
|
+
{
|
95
|
+
for (pin = 0 ; pin < 8 ; ++pin)
|
96
|
+
{
|
97
|
+
if (globalCounter [pin] != myCounter [pin])
|
98
|
+
{
|
99
|
+
printf (" Int on pin %d: Counter: %5d\n", pin, globalCounter [pin]) ;
|
100
|
+
myCounter [pin] = globalCounter [pin] ;
|
101
|
+
++gotOne ;
|
102
|
+
}
|
103
|
+
}
|
104
|
+
if (gotOne != 0)
|
105
|
+
break ;
|
106
|
+
}
|
107
|
+
}
|
108
|
+
|
109
|
+
return 0 ;
|
110
|
+
}
|
@@ -0,0 +1,347 @@
|
|
1
|
+
/*
|
2
|
+
* lcd-adafruit.c:
|
3
|
+
* Text-based LCD driver test code
|
4
|
+
* This is designed to drive the Adafruit RGB LCD Plate
|
5
|
+
* with the additional 5 buttons for the Raspberry Pi
|
6
|
+
*
|
7
|
+
* Copyright (c) 2012-2013 Gordon Henderson.
|
8
|
+
***********************************************************************
|
9
|
+
* This file is part of wiringPi:
|
10
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
11
|
+
*
|
12
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
13
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
14
|
+
* the Free Software Foundation, either version 3 of the License, or
|
15
|
+
* (at your option) any later version.
|
16
|
+
*
|
17
|
+
* wiringPi is distributed in the hope that it will be useful,
|
18
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
19
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
20
|
+
* GNU Lesser General Public License for more details.
|
21
|
+
*
|
22
|
+
* You should have received a copy of the GNU Lesser General Public License
|
23
|
+
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
24
|
+
***********************************************************************
|
25
|
+
*/
|
26
|
+
|
27
|
+
#include <stdio.h>
|
28
|
+
#include <stdlib.h>
|
29
|
+
#include <unistd.h>
|
30
|
+
#include <string.h>
|
31
|
+
#include <time.h>
|
32
|
+
|
33
|
+
#include <wiringPi.h>
|
34
|
+
#include <mcp23017.h>
|
35
|
+
#include <lcd.h>
|
36
|
+
|
37
|
+
#ifndef TRUE
|
38
|
+
# define TRUE (1==1)
|
39
|
+
# define FALSE (1==2)
|
40
|
+
#endif
|
41
|
+
|
42
|
+
|
43
|
+
// Defines for the Adafruit Pi LCD interface board
|
44
|
+
|
45
|
+
#define AF_BASE 100
|
46
|
+
#define AF_RED (AF_BASE + 6)
|
47
|
+
#define AF_GREEN (AF_BASE + 7)
|
48
|
+
#define AF_BLUE (AF_BASE + 8)
|
49
|
+
|
50
|
+
#define AF_E (AF_BASE + 13)
|
51
|
+
#define AF_RW (AF_BASE + 14)
|
52
|
+
#define AF_RS (AF_BASE + 15)
|
53
|
+
|
54
|
+
#define AF_DB4 (AF_BASE + 12)
|
55
|
+
#define AF_DB5 (AF_BASE + 11)
|
56
|
+
#define AF_DB6 (AF_BASE + 10)
|
57
|
+
#define AF_DB7 (AF_BASE + 9)
|
58
|
+
|
59
|
+
#define AF_SELECT (AF_BASE + 0)
|
60
|
+
#define AF_RIGHT (AF_BASE + 1)
|
61
|
+
#define AF_DOWN (AF_BASE + 2)
|
62
|
+
#define AF_UP (AF_BASE + 3)
|
63
|
+
#define AF_LEFT (AF_BASE + 4)
|
64
|
+
|
65
|
+
|
66
|
+
// User-Defined character test
|
67
|
+
|
68
|
+
static unsigned char newChar [8] =
|
69
|
+
{
|
70
|
+
0b00100,
|
71
|
+
0b00100,
|
72
|
+
0b00000,
|
73
|
+
0b00100,
|
74
|
+
0b01110,
|
75
|
+
0b11011,
|
76
|
+
0b11011,
|
77
|
+
0b10001,
|
78
|
+
} ;
|
79
|
+
|
80
|
+
// Global lcd handle:
|
81
|
+
|
82
|
+
static int lcdHandle ;
|
83
|
+
|
84
|
+
/*
|
85
|
+
* usage:
|
86
|
+
*********************************************************************************
|
87
|
+
*/
|
88
|
+
|
89
|
+
int usage (const char *progName)
|
90
|
+
{
|
91
|
+
fprintf (stderr, "Usage: %s colour\n", progName) ;
|
92
|
+
return EXIT_FAILURE ;
|
93
|
+
}
|
94
|
+
|
95
|
+
|
96
|
+
/*
|
97
|
+
* scrollMessage:
|
98
|
+
*********************************************************************************
|
99
|
+
*/
|
100
|
+
|
101
|
+
static const char *message =
|
102
|
+
" "
|
103
|
+
"Wiring Pi by Gordon Henderson. HTTP://WIRINGPI.COM/"
|
104
|
+
" " ;
|
105
|
+
|
106
|
+
void scrollMessage (int line, int width)
|
107
|
+
{
|
108
|
+
char buf [32] ;
|
109
|
+
static int position = 0 ;
|
110
|
+
static int timer = 0 ;
|
111
|
+
|
112
|
+
if (millis () < timer)
|
113
|
+
return ;
|
114
|
+
|
115
|
+
timer = millis () + 200 ;
|
116
|
+
|
117
|
+
strncpy (buf, &message [position], width) ;
|
118
|
+
buf [width] = 0 ;
|
119
|
+
lcdPosition (lcdHandle, 0, line) ;
|
120
|
+
lcdPuts (lcdHandle, buf) ;
|
121
|
+
|
122
|
+
if (++position == (strlen (message) - width))
|
123
|
+
position = 0 ;
|
124
|
+
}
|
125
|
+
|
126
|
+
|
127
|
+
/*
|
128
|
+
* setBacklightColour:
|
129
|
+
* The colour outputs are inverted.
|
130
|
+
*********************************************************************************
|
131
|
+
*/
|
132
|
+
|
133
|
+
static void setBacklightColour (int colour)
|
134
|
+
{
|
135
|
+
colour &= 7 ;
|
136
|
+
|
137
|
+
digitalWrite (AF_RED, !(colour & 1)) ;
|
138
|
+
digitalWrite (AF_GREEN, !(colour & 2)) ;
|
139
|
+
digitalWrite (AF_BLUE, !(colour & 4)) ;
|
140
|
+
}
|
141
|
+
|
142
|
+
|
143
|
+
/*
|
144
|
+
* adafruitLCDSetup:
|
145
|
+
* Setup the Adafruit board by making sure the additional pins are
|
146
|
+
* set to the correct modes, etc.
|
147
|
+
*********************************************************************************
|
148
|
+
*/
|
149
|
+
|
150
|
+
static void adafruitLCDSetup (int colour)
|
151
|
+
{
|
152
|
+
int i ;
|
153
|
+
|
154
|
+
// Backlight LEDs
|
155
|
+
|
156
|
+
pinMode (AF_RED, OUTPUT) ;
|
157
|
+
pinMode (AF_GREEN, OUTPUT) ;
|
158
|
+
pinMode (AF_BLUE, OUTPUT) ;
|
159
|
+
setBacklightColour (colour) ;
|
160
|
+
|
161
|
+
// Input buttons
|
162
|
+
|
163
|
+
for (i = 0 ; i <= 4 ; ++i)
|
164
|
+
{
|
165
|
+
pinMode (AF_BASE + i, INPUT) ;
|
166
|
+
pullUpDnControl (AF_BASE + i, PUD_UP) ; // Enable pull-ups, switches close to 0v
|
167
|
+
}
|
168
|
+
|
169
|
+
// Control signals
|
170
|
+
|
171
|
+
pinMode (AF_RW, OUTPUT) ; digitalWrite (AF_RW, LOW) ; // Not used with wiringPi - always in write mode
|
172
|
+
|
173
|
+
// The other control pins are initialised with lcdInit ()
|
174
|
+
|
175
|
+
lcdHandle = lcdInit (2, 16, 4, AF_RS, AF_E, AF_DB4,AF_DB5,AF_DB6,AF_DB7, 0,0,0,0) ;
|
176
|
+
|
177
|
+
if (lcdHandle < 0)
|
178
|
+
{
|
179
|
+
fprintf (stderr, "lcdInit failed\n") ;
|
180
|
+
exit (EXIT_FAILURE) ;
|
181
|
+
}
|
182
|
+
}
|
183
|
+
|
184
|
+
|
185
|
+
/*
|
186
|
+
* waitForEnter:
|
187
|
+
* On the Adafruit display, wait for the select button
|
188
|
+
*********************************************************************************
|
189
|
+
*/
|
190
|
+
|
191
|
+
static void waitForEnter (void)
|
192
|
+
{
|
193
|
+
printf ("Press SELECT to continue: ") ; fflush (stdout) ;
|
194
|
+
|
195
|
+
while (digitalRead (AF_SELECT) == HIGH) // Wait for push
|
196
|
+
delay (1) ;
|
197
|
+
|
198
|
+
while (digitalRead (AF_SELECT) == LOW) // Wait for release
|
199
|
+
delay (1) ;
|
200
|
+
|
201
|
+
printf ("OK\n") ;
|
202
|
+
}
|
203
|
+
|
204
|
+
|
205
|
+
/*
|
206
|
+
* speedTest:
|
207
|
+
* Test the update speed of the display
|
208
|
+
*********************************************************************************
|
209
|
+
*/
|
210
|
+
|
211
|
+
static void speedTest (void)
|
212
|
+
{
|
213
|
+
unsigned int start, end, taken ;
|
214
|
+
int times ;
|
215
|
+
|
216
|
+
lcdClear (lcdHandle) ;
|
217
|
+
start = millis () ;
|
218
|
+
for (times = 0 ; times < 10 ; ++times)
|
219
|
+
{
|
220
|
+
lcdPuts (lcdHandle, "0123456789ABCDEF") ;
|
221
|
+
lcdPuts (lcdHandle, "0123456789ABCDEF") ;
|
222
|
+
}
|
223
|
+
end = millis () ;
|
224
|
+
taken = (end - start) / 10;
|
225
|
+
|
226
|
+
lcdClear (lcdHandle) ;
|
227
|
+
lcdPosition (lcdHandle, 0, 0) ; lcdPrintf (lcdHandle, "Speed: %dmS", taken) ;
|
228
|
+
lcdPosition (lcdHandle, 0, 1) ; lcdPrintf (lcdHandle, "For full update") ;
|
229
|
+
|
230
|
+
waitForEnter () ;
|
231
|
+
|
232
|
+
lcdClear (lcdHandle) ;
|
233
|
+
lcdPosition (lcdHandle, 0, 0) ; lcdPrintf (lcdHandle, "Time: %dmS", taken / 32) ;
|
234
|
+
lcdPosition (lcdHandle, 0, 1) ; lcdPrintf (lcdHandle, "Per character") ;
|
235
|
+
|
236
|
+
waitForEnter () ;
|
237
|
+
|
238
|
+
lcdClear (lcdHandle) ;
|
239
|
+
lcdPosition (lcdHandle, 0, 0) ; lcdPrintf (lcdHandle, "%d cps...", 32000 / taken) ;
|
240
|
+
|
241
|
+
waitForEnter () ;
|
242
|
+
}
|
243
|
+
|
244
|
+
|
245
|
+
/*
|
246
|
+
* The works
|
247
|
+
*********************************************************************************
|
248
|
+
*/
|
249
|
+
|
250
|
+
int main (int argc, char *argv[])
|
251
|
+
{
|
252
|
+
int colour ;
|
253
|
+
int cols = 16 ;
|
254
|
+
int waitForRelease = FALSE ;
|
255
|
+
|
256
|
+
struct tm *t ;
|
257
|
+
time_t tim ;
|
258
|
+
|
259
|
+
char buf [32] ;
|
260
|
+
|
261
|
+
if (argc != 2)
|
262
|
+
return usage (argv [0]) ;
|
263
|
+
|
264
|
+
printf ("Raspberry Pi Adafruit LCD test\n") ;
|
265
|
+
printf ("==============================\n") ;
|
266
|
+
|
267
|
+
colour = atoi (argv [1]) ;
|
268
|
+
|
269
|
+
wiringPiSetupSys () ;
|
270
|
+
mcp23017Setup (AF_BASE, 0x20) ;
|
271
|
+
|
272
|
+
adafruitLCDSetup (colour) ;
|
273
|
+
|
274
|
+
lcdPosition (lcdHandle, 0, 0) ; lcdPuts (lcdHandle, "Gordon Henderson") ;
|
275
|
+
lcdPosition (lcdHandle, 0, 1) ; lcdPuts (lcdHandle, " wiringpi.com ") ;
|
276
|
+
|
277
|
+
waitForEnter () ;
|
278
|
+
|
279
|
+
lcdPosition (lcdHandle, 0, 1) ; lcdPuts (lcdHandle, "Adafruit RGB LCD") ;
|
280
|
+
|
281
|
+
waitForEnter () ;
|
282
|
+
|
283
|
+
lcdCharDef (lcdHandle, 2, newChar) ;
|
284
|
+
|
285
|
+
lcdClear (lcdHandle) ;
|
286
|
+
lcdPosition (lcdHandle, 0, 0) ;
|
287
|
+
lcdPuts (lcdHandle, "User Char: ") ;
|
288
|
+
lcdPutchar (lcdHandle, 2) ;
|
289
|
+
|
290
|
+
lcdCursor (lcdHandle, TRUE) ;
|
291
|
+
lcdCursorBlink (lcdHandle, TRUE) ;
|
292
|
+
|
293
|
+
waitForEnter () ;
|
294
|
+
|
295
|
+
lcdCursor (lcdHandle, FALSE) ;
|
296
|
+
lcdCursorBlink (lcdHandle, FALSE) ;
|
297
|
+
|
298
|
+
speedTest () ;
|
299
|
+
|
300
|
+
lcdClear (lcdHandle) ;
|
301
|
+
|
302
|
+
for (;;)
|
303
|
+
{
|
304
|
+
scrollMessage (0, cols) ;
|
305
|
+
|
306
|
+
tim = time (NULL) ;
|
307
|
+
t = localtime (&tim) ;
|
308
|
+
|
309
|
+
sprintf (buf, "%02d:%02d:%02d", t->tm_hour, t->tm_min, t->tm_sec) ;
|
310
|
+
|
311
|
+
lcdPosition (lcdHandle, (cols - 8) / 2, 1) ;
|
312
|
+
lcdPuts (lcdHandle, buf) ;
|
313
|
+
|
314
|
+
// Check buttons to cycle colour
|
315
|
+
|
316
|
+
// If Up or Down are still pushed, then skip
|
317
|
+
|
318
|
+
if (waitForRelease)
|
319
|
+
{
|
320
|
+
if ((digitalRead (AF_UP) == LOW) || (digitalRead (AF_DOWN) == LOW))
|
321
|
+
continue ;
|
322
|
+
else
|
323
|
+
waitForRelease = FALSE ;
|
324
|
+
}
|
325
|
+
|
326
|
+
if (digitalRead (AF_UP) == LOW) // Pushed
|
327
|
+
{
|
328
|
+
colour = colour + 1 ;
|
329
|
+
if (colour == 8)
|
330
|
+
colour = 0 ;
|
331
|
+
setBacklightColour (colour) ;
|
332
|
+
waitForRelease = TRUE ;
|
333
|
+
}
|
334
|
+
|
335
|
+
if (digitalRead (AF_DOWN) == LOW) // Pushed
|
336
|
+
{
|
337
|
+
colour = colour - 1 ;
|
338
|
+
if (colour == -1)
|
339
|
+
colour = 7 ;
|
340
|
+
setBacklightColour (colour) ;
|
341
|
+
waitForRelease = TRUE ;
|
342
|
+
}
|
343
|
+
|
344
|
+
}
|
345
|
+
|
346
|
+
return 0 ;
|
347
|
+
}
|