def __init__(self): # No communications or arming yet self.comms = None self.armed = False # Do basic Tk initialization self.root = Tk() self.root.configure(bg=BACKGROUND_COLOR) self.root.resizable(False, False) self.root.title('Hackflight Ground Control Station') left = (self.root.winfo_screenwidth() - DISPLAY_WIDTH) / 2 top = (self.root.winfo_screenheight() - DISPLAY_HEIGHT) / 2 self.root.geometry('%dx%d+%d+%d' % (DISPLAY_WIDTH, DISPLAY_HEIGHT, left, top)) self.frame = Frame(self.root) self.root.wm_iconbitmap(bitmap = "@media/icon.xbm") self.root.tk.call('wm', 'iconphoto', self.root._w, PhotoImage('icon.png')) self.root.protocol('WM_DELETE_WINDOW', self.quit) # Create panes for two rows of widgets self.pane1 = self._add_pane() self.pane2 = self._add_pane() # Add a buttons self.button_connect = self._add_button('Connect', self.pane1, self._connect_callback) self.button_setup = self._add_button('Setup', self.pane2, self._setup_callback) self.button_motors = self._add_button('Motors', self.pane2, self._motors_button_callback) self.button_receiver = self._add_button('Receiver', self.pane2, self._receiver_button_callback) self.button_messages = self._add_button('Messages', self.pane2, self._messages_button_callback) #self.button_maps = self._add_button('Maps', self.pane2, self._maps_button_callback, disabled=False) # Prepare for adding ports as they are detected by our timer task self.portsvar = StringVar(self.root) self.portsmenu = None self.connected = False self.ports = [] # Finalize Tk stuff self.frame.pack() self.canvas = Canvas(self.root, width=DISPLAY_WIDTH, height=DISPLAY_HEIGHT, background='black') self.canvas.pack() # Add widgets for motor-testing dialog; hide them immediately self.motors = Motors(self) self.motors.stop() # Create receiver dialog self.receiver = Receiver(self) # Create messages dialog self.messages = Messages(self) # Create setup dialog self.setup = Setup(self) self._schedule_connection_task() # Create a maps dialog #self.maps = Maps(self, yoffset=-30) # Create a splash image self.splashimage = PhotoImage(file='media/splash.png') self._show_splash() # Create a message parser self.parser = MSP_Parser() # Set up parser's request strings self.attitude_request = self.parser.serialize_ATTITUDE_Request() self.rc_request = self.parser.serialize_RC_Request() # No messages yet self.yaw_pitch_roll = 0,0,0 self.rxchannels = 0,0,0,0,0 # A hack to support display in Setup dialog self.active_axis = 0
along with this code. If not, see <http:#www.gnu.org/licenses/>. ''' PORT = '/dev/ttyACM0' import serial from msppg import MSP_Parser def handler(agl, flowx, flowy): print(agl, flowx, flowy) port = serial.Serial(PORT, 115200) parser = MSP_Parser() parser.set_RANGE_AND_FLOW_Handler(handler) while True: c = None try: c = port.read() except KeyboardInterrupt: port.close() break