1 /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
17 var assert = require('assert');
18 var Gpio = require('gpio');
19 var gpio = new Gpio();
26 if (process.platform === 'linux') {
28 mode = gpio.MODE.NONE;
29 } else if (process.platform === 'nuttx') {
30 pin = require('stm32f4dis').pin.PA10;
31 mode = gpio.MODE.PUSHPULL;
40 direction: gpio.DIRECTION.OUT,
45 assert.notEqual(gpio.DIRECTION.IN, undefined);
46 assert.notEqual(gpio.DIRECTION.OUT, undefined);
47 assert.notEqual(gpio.MODE.NONE, undefined);
48 assert.notEqual(gpio.MODE.PULLUP, undefined);
49 assert.notEqual(gpio.MODE.PULLDOWN, undefined);
50 assert.notEqual(gpio.MODE.FLOAT, undefined);
51 assert.notEqual(gpio.MODE.PUSHPULL, undefined);
52 assert.notEqual(gpio.MODE.OPENDRAIN, undefined);
55 // turn on LED for 3000ms
57 assert.equal(err, null);
59 gpio10.write(LED_ON, function(writeErr) {
60 assert.equal(writeErr, null);
61 console.log('gpio write');
63 gpio10.read(function(readErr, value) {
64 assert.equal(readErr, null);
65 console.log('gpio read:', value);
66 assert.equal(LED_ON, value);
68 setTimeout(function() {
69 gpio10.writeSync(LED_OFF);
70 assert.equal(LED_OFF, gpio10.readSync());