pixtendv2core (version 0.1.0) | index /home/pi/pplv2/pixtendv2core/__init__.py

`# coding=utf-8`

Package Contents

``

Classes

``

__builtin__.object
  PiXtendV2Core

class PiXtendV2Core(__builtin__.object)

``

`The PiXtendV2 base class can be used to build PiXtend V2 modules, which use the same code base, thus reducing
code multiplication. This class implements the most basic functions, properties and infrastructure needed to
create a PiXtend V2 module in Python. This class cannot run on its own, it needs to be inherited by a child
class and the functions '_pack_spi_data' and '_unpack_spi_data' have to be implemented there as these are
defined as abstract functions and cannot be used directly.
Furthermore, for the SPI data transfer to work correctly, the child class needs to implement a list[int] variable
which holds the data which is sent to the microcontroller. The needed list[int] length can be found in the
SPI protocol specification of the PiXtend V2 board.
`

Methods defined here:

__del__(self)
  `Destructor of the Pixtend V2 class. Delete objects.`

__init__(self, spi_speed=700000, com_interval=0.03, model=0)
  `Constructor of the PixtendV2 base class. Setup SPI communication, base variables and start
  the cyclic communication using a timer from the threading module.
  :param spi_speed: int
  :param com_interval: float
  :param model: int`

set_dac_output(self, dac_channel=0, value=0)
  `Set the analog output value for the chosen DAC. The value 0 or constant DAC_A selects DAC A and the value 1 or
  constant DAC_B selects DAC B.
  Example:
  Selecting and setting DAC A:
  p.set_dac_output (p.DAC_A, 512)
  Selecting and setting DAC B:
  p.set_dac_output (p.DAC_B, 256)
  :param int dac_channel: Number of the DAC to set the new value to
  :param int value: Output value for the chosen DAC.
  :raises ValueError: If value is smaller then 0 or larger then 1023`

Static methods defined here:

clear_bit(int_type, offset)
  `clear_bit() returns an integer with the bit at 'offset' cleared, set to 0.
  :param int int_type: Integer value in which to clear one bit
  :param int offset: Offset value which bit to clear
  :return: Integer with bit cleared a 'offset'
  :rtype: int`

set_bit(int_type, offset)
  `set_bit() returns an integer with the bit at 'offset' set to 1.
  :param int int_type: Integer value in which to set one bit
  :param int offset: Offset value which bit to set
  :return: Integer with bit set at 'offset'
  :rtype: int`

test_bit(int_type, offset)
  `test_bit() returns 1, if the bit at 'offset' is one else 0 if the bit is not set.
  :param int int_type: Integer value to test
  :param int offset: Offset value which bit to test
  :return: Integer based value of 0 if bit at 'offset' is not set or 1 if bit is set
  :rtype: int`

toggle_bit(int_type, offset)
  `toggle_bit() returns an integer with the bit at 'offset' inverted, 0 -> 1 and 1 -> 0.
  :param int int_type: Integer value to toggle one bit within
  :param int offset: Offset value which bit to toggle
  :return: integer with bit toggled at 'offset'
  :rtype: int`

Data descriptors defined here:

__dict__
  `dictionary for instance variables (if defined)`

__weakref__
  `list of weak references to the object (if defined)`

crc_header_in_error
  `Get the error state of the CRC check performed on the SPI data header. If the CRC comparision is wrong
  the value will be True, if the header of the SPI data is correct, the value will be False.
  :return: Current value, False means no error, True means the header is not correct, error
  :rtype: bool`

firmware
  `Get the microcontroller's firmware version.
  :return: Current value
  :rtype: int`

gpio0
  `Get or Set the state of GPIO 0. The value False means 'off' and a value of True means 'on'.
  Example:
  p.gpio0 = p.ON # Turns the GPIO on
  p.gpio0 = p.OFF # Turns the GPIO off
  or use
  p.gpio0 = True # Turns the GPIO on
  p.gpio0 = False # Turns the GPIO off
  :return: Current value
  :rtype: bool`

gpio0_ctrl
  `Get or Set the configuration of GPIO 0. Possible values are 0 (Input), 1 (Output), 2 (DHT11) or 3 (DHT22).
  :return: Current configuration
  :rtype: int
  :raises ValueError: If the passed value is not 0, 1, 2 or 3`

gpio1
  `Get or Set the state of GPIO 1. The value False means 'off' and a value of True means 'on'.
  Example:
  p.gpio1 = p.ON # Turns the GPIO on
  p.gpio1 = p.OFF # Turns the GPIO off
  or use
  p.gpio1 = True # Turns the GPIO on
  p.gpio1 = False # Turns the GPIO off
  :return: Current value
  :rtype: bool`

gpio1_ctrl
  `Get or Set the configuration of GPIO 1. Possible values are 0 (Input), 1 (Output), 2 (DHT11) or 3 (DHT22).
  :return: Current configuration
  :rtype: int
  :raises ValueError: If the passed value is not 0, 1, 2 or 3`

gpio2
  `Get or Set the state of GPIO 2. The value False means 'off' and a value of True means 'on'.
  Example:
  p.gpio2 = p.ON # Turns the GPIO on
  p.gpio2 = p.OFF # Turns the GPIO off
  or use
  p.gpio2 = True # Turns the GPIO on
  p.gpio2 = False # Turns the GPIO off
  :return: Current value
  :rtype: bool`

gpio2_ctrl
  `Get or Set the configuration of GPIO 2. Possible values are 0 (Input), 1 (Output), 2 (DHT11) or 3 (DHT22).
  :return: Current configuration
  :rtype: int
  :raises ValueError: If the passed value is not 0, 1, 2 or 3`

gpio3
  `Get or Set the state of GPIO 3. The value False means 'off' and a value of True means 'on'.
  Example:
  p.gpio3 = p.ON # Turns the GPIO on
  p.gpio3 = p.OFF # Turns the GPIO off
  or use
  p.gpio3 = True # Turns the GPIO on
  p.gpio3 = False # Turns the GPIO off
  :return: Current value
  :rtype: bool`

gpio3_ctrl
  `Get or Set the configuration of GPIO 3. Possible values are 0 (Input), 1 (Output), 2 (DHT11) or 3 (DHT22).
  :return: Current configuration
  :rtype: int
  :raises ValueError: If the passed value is not 0, 1, 2 or 3`

gpio_pullups_enable
  `Enable or Disable the GPIO 0-3 pullups if the GPIOs are configured as outputs and the pullups are needed.
  Setting this property to True enables the pullups, if it is set to False the pullups remain off.
  :return: Current value
  :rtype: bool`

hardware
  `Get the PiXtend V2 hardware revision.
  :return: Current value
  :rtype: int`

hum_input0_raw
  `Get the humidity raw value from humidity input 0.
  :return: Current value
  :rtype: int`

hum_input1_raw
  `Get the humidity raw value from humidity input 1.
  :return: Current value
  :rtype: int`

hum_input2_raw
  `Get the humidity raw value from humidity input 2.
  :return: Current value
  :rtype: int`

hum_input3_raw
  `Get the humidity raw value from humidity input 3.
  :return: Current value
  :rtype: int`

humid0
  `Get the converted humidity value from humidity input 0 if a DHT11/DHT22 sensor is physically attached.
  :return: Current value
  :rtype: float`

humid1
  `Get the converted humidity value from humidity input 1 if a DHT11/DHT22 sensor is physically attached.
  :return: Current value
  :rtype: float`

humid2
  `Get the converted humidity value from humidity input 2 if a DHT11/DHT22 sensor is physically attached.
  :return: Current value
  :rtype: float`

humid3
  `Get the converted humidity value from humidity input 3 if a DHT11/DHT22 sensor is physically attached.
  :return: Current value
  :rtype: float`

model_in
  `Get the PiXtend V2 model information from the microcontroller.
  :return: Current value
  :rtype: int`

model_in_error
  `Get the result of the comparison between the configured model, supplied by the child class through the init
  function (constructor) when the object is created, and the reported model by the microcontroller.
  If the configured model and the reported model match, the value will be False,
  if they don't match, the value will be True and signifies an error.
  :return: Current value, False means no error, True means the reported model does not match
  :rtype: bool`

retain_copy
  `Get or Set the microcontroller's Retain memory option to copy incoming data to the outgoing data
  stream. This way the data which will be stored on the microcontroller, in the event of a sudden power loss,
  can be verified that the data really reaches the microcontroller and that values are correct. This option is
  mainly intended for debugging, but can be used by anyone.
  :return: Current value
  :rtype: bool
  :raises ValueError: If the passed value is not True or False`

retain_enable
  `Get or Set the microcontroller's Retain memory option to enabled. With this option active a specified amount of
  data will be stored in the microcontroller's flash memory in the event of a sudden power loss. The exact amount
  of int's/bytes which a PiXtend V2 board can store can be found in the SPI protocol specifications.
  :return: Current value
  :rtype: bool
  :raises ValueError: If the passed value is not True or False`

save_state
  `Get or Set the microcontroller's SaveState bit in case the computer has to shutdown or needs to reboot.
  Settings this property to True will halt the microcontroller and a reset is needed in order to start any
  communication again.
  :return: Current value
  :rtype: bool
  :raises ValueError: If the passed value is not True or False`

state_led_off
  `Get or Set if the State LED (L1) on the PiXtend V2 board is on or off.
  True turns the LED off and False leave the State LED (L1) on.
  :return: Current value
  :rtype: bool
  :raises ValueError: If the passed value is not True or False`

temp0
  `Get the converted temperature value from temperature input 0 from a DHT11 or DHT22 sensor.
  :return: Current value
  :rtype: float`

temp1
  `Get the converted temperature value from temperature input 1 from a DHT11 or DHT22 sensor.
  :return: Current value
  :rtype: float`

temp2
  `Get the converted temperature value from temperature input 2 from a DHT11 or DHT22 sensor.
  :return: Current value
  :rtype: float`

temp3
  `Get the converted temperature value from temperature input 3 from a DHT11 or DHT22 sensor.
  :return: Current value
  :rtype: float`

temp_input0_raw
  `Get the temperature raw value from temperature input 0.
  :return: Current value
  :rtype: int`

temp_input1_raw
  `Get the temperature raw value from temperature input 1.
  :return: Current value
  :rtype: int`

temp_input2_raw
  `Get the temperature raw value from temperature input 2.
  :return: Current value
  :rtype: int`

temp_input3_raw
  `Get the temperature raw value from temperature input 3.
  :return: Current value
  :rtype: int`

uc_state
  `The UCSate byte from the microcontroller contains information of the following internal states:
  Bit 0: Run - The microcontroller is up and running, this is just a helper bit
  Bit 4: Error0 - Bit 0 of the 4 bit error number from the microcontroller. Together with the next 3
  Bit 5: Error1 - bits a 4 bit number can be formed which results in an error number which is
  Bit 6: Error2 - listed in the SPI protocol specification or the software manual.
  Bit 7: Error3
  :return: Current value
  :rtype: int`

uc_warnings
  `The UCWarnings byte from the microcontroller contains information of the following internal errors:
  Bit 1: RetainCRCError - Signals a CRC error in the retain data in the microcontroller
  Bit 2: RetainVoltageError - The supply voltage is below 19 volts, the Retain memory option cannot be used.
  :return: Current value
  :rtype: int`

use_fahrenheit
  `Get or Set if the conversion of the temperature raw value should be done in Fahrenheit.
  Default is 'False', meaning by getting the temperature from temp0 to temp3
  the value will be in degrees Celsius, if set to 'True' the values will be in Fahrenheit.
  :returns: Bool value, 'False' for Celsius and 'True' for Fahrenheit
  :rtype: bool`

watchdog
  `Get or Set the PiXtend V2 watchdog option. WDT_OFF or 0 ms means the watchdog is disabled. One of the
  following time values 16 ms, 32 ms, 64 ms, 125 ms, 250 ms, 500 ms, 1000 ms (1s), 2000 ms (2s), 4000 ms (4s)
  and 8000 ms (8s) turns the watchdog function in the microcontroller on. If no SPI communication occurs within
  this time frame, the microcontroller will stop working and goes into save state. Only a reset or power cycle
  will bring it back to life once it has entered this stage.
  :return: Current value
  :rtype: int
  :raises ValueError: If the passed value is not one of the following: 16, 32, 64, 125, 250, 500, 1000,
  2000, 4000 or 8000`

Data and other attributes defined here:

BIT_0 = 0

BIT_1 = 1

BIT_10 = 10

BIT_11 = 11

BIT_12 = 12

BIT_13 = 13

BIT_14 = 14

BIT_15 = 15

BIT_2 = 2

BIT_3 = 3

BIT_4 = 4

BIT_5 = 5

BIT_6 = 6

BIT_7 = 7

BIT_8 = 8

BIT_9 = 9

COM_INTERVAL_DEFAULT = 0.03

COM_INTERVAL_DHT = 0.03

COM_INTERVAL_MINIMUM = 0.01

DAC_A = 0

DAC_B = 1

DHT11 = 0

DHT22 = 1

GPIO_DHT11 = 2

GPIO_DHT22 = 3

GPIO_INPUT = 0

GPIO_OUTPUT = 1

JUMPER_10V = 1

JUMPER_5V = 0

MC_RESET_PIN = 23

OFF = False

ON = True

PIXTENDV2S_MODEL = 83

PWM_MODE = 1

RS232 = 0

RS485 = 0

SERVO_MODE = 0

SPI_ENABLE_PIN = 24

SPI_NOT_FOUND = -1

SPI_SPEED = 700000

WDT_125MS = 125

WDT_16MS = 16

WDT_1S = 1000

WDT_250MS = 250

WDT_2S = 2000

WDT_32MS = 32

WDT_4S = 4000

WDT_500MS = 500

WDT_64MS = 64

WDT_8S = 8000

WDT_OFF = 0

__abstractmethods__ = frozenset(['_pack_spi_data', '_unpack_spi_data'])

__metaclass__ = <class 'abc.ABCMeta'>
  `Metaclass for defining Abstract Base Classes (ABCs).
  Use this metaclass to create an ABC. An ABC can be subclassed
  directly, and then acts as a mix-in class. You can also register
  unrelated concrete classes (even built-in classes) and unrelated
  ABCs as 'virtual subclasses' -- these and their descendants will
  be considered subclasses of the registering ABC by the built-in
  issubclass() function, but the registering ABC won't show up in
  their MRO (Method Resolution Order) nor will method
  implementations defined by the registering ABC be callable (not
  even via super()).`

Data
`` |  | __author__ = 'Robin Turner' __version__ = '0.1.0'

Author
`` |  | Robin Turner