Пример #1
0
def reset_atmega_handler():
    if not has_valid_id():
        print("ERROR: Failed to reset Chip. No Valid ID entered.")
        return '0'

    reset_atmega(HARDWARE)
    return '1'
Пример #2
0
def connect(port=conf['serial_port'], baudrate=conf['baudrate'], verbose=True):
    global SerialLoop
    if not SerialLoop:
        SerialLoop = SerialLoopClass()

        # Create serial device with read timeout set to 0.
        # This results in the read() being non-blocking.
        # Write on the other hand uses a large timeout but should not be blocking
        # much because we ask it only to write TX_CHUNK_SIZE at a time.
        # BUG WARNING: the pyserial write function does not report how
        # many bytes were actually written if this is different from requested.
        # Work around: use a big enough timeout and a small enough chunk size.
        try:
            if conf['usb_reset_hack']:
                import flash
                flash.usb_reset_hack()
            # connect
            SerialLoop.device = serial.Serial(port,
                                              baudrate,
                                              timeout=0,
                                              writeTimeout=4)
            if conf['hardware'] == 'standard':
                # clear throat
                # Toggle DTR to reset Arduino
                SerialLoop.device.setDTR(False)
                time.sleep(1)
                SerialLoop.device.flushInput()
                SerialLoop.device.setDTR(True)
                # for good measure
                SerialLoop.device.flushOutput()
            else:
                import flash
                flash.reset_atmega()
                time.sleep(0.5)
                SerialLoop.device.flushInput()
                SerialLoop.device.flushOutput()

            start = time.time()
            while True:
                if time.time() - start > 2:
                    if verbose:
                        print("ERROR: Cannot get 'hello' from controller")
                    raise serial.SerialException
                data = SerialLoop.device.read(1)
                if data.find(ord(INFO_HELLO)) > -1:
                    if verbose:
                        print("Controller says Hello!")
                        print("Connected on serial port: %s" % (port))
                    break

            SerialLoop.start()  # this calls run() in a thread
        except serial.SerialException:
            SerialLoop = None
            if verbose:
                print("ERROR: Cannot connect serial on port: %s" % (port))
    else:
        if verbose:
            print("ERROR: disconnect first")
Пример #3
0
def reset():
    import flash
    reconnect = False
    if connected():
        close()
        reconnect = True
    flash.reset_atmega()
    if reconnect:
        connect()
Пример #4
0
def reset():
    import flash
    reconnect = False
    if connected():
        close()
        reconnect = True
    flash.reset_atmega()
    if reconnect:
        connect()
Пример #5
0
def connect(port=conf['serial_port'], baudrate=conf['baudrate'], verbose=True):
    global SerialLoop
    if not SerialLoop:
        SerialLoop = SerialLoopClass()

        # Create serial device with read timeout set to 0.
        # This results in the read() being non-blocking.
        # Write on the other hand uses a large timeout but should not be blocking
        # much because we ask it only to write TX_CHUNK_SIZE at a time.
        # BUG WARNING: the pyserial write function does not report how
        # many bytes were actually written if this is different from requested.
        # Work around: use a big enough timeout and a small enough chunk size.
        try:
            if conf['usb_reset_hack']:
                import flash
                flash.usb_reset_hack()
            # connect
            SerialLoop.device = serial.Serial(port, baudrate, timeout=0, writeTimeout=4)
            if conf['hardware'] == 'standard':
                # clear throat
                # Toggle DTR to reset Arduino
                SerialLoop.device.setDTR(False)
                time.sleep(1)
                SerialLoop.device.flushInput()
                SerialLoop.device.setDTR(True)
                # for good measure
                SerialLoop.device.flushOutput()
            else:
                import flash
                flash.reset_atmega()
                time.sleep(0.5)
                SerialLoop.device.flushInput()
                SerialLoop.device.flushOutput()

            start = time.time()
            while True:
                if time.time() - start > 2:
                    if verbose:
                        print "ERROR: Cannot get 'hello' from controller"
                    raise serial.SerialException
                char = SerialLoop.device.read(1)
                if char == INFO_HELLO:
                    if verbose:
                        print "Controller says Hello!"
                    break

            SerialLoop.start()  # this calls run() in a thread
        except serial.SerialException:
            SerialLoop = None
            if verbose:
                print "ERROR: Cannot connect serial on port: %s" % (port)
    else:
        if verbose:
            print "ERROR: disconnect first"
Пример #6
0
def reset_atmega_handler():
    reset_atmega(HARDWARE)
    return '1'
Пример #7
0
def reset_atmega_handler():
    reset_atmega(HARDWARE)
    return '1'
Пример #8
0
def reset_atmega_handler():
    if not admin_check():
      return None
    reset_atmega(HARDWARE)
    return '1'
Пример #9
0
def reset_atmega_handler():
    global user_approved
    if not user_approved:
        return 'Access denied'
    reset_atmega(HARDWARE)
    return '1'