Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Commit 5201242

Browse files
committed
[samples] Fix GPIO-Outputs.js sample to handle open failures
This lets it succeed on A101 where certain pins can't be opened with the default configuration. Fixes #1690 Signed-off-by: Geoff Gustafson <geoff@linux.intel.com>
1 parent 2b50252 commit 5201242

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

samples/tests/GPIO-Inputs.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ for (var i = 0; i < pincount; i++) {
112112
};
113113
if (controllerIndex < 0 ||
114114
testpins[i][controllerIndex] == intController) {
115-
console.log('rising for', testpins[i]);
116115
init['edge'] = 'rising';
117116
}
118117
gpios[i] = gpio.open(init);

samples/tests/GPIO-Outputs.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ var gpio = require('gpio');
1212

1313
var testpins;
1414
if (board.name == 'arduino_101') {
15-
// expected results: works with IO2, IO4, IO7-8, IO10-13; others have
16-
// incompatible pinmux settings, I think
15+
// expected results: works with IO2, IO4, IO7, IO12-13; not sure why IO8,
16+
// IO10-11 not working; others can only be used from ARC side
1717
testpins = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13];
1818
}
1919
else if (board.name == 'frdm_k64f') {
@@ -79,14 +79,22 @@ else if (board.name == 'nucleo_f411re') {
7979
var pincount = testpins.length;
8080
var gpios = [];
8181
for (var i = 0; i < pincount; i++) {
82-
gpios[i] = gpio.open({pin: testpins[i]});
82+
try {
83+
gpios[i] = gpio.open({pin: testpins[i]});
84+
}
85+
catch (e) {
86+
console.log('Error opening pin ' + testpins[i] + ':', e.message);
87+
}
8388
}
8489

8590
// toggle all pins off in sequence, then on in sequence, and so on
8691
var tick = 75, toggle = 0;
8792
var index = 0;
8893
setInterval(function () {
89-
gpios[index++].write(toggle);
94+
var gpio = gpios[index++];
95+
if (gpio) {
96+
gpio.write(toggle);
97+
}
9098
if (index >= pincount) {
9199
toggle = 1 - toggle;
92100
index = 0;

0 commit comments

Comments
 (0)