wiringpi 2.0.0 → 2.32.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 +4 -4
- data/ext/wiringpi/WiringPi/devLib/maxdetect.c +100 -27
- data/ext/wiringpi/WiringPi/devLib/maxdetect.h +0 -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/PiFace/ladder.c +0 -0
- data/ext/wiringpi/WiringPi/examples/max31855.c +60 -0
- data/ext/wiringpi/WiringPi/examples/rht03.c +32 -15
- data/ext/wiringpi/WiringPi/examples/scrollPhat/scphat.c +230 -0
- data/ext/wiringpi/WiringPi/examples/scrollPhat/test.c +115 -0
- data/ext/wiringpi/WiringPi/gpio/gpio.c +88 -37
- data/ext/wiringpi/WiringPi/gpio/readall.c +41 -9
- data/ext/wiringpi/WiringPi/gpio/version.h +1 -1
- data/ext/wiringpi/WiringPi/wiringPi/ads1115.c +293 -0
- data/ext/wiringpi/WiringPi/wiringPi/ads1115.h +55 -0
- data/ext/wiringpi/WiringPi/wiringPi/drcSerial.c +4 -9
- data/ext/wiringpi/WiringPi/wiringPi/max31855.c +41 -23
- data/ext/wiringpi/WiringPi/wiringPi/max5322.c +2 -2
- data/ext/wiringpi/WiringPi/wiringPi/mcp23008.c +2 -2
- data/ext/wiringpi/WiringPi/wiringPi/mcp23016.c +2 -2
- data/ext/wiringpi/WiringPi/wiringPi/mcp23017.c +2 -2
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.c +3 -4
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.c +3 -4
- data/ext/wiringpi/WiringPi/wiringPi/mcp3002.c +2 -2
- data/ext/wiringpi/WiringPi/wiringPi/mcp3004.c +2 -2
- data/ext/wiringpi/WiringPi/wiringPi/mcp3422.c +33 -18
- data/ext/wiringpi/WiringPi/wiringPi/mcp3422.h +6 -6
- data/ext/wiringpi/WiringPi/wiringPi/mcp4802.c +2 -2
- data/ext/wiringpi/WiringPi/wiringPi/pcf8574.c +2 -2
- data/ext/wiringpi/WiringPi/wiringPi/pcf8591.c +2 -2
- data/ext/wiringpi/WiringPi/wiringPi/sn3218.c +2 -2
- data/ext/wiringpi/WiringPi/wiringPi/sr595.c +1 -1
- data/ext/wiringpi/WiringPi/wiringPi/wiringPi.c +418 -132
- data/ext/wiringpi/WiringPi/wiringPi/wiringPi.h +47 -37
- data/ext/wiringpi/WiringPi/wiringPi/wpiExtensions.c +38 -9
- data/ext/wiringpi/extconf.rb +26 -2
- data/ext/wiringpi/wiringpi_wrap.c +3456 -981
- metadata +9 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f545ed34cf56756ec3feb322afbc289a5bd29223
|
4
|
+
data.tar.gz: bcbf2d1f7685d9ec0b7400b750be7b405fde1086
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d9fb93661542bc98b743184ad55fb8bf241e9b01fa9e91774671060aa984fa02bd40b8245085010b3cc30dc955ae3689206a792794b5e26491ba64cf9f4145f
|
7
|
+
data.tar.gz: 844fce642b0eea71ee3f9ed0c74ebfe486ec1301023d925fc1c65815a1ddd06146525e4873d5fab273e6ea7d85eebe0e27cae172fe0731f13afae501b81b783e
|
@@ -22,7 +22,8 @@
|
|
22
22
|
***********************************************************************
|
23
23
|
*/
|
24
24
|
|
25
|
-
|
25
|
+
#include <sys/time.h>
|
26
|
+
#include <stdio.h>
|
26
27
|
//#include <stdlib.h>
|
27
28
|
//#include <unistd.h>
|
28
29
|
|
@@ -38,21 +39,43 @@
|
|
38
39
|
|
39
40
|
/*
|
40
41
|
* maxDetectLowHighWait:
|
41
|
-
* Wait for a transition from
|
42
|
+
* Wait for a transition from low to high on the bus
|
42
43
|
*********************************************************************************
|
43
44
|
*/
|
44
45
|
|
45
|
-
static
|
46
|
+
static int maxDetectLowHighWait (const int pin)
|
46
47
|
{
|
47
|
-
|
48
|
+
struct timeval now, timeOut, timeUp ;
|
49
|
+
|
50
|
+
// If already high then wait for pin to go low
|
51
|
+
|
52
|
+
gettimeofday (&now, NULL) ;
|
53
|
+
timerclear (&timeOut) ;
|
54
|
+
timeOut.tv_usec = 1000 ;
|
55
|
+
timeradd (&now, &timeOut, &timeUp) ;
|
48
56
|
|
49
57
|
while (digitalRead (pin) == HIGH)
|
50
|
-
|
51
|
-
|
58
|
+
{
|
59
|
+
gettimeofday (&now, NULL) ;
|
60
|
+
if (timercmp (&now, &timeUp, >))
|
61
|
+
return FALSE ;
|
62
|
+
}
|
63
|
+
|
64
|
+
// Wait for it to go HIGH
|
65
|
+
|
66
|
+
gettimeofday (&now, NULL) ;
|
67
|
+
timerclear (&timeOut) ;
|
68
|
+
timeOut.tv_usec = 1000 ;
|
69
|
+
timeradd (&now, &timeOut, &timeUp) ;
|
52
70
|
|
53
71
|
while (digitalRead (pin) == LOW)
|
54
|
-
|
55
|
-
|
72
|
+
{
|
73
|
+
gettimeofday (&now, NULL) ;
|
74
|
+
if (timercmp (&now, &timeUp, >))
|
75
|
+
return FALSE ;
|
76
|
+
}
|
77
|
+
|
78
|
+
return TRUE ;
|
56
79
|
}
|
57
80
|
|
58
81
|
|
@@ -69,7 +92,8 @@ static unsigned int maxDetectClockByte (const int pin)
|
|
69
92
|
|
70
93
|
for (bit = 0 ; bit < 8 ; ++bit)
|
71
94
|
{
|
72
|
-
maxDetectLowHighWait (pin)
|
95
|
+
if (!maxDetectLowHighWait (pin))
|
96
|
+
return 0 ;
|
73
97
|
|
74
98
|
// bit starting now - we need to time it.
|
75
99
|
|
@@ -95,6 +119,11 @@ int maxDetectRead (const int pin, unsigned char buffer [4])
|
|
95
119
|
int i ;
|
96
120
|
unsigned int checksum ;
|
97
121
|
unsigned char localBuf [5] ;
|
122
|
+
struct timeval now, then, took ;
|
123
|
+
|
124
|
+
// See how long we took
|
125
|
+
|
126
|
+
gettimeofday (&then, NULL) ;
|
98
127
|
|
99
128
|
// Wake up the RHT03 by pulling the data line low, then high
|
100
129
|
// Low for 10mS, high for 40uS.
|
@@ -106,7 +135,8 @@ int maxDetectRead (const int pin, unsigned char buffer [4])
|
|
106
135
|
|
107
136
|
// Now wait for sensor to pull pin low
|
108
137
|
|
109
|
-
maxDetectLowHighWait (pin)
|
138
|
+
if (!maxDetectLowHighWait (pin))
|
139
|
+
return FALSE ;
|
110
140
|
|
111
141
|
// and read in 5 bytes (40 bits)
|
112
142
|
|
@@ -121,6 +151,22 @@ int maxDetectRead (const int pin, unsigned char buffer [4])
|
|
121
151
|
}
|
122
152
|
checksum &= 0xFF ;
|
123
153
|
|
154
|
+
// See how long we took
|
155
|
+
|
156
|
+
gettimeofday (&now, NULL) ;
|
157
|
+
timersub (&now, &then, &took) ;
|
158
|
+
|
159
|
+
// Total time to do this should be:
|
160
|
+
// 10mS + 40µS - reset
|
161
|
+
// + 80µS + 80µS - sensor doing its low -> high thing
|
162
|
+
// + 40 * (50µS + 27µS (0) or 70µS (1) )
|
163
|
+
// = 15010µS
|
164
|
+
// so if we take more than that, we've had a scheduling interruption and the
|
165
|
+
// reading is probably bogus.
|
166
|
+
|
167
|
+
if ((took.tv_sec != 0) || (took.tv_usec > 16000))
|
168
|
+
return FALSE ;
|
169
|
+
|
124
170
|
return checksum == localBuf [4] ;
|
125
171
|
}
|
126
172
|
|
@@ -128,38 +174,65 @@ int maxDetectRead (const int pin, unsigned char buffer [4])
|
|
128
174
|
/*
|
129
175
|
* readRHT03:
|
130
176
|
* Read the Temperature & Humidity from an RHT03 sensor
|
177
|
+
* Values returned are *10, so 123 is 12.3.
|
131
178
|
*********************************************************************************
|
132
179
|
*/
|
133
180
|
|
134
181
|
int readRHT03 (const int pin, int *temp, int *rh)
|
135
182
|
{
|
136
|
-
static
|
137
|
-
static
|
138
|
-
static
|
139
|
-
static int lastResult = TRUE ;
|
183
|
+
static struct timeval then ; // will initialise to zero
|
184
|
+
static int lastTemp = 0 ;
|
185
|
+
static int lastRh = 0 ;
|
140
186
|
|
187
|
+
int result ;
|
188
|
+
struct timeval now, timeOut ;
|
141
189
|
unsigned char buffer [4] ;
|
142
190
|
|
143
|
-
//
|
191
|
+
// The data sheets say to not read more than once every 2 seconds, so you
|
192
|
+
// get the last good reading
|
144
193
|
|
145
|
-
|
194
|
+
gettimeofday (&now, NULL) ;
|
195
|
+
if (timercmp (&now, &then, <))
|
146
196
|
{
|
147
|
-
*temp = lastTemp ;
|
148
197
|
*rh = lastRh ;
|
149
|
-
|
198
|
+
*temp = lastTemp ;
|
199
|
+
return TRUE ;
|
150
200
|
}
|
201
|
+
|
202
|
+
// Set timeout for next read
|
203
|
+
|
204
|
+
gettimeofday (&now, NULL) ;
|
205
|
+
timerclear (&timeOut) ;
|
206
|
+
timeOut.tv_sec = 2 ;
|
207
|
+
timeradd (&now, &timeOut, &then) ;
|
208
|
+
|
209
|
+
// Read ...
|
151
210
|
|
152
|
-
|
211
|
+
result = maxDetectRead (pin, buffer) ;
|
212
|
+
|
213
|
+
if (!result) // Try again, but just once
|
214
|
+
result = maxDetectRead (pin, buffer) ;
|
215
|
+
|
216
|
+
if (!result)
|
217
|
+
return FALSE ;
|
153
218
|
|
154
|
-
|
219
|
+
*rh = (buffer [0] * 256 + buffer [1]) ;
|
220
|
+
*temp = (buffer [2] * 256 + buffer [3]) ;
|
221
|
+
|
222
|
+
if ((*temp & 0x8000) != 0) // Negative
|
155
223
|
{
|
156
|
-
*temp
|
157
|
-
*
|
158
|
-
nextTime = millis () + 2000 ;
|
159
|
-
return TRUE ;
|
224
|
+
*temp &= 0x7FFF ;
|
225
|
+
*temp = -*temp ;
|
160
226
|
}
|
161
|
-
|
162
|
-
|
227
|
+
|
228
|
+
// Discard obviously bogus readings - the checksum can't detect a 2-bit error
|
229
|
+
// (which does seem to happen - no realtime here)
|
230
|
+
|
231
|
+
if ((*rh > 999) || (*temp > 800) || (*temp < -400))
|
163
232
|
return FALSE ;
|
164
|
-
|
233
|
+
|
234
|
+
lastRh = *rh ;
|
235
|
+
lastTemp = *temp ;
|
236
|
+
|
237
|
+
return TRUE ;
|
165
238
|
}
|
File without changes
|
@@ -0,0 +1,430 @@
|
|
1
|
+
/*
|
2
|
+
* scrollPhat.c:
|
3
|
+
* Simple driver for the Pimoroni Scroll Phat device
|
4
|
+
*
|
5
|
+
* Copyright (c) 2015 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 published by
|
12
|
+
* the Free Software Foundation, either version 3 of the License, or
|
13
|
+
* (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 License
|
21
|
+
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
22
|
+
***********************************************************************
|
23
|
+
*/
|
24
|
+
|
25
|
+
#include <stdio.h>
|
26
|
+
#include <stdlib.h>
|
27
|
+
#include <stdarg.h>
|
28
|
+
#include <string.h>
|
29
|
+
#include <time.h>
|
30
|
+
|
31
|
+
#include <wiringPiI2C.h>
|
32
|
+
|
33
|
+
#include "scrollPhatFont.h"
|
34
|
+
#include "scrollPhat.h"
|
35
|
+
|
36
|
+
// Size
|
37
|
+
|
38
|
+
#define SP_WIDTH 11
|
39
|
+
#define SP_HEIGHT 5
|
40
|
+
|
41
|
+
// I2C
|
42
|
+
|
43
|
+
#define PHAT_I2C_ADDR 0x60
|
44
|
+
|
45
|
+
// Software copy of the framebuffer
|
46
|
+
// it's 8-bit deep although the display itself is only 1-bit deep.
|
47
|
+
|
48
|
+
static unsigned char frameBuffer [SP_WIDTH * SP_HEIGHT] ;
|
49
|
+
|
50
|
+
static int lastX, lastY ;
|
51
|
+
static int printDelayFactor ;
|
52
|
+
static int scrollPhatFd ;
|
53
|
+
|
54
|
+
static int putcharX ;
|
55
|
+
|
56
|
+
#undef DEBUG
|
57
|
+
|
58
|
+
|
59
|
+
/*
|
60
|
+
* delay:
|
61
|
+
* Wait for some number of milliseconds.
|
62
|
+
* This taken from wiringPi as there is no-need to include the whole of
|
63
|
+
* wiringPi just for the delay function.
|
64
|
+
*********************************************************************************
|
65
|
+
*/
|
66
|
+
|
67
|
+
static void delay (unsigned int howLong)
|
68
|
+
{
|
69
|
+
struct timespec sleeper, dummy ;
|
70
|
+
|
71
|
+
sleeper.tv_sec = (time_t)(howLong / 1000) ;
|
72
|
+
sleeper.tv_nsec = (long)(howLong % 1000) * 1000000 ;
|
73
|
+
|
74
|
+
nanosleep (&sleeper, &dummy) ;
|
75
|
+
}
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
/*
|
80
|
+
* scrollPhatUpdate:
|
81
|
+
* Copy our software version to the real display
|
82
|
+
*********************************************************************************
|
83
|
+
*/
|
84
|
+
|
85
|
+
void scrollPhatUpdate (void)
|
86
|
+
{
|
87
|
+
register int x, y ;
|
88
|
+
register unsigned char data, pixel ;
|
89
|
+
unsigned char pixels [SP_WIDTH] ;
|
90
|
+
|
91
|
+
#ifdef DEBUG
|
92
|
+
printf ("+-----------+\n") ;
|
93
|
+
for (y = 0 ; y < SP_HEIGHT ; ++y)
|
94
|
+
{
|
95
|
+
putchar ('|') ;
|
96
|
+
for (x = 0 ; x < SP_WIDTH ; ++x)
|
97
|
+
{
|
98
|
+
pixel = frameBuffer [x + y * SP_WIDTH] ;
|
99
|
+
putchar (pixel == 0 ? ' ' : '*') ;
|
100
|
+
}
|
101
|
+
printf ("|\n") ;
|
102
|
+
}
|
103
|
+
printf ("+-----------+\n") ;
|
104
|
+
#endif
|
105
|
+
|
106
|
+
for (x = 0 ; x < SP_WIDTH ; ++x)
|
107
|
+
{
|
108
|
+
data = 0 ;
|
109
|
+
for (y = 0 ; y < SP_HEIGHT ; ++y)
|
110
|
+
{
|
111
|
+
pixel = frameBuffer [x + y * SP_WIDTH] ;
|
112
|
+
data = (data << 1) | ((pixel == 0) ? 0 : 1) ;
|
113
|
+
}
|
114
|
+
pixels [x] = data ;
|
115
|
+
}
|
116
|
+
|
117
|
+
for (x = 0 ; x < SP_WIDTH ; ++x)
|
118
|
+
wiringPiI2CWriteReg8 (scrollPhatFd, 1 + x, pixels [x]) ;
|
119
|
+
|
120
|
+
wiringPiI2CWriteReg8 (scrollPhatFd, 0x0C, 0) ;
|
121
|
+
}
|
122
|
+
|
123
|
+
|
124
|
+
/*
|
125
|
+
*********************************************************************************
|
126
|
+
* Standard Graphical Functions
|
127
|
+
*********************************************************************************
|
128
|
+
*/
|
129
|
+
|
130
|
+
|
131
|
+
/*
|
132
|
+
* scrollPhatPoint:
|
133
|
+
* Plot a pixel. Crude clipping - speed is not the essence here.
|
134
|
+
*********************************************************************************
|
135
|
+
*/
|
136
|
+
|
137
|
+
void scrollPhatPoint (int x, int y, int colour)
|
138
|
+
{
|
139
|
+
lastX = x ;
|
140
|
+
lastY = y ;
|
141
|
+
|
142
|
+
if ((x < 0) || (x >= SP_WIDTH) || (y < 0) || (y >= SP_HEIGHT))
|
143
|
+
return ;
|
144
|
+
|
145
|
+
frameBuffer [x + y * SP_WIDTH] = colour ;
|
146
|
+
}
|
147
|
+
|
148
|
+
|
149
|
+
/*
|
150
|
+
* scrollPhatLine: scrollPhatLineTo:
|
151
|
+
* Classic Bressenham Line code - rely on the point function to do the
|
152
|
+
* clipping for us here.
|
153
|
+
*********************************************************************************
|
154
|
+
*/
|
155
|
+
|
156
|
+
void scrollPhatLine (int x0, int y0, int x1, int y1, int colour)
|
157
|
+
{
|
158
|
+
int dx, dy ;
|
159
|
+
int sx, sy ;
|
160
|
+
int err, e2 ;
|
161
|
+
|
162
|
+
lastX = x1 ;
|
163
|
+
lastY = y1 ;
|
164
|
+
|
165
|
+
dx = abs (x1 - x0) ;
|
166
|
+
dy = abs (y1 - y0) ;
|
167
|
+
|
168
|
+
sx = (x0 < x1) ? 1 : -1 ;
|
169
|
+
sy = (y0 < y1) ? 1 : -1 ;
|
170
|
+
|
171
|
+
err = dx - dy ;
|
172
|
+
|
173
|
+
for (;;)
|
174
|
+
{
|
175
|
+
scrollPhatPoint (x0, y0, colour) ;
|
176
|
+
|
177
|
+
if ((x0 == x1) && (y0 == y1))
|
178
|
+
break ;
|
179
|
+
|
180
|
+
e2 = 2 * err ;
|
181
|
+
|
182
|
+
if (e2 > -dy)
|
183
|
+
{
|
184
|
+
err -= dy ;
|
185
|
+
x0 += sx ;
|
186
|
+
}
|
187
|
+
|
188
|
+
if (e2 < dx)
|
189
|
+
{
|
190
|
+
err += dx ;
|
191
|
+
y0 += sy ;
|
192
|
+
}
|
193
|
+
}
|
194
|
+
|
195
|
+
}
|
196
|
+
|
197
|
+
void scrollPhatLineTo (int x, int y, int colour)
|
198
|
+
{
|
199
|
+
scrollPhatLine (lastX, lastY, x, y, colour) ;
|
200
|
+
}
|
201
|
+
|
202
|
+
|
203
|
+
/*
|
204
|
+
* scrollPhatRectangle:
|
205
|
+
* A rectangle is a spoilt days fishing
|
206
|
+
*********************************************************************************
|
207
|
+
*/
|
208
|
+
|
209
|
+
void scrollPhatRectangle (int x1, int y1, int x2, int y2, int colour, int filled)
|
210
|
+
{
|
211
|
+
register int x ;
|
212
|
+
|
213
|
+
if (filled)
|
214
|
+
{
|
215
|
+
/**/ if (x1 == x2)
|
216
|
+
scrollPhatLine (x1, y1, x2, y2, colour) ;
|
217
|
+
else if (x1 < x2)
|
218
|
+
for (x = x1 ; x <= x2 ; ++x)
|
219
|
+
scrollPhatLine (x, y1, x, y2, colour) ;
|
220
|
+
else
|
221
|
+
for (x = x2 ; x <= x1 ; ++x)
|
222
|
+
scrollPhatLine (x, y1, x, y2, colour) ;
|
223
|
+
}
|
224
|
+
else
|
225
|
+
{
|
226
|
+
scrollPhatLine (x1, y1, x2, y1, colour) ;
|
227
|
+
scrollPhatLineTo (x2, y2, colour) ;
|
228
|
+
scrollPhatLineTo (x1, y2, colour) ;
|
229
|
+
scrollPhatLineTo (x1, y1, colour) ;
|
230
|
+
}
|
231
|
+
}
|
232
|
+
|
233
|
+
|
234
|
+
/*
|
235
|
+
* scrollPhatPutchar:
|
236
|
+
* Print a single character to the screen then advance the pointer by an
|
237
|
+
* appropriate ammount (variable width font).
|
238
|
+
* We rely on the clipping done by the pixel plot function to keep us
|
239
|
+
* out of trouble.
|
240
|
+
* Return the width + space
|
241
|
+
*********************************************************************************
|
242
|
+
*/
|
243
|
+
|
244
|
+
int scrollPhatPutchar (int c)
|
245
|
+
{
|
246
|
+
register int x, y ;
|
247
|
+
|
248
|
+
unsigned char line ;
|
249
|
+
unsigned char *fontPtr ;
|
250
|
+
unsigned char *p2 ;
|
251
|
+
int lineWidth, width, mask ;
|
252
|
+
|
253
|
+
// The font is printable characters, uppercase only...
|
254
|
+
// and somewhat varaible width...
|
255
|
+
|
256
|
+
c &= 0x7F ;
|
257
|
+
if (c > 0x60)
|
258
|
+
c -= 64 ;
|
259
|
+
else
|
260
|
+
c -= 32 ;
|
261
|
+
|
262
|
+
fontPtr = scrollPhatFont + c * fontHeight ;
|
263
|
+
|
264
|
+
// Work out width of this character
|
265
|
+
// There probably is a more efficient way to do this, but...
|
266
|
+
|
267
|
+
p2 = fontPtr ;
|
268
|
+
width = 0 ;
|
269
|
+
for (y = 0 ; y < fontHeight ; ++y)
|
270
|
+
{
|
271
|
+
mask = 0x80 ;
|
272
|
+
for (lineWidth = 8 ; lineWidth > 0 ; --lineWidth)
|
273
|
+
{
|
274
|
+
if ((*p2 & mask) != 0)
|
275
|
+
break ;
|
276
|
+
mask >>= 1 ;
|
277
|
+
}
|
278
|
+
if (lineWidth > width)
|
279
|
+
width = lineWidth ;
|
280
|
+
|
281
|
+
++p2 ;
|
282
|
+
}
|
283
|
+
|
284
|
+
if (width == 0) // Likely to be a blank or space character
|
285
|
+
width = 3 ;
|
286
|
+
|
287
|
+
for (y = fontHeight - 1 ; y >= 0 ; --y)
|
288
|
+
{
|
289
|
+
x = 0 ;
|
290
|
+
line = *fontPtr++ ;
|
291
|
+
for (mask = 1 << (width - 1) ; mask != 0 ; mask >>= 1)
|
292
|
+
{
|
293
|
+
scrollPhatPoint (putcharX + x, y, (line & mask)) ;
|
294
|
+
++x ;
|
295
|
+
}
|
296
|
+
}
|
297
|
+
|
298
|
+
// make a line of space
|
299
|
+
|
300
|
+
for (y = fontHeight - 1 ; y >= 0 ; --y)
|
301
|
+
scrollPhatPoint (putcharX + width, y, 0) ;
|
302
|
+
|
303
|
+
putcharX = putcharX + width + 1 ;
|
304
|
+
|
305
|
+
return width + 1 ;
|
306
|
+
}
|
307
|
+
|
308
|
+
|
309
|
+
/*
|
310
|
+
* scrollPhatPuts:
|
311
|
+
* Send a string to the display - and scroll it across.
|
312
|
+
* This is somewhat of a hack in that we print the entire string to the
|
313
|
+
* display and let the point clipping take care of what's off-screen...
|
314
|
+
*********************************************************************************
|
315
|
+
*/
|
316
|
+
|
317
|
+
void scrollPhatPuts (const char *str)
|
318
|
+
{
|
319
|
+
int i ;
|
320
|
+
int movingX = 0 ;
|
321
|
+
const char *s ;
|
322
|
+
int pixelLen ;
|
323
|
+
|
324
|
+
// Print it once, then we know the width in pixels...
|
325
|
+
|
326
|
+
putcharX = 0 ;
|
327
|
+
s = str ;
|
328
|
+
while (*s)
|
329
|
+
scrollPhatPutchar (*s++) ;
|
330
|
+
|
331
|
+
pixelLen = putcharX ;
|
332
|
+
|
333
|
+
// Now scroll it by printing it and moving left one pixel
|
334
|
+
|
335
|
+
movingX = 0 ;
|
336
|
+
for (i = 0 ; i < pixelLen ; ++i)
|
337
|
+
{
|
338
|
+
putcharX = movingX ;
|
339
|
+
s = str ;
|
340
|
+
while (*s)
|
341
|
+
scrollPhatPutchar (*s++) ;
|
342
|
+
--movingX ;
|
343
|
+
scrollPhatUpdate () ;
|
344
|
+
delay (printDelayFactor) ;
|
345
|
+
}
|
346
|
+
}
|
347
|
+
|
348
|
+
|
349
|
+
/*
|
350
|
+
* scrollPhatPrintf:
|
351
|
+
* Does what it says
|
352
|
+
*********************************************************************************
|
353
|
+
*/
|
354
|
+
|
355
|
+
void scrollPhatPrintf (const char *message, ...)
|
356
|
+
{
|
357
|
+
va_list argp ;
|
358
|
+
char buffer [1024] ;
|
359
|
+
|
360
|
+
va_start (argp, message) ;
|
361
|
+
vsnprintf (buffer, 1023, message, argp) ;
|
362
|
+
va_end (argp) ;
|
363
|
+
|
364
|
+
scrollPhatPuts (buffer) ;
|
365
|
+
}
|
366
|
+
|
367
|
+
|
368
|
+
/*
|
369
|
+
* scrollPhatPrintSpeed:
|
370
|
+
* Change the print speed - mS per shift by 1 pixel
|
371
|
+
*********************************************************************************
|
372
|
+
*/
|
373
|
+
|
374
|
+
void scrollPhatPrintSpeed (const int pps)
|
375
|
+
{
|
376
|
+
if (pps < 0)
|
377
|
+
printDelayFactor = 0 ;
|
378
|
+
else
|
379
|
+
printDelayFactor = pps ;
|
380
|
+
}
|
381
|
+
|
382
|
+
|
383
|
+
/*
|
384
|
+
* scrollPhatClear:
|
385
|
+
* Clear the display
|
386
|
+
*********************************************************************************
|
387
|
+
*/
|
388
|
+
|
389
|
+
void scrollPhatClear (void)
|
390
|
+
{
|
391
|
+
register int i ;
|
392
|
+
register unsigned char *ptr = frameBuffer ;
|
393
|
+
|
394
|
+
for (i = 0 ; i < (SP_WIDTH * SP_HEIGHT) ; ++i)
|
395
|
+
*ptr++ = 0 ;
|
396
|
+
|
397
|
+
scrollPhatUpdate () ;
|
398
|
+
}
|
399
|
+
|
400
|
+
|
401
|
+
/*
|
402
|
+
* scrollPhatIntensity:
|
403
|
+
* Set the display brightness - percentage
|
404
|
+
*********************************************************************************
|
405
|
+
*/
|
406
|
+
|
407
|
+
void scrollPhatIntensity (const int percent)
|
408
|
+
{
|
409
|
+
wiringPiI2CWriteReg8 (scrollPhatFd, 0x19, (127 * percent) / 100) ;
|
410
|
+
}
|
411
|
+
|
412
|
+
|
413
|
+
/*
|
414
|
+
* scrollPhatSetup:
|
415
|
+
* Initialise the Scroll Phat display
|
416
|
+
*********************************************************************************
|
417
|
+
*/
|
418
|
+
|
419
|
+
int scrollPhatSetup (void)
|
420
|
+
{
|
421
|
+
if ((scrollPhatFd = wiringPiI2CSetup (PHAT_I2C_ADDR)) < 0)
|
422
|
+
return scrollPhatFd ;
|
423
|
+
|
424
|
+
wiringPiI2CWriteReg8 (scrollPhatFd, 0x00, 0x03) ; // Enable display, set to 5x11 mode
|
425
|
+
scrollPhatIntensity (10) ;
|
426
|
+
scrollPhatClear () ;
|
427
|
+
scrollPhatPrintSpeed (100) ;
|
428
|
+
|
429
|
+
return 0 ;
|
430
|
+
}
|