d)。 将Python代码直接复制到Apalis iMX6上面测试运行结果如下:
。/ 阻塞模式下,最后是通过Ctrl-C强制退出程序
-----------------------
root@apalis-imx6:~# 。/gpiotest_block.py
The LED initial status is ON
The LED turns OFF
interrupt times is 1
The LED turns ON
interrupt times is 2
^Clibsoc-gpio-debug: Interrupted system call
Traceback (most recent call last):
File “。/gpiotest_block.py”, line 54, in
main(gpio_input_id, gpio_output_id)
File “。/gpiotest_block.py”, line 45, in main
test_interrupt_handler(gpio_in, gpio_out)
File “。/gpiotest_block.py”, line 12, in test_interrupt_handler
gpio_in.wait_for_interrupt(-1)
File “/usr/lib/python3.5/site-packages/libsoc/gpio.py”, line 118, in wait_for_interrupt
if api.libsoc_gpio_wait_interrupt(self._gpio, timeout) != 0:
KeyboardInterrupt
-----------------------
。/ 非阻塞模式下
-----------------------
root@apalis-imx6:~# 。/gpiotest_nonblock.py
The LED initial status is ON
please enter ‘Q’ to quit
The LED turns OFF
The LED turns ON
The LED turns OFF
Q
Do you really want to quit? yes or no
yes
root@apalis-imx6:~#
-----------------------
4)。 使用PyQt5实现图形化界面GPIO中断程序
a)。 硬件配置和连接和上面的测试场景一致。
b)。 为了方便开发PyQt5界面,首先通过Qtcreator创建如下QWidget项目UI界面
// LED Status 右边的 QFrame 方框以及QLable用于显示LED当前的状态
// ‘Turn ON’和’Turn OFF’ 两个PushButton用于通过界面控制LED状态,’Exit’ PushButton用于退出程序