Ejemplo n.º 1
0
def get_default_bus():
    """Return the default bus number based on the device platform.  For a
    Raspberry Pi either bus 0 or 1 (based on the Pi revision) will be returned.
    For a Beaglebone Black the first user accessible bus, 1, will be returned.
    """
    plat = Platform.platform_detect()
    if plat == Platform.RASPBERRY_PI:
        if Platform.pi_revision() == 1:
            # Revision 1 Pi uses I2C bus 0.
            return 0
        else:
            # Revision 2 Pi uses I2C bus 1.
            return 1
    elif plat == Platform.BEAGLEBONE_BLACK:
        # Beaglebone Black has multiple I2C buses, default to 1 (P9_19 and P9_20).
        return 1
    elif plat == Platform.CHIP:
        # CHIP has 2 user accessible I2C busses, default to 2 (U1425 and U14_26)
        # We want the CHIP to default to 2 as the PocketCHIP header breaks out
        # this interface
        # But, the CHIP Pro defaults to bus 1
        import CHIP_IO.Utilities as UT
        if UT.is_chip_pro():
            return 1
        else:
            return 2
    else:
        raise RuntimeError('Could not determine default I2C bus for platform.')
	def test_revision_1(self):
		with patch('__builtin__.open') as mock_open:
			handle = mock_open.return_value.__enter__.return_value
			handle.__iter__.return_value = iter(['Revision : 0002'])
			rev = Platform.pi_revision()
			self.assertEquals(rev, 1)
		with patch('__builtin__.open') as mock_open:
			handle = mock_open.return_value.__enter__.return_value
			handle.__iter__.return_value = iter(['Revision : 0003'])
			rev = Platform.pi_revision()
			self.assertEquals(rev, 1)
Ejemplo n.º 3
0
 def test_revision_1(self):
     with patch('__builtin__.open') as mock_open:
         handle = mock_open.return_value.__enter__.return_value
         handle.__iter__.return_value = iter(['Revision : 0002'])
         rev = Platform.pi_revision()
         self.assertEquals(rev, 1)
     with patch('__builtin__.open') as mock_open:
         handle = mock_open.return_value.__enter__.return_value
         handle.__iter__.return_value = iter(['Revision : 0003'])
         rev = Platform.pi_revision()
         self.assertEquals(rev, 1)
Ejemplo n.º 4
0
def get_default_bus():
    """Return the default bus number based on the device platform.  For a
    Raspberry Pi either bus 0 or 1 (based on the Pi revision) will be returned.
    """
    plat = Platform.platform_detect()
    if plat == Platform.RASPBERRY_PI:
        if Platform.pi_revision() == 1:
            # Revision 1 Pi uses I2C bus 0.
            return 0
        else:
            # Revision 2 Pi uses I2C bus 1.
            return 1
    else:
        raise RuntimeError('Could not determine default I2C bus for platform.')
Ejemplo n.º 5
0
	def __init__(self, dc, spi, rst=None, gpio=None, width=ILI9341_TFTWIDTH,
		height=ILI9341_TFTHEIGHT):
		"""Create an instance of the display using SPI communication.  Must
		provide the GPIO pin number for the D/C pin and the SPI driver.  Can
		optionally provide the GPIO pin number for the reset pin as the rst
		parameter.
		"""
		self._dc = dc
		self._rst = rst
		self._spi = spi
		self._gpio = gpio
		self.width = width
		self.height = height
		if self._gpio is None:
			self._gpio = GPIO.get_platform_gpio()
		# Set DC as output.
		self._gpio.setup(dc, GPIO.OUT)
		# Setup reset as output (if provided).
		if rst is not None:
			self._gpio.setup(rst, GPIO.OUT)
		# Set SPI to mode 0, MSB first.
		spi.set_mode(0)
		spi.set_bit_order(SPI.MSBFIRST)
	
                # Clock nerfed for the Minnowboard	
                if(Platform.platform_detect() == 3):
                    spi.set_clock_hz(1000000)
                else:
                    spi.set_clock_hz(64000000)
		
                # Create an image buffer.
		self.buffer = Image.new('RGB', (width, height))
Ejemplo n.º 6
0
def get_platform_gpio(**keywords):
    """Attempt to return a GPIO instance for the platform which the code is being
    executed on.  Currently supports only the Raspberry Pi using the RPi.GPIO
    library and Beaglebone Black using the Adafruit_BBIO library.  Will throw an
    exception if a GPIO instance can't be created for the current platform.  The
    returned GPIO object is an instance of BaseGPIO.
    """

    print "GPIO.py get_platform_gpio()"




    plat = Platform.platform_detect()
    if plat == Platform.RASPBERRY_PI:
        import RPi.GPIO
        return RPiGPIOAdapter(RPi.GPIO, **keywords)
    #elif plat == Platform.BEAGLEBONE_BLACK:
        #import Adafruit_BBIO.GPIO
        #return AdafruitBBIOAdapter(Adafruit_BBIO.GPIO, **keywords)
    #elif plat == Platform.MINNOWBOARD:
        #import mraa
        #return AdafruitMinnowAdapter(mraa, **keywords)
    elif plat == Platform.UNKNOWN:
        raise RuntimeError('Could not determine platform.')
Ejemplo n.º 7
0
def get_platform_pwm(**keywords):
    """Attempt to return a PWM instance for the platform which the code is being
    executed on.  Currently supports only the Raspberry Pi using the RPi.GPIO
    library and Beaglebone Black using the Adafruit_BBIO library.  Will throw an
    exception if a PWM instance can't be created for the current platform.  The
    returned PWM object has the same interface as the RPi_PWM_Adapter and
    BBIO_PWM_Adapter classes.
    """
    plat = Platform.platform_detect()
    if plat == Platform.RASPBERRY_PI:
        import RPi.GPIO
        return RPi_PWM_Adapter(RPi.GPIO, **keywords)
    elif plat == Platform.BEAGLEBONE_BLACK:
        import Adafruit_BBIO.PWM
        return BBIO_PWM_Adapter(Adafruit_BBIO.PWM, **keywords)
    elif plat == Platform.CHIP:
        if "pwmtype" in keywords.keys():
            if keywords["pwmtype"] == "pwm":
                import CHIP_IO.PWM
                return CHIP_PWM_Adapter(CHIP_IO.PWM)
            elif keywords["pwmtype"] == "softpwm":
                import CHIP_IO.SOFTPWM
                return CHIP_PWM_Adapter(CHIP_IO.SOFTPWM)
        else:
            raise ValueError('For CHIP, you need to specify pwmtype in argument with value pwm or softpwm: get_platform_pwm(pwmtype="pwm") or get_platform_type(pwmtype="softpwm")')
    elif plat == Platform.UNKNOWN:
        raise RuntimeError('Could not determine platform.')
Ejemplo n.º 8
0
	def __init__(self, dc, spi, rst=None, gpio=None, width=HX8357_TFTWIDTH,
		height=HX8357_TFTHEIGHT):
		"""Create an instance of the display using SPI communication.  Must
		provide the GPIO pin number for the D#C pin and the SPI driver.  Can
		optionally provide the GPIO pin number for the reset pin as the rst
		parameter.
		"""
		self._dc = dc
		self._rst = rst
		self._spi = spi
		self._gpio = gpio
		self.width = width
		self.height = height
		if self._gpio is None:
			self._gpio = GPIO.get_platform_gpio()
		# Set DC as output.
		self._gpio.setup(dc, GPIO.OUT)
		# Setup reset as output (if provided).
		if rst is not None:
			self._gpio.setup(rst, GPIO.OUT)
		# Set SPI to mode 0, MSB first.
		spi.set_mode(0)
		spi.set_bit_order(SPI.MSBFIRST)
                
                #need to nerf the clock for Minnow
                if(Platform.platform_detect() == 3): 
		    spi.set_clock_hz(16000000)
                    print 'Rate: MAX'
                else:
                    spi.set_clock_hz(64000000)
                    print 'Rate: 64hz'

		# Create an image buffer.
		self.buffer = Image.new('RGB', (width, height))
Ejemplo n.º 9
0
def main():
    print "RUNNING ACCELEROMETER TEST"
    if (detect_device()):
        return
    set_full_res(1)
    set_range(RANGE_8G)
    set_rate(BW_50)
    set_accelerometer_sensitivity()
    device_start()
    calibrate()
    disable_interrupts()
    set_interrupt_level(INT_ACT_LOW)
    gpio = GPIO.get_platform_gpio()

    #checking for the CHIP platform#
    if (5 == Platform.platform_detect()):
        print "CHIP platform running\n"
    else:
        print "Not running on CHIP device\n"
        exit()

    fifo_int_pin = "PWM1"
    #set AP-EINT1n as the interrupt pin#
    gpio.setup(fifo_int_pin, GPIO.IN)
    print "#", gpio.input(fifo_int_pin)
    #add a callback fn() for falling event on fifo_interrupt#
    gpio.add_event_detect(fifo_int_pin, GPIO.FALLING)
    gpio.add_event_callback(fifo_int_pin, fifo_overflow_handle)
    set_interrupt(INT_ENABLE_WATERMARK, 1)
    if (is_interrupt_enable(INT_ENABLE_WATERMARK)):
        print "int enabled"
    enable_fifo_mode(FIFO_STREAM, FIFO_SAMPLES)
    while 1:
        pass
Ejemplo n.º 10
0
def get_platform_pwm(**keywords):
    """Attempt to return a PWM instance for the platform which the code is being
    executed on.  Currently supports only the Raspberry Pi using the RPi.GPIO
    library and Beaglebone Black using the Adafruit_BBIO library.  Will throw an
    exception if a PWM instance can't be created for the current platform.  The
    returned PWM object has the same interface as the RPi_PWM_Adapter and
    BBIO_PWM_Adapter classes.
    """
    plat = Platform.platform_detect()
    if plat == Platform.RASPBERRY_PI:
        import RPi.GPIO
        return RPi_PWM_Adapter(RPi.GPIO, **keywords)
    elif plat == Platform.BEAGLEBONE_BLACK:
        import Adafruit_BBIO.PWM
        return BBIO_PWM_Adapter(Adafruit_BBIO.PWM, **keywords)
    elif plat == Platform.CHIP:
        if "pwmtype" in keywords.keys():
            if keywords["pwmtype"] == "pwm":
                import CHIP_IO.PWM
                return CHIP_PWM_Adapter(CHIP_IO.PWM)
            elif keywords["pwmtype"] == "softpwm":
                import CHIP_IO.SOFTPWM
                return CHIP_PWM_Adapter(CHIP_IO.SOFTPWM)
        else:
            raise ValueError(
                'For CHIP, you need to specify pwmtype in argument with value pwm or softpwm: get_platform_pwm(pwmtype="pwm") or get_platform_type(pwmtype="softpwm")'
            )
    elif plat == Platform.UNKNOWN:
        raise RuntimeError('Could not determine platform.')
Ejemplo n.º 11
0
def get_platform_gpio(**keywords):
    """Attempt to return a GPIO instance for the platform which the code is being
    executed on.  Currently supports only the Orange Pi and the Raspberry Pi using 
    the RPi.GPIO library and Beaglebone Black using the Adafruit_BBIO library.  
    Will throw an exception if a GPIO instance can't be created for the current platform.  
    The returned GPIO object is an instance of BaseGPIO.
    """
    plat = Platform.platform_detect()
    if plat == Platform.RASPBERRY_PI:
        import RPi.GPIO
        return RPiGPIOAdapter(RPi.GPIO, **keywords)
    elif plat == Platform.ORANGE_PI:
        import OPi.GPIO
        return OPiGPIOAdapter(OPi.GPIO, **keywords)
    elif plat == Platform.BEAGLEBONE_BLACK:
        import Adafruit_BBIO.GPIO
        return AdafruitBBIOAdapter(Adafruit_BBIO.GPIO, **keywords)
    elif plat == Platform.MINNOWBOARD:
        import mraa
        return AdafruitMinnowAdapter(mraa, **keywords)
    elif plat == Platform.JETSON_NANO:
        import Jetson.GPIO
        return RPiGPIOAdapter(Jetson.GPIO, **keywords)
    elif plat == Platform.UNKNOWN:
        raise RuntimeError('Could not determine platform.')
Ejemplo n.º 12
0
def get_default_bus():
    """Return the default bus number based on the device platform.  For a
    Raspberry Pi either bus 0 or 1 (based on the Pi revision) will be returned.
    For a Beaglebone Black the first user accessible bus, 1, will be returned.
    """
    plat = Platform.platform_detect()
    if plat == Platform.RASPBERRY_PI:
        if Platform.pi_revision() == 1:
            # Revision 1 Pi uses I2C bus 0.
            return 0
        else:
            # Revision 2 Pi uses I2C bus 1.
            return 1
    elif plat == Platform.BEAGLEBONE_BLACK:
        # Beaglebone Black has multiple I2C buses, default to 1 (P9_19 and P9_20).
        return 1
    else:
        raise RuntimeError('Could not determine default I2C bus for platform.')
Ejemplo n.º 13
0
def get_default_bus():
    """Return the default bus number based on the device platform.  For a
    Raspberry Pi either bus 0 or 1 (based on the Pi revision) will be returned.
    For a Beaglebone Black the first user accessible bus, 1, will be returned.
    """
    plat = Platform.platform_detect()
    if plat == Platform.RASPBERRY_PI:
        if Platform.pi_revision() == 1:
            # Revision 1 Pi uses I2C bus 0.
            return 0
        else:
            # Revision 2 Pi uses I2C bus 1.
            return 1
    elif plat == Platform.BEAGLEBONE_BLACK:
        # Beaglebone Black has multiple I2C buses, default to 1 (P9_19 and P9_20).
        return 1
    else:
        raise RuntimeError('Could not determine default I2C bus for platform.')
Ejemplo n.º 14
0
def require_repeated_start():
    """Enable repeated start conditions for I2C register reads.  This is the
    normal behavior for I2C, however on some platforms like the Raspberry Pi
    there are bugs which disable repeated starts unless explicitly enabled with
    this function.  See this thread for more details:
      http://www.raspberrypi.org/forums/viewtopic.php?f=44&t=15840
    """
    plat = Platform.platform_detect()
    if plat == Platform.RASPBERRY_PI and Platform.pi_version() == "BCM2708":
        # On the Raspberry Pi there is a bug where register reads don't send a
        # repeated start condition like the kernel smbus I2C driver functions
        # define.  As a workaround this bit in the BCM2708 driver sysfs tree can
        # be changed to enable I2C repeated starts.
        subprocess.check_call(
            'chmod 666 /sys/module/i2c_bcm2708/parameters/combined',
            shell=True)
        subprocess.check_call(
            'echo -n 1 > /sys/module/i2c_bcm2708/parameters/combined',
            shell=True)
Ejemplo n.º 15
0
def get_platform_gpio(**keywords):
    """Attempt to return a GPIO instance for the platform which the code is being
    executed on.  Will throw an exception if a GPIO instance can't be created for the current platform.  
    The returned GPIO object is an instance of BaseGPIO.
    """
    plat = Platform.platform_detect()
    if plat == Platform.RASPBERRY_PI:
        import RPi.GPIO
        return RPiGPIOAdapter(RPi.GPIO, **keywords)
    elif plat == Platform.UNKNOWN:
        raise RuntimeError('Could not determine platform.')
Ejemplo n.º 16
0
def get_platform_gpio(**keywords):
    """Attempt to return a GPIO instance for the platform which the code is being
    executed on.  Currently supports only the Raspberry Pi using the RPi.GPIO
    library and Beaglebone Black using the Adafruit_BBIO library.  Will throw an
    exception if a GPIO instance can't be created for the current platform.  The
    returned GPIO object is an instance of BaseGPIO.
    """
    plat = Platform.platform_detect()
    if plat == Platform.RASPBERRY_PI:
        import RPi.GPIO
        return RPiGPIOAdapter(RPi.GPIO, **keywords)
    elif plat == Platform.UNKNOWN:
        raise RuntimeError('Could not determine platform.')
Ejemplo n.º 17
0
def get_default_bus():
    """Return the default bus number based on the device platform.  For a
    Raspberry Pi either bus 0 or 1 (based on the Pi revision) will be returned.
    For a Beaglebone Black the first user accessible bus, 1, will be returned.
    """
    plat = Platform.platform_detect()
    if plat == Platform.RASPBERRY_PI:
        if Platform.pi_revision() == 1:
            # Revision 1 Pi uses I2C bus 0.
            return 0
        else:
            # Revision 2 Pi uses I2C bus 1.
            return 1
    elif plat == Platform.BEAGLEBONE_BLACK:
        # Beaglebone Black has multiple I2C buses, default to 1 (P9_19 and P9_20).
        return 1
    elif plat == Platform.CHIP:
        # CHIP has 2 user accessible I2C busses, default to 2 (U1425 and U14_26)
        # The 4.4 Kernel CHIPs remove i2c-1 for the ability to set with a dtb overlay
        # and therefore isn't accessible without one
        return 2
    else:
        raise RuntimeError("Could not determine default I2C bus for platform.")
Ejemplo n.º 18
0
def get_default_bus():
    """Return the default bus number based on the device platform.  For a
    Raspberry Pi either bus 0 or 1 (based on the Pi revision) will be returned.
    For a Beaglebone Black the first user accessible bus, 1, will be returned.
    """
    plat = Platform.platform_detect()
    if plat == Platform.RASPBERRY_PI:
        if Platform.pi_revision() == 1:
            # Revision 1 Pi uses I2C bus 0.
            return 0
        else:
            # Revision 2 Pi uses I2C bus 1.
            return 1
    elif plat == Platform.BEAGLEBONE_BLACK:
        # Beaglebone Black has multiple I2C buses, default to 1 (P9_19 and P9_20).
        return 1
    elif plat == Platform.CHIP:
        # CHIP has 2 user accessible I2C busses, default to 2 (U1425 and U14_26)
        # The 4.4 Kernel CHIPs remove i2c-1 for the ability to set with a dtb overlay
        # and therefore isn't accessible without one
        return 2
    else:
        raise RuntimeError('Could not determine default I2C bus for platform.')
Ejemplo n.º 19
0
def require_repeated_start():
    """Enable repeated start conditions for I2C register reads.  This is the
    normal behavior for I2C, however on some platforms like the Raspberry Pi
    there are bugs which disable repeated starts unless explicitly enabled with
    this function.  See this thread for more details:
      http://www.raspberrypi.org/forums/viewtopic.php?f=44&t=15840
    """
    plat = Platform.platform_detect()
    if plat == Platform.RASPBERRY_PI:
        # On the Raspberry Pi there is a bug where register reads don't send a
        # repeated start condition like the kernel smbus I2C driver functions
        # define.  As a workaround this bit in the BCM2708 driver sysfs tree can
        # be changed to enable I2C repeated starts.
        subprocess.check_call('chmod 666 /sys/module/i2c_bcm2708/parameters/combined', shell=True)
        subprocess.check_call('echo -n 1 > /sys/module/i2c_bcm2708/parameters/combined', shell=True)
Ejemplo n.º 20
0
def get_default_bus():
    """Return the default bus number based on the device platform.  For a
    Raspberry Pi either bus 0 or 1 (based on the Pi revision) will be returned.
    For a Beaglebone Black the first user accessible bus, 1, will be returned.
    """
    plat = Platform.platform_detect()
    if plat == Platform.RASPBERRY_PI:
        if Platform.pi_revision() == 1:
            # Revision 1 Pi uses I2C bus 0.
            return 0
        else:
            # Revision 2 Pi uses I2C bus 1.
            return 1
    elif plat == Platform.BEAGLEBONE_BLACK:
        # Beaglebone Black has multiple I2C buses, default to 1 (P9_19 and P9_20).
        return 1
####################################################################################################
#our modifaction to allow this code to work with the jetson tx2 board bus 0
    elif plat == Platform.JETSON_TX2:
        # change the return value to the i2c bus you want to use.
        return 1
        #return 0 orginally at BUS 0 adjusting code for all sensors to be BUS 1
    else:
        raise RuntimeError('Could not determine default I2C bus for platform.')
Ejemplo n.º 21
0
def get_platform_pwm(**keywords):
    """Attempt to return a PWM instance for the platform which the code is being
    executed on.  Currently supports only the Raspberry Pi using the RPi.GPIO
    library and Beaglebone Black using the Adafruit_BBIO library.  Will throw an
    exception if a PWM instance can't be created for the current platform.  The
    returned PWM object has the same interface as the RPi_PWM_Adapter and
    BBIO_PWM_Adapter classes.
    """
    plat = Platform.platform_detect()
    if plat == Platform.RASPBERRY_PI:
        import RPi.GPIO
        return RPi_PWM_Adapter(RPi.GPIO, **keywords)
    elif plat == Platform.BEAGLEBONE_BLACK:
        import Adafruit_BBIO.PWM
        return BBIO_PWM_Adapter(Adafruit_BBIO.PWM, **keywords)
    elif plat == Platform.UNKNOWN:
        raise RuntimeError('Could not determine platform.')
Ejemplo n.º 22
0
def get_platform_pwm(**keywords):
    """Attempt to return a PWM instance for the platform which the code is being
    executed on.  Currently supports only the Raspberry Pi using the RPi.GPIO
    library and Beaglebone Black using the Adafruit_BBIO library.  Will throw an
    exception if a PWM instance can't be created for the current platform.  The
    returned PWM object has the same interface as the RPi_PWM_Adapter and
    BBIO_PWM_Adapter classes.
    """
    plat = Platform.platform_detect()
    if plat == Platform.RASPBERRY_PI:
        import RPi.GPIO
        return RPi_PWM_Adapter(RPi.GPIO, **keywords)
    elif plat == Platform.BEAGLEBONE_BLACK:
        import Adafruit_BBIO.PWM
        return BBIO_PWM_Adapter(Adafruit_BBIO.PWM, **keywords)
    elif plat == Platform.UNKNOWN:
        raise RuntimeError('Could not determine platform.')
Ejemplo n.º 23
0
def get_platform_gpio(**keywords):
	"""Attempt to return a GPIO instance for the platform which the code is being
	executed on.  Currently supports only the Raspberry Pi using the RPi.GPIO
	library and Beaglebone Black using the Adafruit_BBIO library.  Will throw an
	exception if a GPIO instance can't be created for the current platform.  The
	returned GPIO object is an instance of BaseGPIO.
	"""
	plat = Platform.platform_detect()
	if plat == Platform.RASPBERRY_PI:
		try:
			from sysfs.gpio import GPIOController
			return LinuxSysFSAdapter(GPIOController(), **keywords)
		except:
			import RPi.GPIO
			return RPiGPIOAdapter(RPi.GPIO, **keywords)
		
	elif plat == Platform.BEAGLEBONE_BLACK:
		import Adafruit_BBIO.GPIO
		return AdafruitBBIOAdapter(Adafruit_BBIO.GPIO, **keywords)
	elif plat == Platform.UNKNOWN:
		raise RuntimeError('Could not determine platform.')
	def test_raspberry_pi(self):
		result = Platform.platform_detect()
		self.assertEquals(result, Platform.RASPBERRY_PI)
 def test_unknown(self):
     result = Platform.platform_detect()
     self.assertEquals(result, Platform.UNKNOWN)
 def test_beaglebone_black(self):
     result = Platform.platform_detect()
     self.assertEquals(result, Platform.BEAGLEBONE_BLACK)
Ejemplo n.º 27
0
import sys

# We intentionally are patching into this namespace as module names so skip the name check.
# pylint: disable=invalid-name
platform = sys.platform

board_id = None
if platform is not None:
    if platform == "esp8266":  # TODO more conservative board-guessing
        board_id = "feather_huzzah"
    elif platform == "samd21":
        board_id = "feather_m0_express"
    elif platform == "pyboard":
        platform = "stm32"
        board_id = "pyboard"
    elif platform == "linux":
        from Adafruit_GPIO import Platform
        if Platform.platform_detect() == Platform.RASPBERRY_PI:
            if Platform.pi_version() == 1:
                board_id = "raspi_1"
            elif Platform.pi_version() == 2:
                board_id = "raspi_2"
            elif Platform.pi_version() == 3:
                board_id = "raspi_3"

implementation = sys.implementation.name
if implementation == "micropython":
    from utime import sleep
elif implementation == "circuitpython" or implementation == "cpython":
    from time import sleep
Ejemplo n.º 28
0
 def test_unknown(self):
     result = Platform.platform_detect()
     self.assertEquals(result, Platform.UNKNOWN)
Ejemplo n.º 29
0
 def test_beaglebone_black(self):
     result = Platform.platform_detect()
     self.assertEquals(result, Platform.BEAGLEBONE_BLACK)
Ejemplo n.º 30
0
import Adafruit_GPIO.Platform as Platform

platform = Platform.platform_detect()

print("Diagnostics:\n")
print("Platform is RPi:", platform == 1)
 def test_revision_2(self):
     with patch("__builtin__.open") as mock_open:
         handle = mock_open.return_value.__enter__.return_value
         handle.__iter__.return_value = iter(["Revision : 000e"])
         rev = Platform.pi_revision()
         self.assertEquals(rev, 2)
Ejemplo n.º 32
0
 def test_raspberry_pi(self):
     result = Platform.platform_detect()
     self.assertEquals(result, Platform.RASPBERRY_PI)
Ejemplo n.º 33
0
        platform = "stm32"
        board_id = "pyboard"
    elif platform == "linux":
        import re
        # we're going to redo the Platform detection, this is a terrible hack
        # for now.
        try:
            # lets see if we're an armbian board
            for line in open("/etc/armbian-release", 'r'):
                #print(line)
                m = re.search('BOARD=(.*)', line)
                if m:
                    board_id = m.group(1)
        except:
            from Adafruit_GPIO import Platform
            if Platform.platform_detect() == Platform.RASPBERRY_PI:
                if Platform.pi_version() == 1:
                    board_id = "raspi_1"
                elif Platform.pi_version() == 2:
                    board_id = "raspi_2"
                elif Platform.pi_version() == 3:
                    board_id = "raspi_3"
            elif Platform.platform_detect() == Platform.BEAGLEBONE_BLACK:
                board_id = "beaglebone_black"

implementation = sys.implementation.name
if implementation == "micropython":
    from utime import sleep
elif implementation == "circuitpython" or implementation == "cpython":
    from time import sleep
Ejemplo n.º 34
0
def init(config_data={}):
    """
    Initializes the module
    """
    def build_pin(name, pin_config, pin=None, index=0):
        if pin is None:
            if isinstance(pin_config[CONF_KEY_PIN], list):
                pin = pin_config[CONF_KEY_PIN][index]
                index_sub = index + pin_config[CONF_KEY_FIRST_INDEX]
            else:
                pin = pin_config[CONF_KEY_PIN]
                index_sub = ""
        if isinstance(pin_config[CONF_KEY_TOPIC], list):
            topic = pin_config[CONF_KEY_TOPIC][index]
        else:
            topic = pin_config[CONF_KEY_TOPIC]
        return {
            "name":
            name.format(index=index + pin_config[CONF_KEY_FIRST_INDEX]),
            CONF_KEY_TOPIC:
            resolve_topic(topic,
                          subtopics=["{module_topic}"],
                          substitutions={
                              "module_topic": raw_config[CONF_KEY_TOPIC],
                              "module_name": TEXT_NAME,
                              "pin": pin,
                              "pin_name": name,
                              "index": index_sub
                          }),
            CONF_KEY_DIRECTION:
            pin_config[CONF_KEY_DIRECTION],
            CONF_KEY_INTERRUPT:
            pin_config[CONF_KEY_INTERRUPT],
            CONF_KEY_RESISTOR:
            pin_config[CONF_KEY_RESISTOR],
            CONF_KEY_INVERT:
            pin_config[CONF_KEY_INVERT],
            CONF_KEY_INITIAL:
            pin_config[CONF_KEY_INITIAL].format(
                payload_on=raw_config[CONF_KEY_PAYLOAD_ON],
                payload_off=raw_config[CONF_KEY_PAYLOAD_OFF])
        }

    global gpio, GPIO_PINS

    pi_version = Platform.pi_version()
    if pi_version:
        log.debug("Platform is Raspberry Pi {}".format(pi_version))
        if pi_version == 1:
            log.error("No platform config for Raspberry Pi 1")
            return False
        elif pi_version == 2:
            log.error("No platform config for Raspberry Pi 2")
            return False
        elif pi_version == 3:
            GPIO_PINS = GPIO_PINS_RPI3

        gpio = GPIO.get_platform_gpio(mode=11)
    else:
        log.error("Unknown platform")
        return False

    raw_config = parse_config(config_data, CONF_OPTIONS, log)
    if raw_config:
        log.debug("Config loaded")

        for name in [
                key for key in raw_config if isinstance(raw_config[key], dict)
        ]:
            named_config = raw_config.pop(name)
            if isinstance(named_config[CONF_KEY_PIN], int):
                pin = named_config[CONF_KEY_PIN]
                if pin not in pins:
                    pins[pin] = build_pin(name, named_config)
                    log.debug(
                        "Configured GPIO{pin:02d} with options: {options}".
                        format(pin=pin, options=pins[pin]))
                else:
                    log.warn(
                        "Duplicate configuration for GPIO{pin:02d} found in '{name}' will be ignored, pin already configured under '{original}'"
                        .format(pin=pin, name=name,
                                original=pins[pin]["name"]))
            elif isinstance(named_config[CONF_KEY_PIN], list):
                for index in range(len(named_config[CONF_KEY_PIN])):
                    pin = named_config[CONF_KEY_PIN][index]
                    if pin not in pins:
                        pins[pin] = build_pin(name, named_config, index=index)
                        log.debug(
                            "Configured GPIO{pin:02d} with options: {options}".
                            format(pin=pin, options=pins[pin]))
                    else:
                        log.warn(
                            "Duplicate configuration for GPIO{pin:02d} found in '{name}' will be ignored, pin already configured under '{original}'"
                            .format(pin=pin,
                                    name=name,
                                    original=pins[pin]["name"]))

        config.update(raw_config)
        return True
    else:
        log.error("Error loading config")
        return False