-
Notifications
You must be signed in to change notification settings - Fork 0
/
rpi_rf.py
108 lines (104 loc) · 4.06 KB
/
rpi_rf.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
#!/usr/bin/env python3
import signal
import sys
import time
import my_room
from rpi_rf import RFDevice
rfdevice = None
debounce = 10
short = 4
long = 0.5
# pylint: disable=unused-argument
def exithandler(signal, frame):
rfdevice.cleanup()
sys.exit(0)
signal.signal(signal.SIGINT, exithandler)
rfdevice = RFDevice(gpio=27)
rfdevice.enable_rx()
timestamp = None
oldtime = time.perf_counter()
oldtime1 = time.perf_counter()
oldtime2 = time.perf_counter()
oldtime3 = time.perf_counter()
print(short)
print(long)
#Received code 835186. is L Switch near entrance
#Received code 818562. is L Switch in hall way
#-------
#Received code 3764961. is big button on car remote <---- Living Room
#Received code 3764962. is next button on car remote <----Leo
#Received code 3764964. is next button on car remote <----My room
#Received code 3764968. is small button on car remote <--- all off
while True:
dt = (time.strftime("%I:%M:%S %p"))
if rfdevice.rx_code_timestamp != timestamp:
timestamp = rfdevice.rx_code_timestamp
now = time.perf_counter()
if ((str(rfdevice.rx_code) == '3764961')) or ((str(rfdevice.rx_code) == '818562')) or ((str(rfdevice.rx_code) == '835186')) :
print(str(rfdevice.rx_code) +
" [pulselength " + str(rfdevice.rx_pulselength) +
", protocol " + str(rfdevice.rx_proto) + "]")
# print("old time" , oldtime)
# print("now time" , now)
elapsed = now - oldtime
print("elapsed" , elapsed)
oldtime = now
# if elapsed < debounce: # Less than 10
# pass
# else:
## oldtime = now
# print("Front Room after debounce Press" , dt)
# oldtime = now
## my_room.living()
# elapsed = now - oldtime
if elapsed > short: # Greater than 4
print("Front Room Short Pressssssss" , dt)
# oldtime = now
if elapsed < long: # Less than 0.5
print("Front Room Long Pressssssssss" , dt)
# oldtime = now
## my_room.lights("Light_3", 4)
# oldtime = now
# print("now time" , now)
oldtime = now
##--------------------------------------leo-------------------------------------------------------------------------
elif ((str(rfdevice.rx_code) == '3764962')):
now1 = time.perf_counter()
elapsed1 = now1 - oldtime1
if elapsed1 < debounce:
my_room.leo_br()
print("Duplicate Button Press - Dimming")
#pass
else:
oldtime1 = now1
print("Leo's Room Lights Pressed" , dt)
my_room.leo()
##--------------------------------My Room-------------------------------------------------------------------------------
elif ((str(rfdevice.rx_code) == '3764964')):
now2 = time.perf_counter()
elapsed2 = now2 - oldtime2
if elapsed2 < debounce:
my_room.lights('Bedroom Light' , 4)
print("Duplicate Button Press - Dimming")
#pass
else:
oldtime2 = now2
print("My Room Lights Pressed" , dt)
my_room.bed()
##--------------------------------------------------------------------------------------------------------
elif ((str(rfdevice.rx_code) == '3764968')):
now3 = time.perf_counter()
elapsed3 = now3 - oldtime3
if elapsed3 < debounce:
#print("Ignoring Duplicate Button Press")
pass
else:
oldtime3 = now3
print("All Room's Lights Off" , dt)
my_room.all_pof()
#-----------------------------------------------------------------------------------------------------------
time.sleep(0.01)
rfdevice.cleanup()
#my_room.living_br()
#print("Duplicate Button Press - Dimming")
#