Returns as bit mask with bit_num set.
Parameters: | bit_num (int) – The bit number. |
---|---|
Returns: | int – the bit mask |
Raises : | RangeError |
>>> bin(pifacecommon.core.get_bit_mask(0))
1
>>> pifacecommon.core.get_bit_mask(1)
2
>>> bin(pifacecommon.core.get_bit_mask(3))
'0b1000'
Returns the lowest bit num from a given bit pattern. Returns None if no bits set.
Parameters: | bit_pattern (int) – The bit pattern. |
---|---|
Returns: | int – the bit number |
Returns: | None – no bits set |
>>> pifacecommon.core.get_bit_num(0)
None
>>> pifacecommon.core.get_bit_num(0b1)
0
>>> pifacecommon.core.get_bit_num(0b11000)
3
An SPI Device at /dev/spi<bus>.<chip_select>.
Sends bytes via the SPI bus.
Parameters: | bytes_to_send (bytes) – The bytes to send on the SPI device. |
---|---|
Returns: | bytes – returned bytes from SPI device |
Raises : | InitError |
Stores events in a queue.
Adds events to the queue. Will ignore events that occur before the settle time for that pin/direction. Such events are assumed to be bouncing.
Maps something to a callback function. (This is an abstract class, you must implement a SomethingFunctionMap).
A device that interrupts using the GPIO pins.
Disables gpio interrupts.
Enables GPIO interrupts.
An interrupt event containting the interrupt flag and capture register values, the chip object from which the interrupt occured and a timestamp.
Maps an IO pin and a direction to callback function.
Listens for port events and calls the registered functions.
>>> def print_flag(event):
... print(event.interrupt_flag)
...
>>> port = pifacecommon.mcp23s17.GPIOA
>>> listener = pifacecommon.interrupts.PortEventListener(port)
>>> listener.register(0, pifacecommon.interrupts.IODIR_ON, print_flag)
>>> listener.activate()
When activated the PortEventListener will run callbacks associated with pins/directions.
When deactivated the PortEventListener will not run anything.
Registers a pin number and direction to a callback function.
Parameters: |
---|
Bring the interrupt pin on the GPIO into Linux userspace.
Remove the GPIO interrupt pin from Linux userspace.
Waits for events on the event queue and calls the registered functions.
Parameters: |
|
---|
Set the interrupt edge on the userspace GPIO pin.
Parameters: | edge (string) – The interrupt edge (‘none’, ‘falling’, ‘rising’). |
---|
Wait until a file exists.
Parameters: | filename (string) – The name of the file to wait for. |
---|
Waits for a port event. When a port event occurs it is placed onto the event queue.
Parameters: |
|
---|
Consult the datasheet for more information.
Microchip’s MCP23S17: A 16-Bit I/O Expander with Serial Interface.
Attribute : | iodira/iodirb – Controls the direction of the data I/O. |
---|---|
Attribute : | ipola/ipolb –This register allows the user to configure the polarity on the corresponding GPIO port bits. |
Attribute : | gpintena/gpintenb – The GPINTEN register controls the interrupt-onchange feature for each pin. |
Attribute : | defvala/defvalb –The default comparison value is configured in the DEFVAL register. |
Attribute : | intcona/intconb –The INTCON register controls how the associated pin value is compared for the interrupt-on-change feature. |
Attribute : | iocon –The IOCON register contains several bits for configuring the device. |
Attribute : | gppua/gppub –The GPPU register controls the pull-up resistors for the port pins. |
Attribute : | intfa/intfb –The INTF register reflects the interrupt condition on the port pins of any pin that is enabled for interrupts via the GPINTEN register. |
Attribute : | intcapa/intcapb – The INTCAP register captures the GPIO port value at the time the interrupt occurred. |
Attribute : | gpioa/gpiob – The GPIO register reflects the value on the port. |
Attribute : | olata/olatb – The OLAT register provides access to the output latches. |
Clears the interrupt flags by ‘read’ing the capture register.
Returns the value of the address specified.
Parameters: | address (int) – The address to read from. |
---|
Returns the bit specified from the address.
Parameters: | |
---|---|
Returns: | int – the bit value from the address |
Writes data to the address specified.
Parameters: |
---|
An 8-bit register inside an MCP23S17.
Base class for objects on an 8-bit register inside an MCP23S17.
A bit inside register inside an MCP23S17.
A negated bit inside register inside an MCP23S17.
An negated 8-bit register inside an MCP23S17.
An 4-bit nibble inside a register inside an MCP23S17.
A negated 4-bit nibble inside a register inside an MCP23S17.