Skip to content

Commit 91cf424

Browse files
authored
Merge pull request #865 from Ackis/master
Blank display when quitting via CTRL-C (Catch SIGINT)
2 parents a180e4c + 17a7132 commit 91cf424

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed

Pi_Hole_Ad_Blocker/fonts/readme.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Silkscreen was created by Jason Kottke and is distributed under the Open Font License, which means that you can use, distribute, or modify it however you wish. More information about the license and Silkscreen is available on the web:
2+
3+
http://scripts.sil.org/OFL
4+
http://www.kottke.org/plus/type/silkscreen/
5+
6+
To install Silkscreen, simply copy the two .ttf files to your fonts directory.

Pi_Hole_Ad_Blocker/fonts/slkscr.ttf

16.7 KB
Binary file not shown.

Pi_Hole_Ad_Blocker/fonts/slkscrb.ttf

15.6 KB
Binary file not shown.

Pi_Hole_Ad_Blocker/stats.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,34 @@
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+
46+
# URL of Pi Hole
4247
api_url = 'http://localhost/admin/api.php'
4348

49+
# Load nice silkscreen font
50+
font = ImageFont.truetype('fonts/slkscr.ttf', 8)
51+
4452
# Create the I2C interface.
4553
i2c = busio.I2C(SCL, SDA)
4654

55+
# Blanks the Pi OLED display.
56+
def blank_screen(display):
57+
display.fill(0)
58+
display.show()
59+
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+
4770
# Create the SSD1306 OLED class.
4871
# The first two parameters are the pixel width and pixel height. Change these
4972
# to the right size for your display!
@@ -55,8 +78,7 @@
5578
DISPLAY_OFF = 50 # off time in seconds
5679

5780
# Clear display.
58-
disp.fill(0)
59-
disp.show()
81+
blank_screen(disp)
6082

6183
# Create blank image for drawing.
6284
# Make sure to create image with mode '1' for 1-bit color.
@@ -79,9 +101,6 @@
79101
# for drawing shapes.
80102
x = 0
81103

82-
# Load nice silkscreen font
83-
font = ImageFont.truetype('/home/pi/slkscr.ttf', 8)
84-
85104
while True:
86105
# Draw a black filled box to clear the image.
87106
draw.rectangle((0, 0, width, height), outline=0, fill=0)
@@ -131,6 +150,6 @@
131150
disp.image(image)
132151
disp.show()
133152
time.sleep(DISPLAY_ON)
134-
disp.fill(0)
135-
disp.show()
153+
# Clear display.
154+
blank_screen(disp)
136155
time.sleep(DISPLAY_OFF)

0 commit comments

Comments
 (0)