Skip to content

Commit 764d922

Browse files
Made Arduino IDE scroll during upload
When esptool is run from the Arduino IDE, the output window doesn't scroll because of the \rs used to make the console update status on a single line. To avoid this, don't attempt to output everything on a single line when scripted (i.e. not running on a TTY) by replacing \r with \n. See esp8266/Arduino#6765 for some discussion.
1 parent 9503fdd commit 764d922

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

esptool.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@
7575
MEM_END_ROM_TIMEOUT = 0.05 # special short timeout for ESP_MEM_END, as it may never respond
7676
DEFAULT_SERIAL_WRITE_TIMEOUT = 10 # timeout for serial port write
7777

78+
if sys.stdout.isatty():
79+
CR = '\r'
80+
else:
81+
CR = '\n'
7882

7983
def timeout_per_mb(seconds_per_mb, size_bytes):
8084
""" Scales timeouts which are size-specific """
@@ -2365,8 +2369,8 @@ def dump_mem(esp, args):
23652369
d = esp.read_reg(args.address + (i * 4))
23662370
f.write(struct.pack(b'<I', d))
23672371
if f.tell() % 1024 == 0:
2368-
print('\r%d bytes read... (%d %%)' % (f.tell(),
2369-
f.tell() * 100 // args.size),
2372+
print(CR +'%d bytes read... (%d %%)' % (f.tell(),
2373+
f.tell() * 100 // args.size),
23702374
end=' ')
23712375
sys.stdout.flush()
23722376
print('Done!')
@@ -2503,7 +2507,7 @@ def write_flash(esp, args):
25032507
written = 0
25042508
t = time.time()
25052509
while len(image) > 0:
2506-
print('\rWriting at 0x%08x... (%d %%)' % (address + seq * esp.FLASH_WRITE_SIZE, 100 * (seq + 1) // blocks), end='')
2510+
print(CR + 'Writing at 0x%08x... (%d %%)' % (address + seq * esp.FLASH_WRITE_SIZE, 100 * (seq + 1) // blocks), end='')
25072511
sys.stdout.flush()
25082512
block = image[0:esp.FLASH_WRITE_SIZE]
25092513
if args.compress:
@@ -2523,11 +2527,11 @@ def write_flash(esp, args):
25232527
if args.compress:
25242528
if t > 0.0:
25252529
speed_msg = " (effective %.1f kbit/s)" % (uncsize / t * 8 / 1000)
2526-
print('\rWrote %d bytes (%d compressed) at 0x%08x in %.1f seconds%s...' % (uncsize, written, address, t, speed_msg))
2530+
print(CR + 'Wrote %d bytes (%d compressed) at 0x%08x in %.1f seconds%s...' % (uncsize, written, address, t, speed_msg))
25272531
else:
25282532
if t > 0.0:
25292533
speed_msg = " (%.1f kbit/s)" % (written / t * 8 / 1000)
2530-
print('\rWrote %d bytes at 0x%08x in %.1f seconds%s...' % (written, address, t, speed_msg))
2534+
print(CR + 'Wrote %d bytes at 0x%08x in %.1f seconds%s...' % (written, address, t, speed_msg))
25312535

25322536
if not args.encrypt:
25332537
try:
@@ -2690,7 +2694,7 @@ def flash_progress(progress, length):
26902694
t = time.time()
26912695
data = esp.read_flash(args.address, args.size, flash_progress)
26922696
t = time.time() - t
2693-
print('\rRead %d bytes at 0x%x in %.1f seconds (%.1f kbit/s)...'
2697+
print(CR + 'Read %d bytes at 0x%x in %.1f seconds (%.1f kbit/s)...'
26942698
% (len(data), args.address, t, len(data) / t * 8 / 1000))
26952699
with open(args.filename, 'wb') as f:
26962700
f.write(data)

0 commit comments

Comments
 (0)