Merge pull request #26254 from muntyan/master

pigpio: add definitions for Gpio.glitchFilter() and pigpio.configureSocketPort()
This commit is contained in:
Mine Starks
2018-06-15 16:10:43 -07:00
committed by GitHub
2 changed files with 51 additions and 2 deletions

View File

@@ -160,15 +160,21 @@ export class Gpio extends NodeJS.EventEmitter {
disableInterrupt(): Gpio;
/**
* Enables alerts for the GPIO.
* Enables alerts for the GPIO. Returns this.
*/
enableAlert(): Gpio;
/**
* Disables aterts for the GPIO.
* Disables aterts for the GPIO. Returns this.
*/
disableAlert(): Gpio;
/**
* Sets a glitch filter on a GPIO. Returns this.
* @param steady Time, in microseconds, during which the level must be stable. Maximum value: 300000
*/
glitchFilter(steady: number): Gpio;
/*----------------------*
* mode
*----------------------*/
@@ -410,3 +416,11 @@ export function terminate(): void;
* @param peripheral an unsigned integer specifying the peripheral for timing (CLOCK_PWM or CLOCK_PCM)
*/
export function configureClock(microseconds: number, peripheral: number): void;
/**
* Configures pigpio to use the specified socket port.
* The default setting is to use port 8888.
* If configureSocketPort is called, it must be called before creating Gpio objects.
* @param port an unsigned integer specifying the pigpio socket port number
*/
export function configureSocketPort(port: number): void;

View File

@@ -5,6 +5,7 @@ import * as assert from 'assert';
const Gpio = pigpio.Gpio;
pigpio.configureClock(1, pigpio.CLOCK_PWM);
pigpio.configureSocketPort(23456);
const led = new Gpio(18, {
mode: Gpio.OUTPUT,
@@ -878,3 +879,37 @@ import * as assert from 'assert';
clearInterval(iv);
}, 2000);
})();
(function gpio_glitch_filter(): void {
const Gpio = pigpio.Gpio;
const input = new Gpio(7, {
mode: Gpio.INPUT,
pullUpDown: Gpio.PUD_OFF,
alert: true
});
const output = new Gpio(8, {
mode: Gpio.OUTPUT
});
let count = 0;
output.digitalWrite(0);
input.glitchFilter(50);
input.on('alert', (level, tick) => {
if (level === 1) {
count++;
console.log(' rising edge, count=' + count);
}
});
output.trigger(30, 1); // alert function should not be executed (blocked by glitchFilter)
setTimeout(() => {
output.trigger(70, 1); // alert function should be executed
}, 500);
setTimeout(() => {
assert.strictEqual(count, 1, 'expected 1 alert function call instead of ' + count);
console.log(" success...");
process.exit(0);
}, 1000);
})();