Skip to content

Commit 017d3e7

Browse files
committed
updates to gpio test code
1 parent c0df837 commit 017d3e7

File tree

4 files changed

+46
-21
lines changed

4 files changed

+46
-21
lines changed

coder-apps/tests/gpio_test/app/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var gpio = require("gpio");
22
gpio.logging = true;
33

4-
var gpioID = 7; //pin 26, bottom right header
4+
var gpioID = 4; //actually pin 7, 4 down on left header
55
var gpioDevice;
66
var connected = false; //ensure only one process talks to us at a time.
77

coder-apps/tests/gpio_test/app/meta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"created": "2013-11-30",
3-
"modified": "2013-12-03",
3+
"modified": "2013-12-08",
44
"color": "#2ecc71",
55
"author": "",
66
"name": "GPIO Test",

coder-apps/tests/gpio_test/static/js/index.js

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,13 @@ $(document).ready( function() {
1818
// enabled is set below by a button click.
1919
var blinkval = 0;
2020
setInterval( function() {
21-
22-
if ( blinkval ) {
23-
blinkval = 0;
24-
} else {
25-
blinkval = 1;
26-
}
2721

2822
if ( enabled ) {
29-
23+
if ( blinkval ) {
24+
blinkval = 0;
25+
} else {
26+
blinkval = 1;
27+
}
3028
Coder.socketConnection.sendData( 'gpio', {
3129
command: "set",
3230
value: blinkval
@@ -39,31 +37,56 @@ $(document).ready( function() {
3937
//Enable or disable the blinker
4038
var enabled = false;
4139
$("#on").click( function() {
42-
Coder.socketConnection.sendData( 'gpio', {
43-
command: "set",
44-
value: 1
45-
});
40+
lightOn();
4641
enabled = true;
4742
});
4843
$("#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() {
5358
enabled = false;
59+
blinkval = 1;
60+
lightOn();
61+
}).on("mouseup", function() {
62+
enabled = false;
63+
blinkval = 0;
64+
lightOff();
5465
});
66+
5567

5668
});
5769

5870
addOutputMessage( "Connecting... see the debug console for log messages." );
5971

6072
});
6173

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+
};
6386

6487
var addOutputMessage = function( text ) {
6588
var $output = $("#output");
6689
$output.prepend( $("<p/>").text( text ) );
6790
console.log( text );
68-
}
91+
};
6992

coder-apps/tests/gpio_test/views/index.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@
2626
<body class="">
2727
<div class="pagecontent">
2828
<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>
3133
<div id="output">
3234

3335
</div>

0 commit comments

Comments
 (0)