Skip to content

Commit ffc94af

Browse files
committed
Catch SIGINT and blank the screen. This means that when running via command line and we press CTRL-C the display will always end up getting blanked before the program quits. Helps with the burn in.
1 parent 3cd02e1 commit ffc94af

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

Pi_Hole_Ad_Blocker/stats.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939
# Import Python Imaging Library
4040
from PIL import Image, ImageDraw, ImageFont
4141

42+
# Signal/sys are used to catch SIGINT.
43+
import signal
44+
import sys
45+
4246
# URL of Pi Hole
4347
api_url = 'http://localhost/admin/api.php'
4448

@@ -53,6 +57,16 @@ def blank_screen(display):
5357
display.fill(0)
5458
display.show()
5559

60+
def SIGINT(sig, frame):
61+
print('Ctrl+C detected. Quitting.')
62+
# Clear display.
63+
blank_screen(disp)
64+
sys.exit(0)
65+
66+
# Catch SIGINT (ctrl-c) and blank the screen.
67+
# This ensures that the screen will be blank when we exit.
68+
signal.signal(signal.SIGINT, SIGINT)
69+
5670
# Create the SSD1306 OLED class.
5771
# The first two parameters are the pixel width and pixel height. Change these
5872
# to the right size for your display!

0 commit comments

Comments
 (0)