Skip to content

Commit

Permalink
Make write delay configurable
Browse files Browse the repository at this point in the history
This adds the --delay parameter, which makes the write delay (previously
hard-coded to 0.3s) configurable. 0.3s is kept as default if no delay is
specified.
  • Loading branch information
jonte committed Dec 12, 2015
1 parent 8b081e6 commit 4f72117
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions luatool/luatool.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,11 @@ def performcheck(self, expected):


class SerialTransport(AbstractTransport):
def __init__(self, port, baud):
def __init__(self, port, baud, delay):
self.port = port
self.baud = baud
self.serial = None
self.delay = delay

try:
self.serial = serial.Serial(port, baud)
Expand All @@ -101,7 +102,7 @@ def writeln(self, data, check=1):
sys.stdout.write("\r\n->")
sys.stdout.write(data.split("\r")[0])
self.serial.write(data)
sleep(0.3)
sleep(self.delay)
if check > 0:
self.performcheck(data)
else:
Expand Down Expand Up @@ -160,7 +161,7 @@ def decidetransport(cliargs):
port = 23
return TcpSocketTransport(host, port)
else:
return SerialTransport(cliargs.port, cliargs.baud)
return SerialTransport(cliargs.port, cliargs.baud, cliargs.delay)


if __name__ == '__main__':
Expand All @@ -179,6 +180,7 @@ def decidetransport(cliargs):
parser.add_argument('-w', '--wipe', action='store_true', help='Delete all lua/lc files on device.')
parser.add_argument('-i', '--id', action='store_true', help='Query the modules chip id.')
parser.add_argument('-e', '--echo', action='store_true', help='Echo output of MCU until script is terminated.')
parser.add_argument('--delay', default=0.3, help='Delay in seconds between each write.', type=float)
parser.add_argument('--delete', default=None, help='Delete a lua/lc file from device.')
parser.add_argument('--ip', default=None, help='Connect to a telnet server on the device (--ip IP[:port])')
args = parser.parse_args()
Expand Down

0 comments on commit 4f72117

Please sign in to comment.