Skip to content

Commit a67cdf0

Browse files
authored
Merge pull request #721 from mathoudebine/fix/7-screen-displays-corrupted-images-on-mac
Fix/7 screen displays corrupted images on mac
2 parents 74a49da + a980fda commit a67cdf0

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

library/lcd/lcd_comm.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import copy
2020
import math
2121
import os
22+
import platform
2223
import queue
2324
import sys
2425
import threading
@@ -139,6 +140,10 @@ def SendLine(self, line: bytes):
139140
def WriteLine(self, line: bytes):
140141
try:
141142
self.serial_write(line)
143+
if platform.system() == "Darwin":
144+
# macOS needs the serial buffer to be flushed regularly to avoid bitmap corruption on the display
145+
# See https://github.com/mathoudebine/turing-smart-screen-python/issues/7
146+
self.lcd_serial.flush()
142147
except serial.SerialTimeoutException:
143148
# We timed-out trying to write to our device, slow things down.
144149
logger.warning("(Write line) Too fast! Slow down!")

library/stats.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,9 @@ def display_themed_radial_bar(theme_data, value, min_size=0, unit='', custom_tex
191191
background_image=get_theme_file_path(theme_data.get("BACKGROUND_IMAGE", None)),
192192
custom_bbox=theme_data.get("CUSTOM_BBOX", (0, 0, 0, 0)),
193193
text_offset=theme_data.get("TEXT_OFFSET", (0, 0)),
194-
bar_background_color = theme_data.get("BAR_BACKGROUND_COLOR", (0, 0, 0)),
195-
draw_bar_background = theme_data.get("DRAW_BAR_BACKGROUND", False),
196-
bar_decoration = theme_data.get("BAR_DECORATION", "")
194+
bar_background_color=theme_data.get("BAR_BACKGROUND_COLOR", (0, 0, 0)),
195+
draw_bar_background=theme_data.get("DRAW_BAR_BACKGROUND", False),
196+
bar_decoration=theme_data.get("BAR_DECORATION", "")
197197
)
198198

199199

@@ -742,11 +742,17 @@ def stats():
742742
else:
743743
date_now = datetime.datetime.now()
744744

745-
if platform.system() == "Windows":
746-
# Windows does not have LC_TIME environment variable, use deprecated getdefaultlocale() that returns language code following RFC 1766
747-
lc_time = locale.getdefaultlocale()[0]
748-
else:
749-
lc_time = babel.dates.LC_TIME
745+
try:
746+
if platform.system() == "Windows":
747+
# Windows does not have LC_TIME environment variable, use deprecated getdefaultlocale() that returns language code following RFC 1766
748+
lc_time = locale.getdefaultlocale()[0]
749+
else:
750+
lc_time = babel.dates.LC_TIME
751+
except:
752+
lc_time = None
753+
754+
if not lc_time:
755+
lc_time = "en_US"
750756

751757
date_theme_data = config.THEME_DATA['STATS']['DATE']
752758
day_theme_data = date_theme_data['DAY']['TEXT']

0 commit comments

Comments
 (0)