def test_wait_for_edge_not_configured_for_input(): with patch("OPi.GPIO.sysfs"): GPIO.setmode(GPIO.BOARD) GPIO.setup(12, GPIO.OUT) with pytest.raises(RuntimeError) as ex: GPIO.wait_for_edge(12, GPIO.RISING) assert str(ex.value) == "Channel 12 is configured for output"
def firstFunction(): global counter global ts global counting count = 1 counter = 0 ts = time.time() while True: if (count == 1): GPIO.wait_for_edge(27, GPIO.RISING) counting = 1 counter += 1 print("Pulse comming ! (%s)") % counter ts = time.time()
def test_wait_for_edge_completes(): with patch("OPi.GPIO.sysfs"): GPIO.setmode(GPIO.BOARD) GPIO.setup(12, GPIO.IN) with patch("OPi.GPIO.event") as mock: mock.blocking_wait_for_edge.return_value = 1 assert GPIO.wait_for_edge(12, GPIO.BOTH) == 12 mock.blocking_wait_for_edge.assert_called_with(7, GPIO.BOTH, -1)
def main(): print('Main started') button, led_button = setup_button() try: while True: GPIO.output(led_button, 1) print('Waiting for button') GPIO.wait_for_edge(button, GPIO.RISING) GPIO.output(led_button, 0) raw_image = get_camera_image() prepared_image = prepear_image(raw_image) print_image(prepared_image) wait_for_print_finish(led_button) except KeyboardInterrupt: print('Keyboard interrupt') GPIO.cleanup() finally: print('Cleanup') GPIO.output(led_button, 0) GPIO.cleanup() # Double cleanup print('Finished')
import time import subprocess GPIO.setmode(GPIO.BOARD) #Select unused GPIO header pin to be used for shutdown InputPin = 12 #PA07/PA_EINT7/SIM_CLK LedOnPin = 13 #PA00/UART2_TX # Set selected pin to input, need pullup resistor external in 3.3V and pin select. GPIO.setup(InputPin, GPIO.IN) # Set selected pin to output. GPIO.setup(LedOnPin, GPIO.OUT) GPIO.output(LedOnPin, 1) if GPIO.input(InputPin): print('Input was HIGH') else: print('Input was LOW') # Wait for a button press on the selected pin (pin pulled to ground, falling edge) GPIO.wait_for_edge(InputPin, GPIO.FALLING) GPIO.output(LedOnPin, 0) print("*** Netctl shutdown activated ***") subprocess.call("/sbin/shutdown now", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
def test_wait_for_edge_not_configured(): with pytest.raises(RuntimeError) as ex: GPIO.wait_for_edge(91, GPIO.RISING) assert str(ex.value) == "Channel 91 is not configured"