예제 #1
0
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)
예제 #2
0
파일: com.py 프로젝트: CalPolyUROV/UROV2016
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())))
    outbound.write(" ")
예제 #3
0
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)
예제 #4
0
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)
예제 #5
0
    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
        outbound.write(chr(buttons2))