Module: caf_rpi_gpio/proxy_iot_gpio

A proxy to read/write GPIO ports in a Raspberry PI.

Source:

Extends

Methods

getPinConfig() → {caf.pinConfig}

Gets the configuration of active GPIO pins.

The type caf.pinConfig is:

{ pinNumber : {
      input: boolean,
      initialState: {high: boolean}=,
      internalResistor: {pullUp: boolean}=,
      watcher: caf.watcherConfig=
   }
}

where pin numbers use physical layout by default, and initialState only applies if input is false.

Missing pins have a default configuration of (input, no resistor).

caf.watcherConfig described in setWatcher

Source:
See:
Returns:

The configuration of active pins.

Type
caf.pinConfig

readAll() → {Object.<pin, boolean>}

Reads the value of all the pins configured as inputs.

Source:
Returns:

Values of input pins. True is HIGH, false is LOW, and pin numbers use physical layout by default.

Type
Object.<pin, boolean>

setPinConfig(config)

Sets a new pin configuration.

Pins that were already set in the desired input/output mode are not reset, i.e., initialState or internalResistor fields are ignored.

If reset is needed, call setPinConfig twice:

  • First call with the pins to reset deleted, which are then given a default configuration (input, no resistor)
  • Second call with the desired config.
Parameters:
Name Type Description
config caf.pinConfig

A new pin configuration.

Source:

setWatcher(pin, watcherConfig)

Sets a watcher that will invoke a method when a particular pin changes state.

It replaces a previous watcher for that pin (if different setup).

The type caf.watcherConfig is:

 { triggerLow: boolean, triggerHigh: boolean, methodName: string,
   debounceMsec: number=}

where:

  • triggerLow: True if transitions to LOW state should activate the watcher.

  • triggerHigh: True if transitions to HIGH state should activate the watcher.

  • methodName: The name of the method used for notifications. It should have a signature of the form function(pin:number, newValue: boolean, cb:caf.cb) and call cb after finish processing.

  • debounceMsec: Time interval after a notification in which any other notification for that pin gets ignored.

Parameters:
Name Type Description
pin number

A pin number to be watched (physical layout by default).

watcherConfig caf.watcherConfig

Configuration for the new watcher.

Source:
Throws:

Error if pin not exported.

unsetWatcher(pin)

Unsets a watcher that will invoke a method when a particular pin changes state.

It does nothing if there was no watcher, or pin was not exported.

Parameters:
Name Type Description
pin number

A pin number to be unwatched (physical layout by default).

Source:

writeMany(newValues)

Writes values for the given pins configured as outputs.

Parameters:
Name Type Description
newValues Object.<pin, boolean>

New values for output pins.

Source:
Throws:

Error If pin not in OUTPUT mode or not configured.