-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
109 lines (85 loc) · 2.87 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
"""
This project is made by Sarim Bin Waseem
github.com/sarimbinwaseem
What is this?
A program to show "current time" and "current salah's ending time"
on a SSD1306 display when a physical button attached to
raspberry pi is pressed.
Next:
1. To add a buzzer sound when the time ends.
2. Implement "signal" to exit gracefully.
It also has a systemd service file so this program can start
at the boot of the system.
sudo cp salah_timings.service /etc/systemd/system/
sudo systemctl enable salah_timings.service
"""
import sys
import threading
import time as timelib
from multiprocessing import Pipe
from Utils.display import Display
from Utils.hardware import Hardware
from Utils.salahtime import SalahTime
def display_loop(*args):
"""display loop to show time on the screen"""
### Getting data and displaying times.
stime = args[1]
display = args[2]
for _ in range(13):
current_time, next_salah_time = stime.get_all_times()
display.draw_rectangle()
display.draw_time_image(current_time, next_salah_time)
# Display image.
display.display_image()
timelib.sleep(0.4)
print(current_time, next_salah_time)
display.clear()
def main():
"""Main entry of the system"""
try:
# Making Pipe to communicate.
recv_conn, send_conn = Pipe()
stime = SalahTime(send_conn)
display = Display()
res = display.begin_display()
if res == -1:
print("[-] Display module may not be connected.")
print("[-] Exiting...!")
sys.exit(1)
display.set_image_support()
display.create_image("Images/image.png")
display.display_image()
timelib.sleep(3)
display.create_blank_image()
display.create_draw()
display.draw_rectangle()
display.clear()
# hard will be used later
hard = Hardware(display_loop, stime, display)
print("[+] Objects initialized...")
# Program is in loop and stuck because of this thread.
# Ending this thread will exit the program. (May not be now)
thread = threading.Thread(target=stime.check_changes, daemon=True)
thread.start()
print("[+] Check for the time change has been started.")
salah_change_buzz = threading.Thread(
target=stime.check_change_of_salah, daemon=True
)
salah_change_buzz.start()
print("[+] Buzzer .")
while True:
DATA = recv_conn.recv()
if DATA == 1:
hard.buzz(1)
elif DATA == 3:
hard.buzz(3)
timelib.sleep(0.9)
except KeyboardInterrupt:
print("[-] Exiting...!")
# display.clear()
stime.check_date_changes_flag = False
stime.check_change_of_salah_flag = False
thread.join()
sys.exit()
if __name__ == "__main__":
main()