pingo API
- class pingo.Board
- Abstract class defining common interface for all boards.
Instance attributes of interest to end-users:
- «board».pins
- A dict with physical pin locations as keys and Pin instances as values.
- «board».cleanup()
- This should be called to release the pins for other applications on some boards. It is called automatically when the script finishes.
Implementations of Board subclasses should:
- Call super(«BoardSubclass», self).__init__() and self._add_pins(«pins») in their __init__ method.
- Implement _set_pin_mode() and _set_pin_state().
- Override cleanup(), if the board needs it.
- filter_pins(*pin_types)
- Get a list of pins that are instances of the given pin_types
See the digital_pins property for an example of use.
- Arguments:
- pin_types: an iterable of types (usually, Pin subclasses)
- digital_pins
- [property] Get list of digital pins
- cleanup()
- Releases pins for use by other applications.
Overriding this stub may or may not be needed in specific drivers. For example, scripts running on boards using standard sysfs GPIO access should unexport the pins before exiting.
- _add_pins(pins)
- Populate board.pins mapping from Pin instances.
The __init__ method of concrete Board subclasses should call this method to populate the board instance pins mapping.
- Arguments:
- pins: an iterable of Pin instances
- _set_pin_mode(pin, mode)
- Abstract method to be implemented by each Board subclass.
The «pin».mode(…) property calls this method because the procedure to set pin mode changes from board to board.
- _set_pin_state(pin, state)
- Abstract method to be implemented by each Board subclass
The «pin».__change_state(…) method calls this method because the procedure to set pin state changes from board to board.
- class pingo.AnalogInputCapable
- Mixin interface for boards that support AnalogInputPin
Concrete AnalogInputCapable subclasses should implement _get_pin_value to read the values of analog pins.
- _get_pin_value(pin)
- Abstract method to be implemented by each Board subclass.
The «AnalogPin».value(…) method calls this method because the procedure to read pin analog signal changes from board to board.
- class pingo.Pin(board, location, gpio_id=None)
- Abstract class defining common interface for all pins.
- class pingo.DigitalPin(board, location, gpio_id=None)
- Defines common interface for all digital pins.
Implementers of board drivers do not need to subclass this class because pins delegate all board-dependent behavior to the board.
- mode
- [property] Get/set pin mode to pingo.IN or pingo.OUT
- state
- [property] Get/set pin state to pingo.HIGH or pingo.LOW
- low()
- Set voltage of pin to pingo.LOW (GND).
- lo()
- Set voltage of pin to pingo.LOW (GND).
- high()
- Set state of the pin to pingo.HIGH (Vcc).
- hi()
- Set state of the pin to pingo.HIGH (Vcc).
- class pingo.AnalogPin(board, location, resolution, gpio_id=None)
- Defines common interface for all analog pins.
Implementers of board drivers do not need to subclass this class because pins delegate all board-dependent behavior to the board.
This pin type supports read operations only.
- __init__(board, location, resolution, gpio_id=None)
-
Parameters: - board – the board to which this ping belongs
- location – the physical location of the pin on the board
- resolution – resolution of the AD converter in bits
- gpio_id – the logical id for GPIO access, if applicable
- value
- [property] Get pin value as an integer from 0 to 2 ** resolution – 1
- ratio(from_min=0, from_max=None, to_min=0.0, to_max=1.0)
- Get pin value as a float, by default from 0.0 to 1.0.
The from... and to... parameters work like in the Arduino map function, converting values from an expected input range to a desired output range.
- percent
- [property] Get pin value as a float from 0.0 to 100.0
Leave a Reply
You must be logged in to post a comment.