wiringpi 1.1.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. checksums.yaml +7 -0
  2. data/ext/wiringpi/WiringPi/devLib/ds1302.c +240 -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 +495 -0
  8. data/ext/wiringpi/WiringPi/devLib/lcd.h +52 -0
  9. data/ext/wiringpi/WiringPi/devLib/lcd128x64.c +673 -0
  10. data/ext/wiringpi/WiringPi/devLib/lcd128x64.h +39 -0
  11. data/ext/wiringpi/WiringPi/devLib/maxdetect.c +165 -0
  12. data/ext/wiringpi/{serial.h → WiringPi/devLib/maxdetect.h} +14 -15
  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 +113 -0
  19. data/ext/wiringpi/WiringPi/devLib/piNes.h +45 -0
  20. data/ext/wiringpi/WiringPi/examples/Gertboard/7segments.c +221 -0
  21. data/ext/wiringpi/WiringPi/examples/Gertboard/buttons.c +83 -0
  22. data/ext/wiringpi/WiringPi/examples/Gertboard/gertboard.c +96 -0
  23. data/ext/wiringpi/WiringPi/examples/Gertboard/record.c +60 -0
  24. data/ext/wiringpi/WiringPi/examples/Gertboard/temperature.c +78 -0
  25. data/ext/wiringpi/WiringPi/examples/Gertboard/voltmeter.c +73 -0
  26. data/ext/wiringpi/WiringPi/examples/Gertboard/vumeter.c +152 -0
  27. data/ext/wiringpi/WiringPi/examples/PiFace/blink.c +59 -0
  28. data/ext/wiringpi/WiringPi/examples/PiFace/buttons.c +103 -0
  29. data/ext/wiringpi/WiringPi/examples/PiFace/ladder.c +337 -0
  30. data/ext/wiringpi/WiringPi/examples/PiFace/metro.c +111 -0
  31. data/ext/wiringpi/WiringPi/examples/PiFace/motor.c +120 -0
  32. data/ext/wiringpi/WiringPi/examples/PiFace/reaction.c +194 -0
  33. data/ext/wiringpi/WiringPi/examples/PiGlow/piGlow0.c +51 -0
  34. data/ext/wiringpi/WiringPi/examples/PiGlow/piGlow1.c +258 -0
  35. data/ext/wiringpi/WiringPi/examples/PiGlow/piglow.c +176 -0
  36. data/ext/wiringpi/WiringPi/examples/blink.c +48 -0
  37. data/ext/wiringpi/WiringPi/examples/blink12.c +111 -0
  38. data/ext/wiringpi/WiringPi/examples/blink12drcs.c +125 -0
  39. data/ext/wiringpi/WiringPi/examples/blink6drcs.c +115 -0
  40. data/ext/wiringpi/WiringPi/examples/blink8.c +57 -0
  41. data/ext/wiringpi/WiringPi/examples/clock.c +201 -0
  42. data/ext/wiringpi/WiringPi/examples/delayTest.c +107 -0
  43. data/ext/wiringpi/WiringPi/examples/ds1302.c +238 -0
  44. data/ext/wiringpi/WiringPi/examples/header.h +23 -0
  45. data/ext/wiringpi/WiringPi/examples/isr-osc.c +118 -0
  46. data/ext/wiringpi/WiringPi/examples/isr.c +110 -0
  47. data/ext/wiringpi/WiringPi/examples/lcd-adafruit.c +347 -0
  48. data/ext/wiringpi/WiringPi/examples/lcd.c +286 -0
  49. data/ext/wiringpi/WiringPi/examples/lowPower.c +68 -0
  50. data/ext/wiringpi/WiringPi/examples/nes.c +67 -0
  51. data/ext/wiringpi/WiringPi/examples/okLed.c +82 -0
  52. data/ext/wiringpi/WiringPi/examples/pwm.c +58 -0
  53. data/ext/wiringpi/WiringPi/examples/q2w/binary.c +79 -0
  54. data/ext/wiringpi/WiringPi/examples/q2w/blink-io.c +61 -0
  55. data/ext/wiringpi/WiringPi/examples/q2w/blink.c +50 -0
  56. data/ext/wiringpi/WiringPi/examples/q2w/bright.c +59 -0
  57. data/ext/wiringpi/WiringPi/examples/q2w/button.c +63 -0
  58. data/ext/wiringpi/WiringPi/examples/q2w/volts.c +62 -0
  59. data/ext/wiringpi/WiringPi/examples/rht03.c +69 -0
  60. data/ext/wiringpi/WiringPi/examples/serialRead.c +48 -0
  61. data/ext/wiringpi/WiringPi/examples/serialTest.c +75 -0
  62. data/ext/wiringpi/WiringPi/examples/servo.c +57 -0
  63. data/ext/wiringpi/WiringPi/examples/softPwm.c +89 -0
  64. data/ext/wiringpi/WiringPi/examples/softTone.c +54 -0
  65. data/ext/wiringpi/WiringPi/examples/speed.c +95 -0
  66. data/ext/wiringpi/WiringPi/examples/spiSpeed.c +118 -0
  67. data/ext/wiringpi/WiringPi/examples/wfi.c +161 -0
  68. data/ext/wiringpi/WiringPi/gpio/gpio.c +1351 -0
  69. data/ext/wiringpi/WiringPi/gpio/pins.c +33 -0
  70. data/ext/wiringpi/WiringPi/gpio/readall.c +334 -0
  71. data/ext/wiringpi/WiringPi/gpio/version.h +1 -0
  72. data/ext/wiringpi/WiringPi/wiringPi/drcSerial.c +201 -0
  73. data/ext/wiringpi/WiringPi/wiringPi/drcSerial.h +33 -0
  74. data/ext/wiringpi/WiringPi/wiringPi/max31855.c +81 -0
  75. data/ext/wiringpi/WiringPi/wiringPi/max31855.h +33 -0
  76. data/ext/wiringpi/WiringPi/wiringPi/max5322.c +84 -0
  77. data/ext/wiringpi/WiringPi/wiringPi/max5322.h +33 -0
  78. data/ext/wiringpi/WiringPi/wiringPi/mcp23008.c +149 -0
  79. data/ext/wiringpi/WiringPi/wiringPi/mcp23008.h +33 -0
  80. data/ext/wiringpi/WiringPi/wiringPi/mcp23016.c +164 -0
  81. data/ext/wiringpi/WiringPi/wiringPi/mcp23016.h +33 -0
  82. data/ext/wiringpi/WiringPi/wiringPi/mcp23016reg.h +48 -0
  83. data/ext/wiringpi/WiringPi/wiringPi/mcp23017.c +195 -0
  84. data/ext/wiringpi/WiringPi/wiringPi/mcp23017.h +33 -0
  85. data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.c +189 -0
  86. data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.h +33 -0
  87. data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.c +236 -0
  88. data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.h +33 -0
  89. data/ext/wiringpi/WiringPi/wiringPi/mcp23x08.h +73 -0
  90. data/ext/wiringpi/WiringPi/wiringPi/mcp23x0817.h +87 -0
  91. data/ext/wiringpi/WiringPi/wiringPi/mcp3002.c +76 -0
  92. data/ext/wiringpi/WiringPi/wiringPi/mcp3002.h +33 -0
  93. data/ext/wiringpi/WiringPi/wiringPi/mcp3004.c +76 -0
  94. data/ext/wiringpi/WiringPi/wiringPi/mcp3004.h +33 -0
  95. data/ext/wiringpi/WiringPi/wiringPi/mcp3422.c +110 -0
  96. data/ext/wiringpi/WiringPi/wiringPi/mcp3422.h +43 -0
  97. data/ext/wiringpi/WiringPi/wiringPi/mcp4802.c +76 -0
  98. data/ext/wiringpi/WiringPi/wiringPi/mcp4802.h +33 -0
  99. data/ext/wiringpi/WiringPi/wiringPi/pcf8574.c +126 -0
  100. data/ext/wiringpi/WiringPi/wiringPi/pcf8574.h +33 -0
  101. data/ext/wiringpi/WiringPi/wiringPi/pcf8591.c +90 -0
  102. data/ext/wiringpi/WiringPi/wiringPi/pcf8591.h +33 -0
  103. data/ext/wiringpi/WiringPi/wiringPi/piHiPri.c +51 -0
  104. data/ext/wiringpi/WiringPi/wiringPi/piThread.c +63 -0
  105. data/ext/wiringpi/WiringPi/wiringPi/sn3218.c +75 -0
  106. data/ext/wiringpi/WiringPi/wiringPi/sn3218.h +33 -0
  107. data/ext/wiringpi/WiringPi/wiringPi/softPwm.c +166 -0
  108. data/ext/wiringpi/WiringPi/wiringPi/softPwm.h +35 -0
  109. data/ext/wiringpi/WiringPi/wiringPi/softServo.c +211 -0
  110. data/ext/wiringpi/WiringPi/wiringPi/softServo.h +35 -0
  111. data/ext/wiringpi/WiringPi/wiringPi/softTone.c +150 -0
  112. data/ext/wiringpi/WiringPi/wiringPi/softTone.h +39 -0
  113. data/ext/wiringpi/WiringPi/wiringPi/sr595.c +109 -0
  114. data/ext/wiringpi/WiringPi/wiringPi/sr595.h +34 -0
  115. data/ext/wiringpi/WiringPi/wiringPi/wiringPi.c +2007 -0
  116. data/ext/wiringpi/WiringPi/wiringPi/wiringPi.h +224 -0
  117. data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.c +232 -0
  118. data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.h +42 -0
  119. data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.c +136 -0
  120. data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.h +36 -0
  121. data/ext/wiringpi/{serial.c → WiringPi/wiringPi/wiringSerial.c} +38 -29
  122. data/ext/wiringpi/WiringPi/wiringPi/wiringSerial.h +38 -0
  123. data/ext/wiringpi/{wiringShift.c → WiringPi/wiringPi/wiringShift.c} +3 -4
  124. data/ext/wiringpi/{wiringShift.h → WiringPi/wiringPi/wiringShift.h} +5 -5
  125. data/ext/wiringpi/WiringPi/wiringPi/wpiExtensions.c +731 -0
  126. data/ext/wiringpi/WiringPi/wiringPi/wpiExtensions.h +26 -0
  127. data/ext/wiringpi/extconf.rb +7 -1
  128. data/ext/wiringpi/wiringpi_wrap.c +1741 -218
  129. data/lib/wiringpi.rb +24 -222
  130. data/lib/wiringpi/event.rb +21 -0
  131. data/lib/wiringpi/gpio.rb +139 -0
  132. data/lib/wiringpi/i2c.rb +26 -0
  133. data/lib/wiringpi/mcp23x17.rb +31 -0
  134. data/lib/wiringpi/serial.rb +49 -0
  135. data/lib/wiringpi/spi.rb +15 -0
  136. metadata +146 -22
  137. data/ext/wiringpi/wiringPi.c +0 -729
  138. data/ext/wiringpi/wiringPi.h +0 -69
@@ -0,0 +1,118 @@
1
+ /*
2
+ * piGlow.c:
3
+ * Easy access to the Pimoroni PiGlow board.
4
+ *
5
+ * Copyright (c) 2013 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 <wiringPi.h>
26
+ #include <sn3218.h>
27
+
28
+ #include "piGlow.h"
29
+
30
+ #define PIGLOW_BASE 577
31
+
32
+ static int leg0 [6] = { 6, 7, 8, 5, 4, 9 } ;
33
+ static int leg1 [6] = { 17, 16, 15, 13, 11, 10 } ;
34
+ static int leg2 [6] = { 0, 1, 2, 3, 14, 12 } ;
35
+
36
+
37
+ /*
38
+ * piGlow1:
39
+ * Light up an individual LED
40
+ *********************************************************************************
41
+ */
42
+
43
+ void piGlow1 (const int leg, const int ring, const int intensity)
44
+ {
45
+ int *legLeds ;
46
+
47
+ if ((leg < 0) || (leg > 2)) return ;
48
+ if ((ring < 0) || (ring > 5)) return ;
49
+
50
+ /**/ if (leg == 0)
51
+ legLeds = leg0 ;
52
+ else if (leg == 1)
53
+ legLeds = leg1 ;
54
+ else
55
+ legLeds = leg2 ;
56
+
57
+ analogWrite (PIGLOW_BASE + legLeds [ring], intensity) ;
58
+ }
59
+
60
+ /*
61
+ * piGlowLeg:
62
+ * Light up all 6 LEDs on a leg
63
+ *********************************************************************************
64
+ */
65
+
66
+ void piGlowLeg (const int leg, const int intensity)
67
+ {
68
+ int i ;
69
+ int *legLeds ;
70
+
71
+ if ((leg < 0) || (leg > 2))
72
+ return ;
73
+
74
+ /**/ if (leg == 0)
75
+ legLeds = leg0 ;
76
+ else if (leg == 1)
77
+ legLeds = leg1 ;
78
+ else
79
+ legLeds = leg2 ;
80
+
81
+ for (i = 0 ; i < 6 ; ++i)
82
+ analogWrite (PIGLOW_BASE + legLeds [i], intensity) ;
83
+ }
84
+
85
+
86
+ /*
87
+ * piGlowRing:
88
+ * Light up 3 LEDs in a ring. Ring 0 is the outermost, 5 the innermost
89
+ *********************************************************************************
90
+ */
91
+
92
+ void piGlowRing (const int ring, const int intensity)
93
+ {
94
+ if ((ring < 0) || (ring > 5))
95
+ return ;
96
+
97
+ analogWrite (PIGLOW_BASE + leg0 [ring], intensity) ;
98
+ analogWrite (PIGLOW_BASE + leg1 [ring], intensity) ;
99
+ analogWrite (PIGLOW_BASE + leg2 [ring], intensity) ;
100
+ }
101
+
102
+ /*
103
+ * piGlowSetup:
104
+ * Initialise the board & remember the pins we're using
105
+ *********************************************************************************
106
+ */
107
+
108
+ void piGlowSetup (int clear)
109
+ {
110
+ sn3218Setup (PIGLOW_BASE) ;
111
+
112
+ if (clear)
113
+ {
114
+ piGlowLeg (0, 0) ;
115
+ piGlowLeg (1, 0) ;
116
+ piGlowLeg (2, 0) ;
117
+ }
118
+ }
@@ -0,0 +1,45 @@
1
+ /*
2
+ * piglow.h:
3
+ * Easy access to the Pimoroni PiGlow board.
4
+ *
5
+ * Copyright (c) 2013 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
+
26
+ #define PIGLOW_RED 0
27
+ #define PIGLOW_ORANGE 1
28
+ #define PIGLOW_YELLOW 2
29
+ #define PIGLOW_GREEN 3
30
+ #define PIGLOW_BLUE 4
31
+ #define PIGLOW_WHITE 5
32
+
33
+
34
+ #ifdef __cplusplus
35
+ extern "C" {
36
+ #endif
37
+
38
+ extern void piGlow1 (const int leg, const int ring, const int intensity) ;
39
+ extern void piGlowLeg (const int leg, const int intensity) ;
40
+ extern void piGlowRing (const int ring, const int intensity) ;
41
+ extern void piGlowSetup (int clear) ;
42
+
43
+ #ifdef __cplusplus
44
+ }
45
+ #endif
@@ -0,0 +1,113 @@
1
+ /*
2
+ * piNes.c:
3
+ * Driver for the NES Joystick controller on the Raspberry Pi
4
+ * Copyright (c) 2012 Gordon Henderson
5
+ ***********************************************************************
6
+ * This file is part of wiringPi:
7
+ * https://projects.drogon.net/raspberry-pi/wiringpi/
8
+ *
9
+ * wiringPi is free software: you can redistribute it and/or modify
10
+ * it under the terms of the GNU Lesser General Public License as
11
+ * published by the Free Software Foundation, either version 3 of the
12
+ * License, or (at your option) any later version.
13
+ *
14
+ * wiringPi is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ * GNU Lesser General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU Lesser General Public
20
+ * License along with wiringPi.
21
+ * If not, see <http://www.gnu.org/licenses/>.
22
+ ***********************************************************************
23
+ */
24
+
25
+ #include <wiringPi.h>
26
+
27
+ #include "piNes.h"
28
+
29
+ #define MAX_NES_JOYSTICKS 8
30
+
31
+ #define NES_RIGHT 0x01
32
+ #define NES_LEFT 0x02
33
+ #define NES_DOWN 0x04
34
+ #define NES_UP 0x08
35
+ #define NES_START 0x10
36
+ #define NES_SELECT 0x20
37
+ #define NES_B 0x40
38
+ #define NES_A 0x80
39
+
40
+
41
+ #define PULSE_TIME 25
42
+
43
+ // Data to store the pins for each controller
44
+
45
+ struct nesPinsStruct
46
+ {
47
+ unsigned int cPin, dPin, lPin ;
48
+ } ;
49
+
50
+ static struct nesPinsStruct nesPins [MAX_NES_JOYSTICKS] ;
51
+
52
+ static int joysticks = 0 ;
53
+
54
+
55
+ /*
56
+ * setupNesJoystick:
57
+ * Create a new NES joystick interface, program the pins, etc.
58
+ *********************************************************************************
59
+ */
60
+
61
+ int setupNesJoystick (int dPin, int cPin, int lPin)
62
+ {
63
+ if (joysticks == MAX_NES_JOYSTICKS)
64
+ return -1 ;
65
+
66
+ nesPins [joysticks].dPin = dPin ;
67
+ nesPins [joysticks].cPin = cPin ;
68
+ nesPins [joysticks].lPin = lPin ;
69
+
70
+ digitalWrite (lPin, LOW) ;
71
+ digitalWrite (cPin, LOW) ;
72
+
73
+ pinMode (lPin, OUTPUT) ;
74
+ pinMode (cPin, OUTPUT) ;
75
+ pinMode (dPin, INPUT) ;
76
+
77
+ return joysticks++ ;
78
+ }
79
+
80
+
81
+ /*
82
+ * readNesJoystick:
83
+ * Do a single scan of the NES Joystick.
84
+ *********************************************************************************
85
+ */
86
+
87
+ unsigned int readNesJoystick (int joystick)
88
+ {
89
+ unsigned int value = 0 ;
90
+ int i ;
91
+
92
+ struct nesPinsStruct *pins = &nesPins [joystick] ;
93
+
94
+ // Toggle Latch - which presents the first bit
95
+
96
+ digitalWrite (pins->lPin, HIGH) ; delayMicroseconds (PULSE_TIME) ;
97
+ digitalWrite (pins->lPin, LOW) ; delayMicroseconds (PULSE_TIME) ;
98
+
99
+ // Read first bit
100
+
101
+ value = digitalRead (pins->dPin) ;
102
+
103
+ // Now get the next 7 bits with the clock
104
+
105
+ for (i = 0 ; i < 7 ; ++i)
106
+ {
107
+ digitalWrite (pins->cPin, HIGH) ; delayMicroseconds (PULSE_TIME) ;
108
+ digitalWrite (pins->cPin, LOW) ; delayMicroseconds (PULSE_TIME) ;
109
+ value = (value << 1) | digitalRead (pins->dPin) ;
110
+ }
111
+
112
+ return value ^ 0xFF ;
113
+ }
@@ -0,0 +1,45 @@
1
+ /*
2
+ * piNes.h:
3
+ * Driver for the NES Joystick controller on the Raspberry Pi
4
+ * Copyright (c) 2012 Gordon Henderson
5
+ ***********************************************************************
6
+ * This file is part of wiringPi:
7
+ * https://projects.drogon.net/raspberry-pi/wiringpi/
8
+ *
9
+ * wiringPi is free software: you can redistribute it and/or modify
10
+ * it under the terms of the GNU Lesser General Public License as
11
+ * published by the Free Software Foundation, either version 3 of the
12
+ * License, or (at your option) any later version.
13
+ *
14
+ * wiringPi is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ * GNU Lesser General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU Lesser General Public
20
+ * License along with wiringPi.
21
+ * If not, see <http://www.gnu.org/licenses/>.
22
+ ***********************************************************************
23
+ */
24
+
25
+ #define MAX_NES_JOYSTICKS 8
26
+
27
+ #define NES_RIGHT 0x01
28
+ #define NES_LEFT 0x02
29
+ #define NES_DOWN 0x04
30
+ #define NES_UP 0x08
31
+ #define NES_START 0x10
32
+ #define NES_SELECT 0x20
33
+ #define NES_B 0x40
34
+ #define NES_A 0x80
35
+
36
+ #ifdef __cplusplus
37
+ extern "C" {
38
+ #endif
39
+
40
+ extern int setupNesJoystick (int dPin, int cPin, int lPin) ;
41
+ extern unsigned int readNesJoystick (int joystick) ;
42
+
43
+ #ifdef __cplusplus
44
+ }
45
+ #endif
@@ -0,0 +1,221 @@
1
+ /*
2
+ * 7segments.c:
3
+ * Simple test program to see if we can drive a 7-segment LED
4
+ * display using the GPIO and little else on the Raspberry Pi
5
+ *
6
+ * Copyright (c) 2013 Gordon Henderson
7
+ ***********************************************************************
8
+ */
9
+
10
+ #undef PHOTO_HACK
11
+
12
+ #include <wiringPi.h>
13
+
14
+ #include <stdio.h>
15
+ #include <time.h>
16
+ #include <ctype.h>
17
+ #include <string.h>
18
+
19
+ /*
20
+ * Segment mapping
21
+ *
22
+ * --a--
23
+ * | |
24
+ * f b
25
+ * | |
26
+ * --g--
27
+ * | |
28
+ * e c
29
+ * | |
30
+ * --d-- p
31
+ */
32
+
33
+ // GPIO Pin Mapping
34
+
35
+ static int digits [6] = { 7, 11, 10, 13, 12, 14 } ;
36
+ static int segments [7] = { 6, 5, 4, 3, 2, 1, 0 } ;
37
+
38
+
39
+ static const int segmentDigits [] =
40
+ {
41
+ // a b c d e f g Segments
42
+ // 6 5 4 3 2 1 0, // wiringPi pin No.
43
+
44
+ 1, 1, 1, 1, 1, 1, 0, // 0
45
+ 0, 1, 1, 0, 0, 0, 0, // 1
46
+ 1, 1, 0, 1, 1, 0, 1, // 2
47
+ 1, 1, 1, 1, 0, 0, 1, // 3
48
+ 0, 1, 1, 0, 0, 1, 1, // 4
49
+ 1, 0, 1, 1, 0, 1, 1, // 5
50
+ 1, 0, 1, 1, 1, 1, 1, // 6
51
+ 1, 1, 1, 0, 0, 0, 0, // 7
52
+ 1, 1, 1, 1, 1, 1, 1, // 8
53
+ 1, 1, 1, 1, 0, 1, 1, // 9
54
+ 1, 1, 1, 0, 1, 1, 1, // A
55
+ 0, 0, 1, 1, 1, 1, 1, // b
56
+ 1, 0, 0, 1, 1, 1, 0, // C
57
+ 0, 1, 1, 1, 1, 0, 1, // d
58
+ 1, 0, 0, 1, 1, 1, 1, // E
59
+ 1, 0, 0, 0, 1, 1, 1, // F
60
+ 0, 0, 0, 0, 0, 0, 0, // blank
61
+ } ;
62
+
63
+
64
+ // display:
65
+ // A global variable which is written to by the main program and
66
+ // read from by the thread that updates the display. Only the first
67
+ // 6 characters are used.
68
+
69
+ char display [8] ;
70
+
71
+
72
+ /*
73
+ * displayDigits:
74
+ * This is our thread that's run concurrently with the main program.
75
+ * Essentially sit in a loop, parsing and displaying the data held in
76
+ * the "display" global.
77
+ *********************************************************************************
78
+ */
79
+
80
+ PI_THREAD (displayDigits)
81
+ {
82
+ int digit, segment ;
83
+ int index, d, segVal ;
84
+
85
+ piHiPri (50) ;
86
+
87
+ for (;;)
88
+ {
89
+ for (digit = 0 ; digit < 6 ; ++digit)
90
+ {
91
+ for (segment = 0 ; segment < 7 ; ++segment)
92
+ {
93
+ d = toupper (display [digit]) ;
94
+ /**/ if ((d >= '0') && (d <= '9')) // Digit
95
+ index = d - '0' ;
96
+ else if ((d >= 'A') && (d <= 'F')) // Hex
97
+ index = d - 'A' + 10 ;
98
+ else
99
+ index = 16 ; // Blank
100
+
101
+ segVal = segmentDigits [index * 7 + segment] ;
102
+
103
+ digitalWrite (segments [segment], segVal) ;
104
+ }
105
+ digitalWrite (digits [digit], 1) ;
106
+ delay (2) ;
107
+ digitalWrite (digits [digit], 0) ;
108
+ }
109
+ }
110
+ }
111
+
112
+
113
+ /*
114
+ * setup:
115
+ * Initialise the hardware and start the thread
116
+ *********************************************************************************
117
+ */
118
+
119
+ void setup (void)
120
+ {
121
+ int i, c ;
122
+
123
+ wiringPiSetup () ;
124
+
125
+ // 7 segments
126
+
127
+ for (i = 0 ; i < 7 ; ++i)
128
+ { digitalWrite (segments [i], 0) ; pinMode (segments [i], OUTPUT) ; }
129
+
130
+ // 6 digits
131
+
132
+ for (i = 0 ; i < 6 ; ++i)
133
+ { digitalWrite (digits [i], 0) ; pinMode (digits [i], OUTPUT) ; }
134
+
135
+ strcpy (display, " ") ;
136
+ piThreadCreate (displayDigits) ;
137
+ delay (10) ; // Just to make sure it's started
138
+
139
+ // Quick countdown LED test sort of thing
140
+
141
+ c = 999999 ;
142
+ for (i = 0 ; i < 10 ; ++i)
143
+ {
144
+ sprintf (display, "%06d", c) ;
145
+ delay (400) ;
146
+ c -= 111111 ;
147
+ }
148
+
149
+ strcpy (display, " ") ;
150
+ delay (400) ;
151
+
152
+ #ifdef PHOTO_HACK
153
+ sprintf (display, "%s", "123456") ;
154
+ for (;;)
155
+ delay (1000) ;
156
+ #endif
157
+
158
+ }
159
+
160
+
161
+ /*
162
+ * teenager:
163
+ * No explanation needed. (Nor one given!)
164
+ *********************************************************************************
165
+ */
166
+
167
+ void teenager (void)
168
+ {
169
+ char *message = " feedbeef babe cafe b00b " ;
170
+ int i ;
171
+
172
+ for (i = 0 ; i < strlen (message) - 4 ; ++i)
173
+ {
174
+ strncpy (display, &message [i], 6) ;
175
+ delay (200) ;
176
+ }
177
+ delay (1000) ;
178
+ for (i = 0 ; i < 3 ; ++i)
179
+ {
180
+ strcpy (display, " ") ;
181
+ delay (150) ;
182
+ strcpy (display, " b00b ") ;
183
+ delay (250) ;
184
+ }
185
+ delay (1000) ;
186
+ strcpy (display, " ") ;
187
+ delay (1000) ;
188
+ }
189
+
190
+
191
+ /*
192
+ *********************************************************************************
193
+ * main:
194
+ * Let the fun begin
195
+ *********************************************************************************
196
+ */
197
+
198
+ int main (void)
199
+ {
200
+ struct tm *t ;
201
+ time_t tim ;
202
+
203
+ setup () ;
204
+ teenager () ;
205
+
206
+ tim = time (NULL) ;
207
+ for (;;)
208
+ {
209
+ while (time (NULL) == tim)
210
+ delay (5) ;
211
+
212
+ tim = time (NULL) ;
213
+ t = localtime (&tim) ;
214
+
215
+ sprintf (display, "%02d%02d%02d", t->tm_hour, t->tm_min, t->tm_sec) ;
216
+
217
+ delay (500) ;
218
+ }
219
+
220
+ return 0 ;
221
+ }