当前位置: 首页>>代码示例>>Python>>正文


Python GPIO.getmode方法代码示例

本文整理汇总了Python中RPi.GPIO.getmode方法的典型用法代码示例。如果您正苦于以下问题:Python GPIO.getmode方法的具体用法?Python GPIO.getmode怎么用?Python GPIO.getmode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RPi.GPIO的用法示例。


在下文中一共展示了GPIO.getmode方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: index

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import getmode [as 别名]
def index(environ, response):

	modes = {
		-1: "MODE_UNKNOWN",
		10: "BOARD",
		11: "BCM",
		40: "SERIAL",
		41: "SPI",
		42: "I2C",
		43: "PWM"
	}
	
	status = "200 OK"
	
	header = [("Content-Type", "application/json")]
	
	result = {
		"GPIO.RPI_INFO": GPIO.RPI_INFO,
		"GPIO.VERSION": GPIO.VERSION,
		"MODE": modes[ GPIO.getmode() ]
	}
	
	response(status, header)
	
	return [json.dumps(result).encode()] 
开发者ID:victorqribeiro,项目名称:rpiapi,代码行数:27,代码来源:index.py

示例2: __init__

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import getmode [as 别名]
def __init__(self, address=0x40):
        """
        init object with i2c address, default is 0x40 for ServoPi board

        :param address: device i2c address, defaults to 0x40
        :type address: int, optional
        """
        self.__address = address
        self.__bus = self.__get_smbus()
        self.__write(self.__MODE1, self.__mode1_default)
        self.__write(self.__MODE2, self.__mode2_default)
        GPIO.setwarnings(False)

        mode = GPIO.getmode()  # check if the GPIO mode has been set

        if (mode == 10):  # Mode set to GPIO.BOARD
            self.__oe_pin = 7
        elif (mode == 11):  # Mode set to GPIO.BCM
            self.__oe_pin = 4
        else:  # Mode not set
            GPIO.setmode(GPIO.BOARD)
            self.__oe_pin = 7

        GPIO.setup(self.__oe_pin, GPIO.OUT) 
开发者ID:abelectronicsuk,项目名称:ABElectronics_Python_Libraries,代码行数:26,代码来源:ServoPi.py

示例3: _gpio_get_pin

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import getmode [as 别名]
def _gpio_get_pin(self, pin):
        if (GPIO.getmode() == GPIO.BOARD and self.GPIOMode == 'BOARD') or (GPIO.getmode() == GPIO.BCM and self.GPIOMode == 'BCM'):
            return pin
        elif GPIO.getmode() == GPIO.BOARD and self.GPIOMode == 'BCM':
            return self._gpio_bcm_to_board(pin)
        elif GPIO.getmode() == GPIO.BCM and self.GPIOMode == 'BOARD':
            return self._gpio_board_to_bcm(pin)
        else:
            return 0 
开发者ID:kantlivelong,项目名称:OctoPrint-PSUControl,代码行数:11,代码来源:__init__.py

示例4: _init_board

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import getmode [as 别名]
def _init_board(self):
        import RPi.GPIO as GPIO

        with self._init_lock:
            if self._initialized and GPIO.getmode():
                return

            GPIO.setmode(self.mode)
            self._initialized = True 
开发者ID:BlackLight,项目名称:platypush,代码行数:11,代码来源:__init__.py

示例5: setup_gpio

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import getmode [as 别名]
def setup_gpio(self):
        try:
            current_mode = GPIO.getmode()
            set_mode = GPIO.BOARD if self._settings.get(["use_board_pin_number"]) else GPIO.BCM
            if current_mode is None:
                outputs = list(filter(
                    lambda item: item['output_type'] == 'regular' or item['output_type'] == 'pwm' or item[
                        'output_type'] == 'temp_hum_control' or item['output_type'] == 'neopixel_direct',
                    self.rpi_outputs))
                inputs = list(filter(lambda item: item['input_type'] == 'gpio', self.rpi_inputs))
                gpios = outputs + inputs
                if gpios:
                    GPIO.setmode(set_mode)
                    tempstr = "BOARD" if set_mode == GPIO.BOARD else "BCM"
                    self._logger.info("Setting GPIO mode to %s", tempstr)
            elif current_mode != set_mode:
                GPIO.setmode(current_mode)
                tempstr = "BOARD" if current_mode == GPIO.BOARD else "BCM"
                self._settings.set(["use_board_pin_number"], True if current_mode == GPIO.BOARD else False)
                warn_msg = "GPIO mode was configured before, GPIO mode will be forced to use: " + tempstr + " as pin numbers. Please update GPIO accordingly!"
                self._logger.info(warn_msg)
                self._plugin_manager.send_plugin_message(self._identifier,
                    dict(is_msg=True, msg=warn_msg, msg_type="error"))
            GPIO.setwarnings(False)
        except Exception as ex:
            self.log_error(ex) 
开发者ID:vitormhenrique,项目名称:OctoPrint-Enclosure,代码行数:28,代码来源:__init__.py

示例6: setup

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import getmode [as 别名]
def setup(robot_config):
    global StepPinForward
    global StepPinBackward
    global StepPinLeft
    global StepPinRight
    global sleeptime
    global rotatetimes
    
    sleeptime = robot_config.getfloat('l298n', 'sleeptime')
    rotatetimes = robot_config.getfloat('l298n', 'rotatetimes')
    
    log.debug("GPIO mode : %s", str(GPIO.getmode()))

    GPIO.setwarnings(False)
    GPIO.cleanup()
    
    if robot_config.getboolean('tts', 'ext_chat'): #ext_chat enabled, add motor commands
        extended_command.add_command('.set_rotate_time', set_rotate_time)
        extended_command.add_command('.set_sleep_time', set_sleep_time)

# TODO passing these as tuples may be unnecessary, it may accept lists as well. 
    StepPinForward = tuple(map(int, robot_config.get('l298n', 'StepPinForward').split(',')))
    StepPinBackward = tuple(map(int,robot_config.get('l298n', 'StepPinBackward').split(',')))
    StepPinLeft = tuple(map(int,robot_config.get('l298n', 'StepPinLeft').split(',')))
    StepPinRight = tuple(map(int,robot_config.get('l298n', 'StepPinRight').split(',')))
	
    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(StepPinForward, GPIO.OUT)
    GPIO.setup(StepPinBackward, GPIO.OUT)
    GPIO.setup(StepPinLeft, GPIO.OUT)
    GPIO.setup(StepPinRight, GPIO.OUT) 
开发者ID:letsRobot,项目名称:letsrobot,代码行数:33,代码来源:l298n.py

示例7: __init__

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import getmode [as 别名]
def __init__(self, bus=0, device=0, spd=1000000, pin_mode=10, pin_rst=-1, debugLevel='WARNING'):
        self.spi = spidev.SpiDev()
        self.spi.open(bus, device)
        self.spi.max_speed_hz = spd

        self.logger = logging.getLogger('mfrc522Logger')
        self.logger.addHandler(logging.StreamHandler())
        level = logging.getLevelName(debugLevel)
        self.logger.setLevel(level)

        gpioMode = GPIO.getmode()
        
        if gpioMode is None:
            GPIO.setmode(pin_mode)
        else:
            pin_mode = gpioMode
            
        if pin_rst == -1:
            if pin_mode == 11:
                pin_rst = 15
            else:
                pin_rst = 22
            
        GPIO.setup(pin_rst, GPIO.OUT)
        GPIO.output(pin_rst, 1)
        self.MFRC522_Init() 
开发者ID:pimylifeup,项目名称:MFRC522-python,代码行数:28,代码来源:MFRC522.py

示例8: _configure_gpio

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import getmode [as 别名]
def _configure_gpio(self):
        if not self._hasGPIO:
            self._logger.error("RPi.GPIO is required.")
            return
        
        self._logger.info("Running RPi.GPIO version %s" % GPIO.VERSION)
        if GPIO.VERSION < "0.6":
            self._logger.error("RPi.GPIO version 0.6.0 or greater required.")
        
        GPIO.setwarnings(False)

        for pin in self._configuredGPIOPins:
            self._logger.debug("Cleaning up pin %s" % pin)
            try:
                GPIO.cleanup(self._gpio_get_pin(pin))
            except (RuntimeError, ValueError) as e:
                self._logger.error(e)
        self._configuredGPIOPins = []

        if GPIO.getmode() is None:
            if self.GPIOMode == 'BOARD':
                GPIO.setmode(GPIO.BOARD)
            elif self.GPIOMode == 'BCM':
                GPIO.setmode(GPIO.BCM)
            else:
                return
        
        if self.sensingMethod == 'GPIO':
            self._logger.info("Using GPIO sensing to determine PSU on/off state.")
            self._logger.info("Configuring GPIO for pin %s" % self.senseGPIOPin)

            if self.senseGPIOPinPUD == 'PULL_UP':
                pudsenseGPIOPin = GPIO.PUD_UP
            elif self.senseGPIOPinPUD == 'PULL_DOWN':
                pudsenseGPIOPin = GPIO.PUD_DOWN
            else:
                pudsenseGPIOPin = GPIO.PUD_OFF
    
            try:
                GPIO.setup(self._gpio_get_pin(self.senseGPIOPin), GPIO.IN, pull_up_down=pudsenseGPIOPin)
                self._configuredGPIOPins.append(self.senseGPIOPin)
            except (RuntimeError, ValueError) as e:
                self._logger.error(e)
        
        if self.switchingMethod == 'GPIO':
            self._logger.info("Using GPIO for On/Off")
            self._logger.info("Configuring GPIO for pin %s" % self.onoffGPIOPin)
            try:
                if not self.invertonoffGPIOPin:
                    initial_pin_output=GPIO.LOW
                else:
                    initial_pin_output=GPIO.HIGH
                GPIO.setup(self._gpio_get_pin(self.onoffGPIOPin), GPIO.OUT, initial=initial_pin_output)
                self._configuredGPIOPins.append(self.onoffGPIOPin)
            except (RuntimeError, ValueError) as e:
                self._logger.error(e) 
开发者ID:kantlivelong,项目名称:OctoPrint-PSUControl,代码行数:58,代码来源:__init__.py


注:本文中的RPi.GPIO.getmode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。