mirror of
https://github.com/Klipper3d/klipper.git
synced 2025-07-07 15:07:33 -06:00
Initial commit of source code.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
37a91e9c10
commit
f582a36e4d
71 changed files with 9950 additions and 0 deletions
32
klippy/util.py
Normal file
32
klippy/util.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
# Low level unix utility functions
|
||||
#
|
||||
# Copyright (C) 2016 Kevin O'Connor <kevin@koconnor.net>
|
||||
#
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license.
|
||||
|
||||
import os, pty, fcntl, termios, signal
|
||||
|
||||
# Return the SIGINT interrupt handler back to the OS default
|
||||
def fix_sigint():
|
||||
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
||||
fix_sigint()
|
||||
|
||||
# Set a file-descriptor as non-blocking
|
||||
def set_nonblock(fd):
|
||||
fcntl.fcntl(fd, fcntl.F_SETFL
|
||||
, fcntl.fcntl(fd, fcntl.F_GETFL) | os.O_NONBLOCK)
|
||||
|
||||
# Support for creating a pseudo-tty for emulating a serial port
|
||||
def create_pty(ptyname):
|
||||
mfd, sfd = pty.openpty()
|
||||
try:
|
||||
os.unlink(ptyname)
|
||||
except os.error:
|
||||
pass
|
||||
os.symlink(os.ttyname(sfd), ptyname)
|
||||
fcntl.fcntl(mfd, fcntl.F_SETFL
|
||||
, fcntl.fcntl(mfd, fcntl.F_GETFL) | os.O_NONBLOCK)
|
||||
old = termios.tcgetattr(mfd)
|
||||
old[3] = old[3] & ~termios.ECHO
|
||||
termios.tcsetattr(mfd, termios.TCSADRAIN, old)
|
||||
return mfd
|
Loading…
Add table
Add a link
Reference in a new issue