forked from ben174/homecontrol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainloop.py
59 lines (46 loc) · 1.18 KB
/
mainloop.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
#!/usr/bin/env python
import RPi.GPIO as GPIO
from record import Recorder
from control import Control
from command import Command
import time
import logging
GPIO_PIN = 3
recorder = Recorder()
control = Control()
logger = None
def main():
button_press()
return
GPIO.setmode(GPIO.BCM)
GPIO.setup(GPIO_PIN, GPIO.IN)
while True:
button_state = GPIO.input(GPIO_PIN)
#print button_state
if button_state == 0:
button_press()
def button_press():
time.sleep(1)
button_state = GPIO.input(GPIO_PIN)
# check if held down for a long time.
if button_state == 0:
recorder.record_command()
else:
command = Command(action='power', value='on')
recorder.control.execute_command(command)
def oldmain():
GPIO.setmode(GPIO.BCM)
GPIO.setup(24, GPIO.IN)
GPIO.setup(25, GPIO.OUT)
GPIO.output(25, True)
while True:
print GPIO.input(24)
def setup_logging():
# silence phue logging
phue_log = logging.getLogger("phue")
phue_log.setLevel(logging.WARNING)
global logger
logger = logging.getLogger("automate")
logger.setLevel(logging.DEBUG)
if __name__ == '__main__':
main()