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

Commit 3e19740

Browse files
grgustafJimmy Huang
authored andcommitted
[samples] Fix GPIO-Outputs.js sample to handle open failures (#1697)
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 aca55c9 commit 3e19740

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
@@ -114,7 +114,6 @@ for (var i = 0; i < pincount; i++) {
114114
};
115115
if (controllerIndex < 0 ||
116116
testpins[i][controllerIndex] == intController) {
117-
console.log('rising for', testpins[i]);
118117
init['edge'] = 'rising';
119118
}
120119
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') {
@@ -78,14 +78,22 @@ else if (board.name == 'nucleo_f411re') {
7878
var pincount = testpins.length;
7979
var gpios = [];
8080
for (var i = 0; i < pincount; i++) {
81-
gpios[i] = gpio.open({pin: testpins[i]});
81+
try {
82+
gpios[i] = gpio.open({pin: testpins[i]});
83+
}
84+
catch (e) {
85+
console.log('Error opening pin ' + testpins[i] + ':', e.message);
86+
}
8287
}
8388

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

0 commit comments

Comments
 (0)