-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathirrecvdata.py
51 lines (46 loc) · 1.66 KB
/
irrecvdata.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
import machine
import utime
import micropython
class irGetCMD(object):
def __init__(self, gpioNum):
self.irRecv = machine.Pin(gpioNum, machine.Pin.IN, machine.Pin.PULL_UP)
self.irRecv.irq(
trigger = machine.Pin.IRQ_RISING | machine.Pin.IRQ_FALLING,
handler = self.__logHandler)
self.logList = []
self.index = 0
self.start = 0
self.dictKeyNum = 0
self.irDict = {}
def __logHandler(self, source):
thisComeInTime = utime.ticks_us()
if self.start == 0:
self.start = thisComeInTime
self.index = 0
return
self.logList.append(utime.ticks_diff(thisComeInTime, self.start))
self.start = thisComeInTime
self.index += 1
def ir_read(self):
utime.sleep_ms(200)
if utime.ticks_diff(utime.ticks_us(), self.start) > 800000 and self.index > 0:
ir_buffer = []
for i in range(3, 66, 2):
if self.logList[i] > 800:
ir_buffer.append(1)
else:
ir_buffer.append(0)
irValue = 0x00000000
for i in range(0, 4):
for j in range(0, 8):
if ir_buffer[i*8+j] == 1:
irValue = irValue << 1
irValue |= 0x01
else:
irValue = irValue << 1
irValue &= 0xfffffffe
# reset
self.logList = []
self.index = 0
self.start = 0
return hex(irValue)