if platform == "linux" or platform == "linux2": p = "/dev/ttyUSB0" elif platform == "darwin": p = "" elif platform == "win32": p = "3" outbound = serial.Serial( port=p, baudrate=9600, parity=serial.PARITY_NONE, # parity is error checking, odd means the message should have an odd number of 1 bits stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS # eight bits of information per pulse/packet ) cont.update() if not cont.isConnected(): print "connect the controller" cont.update() while not cont.isConnected(): cont.update() print "controller connected" # this is the main loop of the program that updates the controller then sends that modified input to the arduino while 1: cont.update() buttons1 = 0x0 buttons2 = 0x0 # going to eight would include the start button; however, it seems that when 0x80 (only the start button) is sent # the arduino lags for a second or two and reports false values for buttons for i in range(0, cont.getNumButtons()): if(cont.getButton(i)): if(cont.getValueForButton(i) <= 0xFF):
def test_1_isConnected(self): cont.update() self.assertTrue(cont.isConnected(), "Controller was not found") print "controller was found"
yawr = 0 rolr = 0 pchl = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] yawl = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] roll = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] mot = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] start = 0 half_m = False while True: if not cont.isConnected( ): # Updates controller and shows whether it is connected. textdelete(98, 50, "controller connected") textwrite(105, 50, "connect the controller", 255, 10, 10) if cont.isConnected(): textdelete(105, 50, "connect the controller") textwrite(98, 50, "controller connected", 10, 125, 10) textwrite(45, 90, "Pressure:") #Labels in black. textwrite(40, 110, "Current:") textwrite(64, 130, "Temperature:") textwrite(34, 150, "Depth:") textwrite(25, 190, "YPR:") textwrite(40, 170, "YPRraw:") textwrite(20, 250, "M1:") #Motor info. Work in progress.
__author__ = 'johna' ports = serial_finder.serial_ports() port = serial_finder.find_port(ports) print "Using: ", port outbound = serial.Serial( port=port, baudrate=9600, parity=serial.PARITY_NONE, # parity is error checking, odd means the message should have an odd number of 1 bits stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, # eight bits of information per pulse/packet timeout=0.1 ) cont.update() if not cont.isConnected(): print "connect the controller" cont.update() while not cont.isConnected(): cont.update() print "controller connected" root = tk.Tk() root.title("Cal Poly Control Center") pressureLabel = tk.Label(root, fg="black", background='white', text="Pressure: ") pressureOut = tk.Label(root, fg="black", background="white") voltageLabel = tk.Label(root, fg="black", background='white', text="Voltage: ") voltageOut = tk.Label(root, fg="black", background="white") accelLabel = tk.Label(root, fg="black", background='white', text="Acceleration: ") accelOut = tk.Label(root, fg="black", background="white")
port=port, baudrate=9600, parity=serial.PARITY_NONE, # parity is error checking, odd means the message should have an odd number of 1 bits stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, # eight bits of information per pulse/packet timeout=0.1 ) textwrite(160, 30, str(port)) no_serial = False else: textdelete(115, 50, "Connect the serial device") textwrite(110, 50, "Serial device Connected", 10, 125, 10) if not cont.isConnected(): # Updates controller and shows whether it is connected. textdelete(98, 70, "Controller connected") textwrite(105, 70, "Connect the controller", 255, 10, 10) else: textdelete(105, 70, "Connect the controller") textwrite(98, 70, "Controller connected", 10, 125, 10) textwrite(45, 90, "Pressure:") #Labels in black. textwrite(40, 110, "Current:") textwrite(64, 130, "Temperature:") textwrite(34, 150, "Depth:") textwrite(25, 190, "YPR:") textwrite(40, 170, "YPRraw:") textwrite(20, 250, "M1:") #Motor info. Work in progress.