-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
60 lines (46 loc) · 1.47 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
import argparse
import json
import pigpio
from pifirestick.config import config
from pifirestick.remote.arcade_stick import ArcadeStick
from pifirestick.remote.remote import Remotes, AudioRecieverRemote, TVRemote
from pifirestick.rotary_encoder.rotary import Decoder
p = argparse.ArgumentParser()
g = p.add_mutually_exclusive_group(required=True)
g.add_argument("-s", "--start", help="Start up the pi_firestick", action="store_true")
g.add_argument("-r", "--record", help="Start up the pi_firestick", action="store_true")
p.add_argument("id", nargs="+", type=str, help="IR codes")
args = p.parse_args()
codes_file = "keycodes.json"
if args.start:
# Setup the Rotary decoder
pi = pigpio.pi()
decoder = Decoder(
pi,
int(config['PINS']['DECODER_A']),
int(config['PINS']['DECODER_B'])
)
# Build the list of remotes we will use
remote_list = [
TVRemote(),
AudioRecieverRemote()
]
remotes = Remotes(decoder, remote_list)
try:
remotes.start()
except KeyboardInterrupt:
exit(0)
elif args.record:
from piir.io import receive
from piir.decode import decode
from piir.prettify import prettify
keys = {}
for keyname in args.id:
while True:
data = decode(receive(int(config['PINS']['IR_READ'])))
if data:
break
keys[keyname] = data
f = open("keycodes.json", "w")
f.write(json.dumps(prettify(keys), indent=2))
f.close()