initial
This commit is contained in:
189
node_modules/onoff/History.md
generated
vendored
Normal file
189
node_modules/onoff/History.md
generated
vendored
Normal file
@ -0,0 +1,189 @@
|
||||
3.1.0 - May 13 2018
|
||||
===================
|
||||
|
||||
* replace new Buffer with Buffer.from or Buffer.alloc
|
||||
* add accessebile property to Gpio class
|
||||
* add HIGH and LOW properties to Gpio class
|
||||
|
||||
3.0.2 - Apr 07 2018
|
||||
===================
|
||||
|
||||
* update dependencies (epoll v2.0.1)
|
||||
* improve performance tests
|
||||
|
||||
3.0.1 - Apr 01 2018
|
||||
===================
|
||||
|
||||
* create poller for both inputs and outputs
|
||||
* add test to verify that gpio direction can be changed
|
||||
|
||||
3.0.0 - Mar 31 2018
|
||||
===================
|
||||
|
||||
* add effective debouncing support
|
||||
* codebase modernized
|
||||
* remove link to outdated tutorial
|
||||
* remove undocumented options method
|
||||
|
||||
2.0.0 - Feb 26 2018
|
||||
===================
|
||||
|
||||
* update dependencies (epoll v2.0.0)
|
||||
* drop support for node.js v0.10, v0.12, v5 and v7
|
||||
|
||||
1.2.0 - Feb 11 2018
|
||||
===================
|
||||
|
||||
* ignore edge argument when instantiating a Gpio for an output
|
||||
|
||||
1.1.9 - Dec 24 2017
|
||||
===================
|
||||
|
||||
* document node 9 support
|
||||
* update BeagleBone performance numbers
|
||||
* many documentation improvements
|
||||
* update BeagleBone Black performance numbers
|
||||
* update dependencies
|
||||
|
||||
1.1.8 - Oct 15 2017
|
||||
===================
|
||||
|
||||
* update dependencies (epoll v1.0.0)
|
||||
|
||||
1.1.7 - Aug 26 2017
|
||||
===================
|
||||
|
||||
* only check permissions for edge file if edge specified [#77](https://github.com/fivdi/onoff/issues/77)
|
||||
|
||||
1.1.5 - Jul 30 2017
|
||||
===================
|
||||
|
||||
* wait until unprivileged file access allowed
|
||||
|
||||
1.1.4 - Jul 15 2017
|
||||
===================
|
||||
|
||||
* improve examples
|
||||
|
||||
1.1.3 - Jun 18 2017
|
||||
===================
|
||||
* upgrade to epoll v0.1.22
|
||||
* document related packages
|
||||
|
||||
1.1.2 - Feb 12 2017
|
||||
===================
|
||||
* documentation improved
|
||||
* upgrade to epoll v0.1.21
|
||||
|
||||
1.1.1 - Jun 05 2016
|
||||
===================
|
||||
* avoid exceptions when cape_universal is enabled on the bbb [#50](https://github.com/fivdi/onoff/issues/50)
|
||||
|
||||
1.1.0 - May 04 2016
|
||||
===================
|
||||
* activeLow option
|
||||
* documentation improved
|
||||
|
||||
1.0.4 - Jan 29 2016
|
||||
===================
|
||||
* documentation improved
|
||||
* epoll v0.1.17
|
||||
|
||||
1.0.3 - Oct 10 2015
|
||||
===================
|
||||
* documentation improved
|
||||
* epoll v0.1.16
|
||||
|
||||
1.0.2 - Feb 18 2015
|
||||
===================
|
||||
* documentation improved
|
||||
|
||||
1.0.1 - Feb 15 2015
|
||||
===================
|
||||
* refactored tests to avoid relying in interrupt generating outputs as linux 3.13 and above no longer supports them
|
||||
* new wiring for tests and examples
|
||||
* pullup and pulldown resistor configuration documented
|
||||
|
||||
1.0.0 - Jan 10 2015
|
||||
===================
|
||||
* use strict mode
|
||||
* jslint improvements
|
||||
* updated dependencies: epoll 0.1.4 -> 0.1.10
|
||||
* new wiring for tests on pi
|
||||
* GPIO access without superuser privileges on Raspbian
|
||||
|
||||
0.3.2 - Apr 18 2014
|
||||
===================
|
||||
* Documented BeagleBone Ångström prerequisites
|
||||
* Updated dependencies: epoll 0.1.2 -> 0.1.4
|
||||
|
||||
0.3.1 - Mar 22 2014
|
||||
===================
|
||||
* Added setDirection functionality [#19](https://github.com/fivdi/onoff/pull/19)
|
||||
* Added setEdge functionality
|
||||
* Updated dependencies: epoll 0.1.0 -> 0.1.2
|
||||
|
||||
0.3.0 - Nov 18 2013
|
||||
===================
|
||||
* Updated dependencies: epoll 0.0.8 -> 0.1.0
|
||||
* Removed persistentWatch option
|
||||
|
||||
0.2.3 - Oct 14 2013
|
||||
===================
|
||||
|
||||
* Use epoll 0.0.8
|
||||
* onoff now plays well with the quick2wire gpio-admin and the WiringPi gpio utilities on the Pi [#14](https://github.com/fivdi/onoff/issues/14)
|
||||
* Documentation improved
|
||||
* New test to monitor interrupt performance
|
||||
* New light switch example
|
||||
|
||||
0.2.2 - Oct 05 2013
|
||||
===================
|
||||
|
||||
* Use epoll 0.0.7
|
||||
* Removed timeout hack in many-interrupts test
|
||||
|
||||
0.2.1 - Sep 25 2013
|
||||
===================
|
||||
|
||||
* Use epoll 0.0.3
|
||||
* Improved five-inputs test
|
||||
|
||||
0.2.0 - Sep 22 2013
|
||||
===================
|
||||
|
||||
* Use epoll module for interrupt detection [#15](https://github.com/fivdi/onoff/issues/15)
|
||||
* 0.11.4+ compatability [#11](https://github.com/fivdi/onoff/issues/10)
|
||||
* One thread for watching all GPIOs rather than one thread per GPIO [#5](https://github.com/fivdi/onoff/issues/5)
|
||||
* Unwatch API added [#4](https://github.com/fivdi/onoff/issues/4)
|
||||
|
||||
0.1.7 - Sep 17 2013
|
||||
===================
|
||||
|
||||
* Remove OS limitations for installing [#12](https://github.com/fivdi/onoff/issues/12)
|
||||
|
||||
0.1.6 - July 15 2013
|
||||
===================
|
||||
|
||||
* Fixed typos
|
||||
* Documented how to watch five or more inputs
|
||||
|
||||
0.1.5 - May 26 2013
|
||||
===================
|
||||
|
||||
* Added test with five inputs
|
||||
|
||||
0.1.0 - Nov 11 2012
|
||||
===================
|
||||
|
||||
* Added Gpio objects
|
||||
* Removed functions, use Gpio objects instead
|
||||
* Performance improvements
|
||||
* Synchronous or asynchronous access to a GPIOs value
|
||||
* Allow applications to handle superuser issues
|
||||
|
||||
0.0.1 - Oct 28 2012
|
||||
===================
|
||||
|
||||
* Initial release
|
||||
|
20
node_modules/onoff/LICENSE
generated
vendored
Normal file
20
node_modules/onoff/LICENSE
generated
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
(The MIT License)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
'Software'), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
536
node_modules/onoff/README.md
generated
vendored
Normal file
536
node_modules/onoff/README.md
generated
vendored
Normal file
@ -0,0 +1,536 @@
|
||||
# onoff
|
||||
|
||||
GPIO access and interrupt detection with **Node.js** on Linux boards like the
|
||||
Raspberry Pi, C.H.I.P. or BeagleBone.
|
||||
|
||||
onoff supports Node.js versions 4, 6, 8 and 10.
|
||||
|
||||
[](https://github.com/sindresorhus/awesome-nodejs)
|
||||
|
||||
## Contents
|
||||
|
||||
* [News & Updates](#news--updates)
|
||||
* [Installation](#installation)
|
||||
* [Usage](#usage)
|
||||
* [LEDs and Buttons](#leds-and-buttons)
|
||||
* [Debouncing Buttons](#debouncing-buttons)
|
||||
* [API](#api)
|
||||
* [How Does onoff Work?](#how-does-onoff-work)
|
||||
* [Configuring Pullup and Pulldown Resistors](#configuring-pullup-and-pulldown-resistors)
|
||||
* [Benchmarks](#benchmarks)
|
||||
* [Related Packages](#related-packages)
|
||||
* [Additional Information](#additional-information)
|
||||
|
||||
## News & Updates
|
||||
|
||||
### May 2018: onoff v3.1.0
|
||||
|
||||
onoff v3.1.0 adds two new features.
|
||||
|
||||
* The new static property Gpio.accessible can be use to determine whether or
|
||||
not GPIO access is possible.
|
||||
* The new static properties Gpio.HIGH and Gpio.LOW can be used in place of
|
||||
the numeric constants 1 and 0.
|
||||
|
||||
### March 2018: onoff v3.0.0
|
||||
|
||||
Prior to v3.0.0 onoff had inadequate and undocumented support for debouncing
|
||||
GPIO inputs. onoff v3.0.0 comes with a very effective debouncing
|
||||
implementation based on lodash.debounce. It's important to know that the new
|
||||
implementation in v3.0.0 is not compatible with the old undocumented
|
||||
implementation as the semantics of the debounceTimeout option which can be
|
||||
specified when invoking the
|
||||
[Gpio Constructor](#gpiogpio-direction--edge--options) have changed.
|
||||
An example of the usage of the debounceTimeout can be found at
|
||||
[Debouncing Buttons](#debouncing-buttons).
|
||||
|
||||
## Installation
|
||||
|
||||
```
|
||||
npm install onoff
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
#### LEDs and Buttons
|
||||
Assume that there's an LED connected to GPIO17 and a momentary push button
|
||||
connected to GPIO4.
|
||||
|
||||
<img src="https://raw.githubusercontent.com/fivdi/onoff/master/examples/light-switch.png">
|
||||
|
||||
When the button is pressed the LED should turn on, when it's released the LED
|
||||
should turn off. This can be achieved with the following code:
|
||||
|
||||
```js
|
||||
const Gpio = require('onoff').Gpio;
|
||||
const led = new Gpio(17, 'out');
|
||||
const button = new Gpio(4, 'in', 'both');
|
||||
|
||||
button.watch(function (err, value) {
|
||||
led.writeSync(value);
|
||||
});
|
||||
```
|
||||
|
||||
Here two Gpio objects are being created. One called led for the LED connected
|
||||
to GPIO17 which is an output, and one called button for the momentary push
|
||||
button connected to GPIO4 which is an input. In addition to specifying that
|
||||
the button is an input, the constructors optional third argument is used to
|
||||
specify that 'both' rising and falling interrupt edges should be configured
|
||||
for the button GPIO as both button presses and releases should be handled.
|
||||
|
||||
After everything has been setup correctly, the buttons watch method is used to
|
||||
specify a callback function to execute every time the button is pressed or
|
||||
released. The value argument passed to the callback function represents the
|
||||
state of the button which will be 1 for pressed and 0 for released. This value
|
||||
is used by the callback to turn the LED on or off using its writeSync method.
|
||||
|
||||
When the above program is running it can be terminated with ctrl-c. However,
|
||||
it doesn't free its resources. It also ignores the err argument passed to
|
||||
the callback. Here's a slightly modified variant of the program that handles
|
||||
ctrl-c gracefully and bails out on error. The resources used by the led and
|
||||
button Gpio objects are released by invoking their unexport method.
|
||||
|
||||
```js
|
||||
const Gpio = require('onoff').Gpio;
|
||||
const led = new Gpio(17, 'out');
|
||||
const button = new Gpio(4, 'in', 'both');
|
||||
|
||||
button.watch(function (err, value) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
led.writeSync(value);
|
||||
});
|
||||
|
||||
process.on('SIGINT', function () {
|
||||
led.unexport();
|
||||
button.unexport();
|
||||
});
|
||||
```
|
||||
|
||||
#### Debouncing Buttons
|
||||
When working with buttons there will often be button bounce issues which
|
||||
result in the hardware thinking that a button was pressed several times
|
||||
although it was only pressed once. onoff provides a software debouncing
|
||||
solution for resolving bounce issues.
|
||||
|
||||
Assume again that there's an LED connected to GPIO17 and a momentary push
|
||||
button connected to GPIO4.
|
||||
|
||||
When the button is pressed the LED should toggle its state. This is a typical
|
||||
example of a situation where there will be button bounce issues. The issue can
|
||||
be resolved by using the debounceTimeout option when creating the Gpio object
|
||||
for the button. In the below program the debounceTimeout is set to 10
|
||||
milliseconds. This delays invoking the watch callback for the button while the
|
||||
button is bouncing. The watch callback will not be invoked until the button
|
||||
stops bouncing and has been in a stable state for 10 milliseconds.
|
||||
|
||||
```js
|
||||
const Gpio = require('onoff').Gpio;
|
||||
const led = new Gpio(17, 'out');
|
||||
const button = new Gpio(4, 'in', 'rising', {debounceTimeout: 10});
|
||||
|
||||
button.watch(function (err, value) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
led.writeSync(led.readSync() ^ 1);
|
||||
});
|
||||
|
||||
process.on('SIGINT', function () {
|
||||
led.unexport();
|
||||
button.unexport();
|
||||
});
|
||||
```
|
||||
|
||||
#### Check accessibility
|
||||
|
||||
Sometimes it may be necessary to determine if the current system supports
|
||||
GPIOs programmatically and mock functionality if it doesn't. `Gpio.accessible`
|
||||
can be used to achieve this.
|
||||
|
||||
```js
|
||||
const Gpio = require('onoff').Gpio;
|
||||
|
||||
const useLed = function (led, value) {
|
||||
led.writeSync(value);
|
||||
}
|
||||
|
||||
let led;
|
||||
|
||||
if (Gpio.accessible) {
|
||||
led = new Gpio(17, 'out');
|
||||
// more real code here
|
||||
} else {
|
||||
led = {
|
||||
writeSync: function (value) {
|
||||
console.log('virtual led now uses value: ' + value);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
useLed(led, 1);
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### Class Gpio
|
||||
|
||||
* [Gpio(gpio, direction [, edge] [, options]) - Constructor](#gpiogpio-direction--edge--options)
|
||||
* [read([callback]) - Read GPIO value asynchronously](#readcallback)
|
||||
* [readSync() - Read GPIO value synchronously](#readsync)
|
||||
* [write(value[, callback]) - Write GPIO value asynchronously](#writevalue-callback)
|
||||
* [writeSync(value) - Write GPIO value synchronously](#writesyncvalue)
|
||||
* [watch(callback) - Watch for hardware interrupts on the GPIO](#watchcallback)
|
||||
* [unwatch([callback]) - Stop watching for hardware interrupts on the GPIO](#unwatchcallback)
|
||||
* [unwatchAll() - Remove all watchers for the GPIO](#unwatchall)
|
||||
* [direction() - Get GPIO direction](#direction)
|
||||
* [setDirection(direction) - Set GPIO direction](#setdirectiondirection)
|
||||
* [edge() - Get GPIO interrupt generating edge](#edge)
|
||||
* [setEdge(edge) - Set GPIO interrupt generating edge](#setedgeedge)
|
||||
* [activeLow() - Get GPIO activeLow setting](#activelow)
|
||||
* [setActiveLow(invert) - Set GPIO activeLow setting](#setactivelowinvert)
|
||||
* [unexport() - Reverse the effect of exporting the GPIO to userspace](#unexport)
|
||||
* [static accessible - Determine whether or not GPIO access is possible](#static-accessible)
|
||||
* [HIGH / LOW - Constants used when reading or writing a GPIO value](#static-high--low)
|
||||
|
||||
##### Gpio(gpio, direction [, edge] [, options])
|
||||
- gpio - An unsigned integer specifying the GPIO number.
|
||||
- direction - A string specifying whether the GPIO should be configured as an
|
||||
input or output. The valid values are: 'in', 'out', 'high', and 'low'. If 'out'
|
||||
is specified the GPIO will be configured as an output and the value of the GPIO
|
||||
will be set to 0. 'high' and 'low' are variants of 'out' that configure the
|
||||
GPIO as an output with an initial level of 1 or 0 respectively.
|
||||
- [edge] - An optional string specifying the interrupt generating edge or
|
||||
edges for an input GPIO. The valid values are: 'none', 'rising', 'falling' or
|
||||
'both'. The default value is 'none' indicating that the GPIO will not generate
|
||||
interrupts. Whether or not interrupts are supported by an input GPIO is GPIO
|
||||
specific. If interrupts are not supported by a GPIO the edge argument should
|
||||
not be specified. The edge argument is ignored for output GPIOs.
|
||||
- [options] - An optional options object.
|
||||
|
||||
Configures the GPIO based on the passed arguments and returns a new Gpio
|
||||
object that can be used to access the GPIO.
|
||||
|
||||
The following options are supported:
|
||||
- debounceTimeout - An unsigned integer specifying a millisecond delay. Delays
|
||||
invoking the watch callback for an interrupt generating input GPIO while the
|
||||
input is bouncing. The watch callback will not be invoked until the input
|
||||
stops bouncing and has been in a stable state for debounceTimeout
|
||||
milliseconds. Optional, if unspecified the input GPIO will not be debounced.
|
||||
- activeLow - A boolean value specifying whether the values read from or
|
||||
written to the GPIO should be inverted. The interrupt generating edge for the
|
||||
GPIO also follow this this setting. The valid values for activeLow are true
|
||||
and false. Setting activeLow to true inverts. Optional, the default value is
|
||||
false.
|
||||
|
||||
GPIOs on Linux are identified by unsigned integers. These are the numbers that
|
||||
should be passed to the onoff Gpio constructor when exporting GPIOs to
|
||||
userspace. For example, pin 11 on the Raspberry Pi expansion header
|
||||
corresponds to GPIO17 in Raspbian Linux. 17 is therefore the number to pass
|
||||
to the onoff Gpio constructor when using pin 11 on the expansion header.
|
||||
|
||||
##### read([callback])
|
||||
- [callback] - An optional completion callback that gets two arguments (err,
|
||||
value), where err is reserved for an error object and value is the number 0
|
||||
or 1 and represents the state of the GPIO.
|
||||
|
||||
Read GPIO value asynchronously.
|
||||
|
||||
Note that most systems support readback of GPIOs configured as outputs. The
|
||||
read method can therefore be invoked for any GPIO, irrespective of whether it
|
||||
was configured as an input or an output. The Raspberry Pi and BeagleBone are
|
||||
examples of such systems.
|
||||
|
||||
##### readSync()
|
||||
Read GPIO value synchronously. Returns the number 0 or 1 to represent the
|
||||
state of the GPIO.
|
||||
|
||||
Note that most systems support readback of GPIOs configured as outputs. The
|
||||
readSync method can therefore be invoked for any GPIO, irrespective of whether
|
||||
it was configured as an input or an output. The Raspberry Pi and BeagleBone
|
||||
are examples of such systems.
|
||||
|
||||
##### write(value[, callback])
|
||||
- value - The number 0 or 1.
|
||||
- [callback] - An optional completion callback that gets one argument (err),
|
||||
where err is reserved for an error object.
|
||||
|
||||
Write GPIO value asynchronously.
|
||||
|
||||
##### writeSync(value)
|
||||
- value - The number 0 or 1.
|
||||
|
||||
Write GPIO value synchronously.
|
||||
|
||||
##### watch(callback)
|
||||
- callback - A callback that gets two arguments (err, value), where err is
|
||||
reserved for an error object and value is the number 0 or 1 and represents the
|
||||
state of the GPIO. The value can also be used to determine whether the
|
||||
interrupt occurred on a rising or falling edge. A value of 0 implies a falling
|
||||
edge interrupt and a value of 1 implies a rising edge interrupt.
|
||||
|
||||
Watch for hardware interrupts on the GPIO. The edge argument that was passed
|
||||
to the constructor determines which hardware interrupts to watch for.
|
||||
|
||||
##### unwatch([callback])
|
||||
- [callback] - The callback to remove.
|
||||
|
||||
Stop watching for hardware interrupts on the GPIO. If callback is specified,
|
||||
only that particular callback is removed. Otherwise all callbacks are removed.
|
||||
|
||||
##### unwatchAll()
|
||||
Remove all hardware interrupt watchers for the GPIO.
|
||||
|
||||
##### direction()
|
||||
Returns the string 'in' or 'out' indicating whether the GPIO is an input or
|
||||
output.
|
||||
|
||||
##### setDirection(direction)
|
||||
- direction - A string specifying whether the GPIO should be configured as an
|
||||
input or output. The valid values are 'in' and 'out'.
|
||||
|
||||
Set GPIO direction.
|
||||
|
||||
##### edge()
|
||||
Returns the string 'none', 'falling', 'rising', or 'both' indicating the
|
||||
interrupt generating edge or edges for the GPIO. Whether or not interrupts are
|
||||
supported by an input GPIO is GPIO specific. If interrupts are not supported
|
||||
the edge method should not be used. Interrupts are not supported by output
|
||||
GPIOs.
|
||||
|
||||
##### setEdge(edge)
|
||||
- edge - A string specifying the interrupt generating edge or edges for an
|
||||
input GPIO. The valid values are: 'none', 'rising', 'falling' or 'both'.
|
||||
Whether or not interrupts are supported by an input GPIO is GPIO specific. If
|
||||
interrupts are not supported the setEdge method should not be used. Interrupts
|
||||
are not supported by output GPIOs.
|
||||
|
||||
Set GPIO interrupt generating edge.
|
||||
|
||||
##### activeLow()
|
||||
Returns true or false indicating whether or not the values read from or written
|
||||
to the GPIO are inverted.
|
||||
|
||||
##### setActiveLow(invert)
|
||||
- invert - A boolean value specifying whether the values read from or written
|
||||
to the GPIO should be inverted. The interrupt generating edge for the GPIO also
|
||||
follow this this setting. The valid values for invert are true and false.
|
||||
Setting activeLow to true inverts. Optional, the default value is false.
|
||||
|
||||
Set GPIO activeLow setting.
|
||||
|
||||
##### unexport()
|
||||
Reverse the effect of exporting the GPIO to userspace. A Gpio object should not
|
||||
be used after invoking its unexport method.
|
||||
|
||||
##### static accessible
|
||||
Determine whether or not GPIO access is possible. true if the current process
|
||||
has the permissions required to export GPIOs to userspace. false otherwise.
|
||||
Loosely speaking, if this property is true it should be possible for the
|
||||
current process to create Gpio objects.
|
||||
|
||||
It is notable that while this property may be false indicating that the
|
||||
current process does not have the permissions required to export GPIOs to
|
||||
userspace, existing exported GPIOs may still be accessible.
|
||||
|
||||
This property is useful for mocking functionality on computers used for
|
||||
development that do not provide access to GPIOs.
|
||||
|
||||
This is a static property and should be accessed as `Gpio.accessible`.
|
||||
|
||||
##### static HIGH / LOW
|
||||
Constants used when reading or writing a GPIO value. Gpio.HIGH and Gpio.LOW
|
||||
can be used in place of the numeric constants 1 and 0.
|
||||
|
||||
### Synchronous API
|
||||
|
||||
Blink the LED connected to GPIO17 for 5 seconds:
|
||||
|
||||
```js
|
||||
const Gpio = require('onoff').Gpio; // Gpio class
|
||||
const led = new Gpio(17, 'out'); // Export GPIO17 as an output
|
||||
|
||||
// Toggle the state of the LED connected to GPIO17 every 200ms.
|
||||
// Here synchronous methods are used. Asynchronous methods are also available.
|
||||
const iv = setInterval(function () {
|
||||
led.writeSync(led.readSync() ^ 1); // 1 = on, 0 = off :)
|
||||
}, 200);
|
||||
|
||||
// Stop blinking the LED and turn it off after 5 seconds
|
||||
setTimeout(function () {
|
||||
clearInterval(iv); // Stop blinking
|
||||
led.writeSync(0); // Turn LED off
|
||||
led.unexport(); // Unexport GPIO and free resources
|
||||
}, 5000);
|
||||
```
|
||||
|
||||
### Asynchronous API
|
||||
|
||||
Blink the LED connected to GPIO17 for 5 seconds:
|
||||
|
||||
```js
|
||||
const Gpio = require('onoff').Gpio; // Gpio class
|
||||
const led = new Gpio(17, 'out'); // Export GPIO17 as an output
|
||||
|
||||
// Toggle the state of the LED connected to GPIO17 every 200ms 'count' times.
|
||||
// Here asynchronous methods are used. Synchronous methods are also available.
|
||||
(function blink(count) {
|
||||
if (count <= 0) {
|
||||
return led.unexport();
|
||||
}
|
||||
|
||||
led.read(function (err, value) { // Asynchronous read
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
led.write(value ^ 1, function (err) { // Asynchronous write
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
setTimeout(function () {
|
||||
blink(count - 1);
|
||||
}, 200);
|
||||
}(25));
|
||||
```
|
||||
|
||||
## How Does onoff Work?
|
||||
|
||||
Internally onoff uses sysfs files located at /sys/class/gpio to access GPIOs
|
||||
and the [epoll package](https://github.com/fivdi/epoll) to detect hardware
|
||||
interrupts. The Linux GPIO sysfs interface for userspace is documented
|
||||
[here](https://www.kernel.org/doc/Documentation/gpio/sysfs.txt).
|
||||
It's a relatively simple interface which can be used to ask the Linux kernel
|
||||
to export control of a GPIO to userspace. After control of a GPIO has been
|
||||
exported to userspace, the GPIO can be configured as an input or output.
|
||||
Thereafter, the state of an input can be read, and the state of an output can
|
||||
be written. Some systems will also allow the state of a output to be read.
|
||||
The GPIO sysfs interface can also be used for interrupt detection. onoff can
|
||||
detect several thousand interrupts per second on both the BeagleBone and the
|
||||
Raspberry Pi.
|
||||
|
||||
## Configuring Pullup and Pulldown Resistors
|
||||
|
||||
As mentioned in section [How Does onoff Work](#how-does-onoff-work) the sysfs
|
||||
interface is used to access GPIOs. The sysfs interface doesn't offer support
|
||||
for configuring pullup and pulldown resistors on GPIOs.
|
||||
|
||||
There are however many platform specific mechanisms for configuring pullup and
|
||||
pulldown resistors that are compatible with onoff. onoff itself doesn't use
|
||||
these mechanisms as one of the goals of onoff is to be platform independent.
|
||||
|
||||
Here we'll take a look at two mechanisms available on the Raspberry Pi for
|
||||
configuring pullup and pulldown resistors.
|
||||
|
||||
The first point to be aware of is that most GPIOs on a Raspberry Pi have
|
||||
either their pullup or pulldown resistor activated by default. The defaults
|
||||
can be seen in Table 6-31 on pages 102 and 103 of the
|
||||
[BCM2835 ARM Peripherals](http://www.farnell.com/datasheets/1521578.pdf)
|
||||
documentation.
|
||||
|
||||
#### Using the gpio Command in /boot/config.txt
|
||||
|
||||
On Raspbian 2018-04-18 or later the `gpio` configuration command can be used
|
||||
in `/boot/config.txt` to configure pullup and pulldown resistors. Further
|
||||
information is available at
|
||||
[New "gpio" config command](https://www.raspberrypi.org/forums/viewtopic.php?f=117&t=208748).
|
||||
|
||||
#### Using Device Tree Overlays
|
||||
|
||||
Device tree overlays can also be used to configure pullup and pulldown
|
||||
resistors. The Wiki page
|
||||
[Enabling Pullup and Pulldown Resistors on The Raspberry Pi](https://github.com/fivdi/onoff/wiki/Enabling-Pullup-and-Pulldown-Resistors-on-The-Raspberry-Pi)
|
||||
describes this mechanism in more detail.
|
||||
|
||||
## Benchmarks
|
||||
|
||||
Three of the onoff tests are used to monitor performance:
|
||||
|
||||
* performance-async.js - determine max. no. of write ops per seconds
|
||||
* performance-sync.js - determine max. no. of writeSync ops per second
|
||||
* performance-interrupt.js - determine max. no. of interrupts per second
|
||||
|
||||
The average of ten runs of these tests using various versions of Node.js
|
||||
and onoff are shown in the following tables.
|
||||
|
||||
**Raspberry Pi 3, 1.2Ghz, Raspbian:**
|
||||
|
||||
node | onoff | kernel | write / sec | writeSync / sec | interrupts / sec
|
||||
:---: | :---: | :---: | ---: | ---: | ---:
|
||||
v8.2.1 | v1.1.4 | 4.9.35-v7+ | 27345 | 318771 | 20094
|
||||
v6.11.1 | v1.1.4 | 4.9.35-v7+ | 26010 | 280180 | 19050
|
||||
v4.8.4 | v1.1.4 | 4.9.35-v7+ | 27674 | 328949 | 18326
|
||||
v0.10.29 | v1.1.4 | 4.9.35-v7+ | 23021 | 188573 | 19352
|
||||
|
||||
**Raspberry Pi 2, 900Mhz, Raspbian:**
|
||||
|
||||
node | onoff | kernel | write / sec | writeSync / sec | interrupts / sec
|
||||
:---: | :---: | :---: | ---: | ---: | ---:
|
||||
v8.2.1 | v1.1.4 | 4.9.35-v7+ | 12792 | 181829 | 9691
|
||||
v6.11.1 | v1.1.4 | 4.9.35-v7+ | 12348 | 167106 | 9215
|
||||
v4.8.4 | v1.1.4 | 4.9.35-v7+ | 13643 | 167248 | 8667
|
||||
v0.10.29 | v1.1.4 | 4.9.35-v7+ | 11368 | 98464 | 9451
|
||||
|
||||
**Raspberry Pi 1, 700Mhz, Raspbian:**
|
||||
|
||||
node | onoff | kernel | write / sec | writeSync / sec | interrupts / sec
|
||||
:---: | :---: | :---: | ---: | ---: | ---:
|
||||
v8.2.1 | v1.1.4 | 4.9.35+ | 2738 | 53589 | 2353
|
||||
v6.11.1 | v1.1.4 | 4.9.35+ | 2565 | 23111 | 1709
|
||||
v4.8.4 | v1.1.4 | 4.9.35+ | 2806 | 33847 | 1590
|
||||
v0.10.29 | v1.1.4 | 4.9.35+ | 2468 | 24837 | 1955
|
||||
|
||||
**BeagleBone Black, 1GHz, Debian 9.2:**
|
||||
|
||||
node | onoff | kernel | write / sec | writeSync / sec | interrupts / sec
|
||||
:---: | :---: | :---: | ---: | ---: | ---:
|
||||
v9.2.0 | v1.1.8 | 4.4.91-ti-r133 | 7584 | 105198 | 6820
|
||||
v8.2.1 | v1.1.8 | 4.4.91-ti-r133 | 7908 | 113476 | 6544
|
||||
v6.11.4 | v1.1.8 | 4.4.91-ti-r133 | 7784 | 100586 | 6079
|
||||
v4.8.4 | v1.1.8 | 4.4.91-ti-r133 | 8236 | 113988 | 5216
|
||||
|
||||
**BeagleBone, 720MHz, Debian 9.2:**
|
||||
|
||||
node | onoff | kernel | write / sec | writeSync / sec | interrupts / sec
|
||||
:---: | :---: | :---: | ---: | ---: | ---:
|
||||
v9.2.0 | v1.1.8 | 4.4.91-ti-r133 | 5348 | 74305 | 4870
|
||||
v8.2.1 | v1.1.8 | 4.4.91-ti-r133 | 5703 | 82007 | 4871
|
||||
v6.11.4 | v1.1.8 | 4.4.91-ti-r133 | 5534 | 72223 | 4247
|
||||
v4.8.4 | v1.1.8 | 4.4.91-ti-r133 | 6020 | 81516 | 3786
|
||||
|
||||
## Related Packages
|
||||
|
||||
Here are a few links to other hardware specific Node.js packages that may be
|
||||
of interest.
|
||||
|
||||
* [pigpio](https://github.com/fivdi/pigpio) - Fast GPIO, PWM, servo control, state change notification and interrupt handling on the Raspberry Pi
|
||||
* [i2c-bus](https://github.com/fivdi/i2c-bus) - I2C serial bus access
|
||||
* [spi-device](https://github.com/fivdi/spi-device) - SPI serial bus access
|
||||
* [mcp-spi-adc](https://github.com/fivdi/mcp-spi-adc) - Analog to digital conversion with the MCP3002/4/8, MCP3202/4/8 and MCP3304
|
||||
|
||||
## Additional Information
|
||||
|
||||
onoff was tested on the following platforms:
|
||||
|
||||
- Raspberry Pi 1, 2 and 3
|
||||
- Raspbian
|
||||
- C.H.I.P.
|
||||
- Debian
|
||||
- BeagleBone, BeagleBone Black and PocketBeagle
|
||||
- Debian
|
||||
|
||||
The suitability of onoff for a particular Linux board is highly dependent on
|
||||
how GPIO interfaces are made available on that board. The
|
||||
[GPIO interfaces](https://www.kernel.org/doc/Documentation/gpio/)
|
||||
documentation describes GPIO access conventions rather than standards that must
|
||||
be followed so GPIO can vary from platform to platform. For example, onoff
|
||||
relies on sysfs files located at /sys/classes/gpio being available. However,
|
||||
these sysfs files for userspace GPIO are optional and may not be available on a
|
||||
particular platform.
|
||||
|
5
node_modules/onoff/examples/accessible.js
generated
vendored
Normal file
5
node_modules/onoff/examples/accessible.js
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
const Gpio = require('../onoff').Gpio; // Gpio class
|
||||
|
||||
console.log('Gpio functionality accessible on this computer?', Gpio.accessible);
|
29
node_modules/onoff/examples/blink-led-async.js
generated
vendored
Normal file
29
node_modules/onoff/examples/blink-led-async.js
generated
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
"use strict";
|
||||
|
||||
const Gpio = require('../onoff').Gpio; // Gpio class
|
||||
const led = new Gpio(17, 'out'); // Export GPIO17 as an output
|
||||
|
||||
// Toggle the state of the LED connected to GPIO17 every 200ms 'count' times.
|
||||
// Here asynchronous methods are used. Synchronous methods are also available.
|
||||
(function blink(count) {
|
||||
if (count <= 0) {
|
||||
return led.unexport();
|
||||
}
|
||||
|
||||
led.read(function (err, value) { // Asynchronous read
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
led.write(value ^ 1, function (err) { // Asynchronous write
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
setTimeout(function () {
|
||||
blink(count - 1);
|
||||
}, 200);
|
||||
}(25));
|
||||
|
18
node_modules/onoff/examples/blink-led.js
generated
vendored
Normal file
18
node_modules/onoff/examples/blink-led.js
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
|
||||
const Gpio = require('../onoff').Gpio; // Gpio class
|
||||
const led = new Gpio(17, 'out'); // Export GPIO17 as an output
|
||||
|
||||
// Toggle the state of the LED connected to GPIO17 every 200ms.
|
||||
// Here synchronous methods are used. Asynchronous methods are also available.
|
||||
const iv = setInterval(function () {
|
||||
led.writeSync(led.readSync() ^ 1); // 1 = on, 0 = off :)
|
||||
}, 200);
|
||||
|
||||
// Stop blinking the LED and turn it off after 5 seconds
|
||||
setTimeout(function () {
|
||||
clearInterval(iv); // Stop blinking
|
||||
led.writeSync(0); // Turn LED off
|
||||
led.unexport(); // Unexport GPIO and free resources
|
||||
}, 5000);
|
||||
|
19
node_modules/onoff/examples/debounce-button.js
generated
vendored
Normal file
19
node_modules/onoff/examples/debounce-button.js
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
|
||||
const Gpio = require('../onoff').Gpio;
|
||||
const led = new Gpio(17, 'out');
|
||||
const button = new Gpio(4, 'in', 'rising', {debounceTimeout: 10});
|
||||
|
||||
button.watch(function (err, value) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
led.writeSync(led.readSync() ^ 1);
|
||||
});
|
||||
|
||||
process.on('SIGINT', function () {
|
||||
led.unexport();
|
||||
button.unexport();
|
||||
});
|
||||
|
19
node_modules/onoff/examples/light-switch.js
generated
vendored
Normal file
19
node_modules/onoff/examples/light-switch.js
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
|
||||
const Gpio = require('../onoff').Gpio;
|
||||
const led = new Gpio(17, 'out');
|
||||
const button = new Gpio(4, 'in', 'both');
|
||||
|
||||
button.watch(function (err, value) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
led.writeSync(value);
|
||||
});
|
||||
|
||||
process.on('SIGINT', function () {
|
||||
led.unexport();
|
||||
button.unexport();
|
||||
});
|
||||
|
BIN
node_modules/onoff/examples/light-switch.png
generated
vendored
Normal file
BIN
node_modules/onoff/examples/light-switch.png
generated
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 227 KiB |
21
node_modules/onoff/examples/mygpio-overlay.dts
generated
vendored
Normal file
21
node_modules/onoff/examples/mygpio-overlay.dts
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
/dts-v1/;
|
||||
/plugin/;
|
||||
|
||||
/ {
|
||||
compatible = "brcm,bcm2708";
|
||||
|
||||
fragment@0 {
|
||||
target = <&gpio>;
|
||||
__overlay__ {
|
||||
pinctrl-names = "default";
|
||||
pinctrl-0 = <&my_pins>;
|
||||
|
||||
my_pins: my_pins {
|
||||
brcm,pins = <7 8 9>; /* gpio no. */
|
||||
brcm,function = <0 0 0>; /* 0:in, 1:out */
|
||||
brcm,pull = <1 1 2>; /* 2:up 1:down 0:none */
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
6
node_modules/onoff/examples/run-examples
generated
vendored
Executable file
6
node_modules/onoff/examples/run-examples
generated
vendored
Executable file
@ -0,0 +1,6 @@
|
||||
#!/bin/sh
|
||||
node blink-led
|
||||
node blink-led-async
|
||||
node wait-for-interrupt
|
||||
node light-switch
|
||||
|
22
node_modules/onoff/examples/wait-for-interrupt.js
generated
vendored
Normal file
22
node_modules/onoff/examples/wait-for-interrupt.js
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
|
||||
const Gpio = require('../onoff').Gpio; // Gpio class
|
||||
|
||||
// Export GPIO4 as an interrupt generating input with a debounceTimeout of 10
|
||||
// milliseconds
|
||||
const button = new Gpio(4, 'in', 'rising', {debounceTimeout: 10});
|
||||
|
||||
console.log('Please press the button on GPIO4...');
|
||||
|
||||
// The callback passed to watch will be invoked when the button connected to
|
||||
// GPIO4 is pressed
|
||||
button.watch(function (err, value) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
console.log('Button pressed!, its value was ' + value);
|
||||
|
||||
button.unexport(); // Unexport GPIO and free resources
|
||||
});
|
||||
|
273
node_modules/onoff/onoff.js
generated
vendored
Normal file
273
node_modules/onoff/onoff.js
generated
vendored
Normal file
@ -0,0 +1,273 @@
|
||||
"use strict";
|
||||
|
||||
const fs = require('fs');
|
||||
const debounce = require('lodash.debounce');
|
||||
const Epoll = require('epoll').Epoll;
|
||||
|
||||
const GPIO_ROOT_PATH = '/sys/class/gpio/';
|
||||
|
||||
// fs reads and writes use Buffers
|
||||
const HIGH_BUF = Buffer.from('1');
|
||||
const LOW_BUF = Buffer.from('0');
|
||||
|
||||
// lib returns numeric data and expects numeric data as arguments
|
||||
const HIGH = 1;
|
||||
const LOW = 0;
|
||||
|
||||
class Gpio {
|
||||
constructor(gpio, direction, edge, options) {
|
||||
if (typeof edge === 'object' && !options) {
|
||||
options = edge;
|
||||
edge = undefined;
|
||||
}
|
||||
|
||||
options = options || {};
|
||||
|
||||
this._gpio = gpio;
|
||||
this._gpioPath = GPIO_ROOT_PATH + 'gpio' + this._gpio + '/';
|
||||
this._debounceTimeout = options.debounceTimeout || 0;
|
||||
this._readBuffer = Buffer.alloc(16);
|
||||
this._listeners = [];
|
||||
|
||||
if (!fs.existsSync(this._gpioPath)) {
|
||||
// The pin hasn't been exported yet so export it
|
||||
fs.writeFileSync(GPIO_ROOT_PATH + 'export', this._gpio);
|
||||
|
||||
// A hack to avoid the issue described here:
|
||||
// https://github.com/raspberrypi/linux/issues/553
|
||||
// I don't like this solution, but it enables compatibility with older
|
||||
// versions of onoff, i.e., the Gpio constructor was and still is
|
||||
// synchronous.
|
||||
let permissionRequiredPaths = [
|
||||
this._gpioPath + 'direction',
|
||||
this._gpioPath + 'active_low',
|
||||
this._gpioPath + 'value',
|
||||
];
|
||||
|
||||
// On some systems the edge file will not exist if the GPIO does not
|
||||
// support interrupts
|
||||
// https://github.com/fivdi/onoff/issues/77#issuecomment-321980735
|
||||
if (edge && direction === 'in') {
|
||||
permissionRequiredPaths.push(this._gpioPath + 'edge');
|
||||
}
|
||||
|
||||
permissionRequiredPaths.forEach((path) => {
|
||||
let tries = 0;
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
tries += 1;
|
||||
const fd = fs.openSync(path, 'r+');
|
||||
fs.closeSync(fd);
|
||||
break;
|
||||
} catch (e) {
|
||||
if (tries === 10000) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
fs.writeFileSync(this._gpioPath + 'direction', direction);
|
||||
|
||||
// On some systems writing to the edge file for an output GPIO will
|
||||
// result in an "EIO, i/o error"
|
||||
// https://github.com/fivdi/onoff/issues/87
|
||||
if (edge && direction === 'in') {
|
||||
fs.writeFileSync(this._gpioPath + 'edge', edge);
|
||||
}
|
||||
|
||||
if (!!options.activeLow) {
|
||||
fs.writeFileSync(this._gpioPath + 'active_low', HIGH_BUF);
|
||||
}
|
||||
} else {
|
||||
// The pin has already been exported, perhaps by onoff itself, perhaps
|
||||
// by quick2wire gpio-admin on the Pi, perhaps by the WiringPi gpio
|
||||
// utility on the Pi, or perhaps by something else. In any case, an
|
||||
// attempt is made to set the direction and edge to the requested
|
||||
// values here. If quick2wire gpio-admin was used for the export, the
|
||||
// user should have access to both direction and edge files. This is
|
||||
// important as gpio-admin sets niether direction nor edge. If the
|
||||
// WiringPi gpio utility was used, the user should have access to edge
|
||||
// file, but not the direction file. This is also ok as the WiringPi
|
||||
// gpio utility can set both direction and edge. If there are any
|
||||
// errors while attempting to perform the modifications, just keep on
|
||||
// truckin'.
|
||||
try {
|
||||
fs.writeFileSync(this._gpioPath + 'direction', direction);
|
||||
} catch (ignore) {
|
||||
}
|
||||
try {
|
||||
// On some systems writing to the edge file for an output GPIO will
|
||||
// result in an "EIO, i/o error"
|
||||
// https://github.com/fivdi/onoff/issues/87
|
||||
if (edge && direction === 'in') {
|
||||
fs.writeFileSync(this._gpioPath + 'edge', edge);
|
||||
}
|
||||
try {
|
||||
fs.writeFileSync(this._gpioPath + 'active_low',
|
||||
!!options.activeLow ? HIGH_BUF : LOW_BUF
|
||||
);
|
||||
} catch (ignore) {
|
||||
}
|
||||
} catch (ignore) {
|
||||
}
|
||||
}
|
||||
|
||||
// Cache fd for performance
|
||||
this._valueFd = fs.openSync(this._gpioPath + 'value', 'r+');
|
||||
|
||||
{
|
||||
// A poller is created for both inputs and outputs. A poller isn't
|
||||
// actully needed for an output but the setDirection method can be
|
||||
// invoked to change the direction of a GPIO from output to input and
|
||||
// then a poller may be needed.
|
||||
const pollerEventHandler = (err, fd, events) => {
|
||||
const value = this.readSync();
|
||||
|
||||
if ((value === LOW && this._fallingEnabled) ||
|
||||
(value === HIGH && this._risingEnabled)) {
|
||||
this._listeners.slice(0).forEach((callback) => {
|
||||
callback(err, value);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
this._risingEnabled = edge === 'both' || edge == 'rising';
|
||||
this._fallingEnabled = edge === 'both' || edge == 'falling';
|
||||
|
||||
// Read GPIO value before polling to prevent an initial unauthentic
|
||||
// interrupt
|
||||
this.readSync();
|
||||
|
||||
if (this._debounceTimeout > 0) {
|
||||
const db = debounce(pollerEventHandler, this._debounceTimeout);
|
||||
|
||||
this._poller = new Epoll((err, fd, events) => {
|
||||
this.readSync(); // Clear interrupt
|
||||
db(err, fd, events);
|
||||
});
|
||||
} else {
|
||||
this._poller = new Epoll(pollerEventHandler);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
read(callback) {
|
||||
fs.read(this._valueFd, this._readBuffer, 0, 1, 0, (err, bytes, buf) => {
|
||||
if (typeof callback === 'function') {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
callback(null, buf[0] === HIGH_BUF[0] ? HIGH : LOW);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
readSync() {
|
||||
fs.readSync(this._valueFd, this._readBuffer, 0, 1, 0);
|
||||
return this._readBuffer[0] === HIGH_BUF[0] ? HIGH : LOW;
|
||||
}
|
||||
|
||||
write(value, callback) {
|
||||
const writeBuffer = value === HIGH ? HIGH_BUF : LOW_BUF;
|
||||
fs.write(this._valueFd, writeBuffer, 0, writeBuffer.length, 0, callback);
|
||||
}
|
||||
|
||||
writeSync(value) {
|
||||
const writeBuffer = value === HIGH ? HIGH_BUF : LOW_BUF;
|
||||
fs.writeSync(this._valueFd, writeBuffer, 0, writeBuffer.length, 0);
|
||||
}
|
||||
|
||||
watch(callback) {
|
||||
this._listeners.push(callback);
|
||||
|
||||
if (this._listeners.length === 1) {
|
||||
this._poller.add(this._valueFd, Epoll.EPOLLPRI);
|
||||
}
|
||||
}
|
||||
|
||||
unwatch(callback) {
|
||||
if (this._listeners.length > 0) {
|
||||
if (typeof callback !== 'function') {
|
||||
this._listeners = [];
|
||||
} else {
|
||||
this._listeners = this._listeners.filter((listener) => {
|
||||
return callback !== listener;
|
||||
});
|
||||
}
|
||||
|
||||
if (this._listeners.length === 0) {
|
||||
this._poller.remove(this._valueFd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unwatchAll() {
|
||||
this.unwatch();
|
||||
}
|
||||
|
||||
direction() {
|
||||
return fs.readFileSync(this._gpioPath + 'direction').toString().trim();
|
||||
}
|
||||
|
||||
setDirection(direction) {
|
||||
fs.writeFileSync(this._gpioPath + 'direction', direction);
|
||||
}
|
||||
|
||||
edge() {
|
||||
return fs.readFileSync(this._gpioPath + 'edge').toString().trim();
|
||||
}
|
||||
|
||||
setEdge(edge) {
|
||||
fs.writeFileSync(this._gpioPath + 'edge', edge);
|
||||
|
||||
this._risingEnabled = edge === 'both' || edge == 'rising';
|
||||
this._fallingEnabled = edge === 'both' || edge == 'falling';
|
||||
}
|
||||
|
||||
activeLow() {
|
||||
return fs.readFileSync(
|
||||
this._gpioPath + 'active_low')[0] === HIGH_BUF[0] ? true : false;
|
||||
}
|
||||
|
||||
setActiveLow(invert) {
|
||||
fs.writeFileSync(this._gpioPath + 'active_low', !!invert ? HIGH_BUF : LOW_BUF);
|
||||
}
|
||||
|
||||
unexport() {
|
||||
this.unwatchAll();
|
||||
fs.closeSync(this._valueFd);
|
||||
try {
|
||||
fs.writeFileSync(GPIO_ROOT_PATH + 'unexport', this._gpio);
|
||||
} catch (ignore) {
|
||||
// Flow of control always arrives here when cape_universal is enabled on
|
||||
// the bbb.
|
||||
}
|
||||
}
|
||||
|
||||
static get accessible() {
|
||||
let fd;
|
||||
|
||||
try {
|
||||
fd = fs.openSync(GPIO_ROOT_PATH + 'export', 'w');
|
||||
} catch(e) {
|
||||
// e.code === 'ENOENT' / 'EACCES' are most common
|
||||
// though any failure to open will also result in a gpio
|
||||
// failure to export.
|
||||
return false;
|
||||
} finally {
|
||||
if (fd) {
|
||||
fs.closeSync(fd);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Gpio.HIGH = HIGH;
|
||||
Gpio.LOW = LOW;
|
||||
|
||||
exports.Gpio = Gpio;
|
71
node_modules/onoff/package.json
generated
vendored
Normal file
71
node_modules/onoff/package.json
generated
vendored
Normal file
@ -0,0 +1,71 @@
|
||||
{
|
||||
"_from": "onoff",
|
||||
"_id": "onoff@3.1.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-5hD6y+AB7vW7Pb30Urb9oGVkxhtG1MdoJaEMGsKbCLzpInKdQJEcvbqOjQ8DV6N9r+acPErfz+Veb+v6VidE9A==",
|
||||
"_location": "/onoff",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "tag",
|
||||
"registry": true,
|
||||
"raw": "onoff",
|
||||
"name": "onoff",
|
||||
"escapedName": "onoff",
|
||||
"rawSpec": "",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "latest"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"#USER",
|
||||
"/"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/onoff/-/onoff-3.1.0.tgz",
|
||||
"_shasum": "90bfb4d689c60842086b0d237d36cd9b84fffddf",
|
||||
"_spec": "onoff",
|
||||
"_where": "/home/wn/workspace-node/PiAlive",
|
||||
"author": {
|
||||
"name": "fivdi"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/fivdi/onoff/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"epoll": "^2.0.1",
|
||||
"lodash.debounce": "^4.0.8"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "GPIO access and interrupt detection with Node.js",
|
||||
"directories": {
|
||||
"example": "examples",
|
||||
"test": "test"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4.0.0"
|
||||
},
|
||||
"homepage": "https://github.com/fivdi/onoff#readme",
|
||||
"keywords": [
|
||||
"gpio",
|
||||
"embedded",
|
||||
"interrupt",
|
||||
"beaglebone",
|
||||
"bbb",
|
||||
"bb",
|
||||
"raspberry",
|
||||
"raspi",
|
||||
"rpi",
|
||||
"pi",
|
||||
"linux"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "onoff.js",
|
||||
"name": "onoff",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/fivdi/onoff.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "cd test && ./run-tests && cd .."
|
||||
},
|
||||
"version": "3.1.0"
|
||||
}
|
18
node_modules/onoff/test/blink-led.js
generated
vendored
Normal file
18
node_modules/onoff/test/blink-led.js
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
|
||||
const Gpio = require('../onoff').Gpio;
|
||||
const led = new Gpio(17, 'out');
|
||||
|
||||
const iv = setInterval(() => {
|
||||
led.writeSync(led.readSync() ^ 1);
|
||||
}, 100);
|
||||
|
||||
setTimeout(() => {
|
||||
clearInterval(iv);
|
||||
|
||||
led.writeSync(0);
|
||||
led.unexport();
|
||||
|
||||
console.log('ok - ' + __filename);
|
||||
}, 2000);
|
||||
|
59
node_modules/onoff/test/change-configuration.js
generated
vendored
Normal file
59
node_modules/onoff/test/change-configuration.js
generated
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
"use strict";
|
||||
|
||||
const assert = require('assert');
|
||||
const Gpio = require('../onoff').Gpio;
|
||||
|
||||
let output = new Gpio(8, 'out');
|
||||
let input = new Gpio(7, 'in', 'both');
|
||||
|
||||
function watchWithSecondConfiguration() {
|
||||
input.watch((err, value) => {
|
||||
assert(!err, 'error during interrupt detection');
|
||||
assert(value === 1, 'expected interrupt on rising edge');
|
||||
|
||||
setTimeout(() => {
|
||||
input.unexport();
|
||||
output.unexport();
|
||||
|
||||
console.log('ok - ' + __filename);
|
||||
}, 10);
|
||||
});
|
||||
|
||||
output.writeSync(1);
|
||||
}
|
||||
|
||||
function changeConfiguration() {
|
||||
input.unwatchAll();
|
||||
|
||||
let temp = output;
|
||||
temp.setDirection('in');
|
||||
output = input;
|
||||
input = temp;
|
||||
|
||||
output.setEdge('none');
|
||||
output.setDirection('out');
|
||||
output.writeSync(0);
|
||||
assert(output.direction() === 'out', 'expected direction to be out');
|
||||
assert(output.edge() === 'none', 'expected edge to be none');
|
||||
assert(output.readSync() === 0, 'expected value to be 0');
|
||||
|
||||
input.setEdge('rising');
|
||||
assert(input.direction() === 'in', 'expected direction to be in');
|
||||
assert(input.edge() === 'rising', 'expected edge to be rising');
|
||||
assert(input.readSync() === 0, 'expected value to be 0');
|
||||
|
||||
watchWithSecondConfiguration();
|
||||
}
|
||||
|
||||
function watchWithFirstConfiguration() {
|
||||
input.watch((err, value) => {
|
||||
assert(!err, 'error during interrupt detection');
|
||||
assert(value === 1, 'expected interrupt on rising edge');
|
||||
|
||||
setTimeout(changeConfiguration, 10);
|
||||
});
|
||||
|
||||
output.writeSync(1);
|
||||
}
|
||||
|
||||
watchWithFirstConfiguration();
|
39
node_modules/onoff/test/configure-and-check-active-low.js
generated
vendored
Normal file
39
node_modules/onoff/test/configure-and-check-active-low.js
generated
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
"use strict";
|
||||
|
||||
/*
|
||||
* In this test, GPIO7 is connected to one end of a 1kΩ current limiting
|
||||
* resistor and GPIO8 is connected to the other end of the resistor.
|
||||
*/
|
||||
const Gpio = require('../onoff').Gpio;
|
||||
const assert = require('assert');
|
||||
const input = new Gpio(7, 'in');
|
||||
const output = new Gpio(8, 'out', {activeLow: true});
|
||||
|
||||
assert(input.activeLow() === false);
|
||||
assert(output.activeLow() === true);
|
||||
output.writeSync(0);
|
||||
assert(input.readSync() === 1);
|
||||
output.writeSync(1);
|
||||
assert(input.readSync() === 0);
|
||||
|
||||
output.setActiveLow(false);
|
||||
assert(input.activeLow() === false);
|
||||
assert(output.activeLow() === false);
|
||||
output.writeSync(0);
|
||||
assert(input.readSync() === 0);
|
||||
output.writeSync(1);
|
||||
assert(input.readSync() === 1);
|
||||
|
||||
input.setActiveLow(true);
|
||||
assert(input.activeLow() === true);
|
||||
assert(output.activeLow() === false);
|
||||
output.writeSync(0);
|
||||
assert(input.readSync() === 1);
|
||||
output.writeSync(1);
|
||||
assert(input.readSync() === 0);
|
||||
|
||||
input.unexport();
|
||||
output.unexport();
|
||||
|
||||
console.log('ok - ' + __filename);
|
||||
|
13
node_modules/onoff/test/configure-and-check-input.js
generated
vendored
Normal file
13
node_modules/onoff/test/configure-and-check-input.js
generated
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
|
||||
const Gpio = require('../onoff').Gpio;
|
||||
const assert = require('assert');
|
||||
const input = new Gpio(4, 'in', 'rising');
|
||||
|
||||
assert(input.direction() === 'in');
|
||||
assert(input.edge() === 'rising');
|
||||
|
||||
input.unexport();
|
||||
|
||||
console.log('ok - ' + __filename);
|
||||
|
35
node_modules/onoff/test/configure-and-check-output.js
generated
vendored
Normal file
35
node_modules/onoff/test/configure-and-check-output.js
generated
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
"use strict";
|
||||
|
||||
const Gpio = require('../onoff').Gpio;
|
||||
const assert = require('assert');
|
||||
const output = new Gpio(17, 'out');
|
||||
|
||||
assert(output.direction() === 'out');
|
||||
|
||||
output.writeSync(1);
|
||||
assert(output.readSync() === 1);
|
||||
|
||||
output.writeSync(0);
|
||||
assert(output.readSync() === 0);
|
||||
|
||||
output.write(1, (err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
output.read((err, value) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
assert(value === 1);
|
||||
|
||||
output.writeSync(0);
|
||||
assert(output.readSync() === 0);
|
||||
|
||||
output.unexport();
|
||||
|
||||
console.log('ok - ' + __filename);
|
||||
});
|
||||
});
|
||||
|
56
node_modules/onoff/test/debounce.js
generated
vendored
Normal file
56
node_modules/onoff/test/debounce.js
generated
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
"use strict";
|
||||
|
||||
const assert = require('assert');
|
||||
const Gpio = require('../onoff').Gpio;
|
||||
const output = new Gpio(8, 'out');
|
||||
const button = new Gpio(7, 'in', 'both', {debounceTimeout: 10});
|
||||
|
||||
let buttonPressedCount = 0;
|
||||
let buttonReleasedCount = 0;
|
||||
|
||||
function simulateToggleButtonStateWithBounce(cb) {
|
||||
let toggleCount = 0;
|
||||
|
||||
const iv = setInterval(() => {
|
||||
if (toggleCount === 19) {
|
||||
clearInterval(iv);
|
||||
return cb();
|
||||
}
|
||||
|
||||
output.writeSync(output.readSync() ^ 1);
|
||||
toggleCount += 1;
|
||||
}, 2);
|
||||
}
|
||||
|
||||
function simulatePressAndReleaseButtonWithBounce() {
|
||||
simulateToggleButtonStateWithBounce(() => {
|
||||
setTimeout(() => {
|
||||
simulateToggleButtonStateWithBounce(() => {
|
||||
setTimeout(() => {
|
||||
assert(buttonPressedCount === 1);
|
||||
assert(buttonReleasedCount === 1);
|
||||
|
||||
button.unexport();
|
||||
output.unexport();
|
||||
|
||||
console.log('ok - ' + __filename);
|
||||
}, 20);
|
||||
});
|
||||
}, 50);
|
||||
});
|
||||
}
|
||||
|
||||
button.watch((err, value) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
if (value === 1) {
|
||||
buttonPressedCount += 1;
|
||||
} else if (value === 0) {
|
||||
buttonReleasedCount += 1;
|
||||
}
|
||||
});
|
||||
|
||||
simulatePressAndReleaseButtonWithBounce();
|
||||
|
15
node_modules/onoff/test/export-many-times.js
generated
vendored
Normal file
15
node_modules/onoff/test/export-many-times.js
generated
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
|
||||
const Gpio = require('../onoff').Gpio;
|
||||
|
||||
for (let i = 1; i <= 1000000; i += 1) {
|
||||
const led = new Gpio(17, 'out');
|
||||
led.writeSync(led.readSync() ^ 1);
|
||||
led.unexport();
|
||||
if (i % 10 === 0) {
|
||||
console.log(i);
|
||||
}
|
||||
}
|
||||
|
||||
console.log('ok - ' + __filename);
|
||||
|
47
node_modules/onoff/test/many-interrupts.js
generated
vendored
Normal file
47
node_modules/onoff/test/many-interrupts.js
generated
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
"use strict";
|
||||
|
||||
const assert = require('assert');
|
||||
const Gpio = require('../onoff').Gpio;
|
||||
const input = new Gpio(7, 'in', 'both');
|
||||
const output = new Gpio(8, 'out');
|
||||
|
||||
let toggleCount = 0;
|
||||
let falling = 0;
|
||||
let rising = 0;
|
||||
|
||||
function toggleOutput() {
|
||||
output.writeSync(output.readSync() ^ 1);
|
||||
toggleCount += 1;
|
||||
}
|
||||
|
||||
function interrupt(err, value) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
if (value === 1) {
|
||||
rising += 1;
|
||||
} else if (value === 0) {
|
||||
falling += 1;
|
||||
}
|
||||
|
||||
assert(output.readSync() === value);
|
||||
|
||||
if (rising + falling < 2000) {
|
||||
toggleOutput();
|
||||
} else {
|
||||
assert(toggleCount === 2000);
|
||||
assert(rising === falling);
|
||||
assert(rising + falling === toggleCount);
|
||||
|
||||
input.unexport();
|
||||
output.writeSync(0);
|
||||
output.unexport();
|
||||
|
||||
console.log('ok - ' + __filename);
|
||||
}
|
||||
}
|
||||
|
||||
input.watch(interrupt);
|
||||
toggleOutput();
|
||||
|
37
node_modules/onoff/test/output-with-edge-bug.js
generated
vendored
Normal file
37
node_modules/onoff/test/output-with-edge-bug.js
generated
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
"use strict";
|
||||
|
||||
// Test for https://github.com/fivdi/onoff/issues/87
|
||||
//
|
||||
// If a Gpio is instantiated for an output GPIO and the edge parameter is
|
||||
// specified then the edge parameter should be ignored. Attempting to write
|
||||
// the sysfs edge file for an output GPIO results in an
|
||||
// "EIO: i/o error, write"
|
||||
|
||||
const Gpio = require('../onoff').Gpio;
|
||||
const assert = require('assert');
|
||||
|
||||
function ensureGpio17Unexported(cb) {
|
||||
let led = new Gpio(17, 'out');
|
||||
|
||||
led.unexport();
|
||||
|
||||
setTimeout(() => {
|
||||
cb();
|
||||
}, 100);
|
||||
}
|
||||
|
||||
ensureGpio17Unexported(() => {
|
||||
let led;
|
||||
|
||||
assert.doesNotThrow(
|
||||
() => {
|
||||
led = new Gpio(17, 'out', 'both');
|
||||
},
|
||||
'can\'t instantiate a Gpio for an output with edge option specified'
|
||||
);
|
||||
|
||||
led.unexport();
|
||||
|
||||
console.log('ok - ' + __filename);
|
||||
});
|
||||
|
73
node_modules/onoff/test/performance-async.js
generated
vendored
Normal file
73
node_modules/onoff/test/performance-async.js
generated
vendored
Normal file
@ -0,0 +1,73 @@
|
||||
"use strict";
|
||||
|
||||
const Gpio = require('../onoff').Gpio;
|
||||
|
||||
const pulseLed = (led, pulseCount, cb) => {
|
||||
let time = process.hrtime();
|
||||
|
||||
const loop = (count) => {
|
||||
if (count === 0) {
|
||||
time = process.hrtime(time);
|
||||
const writesPerSecond = pulseCount * 2 / (time[0] + time[1] / 1E9);
|
||||
return cb(null, writesPerSecond);
|
||||
}
|
||||
|
||||
led.write(1, (err) => {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
led.write(0, (err) => {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
loop(count - 1);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
loop(pulseCount);
|
||||
};
|
||||
|
||||
const asyncWritesPerSecond = (cb) => {
|
||||
const led = new Gpio(17, 'out');
|
||||
let writes = 0;
|
||||
|
||||
const loop = (count) => {
|
||||
if (count === 0) {
|
||||
led.unexport();
|
||||
return cb(null, writes / 10);
|
||||
}
|
||||
|
||||
pulseLed(led, 10000, (err, writesPerSecond) => {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
writes += writesPerSecond;
|
||||
|
||||
loop(count - 1);
|
||||
});
|
||||
};
|
||||
|
||||
// Do a dry run first to get the runtime primed
|
||||
pulseLed(led, 5000, (err, writesPerSecond) => {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
loop(10);
|
||||
});
|
||||
};
|
||||
|
||||
asyncWritesPerSecond((err, averageWritesPerSecond) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
console.log('ok - ' + __filename);
|
||||
console.log(
|
||||
' ' + Math.floor(averageWritesPerSecond) + ' async writes per second'
|
||||
);
|
||||
});
|
||||
|
46
node_modules/onoff/test/performance-interrupt.js
generated
vendored
Normal file
46
node_modules/onoff/test/performance-interrupt.js
generated
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
"use strict";
|
||||
|
||||
/*
|
||||
* In this test, GPIO7 is connected to one end of a 1kΩ current limiting
|
||||
* resistor and GPIO8 is connected to the other end of the resistor. GPIO7 is
|
||||
* an interrupt generating input and GPIO8 is an output. By toggling the state
|
||||
* of the output an interrupt is generated. The output is toggled as often as
|
||||
* possible to determine the maximum rate at which interrupts can be handled.
|
||||
*/
|
||||
const Gpio = require('../onoff').Gpio;
|
||||
const input = new Gpio(7, 'in', 'both');
|
||||
const output = new Gpio(8, 'out');
|
||||
|
||||
let irqCount = 0;
|
||||
let iv;
|
||||
|
||||
// Exit handler
|
||||
function exit() {
|
||||
input.unexport();
|
||||
output.unexport();
|
||||
|
||||
clearInterval(iv);
|
||||
}
|
||||
process.on('SIGINT', exit);
|
||||
|
||||
// Interrupt handler
|
||||
input.watch((err, value) => {
|
||||
if (err) {
|
||||
exit();
|
||||
}
|
||||
|
||||
irqCount += 1;
|
||||
|
||||
// Trigger next interrupt by toggling output.
|
||||
output.writeSync(value === 0 ? 1 : 0);
|
||||
});
|
||||
|
||||
// Print number of interrupts once a second.
|
||||
iv = setInterval(() => {
|
||||
console.log(irqCount);
|
||||
irqCount = 0;
|
||||
}, 1000);
|
||||
|
||||
// Trigger first interrupt by toggling output.
|
||||
output.writeSync(output.readSync() === 0 ? 1 : 0);
|
||||
|
40
node_modules/onoff/test/performance-sync.js
generated
vendored
Normal file
40
node_modules/onoff/test/performance-sync.js
generated
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
"use strict";
|
||||
|
||||
const Gpio = require('../onoff').Gpio;
|
||||
|
||||
const pulseLed = (led, pulseCount) => {
|
||||
let time = process.hrtime();
|
||||
|
||||
for (let i = 0; i !== pulseCount; i += 1) {
|
||||
led.writeSync(1);
|
||||
led.writeSync(0);
|
||||
}
|
||||
|
||||
time = process.hrtime(time);
|
||||
|
||||
const writesPerSecond = pulseCount * 2 / (time[0] + time[1] / 1E9);
|
||||
|
||||
return writesPerSecond;
|
||||
}
|
||||
|
||||
const syncWritesPerSecond = () => {
|
||||
const led = new Gpio(17, 'out');
|
||||
let writes = 0;
|
||||
|
||||
// Do a dry run first to get the runtime primed
|
||||
pulseLed(led, 50000);
|
||||
|
||||
for (let i = 0; i !== 10; i += 1) {
|
||||
writes += pulseLed(led, 100000);
|
||||
}
|
||||
|
||||
led.unexport();
|
||||
|
||||
return writes / 10;
|
||||
}
|
||||
|
||||
console.log('ok - ' + __filename);
|
||||
console.log(
|
||||
' ' + Math.floor(syncWritesPerSecond()) + ' sync writes per second'
|
||||
);
|
||||
|
5
node_modules/onoff/test/run-performance-tests
generated
vendored
Executable file
5
node_modules/onoff/test/run-performance-tests
generated
vendored
Executable file
@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
node performance-async
|
||||
node performance-sync
|
||||
node performance-interrupt
|
||||
|
12
node_modules/onoff/test/run-tests
generated
vendored
Executable file
12
node_modules/onoff/test/run-tests
generated
vendored
Executable file
@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
node blink-led
|
||||
node change-configuration
|
||||
node configure-and-check-active-low
|
||||
node configure-and-check-input
|
||||
node configure-and-check-output
|
||||
node debounce
|
||||
node many-interrupts
|
||||
node output-with-edge-bug
|
||||
node wait-for-interrupt
|
||||
node wait-for-many-interrupts
|
||||
|
24
node_modules/onoff/test/wait-for-interrupt.js
generated
vendored
Normal file
24
node_modules/onoff/test/wait-for-interrupt.js
generated
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
"use strict";
|
||||
|
||||
const Gpio = require('../onoff').Gpio;
|
||||
const assert = require('assert');
|
||||
const button = new Gpio(4, 'in', 'both');
|
||||
|
||||
assert(button.direction() === 'in');
|
||||
assert(button.edge() === 'both');
|
||||
|
||||
console.info('Please press button connected to GPIO #4...');
|
||||
|
||||
button.watch((err, value) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
assert(value === 0 || value === 1);
|
||||
|
||||
button.unexport();
|
||||
|
||||
console.log('ok - ' + __filename);
|
||||
console.log(' button pressed, value was ' + value);
|
||||
});
|
||||
|
29
node_modules/onoff/test/wait-for-many-interrupts.js
generated
vendored
Normal file
29
node_modules/onoff/test/wait-for-many-interrupts.js
generated
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
"use strict";
|
||||
|
||||
const Gpio = require('../onoff').Gpio;
|
||||
const assert = require('assert');
|
||||
const button = new Gpio(4, 'in', 'rising', {
|
||||
debounceTimeout : 10
|
||||
});
|
||||
let count = 0;
|
||||
|
||||
assert(button.direction() === 'in');
|
||||
assert(button.edge() === 'rising');
|
||||
|
||||
console.info('Please press button connected to GPIO4 5 times...');
|
||||
|
||||
button.watch((err, value) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
count += 1;
|
||||
|
||||
console.log('button pressed ' + count + ' times, value was ' + value);
|
||||
|
||||
if (count === 5) {
|
||||
button.unexport();
|
||||
console.log('ok - ' + __filename);
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user