⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 remote_control.py

📁 Most satellite dish actuators send a series of pulses to indicate their position. By counting pulse
💻 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 + -