39
39
# Import Python Imaging Library
40
40
from PIL import Image , ImageDraw , ImageFont
41
41
42
- # Signal/sys are used to catch SIGINT.
43
- import signal
44
- import sys
45
-
46
- # URL of Pi Hole
47
42
api_url = 'http://localhost/admin/api.php'
48
43
49
- # Load nice silkscreen font
50
- font = ImageFont .truetype ('fonts/slkscr.ttf' , 8 )
51
-
52
44
# Create the I2C interface.
53
45
i2c = busio .I2C (SCL , SDA )
54
46
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
-
70
47
# Create the SSD1306 OLED class.
71
48
# The first two parameters are the pixel width and pixel height. Change these
72
49
# to the right size for your display!
@@ -78,7 +55,8 @@ def SIGINT(sig, frame):
78
55
DISPLAY_OFF = 50 # off time in seconds
79
56
80
57
# Clear display.
81
- blank_screen (disp )
58
+ disp .fill (0 )
59
+ disp .show ()
82
60
83
61
# Create blank image for drawing.
84
62
# Make sure to create image with mode '1' for 1-bit color.
@@ -101,6 +79,9 @@ def SIGINT(sig, frame):
101
79
# for drawing shapes.
102
80
x = 0
103
81
82
+ # Load nice silkscreen font
83
+ font = ImageFont .truetype ('/home/pi/slkscr.ttf' , 8 )
84
+
104
85
while True :
105
86
# Draw a black filled box to clear the image.
106
87
draw .rectangle ((0 , 0 , width , height ), outline = 0 , fill = 0 )
@@ -150,6 +131,6 @@ def SIGINT(sig, frame):
150
131
disp .image (image )
151
132
disp .show ()
152
133
time .sleep (DISPLAY_ON )
153
- # Clear display.
154
- blank_screen ( disp )
134
+ disp . fill ( 0 )
135
+ disp . show ( )
155
136
time .sleep (DISPLAY_OFF )
0 commit comments