3939# Import Python Imaging Library
4040from 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
4742api_url = 'http://localhost/admin/api.php'
4843
49- # Load nice silkscreen font
50- font = ImageFont .truetype ('fonts/slkscr.ttf' , 8 )
51-
5244# Create the I2C interface.
5345i2c = busio .I2C (SCL , SDA )
5446
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-
7047# Create the SSD1306 OLED class.
7148# The first two parameters are the pixel width and pixel height. Change these
7249# to the right size for your display!
@@ -78,7 +55,8 @@ def SIGINT(sig, frame):
7855DISPLAY_OFF = 50 # off time in seconds
7956
8057# Clear display.
81- blank_screen (disp )
58+ disp .fill (0 )
59+ disp .show ()
8260
8361# Create blank image for drawing.
8462# Make sure to create image with mode '1' for 1-bit color.
@@ -101,6 +79,9 @@ def SIGINT(sig, frame):
10179# for drawing shapes.
10280x = 0
10381
82+ # Load nice silkscreen font
83+ font = ImageFont .truetype ('/home/pi/slkscr.ttf' , 8 )
84+
10485while True :
10586 # Draw a black filled box to clear the image.
10687 draw .rectangle ((0 , 0 , width , height ), outline = 0 , fill = 0 )
@@ -150,6 +131,6 @@ def SIGINT(sig, frame):
150131 disp .image (image )
151132 disp .show ()
152133 time .sleep (DISPLAY_ON )
153- # Clear display.
154- blank_screen ( disp )
134+ disp . fill ( 0 )
135+ disp . show ( )
155136 time .sleep (DISPLAY_OFF )
0 commit comments