def flash_firmware_handler(firmware_file=FIRMWARE): global SERIAL_PORT, GUESS_PREFIX return_code = 1 if SerialManager.is_connected(): SerialManager.close() # get serial port by url argument # e.g: /flash_firmware?port=COM3 if 'port' in request.GET.keys(): serial_port = request.GET['port'] if serial_port[:3] == "COM" or serial_port[:4] == "tty.": SERIAL_PORT = serial_port # get serial port by enumeration method # currenty this works on windows only for updating the firmware if not SERIAL_PORT: SERIAL_PORT = SerialManager.match_device(GUESS_PREFIX, BITSPERSECOND) # resort to brute force methode # find available com ports and try them all if not SERIAL_PORT: comport_list = SerialManager.list_devices(BITSPERSECOND) for port in comport_list: print "Trying com port: " + port return_code = flash_upload(port, resources_dir(), firmware_file, HARDWARE) if return_code == 0: print "Success with com port: " + port SERIAL_PORT = port break else: return_code = flash_upload(SERIAL_PORT, resources_dir(), firmware_file, HARDWARE) ret = [] ret.append('Using com port: %s<br>' % (SERIAL_PORT)) ret.append('Using firmware: %s<br>' % (firmware_file)) if return_code == 0: print "SUCCESS: Arduino appears to be flashed." ret.append('<h2>Successfully Flashed!</h2><br>') ret.append('<a href="/">return</a>') return ''.join(ret) else: print "ERROR: Failed to flash Arduino." ret.append( '<h2>Flashing Failed!</h2> Check terminal window for possible errors. ' ) ret.append( 'Most likely LasaurApp could not find the right serial port.') ret.append('<br><a href="/flash_firmware/' + firmware_file + '">try again</a> or <a href="/">return</a><br><br>') if os.name != 'posix': ret.append( 'If you know the COM ports the Arduino is connected to you can specifically select it here:' ) for i in range(1, 13): ret.append( '<br><a href="/flash_firmware?port=COM%s">COM%s</a>' % (i, i)) return ''.join(ret)
def flash_firmware_handler(firmware_file=FIRMWARE): global user_approved global user_admin if not user_approved and user_admin: return 'Access denied' logger.log(current_user, 'Flashing ATMEGA') return_code = 1 if SerialManager.is_connected(): SerialManager.close() # get serial port by url argument # e.g: /flash_firmware?port=COM3 if 'port' in request.GET.keys(): serial_port = request.GET['port'] if serial_port[:3] == "COM" or serial_port[:4] == "tty.": SERIAL_PORT = serial_port # get serial port by enumeration method # currenty this works on windows only for updating the firmware if not SERIAL_PORT: SERIAL_PORT = SerialManager.match_device(GUESS_PREFIX, BITSPERSECOND) # resort to brute force methode # find available com ports and try them all if not SERIAL_PORT: comport_list = SerialManager.list_devices(BITSPERSECOND) for port in comport_list: print "Trying com port: " + port return_code = flash_upload(port, resources_dir(), firmware_file, HARDWARE) if return_code == 0: print "Success with com port: " + port SERIAL_PORT = port break else: return_code = flash_upload(SERIAL_PORT, resources_dir(), firmware_file, HARDWARE) ret = [] ret.append('Using com port: %s<br>' % (SERIAL_PORT)) ret.append('Using firmware: %s<br>' % (firmware_file)) if return_code == 0: print "SUCCESS: Arduino appears to be flashed." ret.append('<h2>Successfully Flashed!</h2><br>') ret.append('<a href="/">return</a>') return ''.join(ret) else: print "ERROR: Failed to flash Arduino." ret.append('<h2>Flashing Failed!</h2> Check terminal window for possible errors. ') ret.append('Most likely LasaurApp could not find the right serial port.') ret.append('<br><a href="/flash_firmware/'+firmware_file+'">try again</a> or <a href="/">return</a><br><br>') if os.name != 'posix': ret. append('If you know the COM ports the Arduino is connected to you can specifically select it here:') for i in range(1,13): ret. append('<br><a href="/flash_firmware?port=COM%s">COM%s</a>' % (i, i)) return ''.join(ret)
def flash_firmware_handler(): global SERIAL_PORT, GUESS_PREFIX return_code = 1 if SerialManager.is_connected(): SerialManager.close() # get serial port by url argument # e.g: /flash_firmware?port=COM3 if "port" in request.GET.keys(): serial_port = request.GET["port"] if serial_port[:3] == "COM" or serial_port[:4] == "tty.": SERIAL_PORT = serial_port # get serial port by enumeration method # currenty this works on windows only for updating the firmware if not SERIAL_PORT: SERIAL_PORT = SerialManager.match_device(GUESS_PREFIX, BITSPERSECOND) # resort to brute force methode # find available com ports and try them all if not SERIAL_PORT: comport_list = SerialManager.list_devices(BITSPERSECOND) for port in comport_list: print "Trying com port: " + port return_code = flash_upload(port, resources_dir()) if return_code == 0: print "Success with com port: " + port SERIAL_PORT = port break else: return_code = flash_upload(SERIAL_PORT, resources_dir()) ret = [] ret.append("Using com port: %s<br>" % (SERIAL_PORT)) if return_code == 0: print "SUCCESS: Arduino appears to be flashed." ret.append("<h2>Successfully Flashed!</h2><br>") ret.append('<a href="/">return</a>') return "".join(ret) else: SERIAL_PORT = None print "ERROR: Failed to flash Arduino." ret.append("<h2>Flashing Failed!</h2> Check Log window for possible errors. ") ret.append('Most likely LasaurApp could not find the right serial port.<br><a href="/">return</a><br><br>') if os.name != "posix": ret.append("If you know the COM ports the Arduino is connected to you can specifically select it here:") for i in range(1, 13): ret.append('<br><a href="/flash_firmware?port=COM%s">COM%s</a>' % (i, i)) return "".join(ret)
pinExt3 = 17 pinTX = 14 pinRX = 15 # read sens pin GPIO.setup(pinSense, GPIO.IN) isSMC11 = GPIO.input(pinSense) # atmega reset pin GPIO.setup(pinReset, GPIO.OUT) GPIO.output(pinReset, GPIO.HIGH) # no need to setup the serial pins # although /boot/cmdline.txt and /etc/inittab needs # to be edited to deactivate the serial terminal login # (basically anything related to ttyAMA0) if args.list_serial_devices: SerialManager.list_devices(BITSPERSECOND) else: if not SERIAL_PORT: if args.port: # (1) get the serial device from the argument list SERIAL_PORT = args.port print "Using serial device '" + SERIAL_PORT + "' from command line." else: # (2) get the serial device from the config file if os.path.isfile(CONFIG_FILE): fp = open(CONFIG_FILE) line = fp.readline().strip() if len(line) > 3: SERIAL_PORT = line print "Using serial device '" + SERIAL_PORT + "' from '" + CONFIG_FILE + "'."
pinTX = 14 pinRX = 15 # read sens pin GPIO.setup(pinSense, GPIO.IN) isSMC11 = GPIO.input(pinSense) # atmega reset pin GPIO.setup(pinReset, GPIO.OUT) GPIO.output(pinReset, GPIO.HIGH) # no need to setup the serial pins # although /boot/cmdline.txt and /etc/inittab needs # to be edited to deactivate the serial terminal login # (basically anything related to ttyAMA0) if args.list_serial_devices: SerialManager.list_devices(BITSPERSECOND) else: if not SERIAL_PORT: if args.port: # (1) get the serial device from the argument list SERIAL_PORT = args.port print "Using serial device '"+ SERIAL_PORT +"' from command line." else: # (2) get the serial device from the config file if os.path.isfile(CONFIG_FILE): fp = open(CONFIG_FILE) line = fp.readline().strip() if len(line) > 3: SERIAL_PORT = line print "Using serial device '"+ SERIAL_PORT +"' from '" + CONFIG_FILE + "'."
debug(True) if hasattr(sys, "_MEIPASS"): print "Data root is: " + sys._MEIPASS print "Persistent storage root is: " + storage_dir() if args.build_and_flash: flash_upload(SERIAL_PORT, resources_dir()) else: if args.host_on_all_interfaces: run_with_callback('') else: run_with_callback('127.0.0.1') print "LasaurApp " + VERSION if args.list_serial_devices: SerialManager.list_devices() else: if args.port: # (1) get the serial device from the argument list SERIAL_PORT = args.port print "Using serial device '"+ SERIAL_PORT +"' from command line." else: # (2) get the serial device from the config file if os.path.isfile(CONFIG_FILE): fp = open(CONFIG_FILE) line = fp.readline().strip() if len(line) > 3: SERIAL_PORT = line print "Using serial device '"+ SERIAL_PORT +"' from '" + CONFIG_FILE + "'." if not SERIAL_PORT: