I am evaluating DietPi to solve a problem that has happened since the Pi3 was released.
If you run a python program at startup from /etc/rc.local that reads the keyboard you get a crash:
oldterm = termios.tcgetattr(fd)
termios error: (25, 'inappropriate ioctl for device')
This did not happen with the Pi2 operating system but does with the Pi3(Pixel) and DietPi.
Is there a way to run the following program automatically at startup without it crashing?
Thanks,
David Taylor
Code: Select all
#!/usr/bin/python
#
# startup.py
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)