Simplified progress display

Added note about corrupt red layer in bw mode
This commit is contained in:
Furrtek
2023-09-03 07:23:14 +02:00
parent 2a8d6a0e81
commit b065ea3a29
9 changed files with 49 additions and 30 deletions

View File

@@ -15,6 +15,7 @@ if (blaster_info[0] == "0"):
ser = serial.Serial(blaster_info[0], 57600, timeout = 5) # 5s timeout for read
ser.reset_input_buffer()
# Flags Repeats Delay Size Data
frameA = [0x00, 0x00, 0x20, 0x00, 0x10, 0x00, 0x0B, 0x00, 0x84, 0x00, 0x00, 0x00, 0x00, 0xAB, 0x09, 0x00, 0x00, 0xF2, 0xA7] # Segment change page
frameB = [0x00, 0x00, 0x20, 0x00, 0x10, 0x00, 0x0D, 0x00, 0x85, 0x00, 0x00, 0x00, 0x00, 0x06, 0xF1, 0x00, 0x00, 0x00, 0x0A, 0x5D, 0x14] # DM show debug infos
@@ -44,6 +45,15 @@ for p in range(0, 8):
print(ser.read())
ba = bytearray()
ba.append(82) # R:Read flash
ser.write(ba)
ser.flush()
i = 0
while ser.inWaiting():
print(str(i) + " " + str(ser.read()))
i += 1
ser.close()
print("Done. Read flash to verify now.")

View File

@@ -19,7 +19,6 @@ def image_convert(image, color_pass):
pixels.append(0 if luma >= 0.1 and luma < 0.9 else 1) # 0 codes color (anything mid grey)
else:
pixels.append(0 if luma < 0.5 else 1) # 0 codes black
return pixels
def record_run(run_count):
@@ -28,7 +27,7 @@ def record_run(run_count):
while run_count:
bits.insert(0, run_count & 1)
run_count >>= 1
# Zero length coding
# Zero length coding - 1
for b in bits[1:]:
compressed.append(0)
if len(bits):
@@ -40,7 +39,7 @@ def usage():
print("img2dm.py port image barcode (page color x y pp4)\n")
print(" port: serial port name (0 for ESL Blaster)")
print(" image: image file")
print(" barcode: 17-character barcode data")
print(" barcode: 17-character ESL barcode data")
print(" page: page number to update (0~15), default: 0")
print(" color: 0:Black and white only, 1:Color-capable ESL, default: 0")
print(" x y: top-left position of image, default: 0 0")
@@ -74,8 +73,6 @@ if (port == "0"):
image = imread(sys.argv[2])
width = image.shape[1]
height = image.shape[0]
# Medium size is 208*112
print("Image is %i*%i, please make sure that this is equal or less than the ESL's display size." % (width, height))
# Get PLID from barcode string
PLID = pr.get_plid(sys.argv[3])
@@ -86,16 +83,18 @@ pos_y = int(sys.argv[7]) if arg_count >= 8 else 0
if arg_count >= 9:
if int(sys.argv[8]):
pp16 = 0
# Medium size is 208*112
print("Image is %i*%i in %s mode, please make sure that this suits your ESL's display." % (width, height, "color" if color_mode else "black and white"))
# First pass for black and white
pixels = image_convert(image, 0)
if color_mode:
# Append second pass for color if needed
# Append second pass for color, if needed
pixels += image_convert(image, 1)
size_raw = len(pixels)
print("Compressing %i bits..." % size_raw)
# First pixel
bits = []
@@ -122,11 +121,11 @@ size_compressed = len(compressed)
# Decide on compression or not
# size_compressed = size_raw # Disable compression
if size_compressed < size_raw:
print("Compression ratio: %.1f%%" % (100 - ((size_compressed * 100) / float(size_raw))))
print("Compression ratio: %.1f%% (%d -> %d bytes)" % (100 - ((size_compressed * 100) / float(size_raw)), size_raw, size_compressed))
data = compressed
compression_type = 2
else:
print("Compression ratio suxx, using raw data")
print("Compression ratio suxx, using raw data instead")
data = pixels
compression_type = 0
@@ -139,15 +138,13 @@ for b in range(0, padding):
padded_data_size = len(data)
frame_count = padded_data_size // bits_per_frame
print("Data size: %i (%i frames)" % (data_size, frame_count))
#print("Data size: %i (%i frames)" % (data_size, frame_count))
frames = []
# Wake-up ping frame
frames.append(pr.make_ping_frame(PLID, pp16, 400))
print("Generating frames...")
# Parameters frame
frame = pr.make_mcu_frame(PLID, 0x05)
pr.append_word(frame, data_size // 8) # Total byte count for group

View File

@@ -49,6 +49,12 @@ def search_esl_blaster():
result[0] = comport
return result
def show_progress(i, total, size, repeats, pp16):
if repeats > 100:
print("Transmitting wake-up frames, please wait...") # Lots of repeats certainly means this is a wake-up frame
else:
print("Transmitting frame %u/%u using %s, length %u, repeated %u times." % (i, total, "PP16" if pp16 else "PP4", size, repeats), end="\r", flush=True)
def transmit_serial(frames, port):
ser = serial.Serial(port, 57600, timeout = 10) # 10s timeout for read
@@ -58,9 +64,9 @@ def transmit_serial(frames, port):
for fr in frames:
data_size = len(fr) - 2
repeats = fr[-2] + (fr[-1] * 256)
if repeats > 255: # Cap to one byte for the simple serial transmitter
repeats = 255
print("Transmitting frame %u/%u, length %u, repeated %u times." % (i, frame_count, data_size, repeats))
if repeats > 255:
repeats = 255 # Cap to one byte for the simple serial transmitter
show_progress(i, frame_count, data_size, repeats, 0)
ba = bytearray()
ba.append(data_size)
@@ -72,7 +78,7 @@ def transmit_serial(frames, port):
ser.flush()
ser.read_until('A')
i += 1
print("")
ser.close()
def transmit_esl_blaster(frames, pp16, port):
@@ -88,10 +94,13 @@ def transmit_esl_blaster(frames, pp16, port):
data_size = len(fr) - 2
repeats = fr[-2] + (fr[-1] * 256)
if repeats > 32767: # Cap to 15 bits because FW V2 uses bit 16 to indicate PP16 protocol
repeats = 32767
print("Transmitting frame %u/%u using %s, length %u, repeated %u times." % (i, frame_count, "PP16" if pp16 else "PP4", data_size, repeats))
if repeats > 32767:
repeats = 32767 # Cap to 15 bits because FW V2 uses bit 16 to indicate PP16 protocol
#if repeats > 100:
# print("Transmitting wake-up frames, please wait...") # Lots of repeats certainly means this is a wake-up frame
#else:
# print("Transmitting frame %u/%u using %s, length %u, repeated %u times." % (i, frame_count, "PP16" if pp16 else "PP4", data_size, repeats), end="\r", flush=True)
show_progress(i, frame_count, data_size, repeats, pp16)
if pp16:
repeats |= 0x8000
@@ -99,7 +108,7 @@ def transmit_esl_blaster(frames, pp16, port):
ba = bytearray()
ba.append(76) # L:Load
ba.append(data_size)
ba.append(30) # 30*50 = 1500 timer ticks between repeats
ba.append(10) # 30*50 = 1500 timer ticks between repeats
ba.append(repeats & 255)
ba.append((repeats // 256) & 255)
for b in range(0, data_size):
@@ -115,5 +124,5 @@ def transmit_esl_blaster(frames, pp16, port):
ser.flush()
ser.read_until(b'K') # Wait for transmit done
i += 1
print("")
ser.close()