Browse Source

Merge remote-tracking branch 'upstream/master'

Godzil 2 years ago
parent
commit
1170da409b
2 changed files with 12 additions and 3 deletions
  1. 8 1
      nodemcu_uploader/main.py
  2. 4 2
      nodemcu_uploader/uploader.py

+ 8 - 1
nodemcu_uploader/main.py

@@ -157,6 +157,13 @@ def main_func():
         type=arg_auto_int,
         default=Uploader.TIMEOUT)
 
+    parser.add_argument(
+        '--autobaud_time', '-a',
+        help='Duration of the autobaud timer',
+        type=float,
+        default=Uploader.AUTOBAUD_TIME,
+    )
+
     subparsers = parser.add_subparsers(
         dest='operation',
         help='Run nodemcu-uploader {command} -h for additional help')
@@ -260,7 +267,7 @@ def main_func():
         return
 
     # let uploader user the default (short) timeout for establishing connection
-    uploader = Uploader(args.port, args.baud, start_baud=args.start_baud)
+    uploader = Uploader(args.port, args.baud, start_baud=args.start_baud, autobaud_time=args.autobaud_time)
 
     # and reset the timeout (if we have the uploader&timeout)
     if args.timeout:

+ 4 - 2
nodemcu_uploader/uploader.py

@@ -40,9 +40,10 @@ class Uploader(object):
     BAUD = 115200
     START_BAUD = 115200
     TIMEOUT = 5
+    AUTOBAUD_TIME = 0.3
     PORT = default_port()
 
-    def __init__(self, port=PORT, baud=BAUD, start_baud=START_BAUD, timeout=TIMEOUT):
+    def __init__(self, port=PORT, baud=BAUD, start_baud=START_BAUD, timeout=TIMEOUT, autobaud_time=AUTOBAUD_TIME):
         self._timeout = Uploader.TIMEOUT
         self.set_timeout(timeout)
         log.info('opening port %s with %s baud', port, start_baud)
@@ -56,6 +57,7 @@ class Uploader(object):
 
         self.start_baud = start_baud
         self.baud = baud
+        self.autobaud_time = autobaud_time
         # Keeps things working, if following conections are made:
         ## RTS = CH_PD (i.e reset)
         ## DTR = GPIO0
@@ -69,7 +71,7 @@ class Uploader(object):
             try:
                 self.__writeln('UUUUUUUUUUUU') # Send enough characters for auto-baud
                 self.__clear_buffers()
-                time.sleep(0.30) # Wait for autobaud timer to expire
+                time.sleep(self.autobaud_time) # Wait for autobaud timer to expire
                 self.__exchange(';') # Get a defined state
                 self.__writeln('print("%sync%");')
                 self.__expect('%sync%\r\n> ')