Skip to content

Commit

Permalink
Add a double-clear mode to try to mitigate burn
Browse files Browse the repository at this point in the history
Per commented https://forums.pimoroni.com/t/inky-frame-7-3-burn-in/24574
try clearing to taupe in a display.clear() first, then to the
destination image. I can't see an immediately easy way to negate the
existing image, and I'm not sure how "negate" is even defined in the
e-ink space, since it'd have to be by cell charge levels, not sRGB
values. (But for e.g. PRI2 streaming the only place the pixel data
exists any more is inside PicoGraphics' framebuffer.)

Also some distractions on trying to flush messages, since the
busy-waiting during both updates in close succession is enough to
*really* delay USB serial messages in an annoying fashion. Unfortunately
there doesn't seem to be a way to do this under MicroPython I can find.
  • Loading branch information
LionsPhil committed Mar 30, 2024
1 parent 4f26923 commit 3db3dbd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
20 changes: 17 additions & 3 deletions paperthin-client/paperthin.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
_WIFI_LED_DECODING_BRIGHTNESS,
_WIFI_LED_HEARTBEAT_BRIGHTNESS,
_WIFI_LED_STANDBY_BRIGHTNESS,
_WIFI_FORCE_RECONNECT)
_WIFI_FORCE_RECONNECT,
_DOUBLE_UPDATE_CLEAR)

# Set up the display and pin that indicates USB power.
# https://forums.pimoroni.com/t/inky-frame-deep-sleep-explanation/19965/9
Expand Down Expand Up @@ -70,7 +71,10 @@ def red_screen_of_death(message: str,
exception: typing.Optional[Exception] = None
) -> typing.NoReturn:
"""Stop and sleep with a *fatal* error. Autoreboot if slow-retriable."""
print(f"RSOD: {message}")
# print() (throughout) could really do with flushing a few places, but
# MicroPython sadly does not support (crashes on!) either the keyword arg
# flush=True print() form, or the full sys.stdout.flush().
print(f"RSOD: {message}") # Should flush.
time.sleep(0.1) # Try to encourage serial to flush BEFORE display.update().
inky_frame.led_busy.on() # Christmas tree mode (but not network)!
inky_frame.button_a.led_on()
Expand Down Expand Up @@ -479,6 +483,14 @@ def maybe_buffer_to_file(size: int, socket: usocket.socket) -> bool:
else:
return False

def maybe_double_clear() -> None:
if _DOUBLE_UPDATE_CLEAR:
print("...preliminary clear to taupe...") # Should flush.
display.set_pen(inky_frame.TAUPE)
display.clear()
display.update()
print("...proceeding to update framebuffer...")

def display_using_decoder(headers: typing.Dict[str, str],
socket: usocket.socket,
decoder,
Expand All @@ -497,6 +509,7 @@ def display_using_decoder(headers: typing.Dict[str, str],
# (...assuming open_RAM keeps the underlying bytes marked in use...)
socket.close()
gc.collect()
maybe_double_clear()
decoder.decode(0, 0, **decoder_args)
if too_big:
os.remove(_TEMPFILE_NAME)
Expand Down Expand Up @@ -536,13 +549,14 @@ def display_response(headers: typing.Dict[str, str],
elif type == "image/x.pico-rle":
# While slow and dumb, this format streams directly to the display.
inky_frame.led_wifi.brightness(_WIFI_LED_DECODING_BRIGHTNESS)
maybe_double_clear()
picorle_decode(socket)
socket.close()
else:
# This is *really* borderline use of "fatal", but.
red_screen_of_death(f"Cannot display server response of type '{type}'!",
True)
print("...done!")
print("...done!") # Should flush.
display.update()

# Ok. Time to do stuff. Reset LEDs and get us online.
Expand Down
9 changes: 8 additions & 1 deletion paperthin-client/paperthin_config_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,11 @@
_WIFI_LED_HEARTBEAT_BRIGHTNESS = 0.0625
_WIFI_LED_STANDBY_BRIGHTNESS = 0.0
# Force WiFi to reconnect if it appears to already be connected.
_WIFI_FORCE_RECONNECT = True
_WIFI_FORCE_RECONNECT = True
# Clear the display to blank before updating to the next image.
# This will delay reading the HTTP response for ~40 seconds for PRI; make sure
# your server config is patient enough with clients. (The total update time
# will also raise to ~80 seconds.)
# https://forums.pimoroni.com/t/inky-frame-7-3-burn-in/24574
# Error screens ignore this; they're delayed enough as it is.
_DOUBLE_UPDATE_CLEAR = False

0 comments on commit 3db3dbd

Please sign in to comment.