mirror of
				https://github.com/KevinMidboe/python-gpiozero.git
				synced 2025-10-29 17:50:37 +00:00 
			
		
		
		
	Last minute changes for 1.2
Warnings about non-physical pins, and period specification for sin/cosine waves in tools
This commit is contained in:
		| @@ -261,11 +261,11 @@ PI_REVISIONS = { | ||||
|     '0013':   ('B+',   '1.2', '2015Q1', 'BCM2835', 'Egoman',    512,  'MicroSD', 4,  1,  False, False, 1,  1,  {'P1': PLUS_P1},               ), | ||||
|     '0014':   ('CM',   '1.1', '2014Q2', 'BCM2835', 'Sony',      512,  'eMMC',    0,  0,  False, False, 2,  2,  {'SODIMM': CM_SODIMM},         ), | ||||
|     '0015':   ('A+',   '1.1', '2014Q4', 'BCM2835', 'Sony',      256,  'MicroSD', 1,  0,  False, False, 1,  1,  {'P1': PLUS_P1},               ), | ||||
|     #'a01041': ('2B',   '1.1', '2015Q1', 'BCM2836', 'Sony',      1024, 'MicroSD', 4,  1,  False, False, 1,  1,  {'P1': PLUS_P1},               ), | ||||
|     #'a21041': ('2B',   '1.1', '2015Q1', 'BCM2836', 'Embest',    1024, 'MicroSD', 4,  1,  False, False, 1,  1,  {'P1': PLUS_P1},               ), | ||||
|     #'900092': ('Zero', '1.2', '2015Q4', 'BCM2835', 'Sony',      512,  'MicroSD', 1,  0,  False, False, 0,  0,  {'P1': PLUS_P1},               ), | ||||
|     #'a02082': ('3B',   '1.2', '2016Q1', 'BCM2837', 'Sony',      1024, 'MicroSD', 4,  1,  True,  True,  1,  1,  {'P1': PLUS_P1},               ), | ||||
|     #'a22082': ('3B',   '1.2', '2016Q1', 'BCM2837', 'Embest',    1024, 'MicroSD', 4,  1,  True,  True,  1,  1,  {'P1': PLUS_P1},               ), | ||||
|     'a01041': ('2B',   '1.1', '2015Q1', 'BCM2836', 'Sony',      1024, 'MicroSD', 4,  1,  False, False, 1,  1,  {'P1': PLUS_P1},               ), | ||||
|     'a21041': ('2B',   '1.1', '2015Q1', 'BCM2836', 'Embest',    1024, 'MicroSD', 4,  1,  False, False, 1,  1,  {'P1': PLUS_P1},               ), | ||||
|     '900092': ('Zero', '1.2', '2015Q4', 'BCM2835', 'Sony',      512,  'MicroSD', 1,  0,  False, False, 0,  0,  {'P1': PLUS_P1},               ), | ||||
|     'a02082': ('3B',   '1.2', '2016Q1', 'BCM2837', 'Sony',      1024, 'MicroSD', 4,  1,  True,  True,  1,  1,  {'P1': PLUS_P1},               ), | ||||
|     'a22082': ('3B',   '1.2', '2016Q1', 'BCM2837', 'Embest',    1024, 'MicroSD', 4,  1,  True,  True,  1,  1,  {'P1': PLUS_P1},               ), | ||||
|     } | ||||
|  | ||||
|  | ||||
| @@ -479,8 +479,12 @@ class PiBoardInfo(namedtuple('PiBoardInfo', ( | ||||
|             The pin function you wish to determine pull-up for. Usually this is | ||||
|             something like "GPIO9" for Broadcom GPIO pin 9. | ||||
|         """ | ||||
|         header, number = self.physical_pin(function) | ||||
|         return self.headers[header][number].pull_up | ||||
|         try: | ||||
|             header, number = self.physical_pin(function) | ||||
|         except PinNoPins: | ||||
|             return False | ||||
|         else: | ||||
|             return self.headers[header][number].pull_up | ||||
|  | ||||
|  | ||||
| _PI_REVISION = None | ||||
|   | ||||
| @@ -12,6 +12,7 @@ import os | ||||
| import mmap | ||||
| import errno | ||||
| import struct | ||||
| import warnings | ||||
| from time import sleep | ||||
| from threading import Thread, Event, Lock | ||||
| from collections import Counter | ||||
| @@ -24,6 +25,8 @@ from ..exc import ( | ||||
|     PinInvalidFunction, | ||||
|     PinFixedPull, | ||||
|     PinSetInput, | ||||
|     PinNonPhysical, | ||||
|     PinNoPins, | ||||
|     ) | ||||
|  | ||||
|  | ||||
| @@ -213,7 +216,12 @@ class NativePin(Pin): | ||||
|             return cls._PINS[number] | ||||
|         except KeyError: | ||||
|             self = super(NativePin, cls).__new__(cls) | ||||
|             cls._PINS[number] = self | ||||
|             try: | ||||
|                 cls.PI_INFO.physical_pin('GPIO%d' % number) | ||||
|             except PinNoPins: | ||||
|                 warnings.warn( | ||||
|                     PinNonPhysical( | ||||
|                         'no physical pins exist for GPIO%d' % number)) | ||||
|             self._number = number | ||||
|             self._func_offset = self._MEM.GPFSEL_OFFSET + (number // 10) | ||||
|             self._func_shift = (number % 10) * 3 | ||||
| @@ -238,6 +246,7 @@ class NativePin(Pin): | ||||
|             self.pull = 'up' if cls.PI_INFO.pulled_up('GPIO%d' % number) else 'floating' | ||||
|             self.bounce = None | ||||
|             self.edges = 'both' | ||||
|             cls._PINS[number] = self | ||||
|             return self | ||||
|  | ||||
|     def __repr__(self): | ||||
|   | ||||
| @@ -6,6 +6,7 @@ from __future__ import ( | ||||
|     ) | ||||
| str = type('') | ||||
|  | ||||
| import warnings | ||||
| import pigpio | ||||
|  | ||||
| from . import Pin | ||||
| @@ -17,6 +18,8 @@ from ..exc import ( | ||||
|     PinInvalidPull, | ||||
|     PinInvalidBounce, | ||||
|     PinInvalidState, | ||||
|     PinNonPhysical, | ||||
|     PinNoPins, | ||||
|     ) | ||||
|  | ||||
|  | ||||
| @@ -107,12 +110,17 @@ class PiGPIOPin(Pin): | ||||
|             return cls._PINS[(host, port, number)] | ||||
|         except KeyError: | ||||
|             self = super(PiGPIOPin, cls).__new__(cls) | ||||
|             cls._PINS[(host, port, number)] = self | ||||
|             try: | ||||
|                 self._connection = cls._CONNECTIONS[(host, port)] | ||||
|             except KeyError: | ||||
|                 self._connection = pigpio.pi(host, port) | ||||
|                 cls._CONNECTIONS[(host, port)] = self._connection | ||||
|             try: | ||||
|                 cls.PI_INFO.physical_pin('GPIO%d' % number) | ||||
|             except PinNoPins: | ||||
|                 warnings.warn( | ||||
|                     PinNonPhysical( | ||||
|                         'no physical pins exist for GPIO%d' % number)) | ||||
|             self._host = host | ||||
|             self._port = port | ||||
|             self._number = number | ||||
| @@ -125,11 +133,11 @@ class PiGPIOPin(Pin): | ||||
|             try: | ||||
|                 self._connection.set_mode(self._number, pigpio.INPUT) | ||||
|             except pigpio.error as e: | ||||
|                 del cls._PINS[(host, port, number)] | ||||
|                 raise ValueError(e) | ||||
|             self._connection.set_pull_up_down(self._number, self.GPIO_PULL_UPS[self._pull]) | ||||
|             self._connection.set_glitch_filter(self._number, 0) | ||||
|             self._connection.set_PWM_range(self._number, 255) | ||||
|             cls._PINS[(host, port, number)] = self | ||||
|             return self | ||||
|  | ||||
|     def __repr__(self): | ||||
|   | ||||
| @@ -6,6 +6,7 @@ from __future__ import ( | ||||
|     ) | ||||
| str = type('') | ||||
|  | ||||
| import warnings | ||||
| from RPi import GPIO | ||||
|  | ||||
| from . import Pin | ||||
| @@ -18,6 +19,8 @@ from ..exc import ( | ||||
|     PinInvalidState, | ||||
|     PinInvalidBounce, | ||||
|     PinPWMFixedValue, | ||||
|     PinNonPhysical, | ||||
|     PinNoPins, | ||||
|     ) | ||||
|  | ||||
|  | ||||
| @@ -84,7 +87,12 @@ class RPiGPIOPin(Pin): | ||||
|             return cls._PINS[number] | ||||
|         except KeyError: | ||||
|             self = super(RPiGPIOPin, cls).__new__(cls) | ||||
|             cls._PINS[number] = self | ||||
|             try: | ||||
|                 cls.PI_INFO.physical_pin('GPIO%d' % number) | ||||
|             except PinNoPins: | ||||
|                 warnings.warn( | ||||
|                     PinNonPhysical( | ||||
|                         'no physical pins exist for GPIO%d' % number)) | ||||
|             self._number = number | ||||
|             self._pull = 'up' if cls.PI_INFO.pulled_up('GPIO%d' % number) else 'floating' | ||||
|             self._pwm = None | ||||
| @@ -94,6 +102,7 @@ class RPiGPIOPin(Pin): | ||||
|             self._when_changed = None | ||||
|             self._edges = GPIO.BOTH | ||||
|             GPIO.setup(self._number, GPIO.IN, self.GPIO_PULL_UPS[self._pull]) | ||||
|             cls._PINS[number] = self | ||||
|             return self | ||||
|  | ||||
|     def __repr__(self): | ||||
|   | ||||
| @@ -7,6 +7,7 @@ from __future__ import ( | ||||
| str = type('') | ||||
|  | ||||
|  | ||||
| import warnings | ||||
| import RPIO | ||||
| import RPIO.PWM | ||||
| from RPIO.Exceptions import InvalidChannelException | ||||
| @@ -21,6 +22,8 @@ from ..exc import ( | ||||
|     PinInvalidBounce, | ||||
|     PinInvalidState, | ||||
|     PinPWMError, | ||||
|     PinNonPhysical, | ||||
|     PinNoPins, | ||||
|     ) | ||||
|  | ||||
|  | ||||
| @@ -81,7 +84,12 @@ class RPIOPin(Pin): | ||||
|             return cls._PINS[number] | ||||
|         except KeyError: | ||||
|             self = super(RPIOPin, cls).__new__(cls) | ||||
|             cls._PINS[number] = self | ||||
|             try: | ||||
|                 cls.PI_INFO.physical_pin('GPIO%d' % number) | ||||
|             except PinNoPins: | ||||
|                 warnings.warn( | ||||
|                     PinNonPhysical( | ||||
|                         'no physical pins exist for GPIO%d' % number)) | ||||
|             self._number = number | ||||
|             self._pull = 'up' if cls.PI_INFO.pulled_up('GPIO%d' % number) else 'floating' | ||||
|             self._pwm = False | ||||
| @@ -93,6 +101,7 @@ class RPIOPin(Pin): | ||||
|                 RPIO.setup(self._number, RPIO.IN, self.GPIO_PULL_UPS[self._pull]) | ||||
|             except InvalidChannelException as e: | ||||
|                 raise ValueError(e) | ||||
|             cls._PINS[number] = self | ||||
|             return self | ||||
|  | ||||
|     def __repr__(self): | ||||
|   | ||||
		Reference in New Issue
	
	Block a user