I have a python program that runs on startup from etc/rc.local
It reads keyboard input for 5 seconds to allow me to abort before the main program starts.
This has worked perfectly on all Pi versions up to Pi3.
When run on the Pi3 it crashes with
oldterm = termios.tcgetattr(fd)
termios error: (25, 'inappropriate ioctl for device')
If I use the Pi3 card in a Pi2 it also crashes with the same error.
If I use a Pi2 card in a Pi2 (or earlier) it works fine.
I am running an os generated by Noobs on a card purchased last week and
have just run apt-get update and apt-get upgrade on it.
Is there a fix for this or could someone on the development team take a look please?
Thanks,
David Taylor
This is my startup program:
Code: Select all
#!/usr/bin/python
#
# startup.py
# Pi3 fails to read keyboard input but Pi2 does!
# run this program from etc/rc.local on the Pi3 version of the os and it will fail
# run this program from etc/rc.local on the Pi2 version of the os and it will work
import os, sys, time
import termios, fcntl
def GetKey():
fd = sys.stdin.fileno()
oldterm = termios.tcgetattr(fd)
newattr = termios.tcgetattr(fd)
newattr[3] = newattr[3] & ~TERMIOS.ICANON & ~TERMIOS.ECHO
newattr[6][TERMIOS.VMIN] = 1
newattr[6][TERMIOS.VTIME] = 0
termios.tcsetattr(fd, termios.TCSANOW, newattr)
oldflags = fcntl.fcntl(fd, fcntl.F_GETFL)
fcntl.fcntl(fd, fcntl.F_SETFL, oldflags | os.O_NONBLOCK)
try:
try:
c = sys.stdin.read(1)
# print "Got character", repr(c)
return c
except IOError: pass
finally:
termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)
if __name__ == "__main__":
# give us a chance to quit before launching
print '### Press q to prevent launch or any other key to launch ###'
bLaunch = True
TERMIOS = termios
i = 0
z = 5
while i < z:
print z - i,
i = i + 1
ch = GetKey()
if ch != None:
if ch == 'q':
print
print 'Launch has been stopped by pressing ' + ch
bLaunch = False
break
time.sleep(1)
if bLaunch == True:
print
print "Launch the main loop here"
exit(0)