wiring_lmk 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +7 -0
  2. data/ext/wiringpi/WiringPi/devLib/ds1302.c +254 -0
  3. data/ext/wiringpi/WiringPi/devLib/ds1302.h +44 -0
  4. data/ext/wiringpi/WiringPi/devLib/font.h +2577 -0
  5. data/ext/wiringpi/WiringPi/devLib/gertboard.c +164 -0
  6. data/ext/wiringpi/WiringPi/devLib/gertboard.h +45 -0
  7. data/ext/wiringpi/WiringPi/devLib/lcd.c +507 -0
  8. data/ext/wiringpi/WiringPi/devLib/lcd.h +52 -0
  9. data/ext/wiringpi/WiringPi/devLib/lcd128x64.c +684 -0
  10. data/ext/wiringpi/WiringPi/devLib/lcd128x64.h +39 -0
  11. data/ext/wiringpi/WiringPi/devLib/maxdetect.c +167 -0
  12. data/ext/wiringpi/WiringPi/devLib/maxdetect.h +40 -0
  13. data/ext/wiringpi/WiringPi/devLib/piFace.c +112 -0
  14. data/ext/wiringpi/WiringPi/devLib/piFace.h +32 -0
  15. data/ext/wiringpi/WiringPi/devLib/piFaceOld.c +178 -0
  16. data/ext/wiringpi/WiringPi/devLib/piGlow.c +118 -0
  17. data/ext/wiringpi/WiringPi/devLib/piGlow.h +45 -0
  18. data/ext/wiringpi/WiringPi/devLib/piNes.c +117 -0
  19. data/ext/wiringpi/WiringPi/devLib/piNes.h +45 -0
  20. data/ext/wiringpi/WiringPi/gpio/extensions.c +700 -0
  21. data/ext/wiringpi/WiringPi/gpio/extensions.h +26 -0
  22. data/ext/wiringpi/WiringPi/gpio/gpio.c +1280 -0
  23. data/ext/wiringpi/WiringPi/gpio/pins.c +33 -0
  24. data/ext/wiringpi/WiringPi/gpio/readall.c +337 -0
  25. data/ext/wiringpi/WiringPi/wiringPi/drcSerial.c +201 -0
  26. data/ext/wiringpi/WiringPi/wiringPi/drcSerial.h +33 -0
  27. data/ext/wiringpi/WiringPi/wiringPi/max31855.c +99 -0
  28. data/ext/wiringpi/WiringPi/wiringPi/max31855.h +33 -0
  29. data/ext/wiringpi/WiringPi/wiringPi/max5322.c +84 -0
  30. data/ext/wiringpi/WiringPi/wiringPi/max5322.h +33 -0
  31. data/ext/wiringpi/WiringPi/wiringPi/mcp23008.c +149 -0
  32. data/ext/wiringpi/WiringPi/wiringPi/mcp23008.h +33 -0
  33. data/ext/wiringpi/WiringPi/wiringPi/mcp23016.c +164 -0
  34. data/ext/wiringpi/WiringPi/wiringPi/mcp23016.h +33 -0
  35. data/ext/wiringpi/WiringPi/wiringPi/mcp23016reg.h +48 -0
  36. data/ext/wiringpi/WiringPi/wiringPi/mcp23017.c +195 -0
  37. data/ext/wiringpi/WiringPi/wiringPi/mcp23017.h +33 -0
  38. data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.c +189 -0
  39. data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.h +33 -0
  40. data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.c +234 -0
  41. data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.h +33 -0
  42. data/ext/wiringpi/WiringPi/wiringPi/mcp23x08.h +73 -0
  43. data/ext/wiringpi/WiringPi/wiringPi/mcp23x0817.h +87 -0
  44. data/ext/wiringpi/WiringPi/wiringPi/mcp3002.c +76 -0
  45. data/ext/wiringpi/WiringPi/wiringPi/mcp3002.h +33 -0
  46. data/ext/wiringpi/WiringPi/wiringPi/mcp3004.c +76 -0
  47. data/ext/wiringpi/WiringPi/wiringPi/mcp3004.h +33 -0
  48. data/ext/wiringpi/WiringPi/wiringPi/mcp3422.c +113 -0
  49. data/ext/wiringpi/WiringPi/wiringPi/mcp3422.h +43 -0
  50. data/ext/wiringpi/WiringPi/wiringPi/mcp4802.c +76 -0
  51. data/ext/wiringpi/WiringPi/wiringPi/mcp4802.h +33 -0
  52. data/ext/wiringpi/WiringPi/wiringPi/pcf8574.c +126 -0
  53. data/ext/wiringpi/WiringPi/wiringPi/pcf8574.h +33 -0
  54. data/ext/wiringpi/WiringPi/wiringPi/pcf8591.c +92 -0
  55. data/ext/wiringpi/WiringPi/wiringPi/pcf8591.h +33 -0
  56. data/ext/wiringpi/WiringPi/wiringPi/piHiPri.c +51 -0
  57. data/ext/wiringpi/WiringPi/wiringPi/piThread.c +63 -0
  58. data/ext/wiringpi/WiringPi/wiringPi/sn3218.c +75 -0
  59. data/ext/wiringpi/WiringPi/wiringPi/sn3218.h +33 -0
  60. data/ext/wiringpi/WiringPi/wiringPi/softPwm.c +168 -0
  61. data/ext/wiringpi/WiringPi/wiringPi/softPwm.h +35 -0
  62. data/ext/wiringpi/WiringPi/wiringPi/softServo.c +247 -0
  63. data/ext/wiringpi/WiringPi/wiringPi/softServo.h +35 -0
  64. data/ext/wiringpi/WiringPi/wiringPi/softTone.c +150 -0
  65. data/ext/wiringpi/WiringPi/wiringPi/softTone.h +39 -0
  66. data/ext/wiringpi/WiringPi/wiringPi/sr595.c +113 -0
  67. data/ext/wiringpi/WiringPi/wiringPi/sr595.h +34 -0
  68. data/ext/wiringpi/WiringPi/wiringPi/wiringPi.c +3688 -0
  69. data/ext/wiringpi/WiringPi/wiringPi/wiringPi.h +229 -0
  70. data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.c +236 -0
  71. data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.h +42 -0
  72. data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.c +121 -0
  73. data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.h +35 -0
  74. data/ext/wiringpi/WiringPi/wiringPi/wiringSerial.c +253 -0
  75. data/ext/wiringpi/WiringPi/wiringPi/wiringSerial.h +38 -0
  76. data/ext/wiringpi/WiringPi/wiringPi/wiringShift.c +83 -0
  77. data/ext/wiringpi/WiringPi/wiringPi/wiringShift.h +41 -0
  78. data/ext/wiringpi/extconf.rb +8 -0
  79. data/ext/wiringpi/wiringpi_wrap.c +4396 -0
  80. data/lib/wiring_lmk.rb +42 -0
  81. data/lib/wiring_lmk/event.rb +21 -0
  82. data/lib/wiring_lmk/gpio.rb +139 -0
  83. data/lib/wiring_lmk/i2c.rb +26 -0
  84. data/lib/wiring_lmk/mcp23x17.rb +31 -0
  85. data/lib/wiring_lmk/serial.rb +49 -0
  86. data/lib/wiring_lmk/spi.rb +15 -0
  87. metadata +136 -0
@@ -0,0 +1,52 @@
1
+ /*
2
+ * lcd.h:
3
+ * Text-based LCD driver.
4
+ * This is designed to drive the parallel interface LCD drivers
5
+ * based in the Hitachi HD44780U controller and compatables.
6
+ *
7
+ * Copyright (c) 2012 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
+ #define MAX_LCDS 8
28
+
29
+ #ifdef __cplusplus
30
+ extern "C" {
31
+ #endif
32
+
33
+ extern void lcdHome (const int fd) ;
34
+ extern void lcdClear (const int fd) ;
35
+ extern void lcdDisplay (const int fd, int state) ;
36
+ extern void lcdCursor (const int fd, int state) ;
37
+ extern void lcdCursorBlink (const int fd, int state) ;
38
+ extern void lcdSendCommand (const int fd, unsigned char command) ;
39
+ extern void lcdPosition (const int fd, int x, int y) ;
40
+ extern void lcdCharDef (const int fd, int index, unsigned char data [8]) ;
41
+ extern void lcdPutchar (const int fd, unsigned char data) ;
42
+ extern void lcdPuts (const int fd, const char *string) ;
43
+ extern void lcdPrintf (const int fd, const char *message, ...) ;
44
+
45
+ extern int lcdInit (const int rows, const int cols, const int bits,
46
+ const int rs, const int strb,
47
+ const int d0, const int d1, const int d2, const int d3, const int d4,
48
+ const int d5, const int d6, const int d7) ;
49
+
50
+ #ifdef __cplusplus
51
+ }
52
+ #endif
@@ -0,0 +1,684 @@
1
+ /*
2
+ * lcd128x64.c:
3
+ * Graphics-based LCD driver.
4
+ * This is designed to drive the parallel interface LCD drivers
5
+ * based on the generic 12864H chips
6
+ *
7
+ * There are many variations on these chips, however they all mostly
8
+ * seem to be similar.
9
+ * This implementation has the Pins from the Pi hard-wired into it,
10
+ * in particular wiringPi pins 0-7 so that we can use
11
+ * digitalWriteByete() to speed things up somewhat.
12
+ *
13
+ * Copyright (c) 2013 Gordon Henderson.
14
+ ***********************************************************************
15
+ * This file is part of wiringPi:
16
+ * https://projects.drogon.net/raspberry-pi/wiringpi/
17
+ *
18
+ * wiringPi is free software: you can redistribute it and/or modify
19
+ * it under the terms of the GNU Lesser General Public License as published by
20
+ * the Free Software Foundation, either version 3 of the License, or
21
+ * (at your option) any later version.
22
+ *
23
+ * wiringPi is distributed in the hope that it will be useful,
24
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
25
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
+ * GNU Lesser General Public License for more details.
27
+ *
28
+ * You should have received a copy of the GNU Lesser General Public License
29
+ * along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
30
+ ***********************************************************************
31
+ */
32
+
33
+ #include <stdio.h>
34
+ #include <stdlib.h>
35
+
36
+ #include "wiringPi.h"
37
+
38
+ #include "font.h"
39
+ #include "lcd128x64.h"
40
+
41
+ // Size
42
+
43
+ #define LCD_WIDTH 128
44
+ #define LCD_HEIGHT 64
45
+
46
+ // Hardware Pins
47
+ // Note pins 0-7 are the 8-bit data port
48
+
49
+ #define CS1 10
50
+ #define CS2 11
51
+ #define STROBE 12
52
+ #define RS 13
53
+
54
+ // Software copy of the framebuffer
55
+ // it's 8-bit deep although the display itself is only 1-bit deep.
56
+
57
+ static unsigned char frameBuffer [LCD_WIDTH * LCD_HEIGHT] ;
58
+
59
+ static int maxX, maxY ;
60
+ static int lastX, lastY ;
61
+ static int xOrigin, yOrigin ;
62
+ static int lcdOrientation = 0 ;
63
+
64
+ /*
65
+ * strobe:
66
+ * Toggle the strobe (Really the "E") pin to the device.
67
+ * According to the docs, data is latched on the falling edge.
68
+ *********************************************************************************
69
+ */
70
+
71
+ static void strobe (void)
72
+ {
73
+ digitalWrite (STROBE, 1) ;
74
+ delayMicroseconds (1) ;
75
+ digitalWrite (STROBE, 0) ;
76
+ delayMicroseconds (5) ;
77
+ }
78
+
79
+
80
+ /*
81
+ * sentData:
82
+ * Send an data or command byte to the display.
83
+ *********************************************************************************
84
+ */
85
+
86
+ static void sendData (const int data, const int chip)
87
+ {
88
+ digitalWrite (chip, 0) ;
89
+ digitalWriteByte (data) ;
90
+ strobe () ;
91
+ digitalWrite (chip, 1) ;
92
+ }
93
+
94
+
95
+ /*
96
+ * sendCommand:
97
+ * Send a command byte to the display
98
+ *********************************************************************************
99
+ */
100
+
101
+ static void sendCommand (const int command, const int chip)
102
+ {
103
+ digitalWrite (RS, 0) ;
104
+ sendData (command, chip) ;
105
+ digitalWrite (RS, 1) ;
106
+ }
107
+
108
+
109
+ /*
110
+ * setCol: SetLine:
111
+ * Set the column and line addresses
112
+ *********************************************************************************
113
+ */
114
+
115
+ static void setCol (int col, const int chip)
116
+ {
117
+ sendCommand (0x40 | (col & 0x3F), chip) ;
118
+ }
119
+
120
+ static void setLine (int line, const int chip)
121
+ {
122
+ sendCommand (0xB8 | (line & 0x07), chip) ;
123
+ }
124
+
125
+
126
+ /*
127
+ * lcd128x64update:
128
+ * Copy our software version to the real display
129
+ *********************************************************************************
130
+ */
131
+
132
+ void lcd128x64update (void)
133
+ {
134
+ int line, x, y, fbLoc ;
135
+ unsigned char byte ;
136
+
137
+ // Left side
138
+
139
+ for (line = 0 ; line < 8 ; ++line)
140
+ {
141
+ setCol (0, CS1) ;
142
+ setLine (line, CS1) ;
143
+
144
+ for (x = 63 ; x >= 0 ; --x)
145
+ {
146
+ byte = 0 ;
147
+ for (y = 0 ; y < 8 ; ++y)
148
+ {
149
+ fbLoc = x + (((7 - line) * 8) + (7 - y)) * LCD_WIDTH ;
150
+ if (frameBuffer [fbLoc] != 0)
151
+ byte |= (1 << y) ;
152
+ }
153
+ sendData (byte, CS1) ;
154
+ }
155
+ }
156
+
157
+ // Right side
158
+
159
+ for (line = 0 ; line < 8 ; ++line)
160
+ {
161
+ setCol (0, CS2) ;
162
+ setLine (line, CS2) ;
163
+
164
+ for (x = 127 ; x >= 64 ; --x)
165
+ {
166
+ byte = 0 ;
167
+ for (y = 0 ; y < 8 ; ++y)
168
+ {
169
+ fbLoc = x + (((7 - line) * 8) + (7 - y)) * LCD_WIDTH ;
170
+ if (frameBuffer [fbLoc] != 0)
171
+ byte |= (1 << y) ;
172
+ }
173
+ sendData (byte, CS2) ;
174
+ }
175
+ }
176
+ }
177
+
178
+
179
+ /*
180
+ * lcd128x64setOrigin:
181
+ * Set the display offset origin
182
+ *********************************************************************************
183
+ */
184
+
185
+ void lcd128x64setOrigin (int x, int y)
186
+ {
187
+ xOrigin = x ;
188
+ yOrigin = y ;
189
+ }
190
+
191
+
192
+ /*
193
+ * lcd128x64setOrientation:
194
+ * Set the display orientation:
195
+ * 0: Normal, the display is portrait mode, 0,0 is top left
196
+ * 1: Landscape
197
+ * 2: Portrait, flipped
198
+ * 3: Landscape, flipped
199
+ *********************************************************************************
200
+ */
201
+
202
+ void lcd128x64setOrientation (int orientation)
203
+ {
204
+ lcdOrientation = orientation & 3 ;
205
+
206
+ lcd128x64setOrigin (0, 0) ;
207
+
208
+ switch (lcdOrientation)
209
+ {
210
+ case 0:
211
+ maxX = LCD_WIDTH ;
212
+ maxY = LCD_HEIGHT ;
213
+ break ;
214
+
215
+ case 1:
216
+ maxX = LCD_HEIGHT ;
217
+ maxY = LCD_WIDTH ;
218
+ break ;
219
+
220
+ case 2:
221
+ maxX = LCD_WIDTH ;
222
+ maxY = LCD_HEIGHT ;
223
+ break ;
224
+
225
+ case 3:
226
+ maxX = LCD_HEIGHT ;
227
+ maxY = LCD_WIDTH ;
228
+ break ;
229
+ }
230
+ }
231
+
232
+
233
+ /*
234
+ * lcd128x64orientCoordinates:
235
+ * Adjust the coordinates given to the display orientation
236
+ *********************************************************************************
237
+ */
238
+
239
+ void lcd128x64orientCoordinates (int *x, int *y)
240
+ {
241
+ register int tmp ;
242
+
243
+ *x += xOrigin ;
244
+ *y += yOrigin ;
245
+ *y = maxY - *y - 1 ;
246
+
247
+ switch (lcdOrientation)
248
+ {
249
+ case 0:
250
+ break;
251
+
252
+ case 1:
253
+ tmp = maxY - *y - 1 ;
254
+ *y = *x ;
255
+ *x = tmp ;
256
+ break;
257
+
258
+ case 2:
259
+ *x = maxX - *x - 1 ;
260
+ *y = maxY - *y - 1 ;
261
+ break;
262
+
263
+ case 3:
264
+ *x = maxX - *x - 1 ;
265
+ tmp = *y ;
266
+ *y = *x ;
267
+ *x = tmp ;
268
+ break ;
269
+ }
270
+ }
271
+
272
+
273
+ /*
274
+ * lcd128x64getScreenSize:
275
+ * Return the max X & Y screen sizes. Needs to be called again, if you
276
+ * change screen orientation.
277
+ *********************************************************************************
278
+ */
279
+
280
+ void lcd128x64getScreenSize (int *x, int *y)
281
+ {
282
+ *x = maxX ;
283
+ *y = maxY ;
284
+ }
285
+
286
+
287
+ /*
288
+ *********************************************************************************
289
+ * Standard Graphical Functions
290
+ *********************************************************************************
291
+ */
292
+
293
+
294
+ /*
295
+ * lcd128x64point:
296
+ * Plot a pixel.
297
+ *********************************************************************************
298
+ */
299
+
300
+ void lcd128x64point (int x, int y, int colour)
301
+ {
302
+ lastX = x ;
303
+ lastY = y ;
304
+
305
+ lcd128x64orientCoordinates (&x, &y) ;
306
+
307
+ if ((x < 0) || (x >= LCD_WIDTH) || (y < 0) || (y >= LCD_HEIGHT))
308
+ return ;
309
+
310
+ frameBuffer [x + y * LCD_WIDTH] = colour ;
311
+ }
312
+
313
+
314
+ /*
315
+ * lcd128x64line: lcd128x64lineTo:
316
+ * Classic Bressenham Line code
317
+ *********************************************************************************
318
+ */
319
+
320
+ void lcd128x64line (int x0, int y0, int x1, int y1, int colour)
321
+ {
322
+ int dx, dy ;
323
+ int sx, sy ;
324
+ int err, e2 ;
325
+
326
+ lastX = x1 ;
327
+ lastY = y1 ;
328
+
329
+ dx = abs (x1 - x0) ;
330
+ dy = abs (y1 - y0) ;
331
+
332
+ sx = (x0 < x1) ? 1 : -1 ;
333
+ sy = (y0 < y1) ? 1 : -1 ;
334
+
335
+ err = dx - dy ;
336
+
337
+ for (;;)
338
+ {
339
+ lcd128x64point (x0, y0, colour) ;
340
+
341
+ if ((x0 == x1) && (y0 == y1))
342
+ break ;
343
+
344
+ e2 = 2 * err ;
345
+
346
+ if (e2 > -dy)
347
+ {
348
+ err -= dy ;
349
+ x0 += sx ;
350
+ }
351
+
352
+ if (e2 < dx)
353
+ {
354
+ err += dx ;
355
+ y0 += sy ;
356
+ }
357
+ }
358
+
359
+ }
360
+
361
+ void lcd128x64lineTo (int x, int y, int colour)
362
+ {
363
+ lcd128x64line (lastX, lastY, x, y, colour) ;
364
+ }
365
+
366
+
367
+ /*
368
+ * lcd128x64rectangle:
369
+ * A rectangle is a spoilt days fishing
370
+ *********************************************************************************
371
+ */
372
+
373
+ void lcd128x64rectangle (int x1, int y1, int x2, int y2, int colour, int filled)
374
+ {
375
+ register int x ;
376
+
377
+ if (filled)
378
+ {
379
+ /**/ if (x1 == x2)
380
+ lcd128x64line (x1, y1, x2, y2, colour) ;
381
+ else if (x1 < x2)
382
+ for (x = x1 ; x <= x2 ; ++x)
383
+ lcd128x64line (x, y1, x, y2, colour) ;
384
+ else
385
+ for (x = x2 ; x <= x1 ; ++x)
386
+ lcd128x64line (x, y1, x, y2, colour) ;
387
+ }
388
+ else
389
+ {
390
+ lcd128x64line (x1, y1, x2, y1, colour) ;
391
+ lcd128x64lineTo (x2, y2, colour) ;
392
+ lcd128x64lineTo (x1, y2, colour) ;
393
+ lcd128x64lineTo (x1, y1, colour) ;
394
+ }
395
+ }
396
+
397
+
398
+ /*
399
+ * lcd128x64circle:
400
+ * This is the midpoint circle algorithm.
401
+ *********************************************************************************
402
+ */
403
+
404
+ void lcd128x64circle (int x, int y, int r, int colour, int filled)
405
+ {
406
+ int ddF_x = 1 ;
407
+ int ddF_y = -2 * r ;
408
+
409
+ int f = 1 - r ;
410
+ int x1 = 0 ;
411
+ int y1 = r ;
412
+
413
+ if (filled)
414
+ {
415
+ lcd128x64line (x, y + r, x, y - r, colour) ;
416
+ lcd128x64line (x + r, y, x - r, y, colour) ;
417
+ }
418
+ else
419
+ {
420
+ lcd128x64point (x, y + r, colour) ;
421
+ lcd128x64point (x, y - r, colour) ;
422
+ lcd128x64point (x + r, y, colour) ;
423
+ lcd128x64point (x - r, y, colour) ;
424
+ }
425
+
426
+ while (x1 < y1)
427
+ {
428
+ if (f >= 0)
429
+ {
430
+ y1-- ;
431
+ ddF_y += 2 ;
432
+ f += ddF_y ;
433
+ }
434
+ x1++ ;
435
+ ddF_x += 2 ;
436
+ f += ddF_x ;
437
+ if (filled)
438
+ {
439
+ lcd128x64line (x + x1, y + y1, x - x1, y + y1, colour) ;
440
+ lcd128x64line (x + x1, y - y1, x - x1, y - y1, colour) ;
441
+ lcd128x64line (x + y1, y + x1, x - y1, y + x1, colour) ;
442
+ lcd128x64line (x + y1, y - x1, x - y1, y - x1, colour) ;
443
+ }
444
+ else
445
+ {
446
+ lcd128x64point (x + x1, y + y1, colour) ;
447
+ lcd128x64point (x - x1, y + y1, colour) ;
448
+ lcd128x64point (x + x1, y - y1, colour) ;
449
+ lcd128x64point (x - x1, y - y1, colour) ;
450
+ lcd128x64point (x + y1, y + x1, colour) ;
451
+ lcd128x64point (x - y1, y + x1, colour) ;
452
+ lcd128x64point (x + y1, y - x1, colour) ;
453
+ lcd128x64point (x - y1, y - x1, colour) ;
454
+ }
455
+ }
456
+ }
457
+
458
+
459
+ /*
460
+ * lcd128x64ellipse:
461
+ * Fast ellipse drawing algorithm by
462
+ * John Kennedy
463
+ * Mathematics Department
464
+ * Santa Monica College
465
+ * 1900 Pico Blvd.
466
+ * Santa Monica, CA 90405
467
+ * jrkennedy6@gmail.com
468
+ * -Confirned in email this algorithm is in the public domain -GH-
469
+ *********************************************************************************
470
+ */
471
+
472
+ static void plot4ellipsePoints (int cx, int cy, int x, int y, int colour, int filled)
473
+ {
474
+ if (filled)
475
+ {
476
+ lcd128x64line (cx + x, cy + y, cx - x, cy + y, colour) ;
477
+ lcd128x64line (cx - x, cy - y, cx + x, cy - y, colour) ;
478
+ }
479
+ else
480
+ {
481
+ lcd128x64point (cx + x, cy + y, colour) ;
482
+ lcd128x64point (cx - x, cy + y, colour) ;
483
+ lcd128x64point (cx - x, cy - y, colour) ;
484
+ lcd128x64point (cx + x, cy - y, colour) ;
485
+ }
486
+ }
487
+
488
+ void lcd128x64ellipse (int cx, int cy, int xRadius, int yRadius, int colour, int filled)
489
+ {
490
+ int x, y ;
491
+ int xChange, yChange, ellipseError ;
492
+ int twoAsquare, twoBsquare ;
493
+ int stoppingX, stoppingY ;
494
+
495
+ twoAsquare = 2 * xRadius * xRadius ;
496
+ twoBsquare = 2 * yRadius * yRadius ;
497
+
498
+ x = xRadius ;
499
+ y = 0 ;
500
+
501
+ xChange = yRadius * yRadius * (1 - 2 * xRadius) ;
502
+ yChange = xRadius * xRadius ;
503
+
504
+ ellipseError = 0 ;
505
+ stoppingX = twoBsquare * xRadius ;
506
+ stoppingY = 0 ;
507
+
508
+ while (stoppingX >= stoppingY) // 1st set of points
509
+ {
510
+ plot4ellipsePoints (cx, cy, x, y, colour, filled) ;
511
+ ++y ;
512
+ stoppingY += twoAsquare ;
513
+ ellipseError += yChange ;
514
+ yChange += twoAsquare ;
515
+
516
+ if ((2 * ellipseError + xChange) > 0 )
517
+ {
518
+ --x ;
519
+ stoppingX -= twoBsquare ;
520
+ ellipseError += xChange ;
521
+ xChange += twoBsquare ;
522
+ }
523
+ }
524
+
525
+ x = 0 ;
526
+ y = yRadius ;
527
+
528
+ xChange = yRadius * yRadius ;
529
+ yChange = xRadius * xRadius * (1 - 2 * yRadius) ;
530
+
531
+ ellipseError = 0 ;
532
+ stoppingX = 0 ;
533
+ stoppingY = twoAsquare * yRadius ;
534
+
535
+ while (stoppingX <= stoppingY) //2nd set of points
536
+ {
537
+ plot4ellipsePoints (cx, cy, x, y, colour, filled) ;
538
+ ++x ;
539
+ stoppingX += twoBsquare ;
540
+ ellipseError += xChange ;
541
+ xChange += twoBsquare ;
542
+
543
+ if ((2 * ellipseError + yChange) > 0 )
544
+ {
545
+ --y ;
546
+ stoppingY -= twoAsquare ;
547
+ ellipseError += yChange ;
548
+ yChange += twoAsquare ;
549
+ }
550
+ }
551
+ }
552
+
553
+
554
+ /*
555
+ * lcd128x64putchar:
556
+ * Print a single character to the screen
557
+ *********************************************************************************
558
+ */
559
+
560
+ void lcd128x64putchar (int x, int y, int c, int bgCol, int fgCol)
561
+ {
562
+ int y1, y2 ;
563
+
564
+ unsigned char line ;
565
+ unsigned char *fontPtr ;
566
+
567
+ // Can't print if we're offscreen
568
+
569
+ //if ((x < 0) || (x >= (maxX - fontWidth)) || (y < 0) || (y >= (maxY - fontHeight)))
570
+ // return ;
571
+
572
+ fontPtr = font + c * fontHeight ;
573
+
574
+ for (y1 = fontHeight - 1 ; y1 >= 0 ; --y1)
575
+ {
576
+ y2 = y + y1 ;
577
+ line = *fontPtr++ ;
578
+ lcd128x64point (x + 0, y2, (line & 0x80) == 0 ? bgCol : fgCol) ;
579
+ lcd128x64point (x + 1, y2, (line & 0x40) == 0 ? bgCol : fgCol) ;
580
+ lcd128x64point (x + 2, y2, (line & 0x20) == 0 ? bgCol : fgCol) ;
581
+ lcd128x64point (x + 3, y2, (line & 0x10) == 0 ? bgCol : fgCol) ;
582
+ lcd128x64point (x + 4, y2, (line & 0x08) == 0 ? bgCol : fgCol) ;
583
+ lcd128x64point (x + 5, y2, (line & 0x04) == 0 ? bgCol : fgCol) ;
584
+ lcd128x64point (x + 6, y2, (line & 0x02) == 0 ? bgCol : fgCol) ;
585
+ lcd128x64point (x + 7, y2, (line & 0x01) == 0 ? bgCol : fgCol) ;
586
+ }
587
+ }
588
+
589
+
590
+ /*
591
+ * lcd128x64puts:
592
+ * Send a string to the display. Obeys \n and \r formatting
593
+ *********************************************************************************
594
+ */
595
+
596
+ void lcd128x64puts (int x, int y, const char *str, int bgCol, int fgCol)
597
+ {
598
+ int c, mx, my ;
599
+
600
+ mx = x ;
601
+ my = y ;
602
+
603
+ while (*str)
604
+ {
605
+ c = *str++ ;
606
+
607
+ if (c == '\r')
608
+ {
609
+ mx = x ;
610
+ continue ;
611
+ }
612
+
613
+ if (c == '\n')
614
+ {
615
+ mx = x ;
616
+ my -= fontHeight ;
617
+ continue ;
618
+ }
619
+
620
+ lcd128x64putchar (mx, my, c, bgCol, fgCol) ;
621
+
622
+ mx += fontWidth ;
623
+ if (mx >= (maxX - fontWidth))
624
+ {
625
+ mx = 0 ;
626
+ my -= fontHeight ;
627
+ }
628
+ }
629
+ }
630
+
631
+
632
+ /*
633
+ * lcd128x64clear:
634
+ * Clear the display to the given colour.
635
+ *********************************************************************************
636
+ */
637
+
638
+ void lcd128x64clear (int colour)
639
+ {
640
+ register int i ;
641
+ register unsigned char *ptr = frameBuffer ;
642
+
643
+ for (i = 0 ; i < (maxX * maxY) ; ++i)
644
+ *ptr++ = colour ;
645
+ }
646
+
647
+
648
+
649
+
650
+ /*
651
+ * lcd128x64setup:
652
+ * Initialise the display and GPIO.
653
+ *********************************************************************************
654
+ */
655
+
656
+ int lcd128x64setup (void)
657
+ {
658
+ int i ;
659
+
660
+ for (i = 0 ; i < 8 ; ++i)
661
+ pinMode (i, OUTPUT) ;
662
+
663
+ digitalWrite (CS1, 1) ;
664
+ digitalWrite (CS2, 1) ;
665
+ digitalWrite (STROBE, 0) ;
666
+ digitalWrite (RS, 1) ;
667
+
668
+ pinMode (CS1, OUTPUT) ;
669
+ pinMode (CS2, OUTPUT) ;
670
+ pinMode (STROBE, OUTPUT) ;
671
+ pinMode (RS, OUTPUT) ;
672
+
673
+ sendCommand (0x3F, CS1) ; // Display ON
674
+ sendCommand (0xC0, CS1) ; // Set display start line to 0
675
+
676
+ sendCommand (0x3F, CS2) ; // Display ON
677
+ sendCommand (0xC0, CS2) ; // Set display start line to 0
678
+
679
+ lcd128x64clear (0) ;
680
+ lcd128x64setOrientation (0) ;
681
+ lcd128x64update () ;
682
+
683
+ return 0 ;
684
+ }