An digital input connected to a pin a PiFace product.
Note
This hides the fact that inputs are active low.
>>> input_port = pifacecommon.core.GPIOB
>>> pifacecommon.core.read_bit(0, input_port)
1
>>> hex(pifacecommon.core.DigitalInputItem(0, input_port).value)
0
The inverse value of the digital input item (inputs are active low).
An digital input port on a PiFace product.
Note
This hides the fact that inputs are active low.
>>> input_port = pifacecommon.core.GPIOB
>>> hex(pifacecommon.core.read(input_port))
'0xFF'
>>> hex(pifacecommon.core.DigitalInputPort(input_port).value)
'0x00'
The value of the digital input port.
A digital item connected to a pin on a PiFace product. Has most of the same properties of a Digital Port.
The value of the digital item.
An output connected to a pin a PiFace Digital product.
Toggles the digital output item’s value.
Sets the digital output item’s value to 0.
Sets the digital output item’s value to 1.
An digital output port on a PiFace product
Turns all outputs off.
Turns all outputs on.
Toggles all outputs.
A digital port on a PiFace product.
The module that handles this port (can be useful for emulator/testing).
The value of the digital port.
Closes the SPI device file descriptor.
Translates a bit num to bit mask.
Parameters: | bit_num (int) – The bit number. |
---|---|
Returns: | int – the bit mask |
Raises : | RangeError |
>>> 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
Initialises the SPI device file descriptor.
Parameters: |
|
---|---|
Raises : | InitError |
Returns the value of the address specified.
Parameters: |
---|
Returns the bit specified from the address.
Parameters: | |
---|---|
Returns: | int – the bit value from the address |
Sleeps for the given number of microseconds.
Parameters: | microseconds (int) – Number of microseconds to sleep for. |
---|
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 |
Writes data to the address specified.
Parameters: |
---|
Writes the value given to the bit in the address specified.
Parameters: |
---|
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).
An interrupt event.
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.core.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: |
---|
Clears the interrupt flags by ‘read’ing the capture register on all boards.
Disables interrupts on the port specified.
Parameters: | port (int) – The port to enable interrupts on (pifacecommon.core.GPIOA, pifacecommon.core.GPIOB) |
---|
Enables interrupts on the port specified.
Parameters: | port (int) – The port to enable interrupts on (pifacecommon.core.GPIOA, pifacecommon.core.GPIOB) |
---|
Waits for events on the event queue and calls the registered functions.
Parameters: |
|
---|
Waits for a port event. When a port event occurs it is placed onto the event queue.
Parameters: |
|
---|