Skip to content

Commit

Permalink
Update documentation and package.json for upcoming release 1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
guymcswain committed Oct 3, 2019
1 parent 30bcb67 commit 05848c4
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ node_modules

# but include these files
!test/regression-1.0.3.js
!test/regression.js


# ignore readme.md derived files
Expand Down
42 changes: 42 additions & 0 deletions examples/usage_promises.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// npm run-script usage
const pigpio = require('../pigpio-client').pigpio({host: process.env.npm_package_config_host});

const ready = new Promise((resolve, reject) => {
pigpio.once('connected', resolve);
pigpio.once('error', reject);
});

function wait(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}

ready.then(async (info) => {
// display information on pigpio and connection status
console.log(JSON.stringify(info,null,2));

// get events from a button on GPIO 17
const button = pigpio.gpio(17);
await button.modeSet('input');
button.notify((level, tick)=> {
console.log(`Button changed to ${level} at ${tick} usec`)
});

// control an LED on GPIO 4
const led = pigpio.gpio(4);
await led.modeSet('output');
await led.write(1); // turn on LED
await wait(500);
await led.write(0); // turn off
await wait(500);

// use waves to blink the LED rapidly (toggle every 100ms)
await led.waveClear();
await led.waveAddPulse([[1, 0, 100000], [0, 1, 100000]]);
const blinkWave = await led.waveCreate();
led.waveChainTx([{loop: true}, {waves: [blinkWave]}, {repeat: true}]);

// wait for 10 seconds, stop the waves
await wait(10000);
await led.waveTxStop();
pigpio.end();
}).catch(console.error);
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "pigpio-client",
"version": "1.3.0",
"description": "A nodejs socket interface to pigpio daemon.",
"description": "A nodejs client for pigpio socket interface.",
"main": "pigpio-client.js",
"directories": {
"test": "test"
Expand All @@ -12,17 +12,19 @@
"nested-error-stacks": "^2.1.0"
},
"scripts": {
"test": "node ./test/regression-1.0.3.js"
"test": "node ./test/regression.js",
"usage": "node ./examples/usage_promises.js"
},
"config": {
"host": "192.168.100.2",
"host": "192.168.100.6",
"gpio": "17",
"baud": "38400"
},
"keywords": [
"pigpiod"
"pigpio", "raspberryPi", "GPIO", "waveforms", "servo", "pwm", "serial"
],
"author": "Guy McSwain",
"contributors": ["Philipp", "Uri Shaked" ],
"license": "MIT",
"repository": {
"type": "git",
Expand Down
42 changes: 20 additions & 22 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
# pigpio-client
The pigpio-client library allows you to connect to a remote Raspberry Pi running
the pigpio server - pigpiod - and manipulate its GPIO pins. This library is implemented
using the pigpio library socket interface. For the underlying detail of the pigpio
socket interface see http://abyz.me.uk/rpi/pigpio/sif.html
Pigpio-client exposes the socket interface APIs of the pigpio library using nodejs. This allows you to connect to a Raspberry Pi, running
remotely or local, and manipulate its GPIO pins with javascript. The pigpio socket interface is described more fully [here:](http://abyz.me.uk/rpi/pigpio/sif.html)

[v1.2.0](https://github.com/guymcswain/pigpio-client/wiki) introduces new APIs: glitchSet, setServoPulsewidth, getServoPulseWidth.
New in [**v1.3.0**](https://github.com/guymcswain/pigpio-client/wiki)
* All APIs work with async/await and promises
* Added `gpio.waveTxStop`
* Repeat forever option for `gpio.waveChainTx`.

### Usage example
#### Installing and Running pigpio daemon
A guide for installing and running pigpiod along with other useful information can be found in the [wiki](https://github.com/guymcswain/pigpio-client/wiki/Install-and-configure-pigpiod)

### pigpio-client usage example
```javascript
const pigpio = require('pigpio-client.js').pigpio({host: 'raspberryHostIP'});
const pigpio = require('pigpio-client').pigpio({host: 'raspberryHostIP'});

const ready = new Promise((resolve, reject) => {
pigpio.once('connected', resolve);
Expand Down Expand Up @@ -42,21 +46,15 @@ ready.then(async (info) => {
await led.waveClear();
await led.waveAddPulse([[1, 0, 100000], [0, 1, 100000]]);
const blinkWave = await led.waveCreate();
await led.waveChainTx([{loop: true}, {waves: [blinkWave]}, {repeat: true}]);
led.waveChainTx([{loop: true}, {waves: [blinkWave]}, {repeat: true}]);

// wait for 10 ms, stop the waves
// wait for 10 sec, stop the waves
await wait(10000);
await led.waveTxStop();
}).catch(console.error);

pigpio.on('disconnected', (reason) => {
console.log('App received disconnected event, reason: ', reason);
console.log('App reconnecting in 1 sec');
setTimeout(() => pigpio.connect({host: 'raspberryHostIP'}), 1000);
});
```
All APIs accept error-first callback as an optional last argument, and also return
a promise (and thus can be safey used with async/await).
a promise (and thus can be safely used with async/await).
Depending on the presence of a callback argument, errors returned by pigpio are delivered in
two ways: Methods called without a callback emit 'error' events. Methods called
with a callback are supplied an `Error` object as the first argument returned.
Expand Down Expand Up @@ -156,9 +154,12 @@ Polls waveform status at interval msec. Defaults to 25msec.
waveform. *Pulse_t* is a tuple [1, 0, delay] for positive pulse, [0, 1, delay]
for negative pulse width = delay. [`gpioWaveAddGeneric`](http://abyz.me.uk/rpi/pigpio/cif.html#gpioWaveAddGeneric).

**`gpio.waveChainTx([wids], {loop:x, delay:y}, cb)`** Transmit a chain of waves
represented by array of wave IDs `wids`. Options object specifies `loop` and `delay`
(between loop) values. [`gpioWaveChain`](http://abyz.me.uk/rpi/pigpio/cif.html#gpioWaveChain)
**`gpio.waveChainTx([{loop:x}, {waves: [wids]}, {delay:y}, {repeat:z}], cb)`**
[`gpioWaveChain`](http://abyz.me.uk/rpi/pigpio/cif.html#gpioWaveChain)
Transmit a chain of waves represented by array of wave IDs `[wids]`. The chain can have **loop**s, be separated by **delay**s and **repeat**ed by inclusion of option objects.
* loop : x, begins a loop. x can be anything
* delay: y, insert of delay of y=0 to 65535 microseconds
* repeat: z, repeat loop z=0 to 65535 times or forever if z=**true**

**`gpio.waveSendSync(wid, cb)`** Synchronizes `wid` to the currently active
waveform. [`gpioWaveTxSend` with mode set to PI_WAVE_MODE_ONE_SHOT_SYNC.](http://abyz.me.uk/rpi/pigpio/cif.html#gpioWaveTxSend)
Expand Down Expand Up @@ -238,6 +239,3 @@ https://github.com/guymcswain/pigpio-client/issues

#### Limitations
Only a single instance of serialport is supported. **<=1.1.x**

#### Installing and Running pigpiod plus other useful information
see [pigpio-client wiki](https://github.com/guymcswain/pigpio-client/wiki/Install-and-configure-pigpiod)

0 comments on commit 05848c4

Please sign in to comment.