mirror of
				https://github.com/KevinMidboe/python-gpiozero.git
				synced 2025-10-29 17:50:37 +00:00 
			
		
		
		
	Add "real" pins tests
This is just a quicky for people to start playing with - it's not complete in any way, shape, or form. This is how I envisage the "real" pin tests being done; part of the test suite with a `skipif` to ensure they don't get run on non-Pi platforms, with a fixture to loop over whatever pin implementations are found (we can't always assume all of them: for example, RPIO doesn't work on a Pi 2), and a relatively simple wiring for the test. In this case I've assumed GPIOs 22 and 27 are wired together. They're next to each other, so a jumper is sufficient to run the test. PRs extending the coverage are very welcome (I've already discovered and fixed several silly bugs in NativePin!). I've left all the interesting hard stuff for people to play with (PWM testing: statistical sampling? debounce compensation testing: timing?). When I've got a second, I'll looking into hooking up my Pi Zero as a Travis-esque test-bed for this, triggered by GitHub webhooks (not sure how I'll deal with reporting yet).
This commit is contained in:
		| @@ -245,6 +245,7 @@ class NativePin(Pin): | ||||
|     def close(self): | ||||
|         self.when_changed = None | ||||
|         self.function = 'input' | ||||
|         self.pull = 'up' if self.number in (2, 3) else 'floating' | ||||
|  | ||||
|     def _get_function(self): | ||||
|         return self.GPIO_FUNCTION_NAMES[(self._MEM[self._func_offset] >> self._func_shift) & 7] | ||||
| @@ -253,7 +254,7 @@ class NativePin(Pin): | ||||
|         try: | ||||
|             value = self.GPIO_FUNCTIONS[value] | ||||
|         except KeyError: | ||||
|             raise PinInvalidFunction('invalid function "%s" for pin %r' % self) | ||||
|             raise PinInvalidFunction('invalid function "%s" for pin %r' % (value, self)) | ||||
|         self._MEM[self._func_offset] = ( | ||||
|             self._MEM[self._func_offset] | ||||
|             & ~(7 << self._func_shift) | ||||
| @@ -282,7 +283,7 @@ class NativePin(Pin): | ||||
|         try: | ||||
|             value = self.GPIO_PULL_UPS[value] | ||||
|         except KeyError: | ||||
|             raise PinInvalidPull('invalid pull direction "%s" for pin %r' % self) | ||||
|             raise PinInvalidPull('invalid pull direction "%s" for pin %r' % (value, self)) | ||||
|         self._MEM[self._MEM.GPPUD_OFFSET] = value | ||||
|         sleep(0.000000214) | ||||
|         self._MEM[self._pull_offset] = 1 << self._pull_shift | ||||
|   | ||||
		Reference in New Issue
	
	Block a user