File tree Expand file tree Collapse file tree 4 files changed +46
-21
lines changed
coder-apps/tests/gpio_test Expand file tree Collapse file tree 4 files changed +46
-21
lines changed Original file line number Diff line number Diff line change 1
1
var gpio = require ( "gpio" ) ;
2
2
gpio . logging = true ;
3
3
4
- var gpioID = 7 ; //pin 26, bottom right header
4
+ var gpioID = 4 ; //actually pin 7, 4 down on left header
5
5
var gpioDevice ;
6
6
var connected = false ; //ensure only one process talks to us at a time.
7
7
Original file line number Diff line number Diff line change 1
1
{
2
2
"created" : " 2013-11-30" ,
3
- "modified" : " 2013-12-03 " ,
3
+ "modified" : " 2013-12-08 " ,
4
4
"color" : " #2ecc71" ,
5
5
"author" : " " ,
6
6
"name" : " GPIO Test" ,
Original file line number Diff line number Diff line change @@ -18,15 +18,13 @@ $(document).ready( function() {
18
18
// enabled is set below by a button click.
19
19
var blinkval = 0 ;
20
20
setInterval ( function ( ) {
21
-
22
- if ( blinkval ) {
23
- blinkval = 0 ;
24
- } else {
25
- blinkval = 1 ;
26
- }
27
21
28
22
if ( enabled ) {
29
-
23
+ if ( blinkval ) {
24
+ blinkval = 0 ;
25
+ } else {
26
+ blinkval = 1 ;
27
+ }
30
28
Coder . socketConnection . sendData ( 'gpio' , {
31
29
command : "set" ,
32
30
value : blinkval
@@ -39,31 +37,56 @@ $(document).ready( function() {
39
37
//Enable or disable the blinker
40
38
var enabled = false ;
41
39
$ ( "#on" ) . click ( function ( ) {
42
- Coder . socketConnection . sendData ( 'gpio' , {
43
- command : "set" ,
44
- value : 1
45
- } ) ;
40
+ lightOn ( ) ;
46
41
enabled = true ;
47
42
} ) ;
48
43
$ ( "#off" ) . click ( function ( ) {
49
- Coder . socketConnection . sendData ( 'gpio' , {
50
- command : "set" ,
51
- value : 0
52
- } ) ;
44
+ lightOff ( ) ;
45
+ enabled = false ;
46
+ } ) ;
47
+ $ ( "#toggle" ) . click ( function ( ) {
48
+ enabled = false ;
49
+ if ( blinkval ) {
50
+ blinkval = 0 ;
51
+ lightOff ( ) ;
52
+ } else {
53
+ blinkval = 1 ;
54
+ lightOn ( ) ;
55
+ }
56
+ } ) ;
57
+ $ ( "#push" ) . on ( "mousedown" , function ( ) {
53
58
enabled = false ;
59
+ blinkval = 1 ;
60
+ lightOn ( ) ;
61
+ } ) . on ( "mouseup" , function ( ) {
62
+ enabled = false ;
63
+ blinkval = 0 ;
64
+ lightOff ( ) ;
54
65
} ) ;
66
+
55
67
56
68
} ) ;
57
69
58
70
addOutputMessage ( "Connecting... see the debug console for log messages." ) ;
59
71
60
72
} ) ;
61
73
62
-
74
+ var lightOn = function ( ) {
75
+ Coder . socketConnection . sendData ( 'gpio' , {
76
+ command : "set" ,
77
+ value : 1
78
+ } ) ;
79
+ } ;
80
+ var lightOff = function ( ) {
81
+ Coder . socketConnection . sendData ( 'gpio' , {
82
+ command : "set" ,
83
+ value : 0
84
+ } ) ;
85
+ } ;
63
86
64
87
var addOutputMessage = function ( text ) {
65
88
var $output = $ ( "#output" ) ;
66
89
$output . prepend ( $ ( "<p/>" ) . text ( text ) ) ;
67
90
console . log ( text ) ;
68
- }
91
+ } ;
69
92
Original file line number Diff line number Diff line change 26
26
< body class ="">
27
27
< div class ="pagecontent ">
28
28
< h1 > GPIO Test</ h1 >
29
- < div id ="on " class ="button "> ON</ div >
30
- < div id ="off " class ="button "> OFF</ div >
29
+ < div id ="on " class ="button "> BLINK</ div >
30
+ < div id ="off " class ="button "> STOP BLINK</ div >
31
+ < div id ="toggle " class ="button "> TOGGLE</ div >
32
+ < div id ="push " class ="button "> PUSH</ div >
31
33
< div id ="output ">
32
34
33
35
</ div >
You can’t perform that action at this time.
0 commit comments