wiringpi-ruby 2.0.0 → 2.1.3
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/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 +238 -0
- data/ext/wiringpi/WiringPi/devLib/maxdetect.h +40 -0
- 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 +177 -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/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/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-thread.c +61 -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-drcn.c +61 -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 +102 -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/max31855.c +60 -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 +86 -0
- data/ext/wiringpi/WiringPi/examples/scrollPhat/scphat.c +230 -0
- data/ext/wiringpi/WiringPi/examples/scrollPhat/test.c +115 -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 +1538 -0
- data/ext/wiringpi/WiringPi/gpio/readall.c +403 -0
- data/ext/wiringpi/WiringPi/version.h +3 -0
- data/ext/wiringpi/WiringPi/wiringPi/ads1115.c +293 -0
- data/ext/wiringpi/WiringPi/wiringPi/ads1115.h +55 -0
- data/ext/wiringpi/WiringPi/wiringPi/bmp180.c +237 -0
- data/ext/wiringpi/WiringPi/wiringPi/bmp180.h +34 -0
- data/ext/wiringpi/WiringPi/wiringPi/drcNet.c +405 -0
- data/ext/wiringpi/WiringPi/wiringPi/drcNet.h +42 -0
- data/ext/wiringpi/WiringPi/wiringPi/drcSerial.c +196 -0
- data/ext/wiringpi/WiringPi/wiringPi/drcSerial.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/ds18b20.c +146 -0
- data/ext/wiringpi/WiringPi/wiringPi/ds18b20.h +34 -0
- data/ext/wiringpi/WiringPi/wiringPi/htu21d.c +150 -0
- data/ext/wiringpi/WiringPi/wiringPi/htu21d.h +34 -0
- data/ext/wiringpi/WiringPi/wiringPi/max31855.c +99 -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 +188 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.c +235 -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 +125 -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/pseudoPins.c +95 -0
- data/ext/wiringpi/WiringPi/wiringPi/pseudoPins.h +26 -0
- data/ext/wiringpi/WiringPi/wiringPi/rht03.c +252 -0
- data/ext/wiringpi/WiringPi/wiringPi/rht03.h +25 -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 +186 -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 +2507 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPi.h +269 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.c +233 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.h +42 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.c +144 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.h +36 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringSerial.c +225 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringSerial.h +38 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringShift.c +83 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringShift.h +41 -0
- data/ext/wiringpi/WiringPi/wiringPi/wpiExtensions.c +928 -0
- data/ext/wiringpi/WiringPi/wiringPi/wpiExtensions.h +26 -0
- data/ext/wiringpi/WiringPi/wiringPiD/daemonise.c +82 -0
- data/ext/wiringpi/WiringPi/wiringPiD/daemonise.h +9 -0
- data/ext/wiringpi/WiringPi/wiringPiD/drcNetCmd.h +43 -0
- data/ext/wiringpi/WiringPi/wiringPiD/network.c +330 -0
- data/ext/wiringpi/WiringPi/wiringPiD/network.h +31 -0
- data/ext/wiringpi/WiringPi/wiringPiD/runRemote.c +126 -0
- data/ext/wiringpi/WiringPi/wiringPiD/runRemote.h +29 -0
- data/ext/wiringpi/WiringPi/wiringPiD/wiringpid.c +382 -0
- data/ext/wiringpi/wiringpi_wrap.c +636 -219
- data/lib/wiringpi.rb +25 -12
- data/lib/wiringpi/gpio.rb +90 -83
- data/lib/wiringpi/i2c.rb +29 -22
- data/lib/wiringpi/modules/mcp23017.rb +15 -0
- data/lib/wiringpi/modules/mcp23s17.rb +16 -0
- data/lib/wiringpi/scrollphat.rb +14 -14
- data/lib/wiringpi/serial.rb +8 -18
- data/lib/wiringpi/spi.rb +14 -11
- data/lib/wiringpi/watch.rb +24 -0
- metadata +160 -4
- data/lib/wiringpi/event.rb +0 -21
- data/lib/wiringpi/mcp23x17.rb +0 -31
@@ -0,0 +1,115 @@
|
|
1
|
+
/*
|
2
|
+
* blink6drcs.c:
|
3
|
+
* Simple sequence over 6 pins on a remote DRC board.
|
4
|
+
* Aimed at the Gertduino, but it's fairly generic.
|
5
|
+
* This version uses DRC to talk to the ATmega on the Gertduino
|
6
|
+
*
|
7
|
+
* Copyright (c) 2012-2014 Gordon Henderson. <projects@drogon.net>
|
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 <wiringPi.h>
|
29
|
+
#include <drcSerial.h>
|
30
|
+
|
31
|
+
#define GERT_BASE 100
|
32
|
+
|
33
|
+
static int pinMap [] =
|
34
|
+
{
|
35
|
+
GERT_BASE + 6, GERT_BASE + 5, GERT_BASE + 3, GERT_BASE + 10, GERT_BASE + 9, GERT_BASE + 13,
|
36
|
+
} ;
|
37
|
+
|
38
|
+
// Simple sequencer data
|
39
|
+
// Triplets of LED, On/Off and delay
|
40
|
+
|
41
|
+
|
42
|
+
int data [] =
|
43
|
+
{
|
44
|
+
0, 1, 1,
|
45
|
+
1, 1, 1,
|
46
|
+
0, 0, 0, 2, 1, 1,
|
47
|
+
1, 0, 0, 3, 1, 1,
|
48
|
+
2, 0, 0, 4, 1, 1,
|
49
|
+
3, 0, 0, 5, 1, 1,
|
50
|
+
4, 0, 1,
|
51
|
+
5, 0, 1,
|
52
|
+
|
53
|
+
0, 0, 1, // Extra delay
|
54
|
+
|
55
|
+
// Back again
|
56
|
+
|
57
|
+
5, 1, 1,
|
58
|
+
4, 1, 1,
|
59
|
+
5, 0, 0, 3, 1, 1,
|
60
|
+
4, 0, 0, 2, 1, 1,
|
61
|
+
3, 0, 0, 1, 1, 1,
|
62
|
+
2, 0, 0, 0, 1, 1,
|
63
|
+
1, 0, 1,
|
64
|
+
0, 0, 1,
|
65
|
+
|
66
|
+
0, 0, 1, // Extra delay
|
67
|
+
|
68
|
+
0, 9, 0, // End marker
|
69
|
+
|
70
|
+
} ;
|
71
|
+
|
72
|
+
|
73
|
+
int main (void)
|
74
|
+
{
|
75
|
+
int pin ;
|
76
|
+
int dataPtr ;
|
77
|
+
int l, s, d ;
|
78
|
+
|
79
|
+
printf ("Raspberry Pi - 6-LED Sequence\n") ;
|
80
|
+
printf ("=============================\n") ;
|
81
|
+
printf ("\n") ;
|
82
|
+
printf (" Use the 2 buttons to temporarily speed up the sequence\n") ;
|
83
|
+
|
84
|
+
wiringPiSetupSys () ; // Not using the Pi's GPIO here
|
85
|
+
drcSetupSerial (GERT_BASE, 20, "/dev/ttyAMA0", 115200) ;
|
86
|
+
|
87
|
+
for (pin = 0 ; pin < 6 ; ++pin)
|
88
|
+
pinMode (pinMap [pin], OUTPUT) ;
|
89
|
+
|
90
|
+
pinMode (GERT_BASE + 16, INPUT) ; // Buttons
|
91
|
+
pinMode (GERT_BASE + 17, INPUT) ;
|
92
|
+
|
93
|
+
pullUpDnControl (GERT_BASE + 16, PUD_UP) ;
|
94
|
+
pullUpDnControl (GERT_BASE + 17, PUD_UP) ;
|
95
|
+
|
96
|
+
dataPtr = 0 ;
|
97
|
+
|
98
|
+
for (;;)
|
99
|
+
{
|
100
|
+
l = data [dataPtr++] ; // LED
|
101
|
+
s = data [dataPtr++] ; // State
|
102
|
+
d = data [dataPtr++] ; // Duration (10ths)
|
103
|
+
|
104
|
+
if (s == 9) // 9 -> End Marker
|
105
|
+
{
|
106
|
+
dataPtr = 0 ;
|
107
|
+
continue ;
|
108
|
+
}
|
109
|
+
|
110
|
+
digitalWrite (pinMap [l], s) ;
|
111
|
+
delay (d * digitalRead (GERT_BASE + 16) * 15 + digitalRead (GERT_BASE + 17) * 20) ;
|
112
|
+
}
|
113
|
+
|
114
|
+
return 0 ;
|
115
|
+
}
|
@@ -0,0 +1,61 @@
|
|
1
|
+
/*
|
2
|
+
* blink8-drcn.c:
|
3
|
+
* Simple sequence over the first 8 GPIO pins - LEDs
|
4
|
+
* Aimed at the Ladder board, but it's fairly generic.
|
5
|
+
*
|
6
|
+
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
7
|
+
***********************************************************************
|
8
|
+
* This file is part of wiringPi:
|
9
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
10
|
+
*
|
11
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
12
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
13
|
+
* the Free Software Foundation, either version 3 of the License, or
|
14
|
+
* (at your option) any later version.
|
15
|
+
*
|
16
|
+
* wiringPi is distributed in the hope that it will be useful,
|
17
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19
|
+
* GNU Lesser General Public License for more details.
|
20
|
+
*
|
21
|
+
* You should have received a copy of the GNU Lesser General Public License
|
22
|
+
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
23
|
+
***********************************************************************
|
24
|
+
*/
|
25
|
+
|
26
|
+
#include <stdio.h>
|
27
|
+
#include <wiringPi.h>
|
28
|
+
#include <drcNet.h>
|
29
|
+
|
30
|
+
int main (void)
|
31
|
+
{
|
32
|
+
int i, led ;
|
33
|
+
|
34
|
+
printf ("Raspberry Pi - 8-LED Sequencer\n") ;
|
35
|
+
printf ("==============================\n") ;
|
36
|
+
printf ("\n") ;
|
37
|
+
printf ("Connect LEDs to the first 8 GPIO pins and watch ...\n") ;
|
38
|
+
|
39
|
+
int pinBase = 100 ;
|
40
|
+
|
41
|
+
// wiringPiSetup () ;
|
42
|
+
drcSetupNet (pinBase, 100, "192.168.254.21", "6124", "123456") ;
|
43
|
+
|
44
|
+
for (i = 0 ; i < 8 ; ++i)
|
45
|
+
pinMode (i + pinBase, OUTPUT) ;
|
46
|
+
|
47
|
+
for (;;)
|
48
|
+
{
|
49
|
+
for (led = 0 ; led < 8 ; ++led)
|
50
|
+
{
|
51
|
+
digitalWrite (led + pinBase, 1) ;
|
52
|
+
delay (10) ;
|
53
|
+
}
|
54
|
+
|
55
|
+
for (led = 0 ; led < 8 ; ++led)
|
56
|
+
{
|
57
|
+
digitalWrite (led + pinBase, 0) ;
|
58
|
+
delay (10) ;
|
59
|
+
}
|
60
|
+
}
|
61
|
+
}
|
@@ -0,0 +1,57 @@
|
|
1
|
+
/*
|
2
|
+
* blink8.c:
|
3
|
+
* Simple sequence over the first 8 GPIO pins - LEDs
|
4
|
+
* Aimed at the Gertboard, but it's fairly generic.
|
5
|
+
*
|
6
|
+
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
7
|
+
***********************************************************************
|
8
|
+
* This file is part of wiringPi:
|
9
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
10
|
+
*
|
11
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
12
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
13
|
+
* the Free Software Foundation, either version 3 of the License, or
|
14
|
+
* (at your option) any later version.
|
15
|
+
*
|
16
|
+
* wiringPi is distributed in the hope that it will be useful,
|
17
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19
|
+
* GNU Lesser General Public License for more details.
|
20
|
+
*
|
21
|
+
* You should have received a copy of the GNU Lesser General Public License
|
22
|
+
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
23
|
+
***********************************************************************
|
24
|
+
*/
|
25
|
+
|
26
|
+
#include <stdio.h>
|
27
|
+
#include <wiringPi.h>
|
28
|
+
|
29
|
+
int main (void)
|
30
|
+
{
|
31
|
+
int i, led ;
|
32
|
+
|
33
|
+
printf ("Raspberry Pi - 8-LED Sequencer\n") ;
|
34
|
+
printf ("==============================\n") ;
|
35
|
+
printf ("\n") ;
|
36
|
+
printf ("Connect LEDs to the first 8 GPIO pins and watch ...\n") ;
|
37
|
+
|
38
|
+
wiringPiSetup () ;
|
39
|
+
|
40
|
+
for (i = 0 ; i < 8 ; ++i)
|
41
|
+
pinMode (i, OUTPUT) ;
|
42
|
+
|
43
|
+
for (;;)
|
44
|
+
{
|
45
|
+
for (led = 0 ; led < 8 ; ++led)
|
46
|
+
{
|
47
|
+
digitalWrite (led, 1) ;
|
48
|
+
delay (100) ;
|
49
|
+
}
|
50
|
+
|
51
|
+
for (led = 0 ; led < 8 ; ++led)
|
52
|
+
{
|
53
|
+
digitalWrite (led, 0) ;
|
54
|
+
delay (100) ;
|
55
|
+
}
|
56
|
+
}
|
57
|
+
}
|
@@ -0,0 +1,201 @@
|
|
1
|
+
/*
|
2
|
+
* clock.c:
|
3
|
+
* Demo of the 128x64 graphics based LCD driver.
|
4
|
+
* This is designed to drive the parallel interface LCD drivers
|
5
|
+
* based on the popular 12864H controller chip.
|
6
|
+
*
|
7
|
+
* This test program assumes the following:
|
8
|
+
* (Which is currently hard-wired into the driver)
|
9
|
+
*
|
10
|
+
* GPIO 0-7 is connected to display data pins 0-7.
|
11
|
+
* GPIO 10 is CS1
|
12
|
+
* GPIO 11 is CS2
|
13
|
+
* GPIO 12 is STROBE
|
14
|
+
* GPIO 10 is RS
|
15
|
+
*
|
16
|
+
* Copyright (c) 2012-2013 Gordon Henderson.
|
17
|
+
***********************************************************************
|
18
|
+
* This file is part of wiringPi:
|
19
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
20
|
+
*
|
21
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
22
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
23
|
+
* the Free Software Foundation, either version 3 of the License, or
|
24
|
+
* (at your option) any later version.
|
25
|
+
*
|
26
|
+
* wiringPi is distributed in the hope that it will be useful,
|
27
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
28
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
29
|
+
* GNU Lesser General Public License for more details.
|
30
|
+
*
|
31
|
+
* You should have received a copy of the GNU Lesser General Public License
|
32
|
+
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
33
|
+
***********************************************************************
|
34
|
+
*/
|
35
|
+
|
36
|
+
#include <stdio.h>
|
37
|
+
#include <stdlib.h>
|
38
|
+
#include <stdint.h>
|
39
|
+
#include <unistd.h>
|
40
|
+
#include <string.h>
|
41
|
+
#include <errno.h>
|
42
|
+
#include <time.h>
|
43
|
+
#include <math.h>
|
44
|
+
|
45
|
+
#include <wiringPi.h>
|
46
|
+
#include <lcd128x64.h>
|
47
|
+
|
48
|
+
#ifndef TRUE
|
49
|
+
# define TRUE (1==1)
|
50
|
+
# define FALSE (1==2)
|
51
|
+
#endif
|
52
|
+
|
53
|
+
double clockRadius ;
|
54
|
+
double thickness, barLen ;
|
55
|
+
int maxX, maxY ;
|
56
|
+
|
57
|
+
double rads (double degs)
|
58
|
+
{
|
59
|
+
return degs * M_PI / 180.0 ;
|
60
|
+
}
|
61
|
+
|
62
|
+
void drawClockHands (void)
|
63
|
+
{
|
64
|
+
time_t t ;
|
65
|
+
struct tm *now ;
|
66
|
+
double angle, p, x0, y0, x1, y1 ;
|
67
|
+
int h24, h, m, s ;
|
68
|
+
char text [20] ;
|
69
|
+
|
70
|
+
time (&t) ;
|
71
|
+
now = localtime (&t) ;
|
72
|
+
|
73
|
+
h24 = now->tm_hour ;
|
74
|
+
m = now->tm_min ;
|
75
|
+
s = now->tm_sec ;
|
76
|
+
|
77
|
+
h = h24 ;
|
78
|
+
if (h > 12)
|
79
|
+
h -= 12 ;
|
80
|
+
|
81
|
+
// Hour hand
|
82
|
+
|
83
|
+
angle = h * 30 + m * 0.5 ;
|
84
|
+
x0 = sin (rads (angle)) * (clockRadius * 0.75) ;
|
85
|
+
y0 = cos (rads (angle)) * (clockRadius * 0.75) ;
|
86
|
+
for (p = -3.0 ; p <= 3.0 ; p += 0.2)
|
87
|
+
{
|
88
|
+
x1 = sin (rads (angle + p)) * (clockRadius * 0.7) ;
|
89
|
+
y1 = cos (rads (angle + p)) * (clockRadius * 0.7) ;
|
90
|
+
lcd128x64line (0, 0, x1, y1, 1) ;
|
91
|
+
lcd128x64lineTo (x0, y0, 1) ;
|
92
|
+
}
|
93
|
+
|
94
|
+
// Minute hand
|
95
|
+
|
96
|
+
angle = m * 6 ;
|
97
|
+
x0 = sin (rads (angle)) * (clockRadius * 0.9) ;
|
98
|
+
y0 = cos (rads (angle)) * (clockRadius * 0.9) ;
|
99
|
+
for (p = -1.0 ; p <= 1.0 ; p += 0.2)
|
100
|
+
{
|
101
|
+
x1 = sin (rads (angle + p)) * (clockRadius * 0.85) ;
|
102
|
+
y1 = cos (rads (angle + p)) * (clockRadius * 0.85) ;
|
103
|
+
lcd128x64line (0, 0, x1, y1, 1) ;
|
104
|
+
lcd128x64lineTo (x0, y0, 1) ;
|
105
|
+
}
|
106
|
+
|
107
|
+
// Second hand
|
108
|
+
|
109
|
+
angle = s * 6 ;
|
110
|
+
x0 = sin (rads (angle)) * (clockRadius * 0.2) ;
|
111
|
+
y0 = cos (rads (angle)) * (clockRadius * 0.2) ;
|
112
|
+
x1 = sin (rads (angle)) * (clockRadius * 0.95) ;
|
113
|
+
y1 = cos (rads (angle)) * (clockRadius * 0.95) ;
|
114
|
+
lcd128x64line (0 - x0, 0 - y0, x1, y1, 1) ;
|
115
|
+
lcd128x64circle (0, 0, clockRadius * 0.1, 0, 1) ;
|
116
|
+
lcd128x64circle (0, 0, clockRadius * 0.05, 1, 1) ;
|
117
|
+
|
118
|
+
// Text:
|
119
|
+
|
120
|
+
sprintf (text, "%02d:%02d:%02d", h24, m, s) ;
|
121
|
+
lcd128x64puts (32, 24, text, 0, 1) ;
|
122
|
+
|
123
|
+
sprintf (text, "%2d/%2d/%2d", now->tm_mday, now->tm_mon + 1, now->tm_year - 100) ;
|
124
|
+
lcd128x64puts (32, -23, text, 0, 1) ;
|
125
|
+
}
|
126
|
+
|
127
|
+
void drawClockFace (void)
|
128
|
+
{
|
129
|
+
int m ;
|
130
|
+
double d, px1, py1, px2, py2 ;
|
131
|
+
|
132
|
+
lcd128x64clear (0) ;
|
133
|
+
lcd128x64circle (0,0, clockRadius, 1, TRUE) ;
|
134
|
+
lcd128x64circle (0,0, clockRadius - thickness, 0, TRUE) ;
|
135
|
+
|
136
|
+
// The four big indicators for 12,15,30 and 45
|
137
|
+
|
138
|
+
lcd128x64rectangle (- 3, clockRadius - barLen, 3, clockRadius, 1, TRUE) ; // 12
|
139
|
+
lcd128x64rectangle (clockRadius - barLen, 3, clockRadius, -3, 1, TRUE) ; // 3
|
140
|
+
lcd128x64rectangle (- 3, -clockRadius + barLen, 3, -clockRadius, 1, TRUE) ; // 6
|
141
|
+
lcd128x64rectangle (-clockRadius + barLen, 3, -clockRadius, -3, 1, TRUE) ; // 9
|
142
|
+
|
143
|
+
|
144
|
+
// Smaller 5 and 1 minute ticks
|
145
|
+
|
146
|
+
for (m = 0 ; m < 60 ; ++m)
|
147
|
+
{
|
148
|
+
px1 = sin (rads (m * 6)) * clockRadius ;
|
149
|
+
py1 = cos (rads (m * 6)) * clockRadius ;
|
150
|
+
if ((m % 5) == 0)
|
151
|
+
d = barLen ;
|
152
|
+
else
|
153
|
+
d = barLen / 2.0 ;
|
154
|
+
|
155
|
+
px2 = sin (rads (m * 6)) * (clockRadius - d) ;
|
156
|
+
py2 = cos (rads (m * 6)) * (clockRadius - d) ;
|
157
|
+
lcd128x64line (px1, py1, px2, py2, 1) ;
|
158
|
+
}
|
159
|
+
}
|
160
|
+
|
161
|
+
void setup (void)
|
162
|
+
{
|
163
|
+
lcd128x64getScreenSize (&maxX, &maxY) ;
|
164
|
+
clockRadius = maxY / 2 - 1 ;
|
165
|
+
thickness = maxX / 48 ;
|
166
|
+
barLen = thickness * 4 ;
|
167
|
+
lcd128x64setOrigin (32, 32) ;
|
168
|
+
}
|
169
|
+
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
/*
|
174
|
+
***********************************************************************
|
175
|
+
* The main program
|
176
|
+
***********************************************************************
|
177
|
+
*/
|
178
|
+
|
179
|
+
int main (int argc, char *argv [])
|
180
|
+
{
|
181
|
+
time_t now ;
|
182
|
+
|
183
|
+
wiringPiSetup () ;
|
184
|
+
|
185
|
+
lcd128x64setup () ;
|
186
|
+
|
187
|
+
setup () ;
|
188
|
+
for (;;)
|
189
|
+
{
|
190
|
+
drawClockFace () ;
|
191
|
+
drawClockHands () ;
|
192
|
+
lcd128x64update () ;
|
193
|
+
|
194
|
+
now = time (NULL) ;
|
195
|
+
while (time (NULL) == now)
|
196
|
+
delay (10) ;
|
197
|
+
}
|
198
|
+
|
199
|
+
|
200
|
+
return 0 ;
|
201
|
+
}
|
@@ -0,0 +1,102 @@
|
|
1
|
+
/*
|
2
|
+
* delayTest.c:
|
3
|
+
* Just a little test program I'm using to experiment with
|
4
|
+
* various timings and latency, etc.
|
5
|
+
*
|
6
|
+
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
7
|
+
***********************************************************************
|
8
|
+
* This file is part of wiringPi:
|
9
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
10
|
+
*
|
11
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
12
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
13
|
+
* the Free Software Foundation, either version 3 of the License, or
|
14
|
+
* (at your option) any later version.
|
15
|
+
*
|
16
|
+
* wiringPi is distributed in the hope that it will be useful,
|
17
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19
|
+
* GNU Lesser General Public License for more details.
|
20
|
+
*
|
21
|
+
* You should have received a copy of the GNU Lesser General Public License
|
22
|
+
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
23
|
+
***********************************************************************
|
24
|
+
*/
|
25
|
+
|
26
|
+
#include <stdio.h>
|
27
|
+
#include <unistd.h>
|
28
|
+
|
29
|
+
#include <sys/time.h>
|
30
|
+
|
31
|
+
#define CYCLES 1000
|
32
|
+
|
33
|
+
int main()
|
34
|
+
{
|
35
|
+
int x ;
|
36
|
+
struct timeval t1, t2, t3 ;
|
37
|
+
int t ;
|
38
|
+
int max, min ;
|
39
|
+
int del ;
|
40
|
+
int underRuns, overRuns, exactRuns, bogusRuns, total ;
|
41
|
+
int descheds ;
|
42
|
+
|
43
|
+
|
44
|
+
// Baseline test
|
45
|
+
|
46
|
+
gettimeofday (&t1, NULL) ;
|
47
|
+
gettimeofday (&t2, NULL) ;
|
48
|
+
|
49
|
+
t = t2.tv_usec - t1.tv_usec ;
|
50
|
+
printf ("Baseline test: %d\n", t);
|
51
|
+
|
52
|
+
for (del = 1 ; del < 200 ; ++del)
|
53
|
+
{
|
54
|
+
underRuns = overRuns = exactRuns = total = 0 ;
|
55
|
+
descheds = 0 ;
|
56
|
+
max = 0 ;
|
57
|
+
min = 999 ;
|
58
|
+
|
59
|
+
for (x = 0 ; x < CYCLES ; ++x)
|
60
|
+
{
|
61
|
+
for (;;) // Repeat this if we get a delay over 999uS
|
62
|
+
{ // -> High probability Linux has deschedulled us
|
63
|
+
gettimeofday (&t1, NULL) ;
|
64
|
+
usleep (del) ;
|
65
|
+
// delayMicroseconds (del) ;
|
66
|
+
gettimeofday (&t2, NULL) ;
|
67
|
+
|
68
|
+
timersub (&t2, &t1, &t3) ;
|
69
|
+
|
70
|
+
t = t3.tv_usec ;
|
71
|
+
|
72
|
+
if (t > 999)
|
73
|
+
{
|
74
|
+
++descheds ;
|
75
|
+
continue ;
|
76
|
+
}
|
77
|
+
else
|
78
|
+
break ;
|
79
|
+
}
|
80
|
+
|
81
|
+
if (t == del)
|
82
|
+
++exactRuns ;
|
83
|
+
else if (t < del)
|
84
|
+
++underRuns ;
|
85
|
+
else if (t > del)
|
86
|
+
++overRuns ;
|
87
|
+
|
88
|
+
if (t > max)
|
89
|
+
max = t ;
|
90
|
+
else if (t < min)
|
91
|
+
min = t ;
|
92
|
+
|
93
|
+
total += t ;
|
94
|
+
}
|
95
|
+
printf ("Delay: %3d. Min: %3d, Max: %3d, Unders: %3d, Overs: %3d, Exacts: %3d, Average: %3d, Descheds: %2d\n",
|
96
|
+
del, min, max, underRuns, overRuns, exactRuns, total / CYCLES, descheds) ;
|
97
|
+
fflush (stdout) ;
|
98
|
+
usleep (1000) ;
|
99
|
+
}
|
100
|
+
|
101
|
+
return 0 ;
|
102
|
+
}
|