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();
21 var ledGpio = null, switchGpio = null;
22 var ledPin, switchPin, ledMode;
24 var SWITCH_ON = false,
30 if (process.platform === 'linux') {
33 ledMode = gpio.MODE.NONE;
34 } else if (process.platform === 'nuttx') {
35 var pin = require('stm32f4dis').pin;
38 ledMode = gpio.MODE.PUSHPULL;
45 direction: gpio.DIRECTION.OUT,
48 this.writeSync(LED_OFF);
51 switchGpio = gpio.open({
53 direction: gpio.DIRECTION.IN
56 var loop = setInterval(function() {
57 if (!ledGpio || !switchGpio) {
61 if ((++loopCnt) == 10) {
65 switchGpio.read(function(err, value) {
71 if (value === SWITCH_ON) {
72 console.log('led on');
73 ledGpio.writeSync(LED_ON);
75 ledGpio.writeSync(LED_OFF);