?? remote_control.py
字號:
#!/usr/bin/python""" Access the postioner."""import os,time,fcntl,sys,structimport raw_keyboardoutputfifo = os.open("/dev/rtf0", os.O_RDWR|os.O_NONBLOCK)commandfifo = os.open("/dev/rtf1", os.O_RDWR|os.O_NONBLOCK) def ReadStatus(fifo): data = "" while len(data) <2: try : data += os.read(fifo,1) except OSError : pass val = struct.unpack("H",data)[0] d = {} d["position"] = val & 0x0fff d["direction"] = {0:"West",1:"East"}[(val & 0x4000) >> 14] d["motor"] = {1:"East",2:"West",3:"Off"}[(val & 0x3000) >> 12] return ddef GetStatus() : os.write(commandfifo,"q") return ReadStatus(outputfifo) def SendCommand(cmnd) : os.write(commandfifo,cmnd) return ReadStatus(outputfifo)print "This program is controlled by key presses:"print " 'w': move west"print " 'e': move east"print " 'h': halt"print " 'q': quit"print "Current status:",GetStatus()while True : kb = raw_keyboard.Keyboard.getch() if kb != "": if kb=="q" : sys.exit(-1) elif kb in ["w","e","h"] : print "Writing '%s' to command fifo"%kb stat = SendCommand(kb) print "Status:",stat else : stat = GetStatus() if stat["motor"]!="Off" : print stat
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -