def test_input(): with patch("LPi.GPIO.sysfs") as mock: mock.input.return_value = GPIO.HIGH GPIO.setmode(GPIO.BOARD) GPIO.setup(23, GPIO.IN) assert GPIO.input(23) == GPIO.HIGH mock.input.assert_called_with(14)
def test_input_and_output(): with patch("LPi.GPIO.sysfs") as mock: mock.input.return_value = GPIO.HIGH GPIO.setmode(GPIO.BOARD) GPIO.setup(23, GPIO.OUT) GPIO.output(23, not GPIO.input(23)) mock.input.assert_called_with(14) mock.output.assert_called_with(14, GPIO.LOW)
def test_input_not_configured(): with pytest.raises(RuntimeError) as ex: GPIO.input(12) assert str(ex.value) == "Channel 12 is not configured"
rf = font.render("Please toggle shutdown switch.", True, (255, 255, 255)) (tx1, ty1) = rf.get_size() myDisp.screen.blit(rf, (800 / 2 - tx1 / 2, iy + 20)) pygame.display.update() pygame.time.wait(1000) #while GPIO.input( 17 ): pygame.time.wait(100) #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ while running: # start data update and display scheduler schedule.run_pending() # Debounce the shutdown switch. The main loop rnus at 100ms. So, if the # button (well, a switch really) counter "btnShutdownCnt" counts above # 25 then the switch must have been on continuously for 2.5 seconds. if GPIO.input(6): btnNextCnt += 1 if btnNextCnt >= 1: btnNextCnt = -5 btnNext(6) else: btnNextCnt = 0 if 0: #GPIO.input( 17 ): btnShutdownCnt += 1 if btnShutdownCnt > 25: print "Shutdown!" myDisp.screen.fill((0, 0, 0)) icon = pygame.image.load(sd + 'shutdown.jpg') (ix, iy) = icon.get_size() myDisp.screen.blit(icon, (800 / 2 - ix / 2, 400 / 2 - iy / 2))