From 28c7670bba135e67e244d63e03c6ef2128677c5e Mon Sep 17 00:00:00 2001 From: Yevgen Muntyan Date: Sun, 3 Jun 2018 22:17:03 -0700 Subject: [PATCH] Add definitions for Gpio.glitchFilter() and pigpio.configureSocketPort() --- types/pigpio/index.d.ts | 18 ++++++++++++++++-- types/pigpio/pigpio-tests.ts | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/types/pigpio/index.d.ts b/types/pigpio/index.d.ts index ea9a312286..79d0ebe0f9 100644 --- a/types/pigpio/index.d.ts +++ b/types/pigpio/index.d.ts @@ -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; diff --git a/types/pigpio/pigpio-tests.ts b/types/pigpio/pigpio-tests.ts index a4679e57f9..90e7d4485d 100644 --- a/types/pigpio/pigpio-tests.ts +++ b/types/pigpio/pigpio-tests.ts @@ -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); +})();