Skip to content

Commit

Permalink
Bug Fix: Only Clear Screen Once on Inactivity
Browse files Browse the repository at this point in the history
Clear screen and screen hide commands were being continuously sent to the ILI9341 display when the display was inactive.  This may have been causing the screen to become unresponsive after some time.  Fixed the code to ensure that the screen is not being constantly cleared on each loop through the display thread.
  • Loading branch information
nebhead committed May 23, 2022
1 parent e5c4cbd commit 6d2b572
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
8 changes: 4 additions & 4 deletions display_ili9341b.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def _display_loop(self):
if self.displaycommand == 'splash':
self._display_splash()
self.displaytimeout = time.time() + 3
self.displaycommand = None
self.displaycommand = 'clear'
time.sleep(3) # Hold splash screen for 3 seconds

if self.displaycommand == 'text':
Expand All @@ -199,11 +199,11 @@ def _display_loop(self):
self.menuactive = False
self.menu['current']['mode'] = 'none'
self.menu['current']['option'] = 0
if not self.displayactive:
self.displaycommand = 'clear'
elif (not self.displaytimeout) and (self.displayactive):
if (self.in_data is not None) and (self.status_data is not None):
self._display_current(self.in_data, self.status_data)
elif (not self.displaytimeout):
self.displaycommand = 'clear'

time.sleep(0.1)

Expand Down Expand Up @@ -317,8 +317,8 @@ def _display_clear(self):

def _display_canvas(self, canvas):
# Display canvas to screen for ILI9341
self.device.backlight(True)
self.device.show()
self.device.backlight(True)
self.device.display(canvas)

def _display_splash(self):
Expand Down
9 changes: 4 additions & 5 deletions display_ili9341e.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ def _init_display_device(self):
# Init Device
self.serial = spi(port=0, device=0, gpio_DC=24, gpio_RST=25, bus_speed_hz=32000000, reset_hold_time=0.2, reset_release_time=0.2)
self.device = ili9341(self.serial, active_low=False, width=self.WIDTH, height=self.HEIGHT, gpio_LIGHT=5, rotate=self.rotation)

# Setup & Start Display Loop Thread
display_thread = threading.Thread(target=self._display_loop)
display_thread.start()
Expand Down Expand Up @@ -163,7 +162,7 @@ def _display_loop(self):
if self.displaycommand == 'splash':
self._display_splash()
self.displaytimeout = time.time() + 3
self.displaycommand = None
self.displaycommand = 'clear'
time.sleep(3) # Hold splash screen for 3 seconds

if self.displaycommand == 'text':
Expand All @@ -187,11 +186,11 @@ def _display_loop(self):
self.menuactive = False
self.menu['current']['mode'] = 'none'
self.menu['current']['option'] = 0
if not self.displayactive:
self.displaycommand = 'clear'
elif (not self.displaytimeout) and (self.displayactive):
if (self.in_data is not None) and (self.status_data is not None):
self._display_current(self.in_data, self.status_data)
elif (not self.displaytimeout):
self.displaycommand = 'clear'

time.sleep(0.1)

Expand Down Expand Up @@ -307,8 +306,8 @@ def _display_clear(self):

def _display_canvas(self, canvas):
# Display canvas to screen for ILI9341
self.device.backlight(True)
self.device.show()
self.device.backlight(True)
self.device.display(canvas)

def _display_splash(self):
Expand Down
8 changes: 4 additions & 4 deletions display_ili9341em.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def _display_loop(self):
if self.displaycommand == 'splash':
self._display_splash()
self.displaytimeout = time.time() + 3
self.displaycommand = None
self.displaycommand = 'clear'
time.sleep(3) # Hold splash screen for 3 seconds

if self.displaycommand == 'text':
Expand All @@ -190,11 +190,11 @@ def _display_loop(self):
self.menuactive = False
self.menu['current']['mode'] = 'none'
self.menu['current']['option'] = 0
if not self.displayactive:
self.displaycommand = 'clear'
elif (not self.displaytimeout) and (self.displayactive):
if (self.in_data is not None) and (self.status_data is not None):
self._display_current(self.in_data, self.status_data)
elif (not self.displaytimeout):
self.displaycommand = 'clear'

time.sleep(0.1)

Expand Down Expand Up @@ -310,8 +310,8 @@ def _display_clear(self):

def _display_canvas(self, canvas):
# Display canvas to screen for ILI9341
self.device.backlight(True)
self.device.show()
self.device.backlight(True)
self.device.display(canvas)

def _display_splash(self):
Expand Down
7 changes: 4 additions & 3 deletions display_pygame_240x320b.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def _display_loop(self):
if self.displaycommand == 'splash':
self._display_splash()
self.displaytimeout = time.time() + 3
self.displaycommand = None
self.displaycommand = 'clear'
pygame.time.delay(3000) # Hold splash screen for 3 seconds

if self.displaycommand == 'text':
Expand All @@ -188,11 +188,11 @@ def _display_loop(self):
self.menuactive = False
self.menu['current']['mode'] = 'none'
self.menu['current']['option'] = 0
if not self.displayactive:
self.displaycommand = 'clear'
elif (not self.displaytimeout) and (self.displayactive):
if (self.in_data is not None) and (self.status_data is not None):
self._display_current(self.in_data, self.status_data)
elif (not self.displaytimeout):
self.displaycommand = 'clear'

pygame.quit()

Expand Down Expand Up @@ -288,6 +288,7 @@ def _draw_auger_icon(self, canvas):
return(canvas)

def _display_clear(self):
print(f'[{time.time()}] Screen Cleared.')
self.display_surface.fill((0,0,0))
pygame.display.update()

Expand Down
6 changes: 3 additions & 3 deletions display_st7789_240x320b.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def _display_loop(self):
if self.displaycommand == 'splash':
self._display_splash()
self.displaytimeout = time.time() + 3
self.displaycommand = None
self.displaycommand = 'clear'
time.sleep(3) # Hold splash screen for 3 seconds

if self.displaycommand == 'text':
Expand All @@ -209,11 +209,11 @@ def _display_loop(self):
self.menuactive = False
self.menu['current']['mode'] = 'none'
self.menu['current']['option'] = 0
if not self.displayactive:
self.displaycommand = 'clear'
elif (not self.displaytimeout) and (self.displayactive):
if (self.in_data is not None) and (self.status_data is not None):
self._display_current(self.in_data, self.status_data)
elif (not self.displaytimeout):
self.displaycommand = 'clear'

time.sleep(0.1)

Expand Down
6 changes: 3 additions & 3 deletions display_st7789_240x320e.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def _display_loop(self):
if self.displaycommand == 'splash':
self._display_splash()
self.displaytimeout = time.time() + 3
self.displaycommand = None
self.displaycommand = 'clear'
time.sleep(3) # Hold splash screen for 3 seconds

if self.displaycommand == 'text':
Expand All @@ -197,11 +197,11 @@ def _display_loop(self):
self.menuactive = False
self.menu['current']['mode'] = 'none'
self.menu['current']['option'] = 0
if not self.displayactive:
self.displaycommand = 'clear'
elif (not self.displaytimeout) and (self.displayactive):
if (self.in_data is not None) and (self.status_data is not None):
self._display_current(self.in_data, self.status_data)
elif (not self.displaytimeout):
self.displaycommand = 'clear'

time.sleep(0.1)

Expand Down

0 comments on commit 6d2b572

Please sign in to comment.