-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.py
executable file
·41 lines (30 loc) · 905 Bytes
/
index.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
#!/usr/bin/python3
#
# Author: jun10000 (https://github.com/jun10000)
#
import os
import sys
from arduinoserial import ArduinoSerial
from ridatabase import RIDatabase
def main():
with RIDatabase() as db, ArduinoSerial() as ser:
while True:
result = ser.readsignal()
db.insert_signal(result)
def create_daemon(func):
pid = os.fork()
if pid > 0:
with open('/var/run/OnkyoRIListener2.pid', 'w') as file:
file.write(str(pid))
sys.exit()
elif pid == 0:
func()
#---------------------------------------------------------------#
#------------------------- Entry Point -------------------------#
#---------------------------------------------------------------#
if __name__ == '__main__':
mode = '' if len(sys.argv) == 1 else sys.argv[1]
if mode == 'debug':
main()
else:
create_daemon(main)