-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrpi_rf2.py
66 lines (56 loc) · 1.77 KB
/
rpi_rf2.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
#!/usr/bin/env python3
import time
from rpi_rf import RFDevice
rfdevice = None
rfdevice = RFDevice(gpio=27)
rfdevice.enable_rx()
big_button = 3764961
rfdevice.rx_callback(gpio=27)
timestamp = None
last_timestamp = None
# timestamp2 = time.perf_counter()
#key = (str(rfdevice.rx_code))
count = 0
def rfff():
command = (str(rfdevice.rx_code))
if command == '3764961':
print("yay")
global count
count += 1
print(count)
if count == 10:
print("long press")
count = 0
if count == 4:
print("short press")
count = 5
# return True
# timestamp2 = time.perf_counter()
# elapsed = timestamp - t
# time_taken = timestamp - round(time.time() , 2) #rounding the long decimal float
# print(time_taken,'seconds')
# print("elapsed" , elapsed)
# if key:
# print(key)
# #with rfff as press_listener: #setting code for listening key-press
# # press_listener.join()
# global t
# t = time.time() #reading time in sec
# if key == False:
# print(key)
# #with rfff(on_release = on_key_release) as release_listener: #setting code for listening key-release
# # release_listener.join()
while True:
if rfdevice.rx_code_timestamp != timestamp:
timestamp = rfdevice.rx_code_timestamp
# count = 0
rfff()
time.sleep(0.50)
# print("elapsed" , elapsed)
# print("time" , timestamp)
# if ((str(rfdevice.rx_code) == '3764961')):
# timestamp2 = rfdevice.rx_code_timestamp
# print("time 2" , timestamp2)
# elapsed = timestamp - timestamp2
# print("elapsed" , elapsed)
# print(str(rfdevice.rx_code))