The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

RPi::WiringPi::Util - Utility methods for RPi::WiringPi Raspberry Pi interface

DESCRIPTION

WARNING: Until version 1.00 is released, the API and other functionality of this module may change, and things may break from time-to-time.

This module contains various utilities for RPi::WiringPi that don't necessarily fit anywhere else. It is a base class, and is not designed to be used independently.

METHODS

gpio_scheme()

Returns the current pin mapping in use. Returns "NULL" it has not yet been set, "WPI" if using wiringPi mapping, "BCM" for standard GPIO map and "PHYS" if using the physical pin map directly.

gpio_map($scheme)

Returns a hash reference in the following format:

    $map => {
        phys_pin_num => gpio_pin_num,
        ...
    };

If no scheme is in place, return will be an empty hash reference.

Parameters:

$scheme

Optional: By default, we'll check if you've already run a setup routine, and if so, we'll use the scheme currently in use. If one is not in use and no $scheme has been sent in, we'll use 'NULL', otherwise if a scheme is sent in, the return will be:

For 'WPI' scheme (wiringPi's numbering scheme):

    $map = {
        phys_pin_num => wiringPi_gpio_pin_num,
        ....
    };

For 'BCM' scheme (Broadcom's numbering scheme (printed on the board)):

    $map = {
        phys_pin_num => Broadcom_gpio_pin_num,
        ...
    };

pin_to_gpio($pin, $scheme)

Converts the specified pin from the specified scheme (WPI, PHYS, BCM) to the BCM number format.

If $scheme is not sent in, we'll attempt to fetch the scheme currently in use and use that.

Example:

    my $num = pin_to_gpio(6, 'WPI');

That will understand the pin number 6 to be the wiringPi representation, and will return the BCM representation.

export_pin($pin_num)

Exports a pin. Not needed if using the setup() initialization method.

Pin number must be the BCM pin number representation.

unexport_pin($pin_num)

Unexports a pin.

Pin number must be the BCM pin number representation.

registered_pins()

Returns an array of RPi::WiringPi::Pin objects that are currently registered, and deemed to be in use.

register_pin($pin_obj)

Registers a GPIO pin within the system for error checking, and proper resetting of the pins in use when required.

Parameters:

$pin_obj

Mandatory: An object instance of RPi::WiringPi::Pin class.

unregister_pin($pin_obj)

Exactly the opposite of register_pin().

ENVIRONMENT VARIABLES

There are certain environment variables available to aid in testing on non-Raspberry Pi boards.

NO_BOARD

Set to true, will bypass the wiringPi board checks. False will re-enable them.

IMPORTANT NOTES

- wiringPi must be installed prior to installing/using this module.
- By default, we use wiringPi's interpretation of GPIO pin mapping. See new method to change this behaviour.
- This module hijacks fatal errors with $SIG{__DIE__}, as well as $SIG{INT}. This is so that in the case of a fatal error, the Raspberry Pi pins are never left in an inconsistent state. By default, we trap the die(), reset all pins to their default (INPUT, LOW), then we exit(). Look at the fatal_exit param in new() to change the behaviour.

cleanup()

Resets all registered pins back to default settings (off). It's important that this method be called in each application.

AUTHOR

Steve Bertrand, <steveb@cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2016 by Steve Bertrand

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.18.2 or, at your option, any later version of Perl 5 you may have available.