def test_3_Axis(self): print "starting Axis test, press a to pass, b to fail" while True: time.sleep(0.1) cont.update() if cont.getButton(cont.A): break if cont.getButton(cont.B): self.assertEqual(True, False, "Axis Test Failed") print "X: ", cont.getPrimaryX(), " Y: ", cont.getPrimaryY(), " X2: ", cont.getSecondaryX(), " Y2: ", cont.getSecondaryY()
def test_2_buttonsWorking(self): notDone = True print "starting button test" buttons = [False, False, False, False, False, False, False, False, False, False] while notDone: cont.update() for x in range(0, 10): if cont.getButton(x) and buttons[x] == False: print "button ", x buttons[x] = True if all(buttons): notDone = False
def update(): global outputLabel 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): buttons1 += cont.getValueForButton(i) else: buttons2 += cont.getValueForButton(i) >> 8 outbound.write("STR") # sends a signal to tell that this is the start of data outbound.write(chr(buttons1)) # writes the buttons first outbound.write(chr(buttons2)) outbound.write(str(int(cont.getPrimaryX()))) # casts the floats to ints, then to strings for simple parsing outbound.write(" ") outbound.write(str(int(cont.getPrimaryY()))) outbound.write(" ") outbound.write(str(int(cont.getSecondaryX()))) outbound.write(" ") outbound.write(str(int(cont.getSecondaryY()))) outbound.write(" ") outbound.write(str(int(cont.getTriggers()))) outbound.write(" ") counter = 10 proceed = False while True and counter > 0: counter -= 1 if outbound.readable(): if 'S' == outbound.read(1): if 'T' == outbound.read(1): if 'R' == outbound.read(1): proceed = True break if(proceed): linesToRead = int(outbound.read(3)) # allows for up to 999 lines to be read... for i in range(0, linesToRead): outputLabel['text'] = outbound.readline().rstrip() outputLabel.after(100, update)
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): buttons1 += cont.getValueForButton(i) else: buttons2 += cont.getValueForButton(i) >> 8 outbound.write("STR") # sends a signal to tell that this is the start of data outbound.write(chr(buttons1)) # writes the buttons first outbound.write(chr(buttons2)) outbound.write(str(int(cont.getPrimaryX()))) # casts the floats to ints, then to strings for simple parsing outbound.write(" ") outbound.write(str(int(cont.getPrimaryY()))) outbound.write(" ") outbound.write(str(int(cont.getSecondaryX()))) outbound.write(" ") outbound.write(str(int(cont.getSecondaryY())))
def update(): 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: buttons1 += cont.getValueForButton(i) else: buttons2 += cont.getValueForButton(i) >> 8 outbound.write("STR") # sends a signal to tell that this is the start of data outbound.write(chr(buttons1)) # writes the buttons first outbound.write(chr(buttons2)) outbound.write(str(int(cont.getPrimaryX()))) # casts the floats to ints, then to strings for simple parsing outbound.write(" ") outbound.write(str(int(cont.getPrimaryY()))) outbound.write(" ") outbound.write(str(int(cont.getSecondaryX()))) outbound.write(" ") outbound.write(str(int(cont.getSecondaryY()))) outbound.write(" ") outbound.write(str(int(cont.getTriggers()))) outbound.write(" ") counter = 10 proceed = False pressureOut["bg"] = "red" voltageOut["bg"] = "red" tempOut["bg"] = "red" accelOut["bg"] = "red" depthOut["bg"] = "red" pressureLabel["bg"] = "red" voltageLabel["bg"] = "red" tempLabel["bg"] = "red" accelLabel["bg"] = "red" depthLabel["bg"] = "red" while True and counter > 0: counter -= 1 if outbound.readable(): if "S" == outbound.read(1): if "T" == outbound.read(1): if "R" == outbound.read(1): proceed = True break if proceed: linesToRead = int(outbound.read(3)) # allows for up to 999 lines to be read... for i in range(0, linesToRead // 2): label = outbound.readline().rstrip().lstrip() if label == "PSR": pressureOut["text"] = outbound.readline().rstrip() pressureOut["bg"] = "green" pressureLabel["bg"] = "green" elif label == "VLT": voltageOut["text"] = outbound.readline().rstrip() voltageOut["bg"] = "green" voltageLabel["bg"] = "green" elif label == "TMP": tempOut["text"] = outbound.readline().rstrip() tempOut["bg"] = "green" tempLabel["bg"] = "green" elif label == "ACL": accelOut["text"] = outbound.readline().rstrip() + "\n" accelOut["text"] += outbound.readline().rstrip() + "\n" accelOut["text"] += outbound.readline().rstrip() accelOut["bg"] = "green" accelLabel["bg"] = "green" elif label == "DPT": depthOut["text"] = outbound.readline().rstrip() depthOut["bg"] = "green" depthLabel["bg"] = "green" else: print "unknown datatype:", label print "data:", outbound.readline().rstrip() root.after(100, update)
port=4, baudrate=115200, parity=serial.PARITY_ODD, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS ) print "connect the controller" cont.update() while not cont.isConnected(): cont.update() print "controller connected" while(1): cont.update() buttons = 0x0 for i in range(0, 8): if cont.getButton(i): buttons += (1 << i) #ser.print("STR")#should I send an ok signal to start the communication? how long does that take? ser.write(chr(buttons)) ser.write(str(int(cont.getPrimaryX()))) ser.write(" ") ser.write(str(int(cont.getPrimaryY()))) ser.write(" ") ser.write(str(int(cont.getSecondaryX()))) ser.write(" ") ser.write(str(int(cont.getSecondaryY()))) ser.write(" ") ser.write(str(int(cont.getTriggers()))) ser.write(" ") time.sleep(0.1) #ser.write("END")#should tis be replied to? or just not sent?
def update(): 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): buttons1 += cont.getValueForButton(i) else: buttons2 += cont.getValueForButton(i) >> 8 outbound.write("STR") # sends a signal to tell that this is the start of data outbound.write(chr(buttons1)) # writes the buttons first outbound.write(chr(buttons2)) outbound.write(str(int(cont.getPrimaryX()))) # casts the floats to ints, then to strings for simple parsing outbound.write(" ") outbound.write(str(int(cont.getPrimaryY()))) outbound.write(" ") outbound.write(str(int(cont.getSecondaryX()))) outbound.write(" ") outbound.write(str(int(cont.getSecondaryY()))) outbound.write(" ") outbound.write(str(int(cont.getTriggers()))) outbound.write(" ") counter = 10 proceed = False pressureOut['bg'] = "red" voltageOut['bg'] = "red" tempOut['bg'] = "red" accelOut['bg'] = "red" depthOut['bg'] = "red" pressureLabel['bg'] = "red" voltageLabel['bg'] = "red" tempLabel['bg'] = "red" accelLabel['bg'] = "red" depthLabel['bg'] = "red" while True and counter > 0: counter -= 1 if outbound.readable(): if 'S' == outbound.read(1): if 'T' == outbound.read(1): if 'R' == outbound.read(1): proceed = True break if(proceed): linesToRead = int(outbound.read(3)) # allows for up to 999 lines to be read... for i in range(0, linesToRead // 2): label = outbound.readline().rstrip().lstrip() if(label == "PSR"): pressureOut['text'] = outbound.readline().rstrip() pressureOut['bg'] = "green" pressureLabel['bg'] = "green" elif(label == "VLT"): voltageOut['text'] = outbound.readline().rstrip() voltageOut['bg'] = "green" voltageLabel['bg'] = "green" elif(label == "TMP"): tempOut['text'] = outbound.readline().rstrip() tempOut['bg'] = "green" tempLabel['bg'] = "green" elif(label == "ACL"): accelOut['text'] = outbound.readline().rstrip() + '\n' accelOut['text'] += outbound.readline().rstrip() + '\n' accelOut['text'] += outbound.readline().rstrip() accelOut['bg'] = "green" accelLabel['bg'] = "green" elif(label == "DPT"): depthOut['text'] = outbound.readline().rstrip() depthOut['bg'] = "green" depthLabel['bg'] = "green" else: print "unknown datatype:", label print "data:", outbound.readline().rstrip() root.after(100, update)
textwrite(20, 290, "M3:") textwrite(20, 310, "M4:") textwrite(20, 330, "M5:") textwrite(20, 350, "M6:") textwrite(20, 370, "X1:") textwrite(20, 390, "X2:") textwrite(56, 450, "Half Power:") 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): buttons1 += cont.getValueForButton(i) else: buttons2 += cont.getValueForButton(i) >> 8 if buttons2 == 1: textdelete(130, 450, str(half_m)) if half_m: half_m = False else: half_m = True try: outbound.write( "STR") # sends a signal to tell that this is the start of data outbound.write(chr(buttons1)) # writes the buttons first