本文整理汇总了Python中Adafruit_GPIO.Platform.platform_detect方法的典型用法代码示例。如果您正苦于以下问题:Python Platform.platform_detect方法的具体用法?Python Platform.platform_detect怎么用?Python Platform.platform_detect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Adafruit_GPIO.Platform
的用法示例。
在下文中一共展示了Platform.platform_detect方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_platform_pwm
# 需要导入模块: from Adafruit_GPIO import Platform [as 别名]
# 或者: from Adafruit_GPIO.Platform import platform_detect [as 别名]
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.')
示例2: __init__
# 需要导入模块: from Adafruit_GPIO import Platform [as 别名]
# 或者: from Adafruit_GPIO.Platform import platform_detect [as 别名]
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))
示例3: get_platform_gpio
# 需要导入模块: from Adafruit_GPIO import Platform [as 别名]
# 或者: from Adafruit_GPIO.Platform import platform_detect [as 别名]
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.')
示例4: require_repeated_start
# 需要导入模块: from Adafruit_GPIO import Platform [as 别名]
# 或者: from Adafruit_GPIO.Platform import platform_detect [as 别名]
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)
示例5: get_platform_pwm
# 需要导入模块: from Adafruit_GPIO import Platform [as 别名]
# 或者: from Adafruit_GPIO.Platform import platform_detect [as 别名]
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.')
示例6: get_default_bus
# 需要导入模块: from Adafruit_GPIO import Platform [as 别名]
# 或者: from Adafruit_GPIO.Platform import platform_detect [as 别名]
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.')
示例7: get_platform_gpio
# 需要导入模块: from Adafruit_GPIO import Platform [as 别名]
# 或者: from Adafruit_GPIO.Platform import platform_detect [as 别名]
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.')
示例8: get_default_bus
# 需要导入模块: from Adafruit_GPIO import Platform [as 别名]
# 或者: from Adafruit_GPIO.Platform import platform_detect [as 别名]
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.")
示例9: test_unknown
# 需要导入模块: from Adafruit_GPIO import Platform [as 别名]
# 或者: from Adafruit_GPIO.Platform import platform_detect [as 别名]
def test_unknown(self):
result = Platform.platform_detect()
self.assertEquals(result, Platform.UNKNOWN)
示例10: test_beaglebone_black
# 需要导入模块: from Adafruit_GPIO import Platform [as 别名]
# 或者: from Adafruit_GPIO.Platform import platform_detect [as 别名]
def test_beaglebone_black(self):
result = Platform.platform_detect()
self.assertEquals(result, Platform.BEAGLEBONE_BLACK)
示例11: test_raspberry_pi
# 需要导入模块: from Adafruit_GPIO import Platform [as 别名]
# 或者: from Adafruit_GPIO.Platform import platform_detect [as 别名]
def test_raspberry_pi(self):
result = Platform.platform_detect()
self.assertEquals(result, Platform.RASPBERRY_PI)