修复 MINI的红外接收的定时器问题
This commit is contained in:
@@ -7,6 +7,7 @@ Micropython library for the IR-Remote/Timer(IR_RX&TX)
|
|||||||
"""
|
"""
|
||||||
import array, time, gc
|
import array, time, gc
|
||||||
from machine import Pin, Timer
|
from machine import Pin, Timer
|
||||||
|
from os import uname
|
||||||
try:
|
try:
|
||||||
from esp32 import RMT
|
from esp32 import RMT
|
||||||
TX_MOED = 1
|
TX_MOED = 1
|
||||||
@@ -27,7 +28,7 @@ class IR_RX:
|
|||||||
self._pulses = array.array('H')
|
self._pulses = array.array('H')
|
||||||
self.code = [None, None, None, memoryview(self._pulses)] #存放[cmd, addr, data, pulses]
|
self.code = [None, None, None, memoryview(self._pulses)] #存放[cmd, addr, data, pulses]
|
||||||
Pin(pin, Pin.IN).irq(handler=self._irq_cb, trigger=(Pin.IRQ_FALLING | Pin.IRQ_RISING))
|
Pin(pin, Pin.IN).irq(handler=self._irq_cb, trigger=(Pin.IRQ_FALLING | Pin.IRQ_RISING))
|
||||||
Timer(timer_id).init(period=5, mode=Timer.PERIODIC, callback=self._timer_cb)
|
Timer(0 if "-C2" in uname().machine else timer_id).init(period=5, mode=Timer.PERIODIC, callback=self._timer_cb)
|
||||||
|
|
||||||
def _irq_cb(self, pin):
|
def _irq_cb(self, pin):
|
||||||
if not self._enable:
|
if not self._enable:
|
||||||
@@ -67,8 +68,8 @@ class IR_RX:
|
|||||||
self._enable = onoff
|
self._enable = onoff
|
||||||
|
|
||||||
class NEC_RX(IR_RX):
|
class NEC_RX(IR_RX):
|
||||||
def __init__(self, pin, bits=None, callback=None):
|
def __init__(self, pin, bits=None, callback=None, timer_id=1):
|
||||||
super().__init__(pin, callback, timeout=15000)
|
super().__init__(pin, callback, timer_id=timer_id)
|
||||||
self._bits = bits
|
self._bits = bits
|
||||||
|
|
||||||
def decode(self):
|
def decode(self):
|
||||||
@@ -103,8 +104,8 @@ class NEC_RX(IR_RX):
|
|||||||
self.code[0:3] = None, None, value
|
self.code[0:3] = None, None, value
|
||||||
|
|
||||||
class RC5_RX(IR_RX):
|
class RC5_RX(IR_RX):
|
||||||
def __init__(self, pin, callback=None):
|
def __init__(self, pin, callback=None, timer_id=1):
|
||||||
super().__init__(pin, callback, timeout=15000)
|
super().__init__(pin, callback, timer_id=timer_id)
|
||||||
|
|
||||||
def decode(self):
|
def decode(self):
|
||||||
pulse_len = len(self._pulses)
|
pulse_len = len(self._pulses)
|
||||||
|
|||||||
Reference in New Issue
Block a user