up ir RX
This commit is contained in:
parent
327c30d795
commit
e4ce25e930
@ -58,12 +58,12 @@ class IR_RX:
|
||||
self._times[self.edge] = t
|
||||
self.edge += 1
|
||||
|
||||
def do_callback(self, cmd, addr, ext, thresh=0):
|
||||
def do_callback(self, byte1, byte2, byte3, packet, thresh=0):
|
||||
self.edge = 0
|
||||
if cmd >= thresh:
|
||||
self.callback(cmd, addr, ext, *self.args)
|
||||
if packet >= thresh:
|
||||
self.callback(byte1, byte2, byte3, packet, *self.args)
|
||||
else:
|
||||
self._errf(cmd)
|
||||
self._errf(packet)
|
||||
|
||||
def error_function(self, func):
|
||||
self._errf = func
|
||||
|
@ -12,7 +12,7 @@ class SONY_ABC(IR_RX): # Abstract base class
|
||||
# 24 bit block has 50 edges and lasts <= 39ms nominal. Add 4ms to time
|
||||
# for tolerances except in 24 bit case where timing is tight with a
|
||||
# repeat period of 45ms.
|
||||
t = int(3 + bits * 1.8) + (1 if bits == 20 else 4)
|
||||
t = int(3 + bits * 1.8) + (1 if bits >= 20 else 4)
|
||||
super().__init__(pin, 2 + bits * 2, t, callback, *args)
|
||||
self._addr = 0
|
||||
self._bits = 24
|
||||
@ -34,6 +34,10 @@ class SONY_ABC(IR_RX): # Abstract base class
|
||||
if not 350 < width < 1000: # 600μs space
|
||||
raise RuntimeError(self.BADSTART)
|
||||
|
||||
byte1 = 0
|
||||
byte2 = 0
|
||||
byte3 = 0
|
||||
packet = 0
|
||||
val = 0 # Data received, LSB 1st
|
||||
x = 2
|
||||
bit = 1
|
||||
@ -41,20 +45,26 @@ class SONY_ABC(IR_RX): # Abstract base class
|
||||
if ticks_diff(self._times[x + 1], self._times[x]) > 900:
|
||||
val |= bit
|
||||
bit <<= 1
|
||||
x += 2
|
||||
cmd = val & 0x7f # 7 bit command
|
||||
val >>= 7
|
||||
if nedges < 42:
|
||||
addr = val & 0xff # 5 or 8 bit addr
|
||||
val = 0
|
||||
else:
|
||||
addr = val & 0x1f # 5 bit addr
|
||||
val >>= 5 # 8 bit extended
|
||||
x += 2
|
||||
packet = val
|
||||
byte1 = val & 0xff # 8 bit command
|
||||
val >>= 8
|
||||
byte2 = val & 0xff # 8 bit command
|
||||
val >>= 8
|
||||
byte3 = val & 0xff # 8 bit command
|
||||
#if nedges < 42:
|
||||
# addr = val & 0xff # 5 or 8 bit addr
|
||||
# val = 0
|
||||
#else:
|
||||
# addr = val & 0x1f # 5 bit addr
|
||||
# val >>= 5 # 8 bit extended
|
||||
except RuntimeError as e:
|
||||
cmd = e.args[0]
|
||||
addr = 0
|
||||
val = 0
|
||||
self.do_callback(cmd, addr, val)
|
||||
packet = e.args[0]
|
||||
byte1 = 0
|
||||
byte2 = 0
|
||||
byte3 = 0
|
||||
#packet = 0
|
||||
self.do_callback(byte1, byte2, byte3, packet)
|
||||
|
||||
class SONY_12(SONY_ABC):
|
||||
def __init__(self, pin, callback, *args):
|
||||
|
@ -27,11 +27,10 @@ elif platform == "rp2":
|
||||
p = Pin(16, Pin.IN)
|
||||
|
||||
# User callback
|
||||
def cb(data, addr, ctrl):
|
||||
if data < 0: # NEC protocol sends repeat codes.
|
||||
print("Repeat code.")
|
||||
else:
|
||||
print(f"Data 0x{data:02x} Addr 0x{addr:04x} Ctrl 0x{ctrl:02x}")
|
||||
def cb(byte1, byte2, byte3, packet):
|
||||
# print("TEST")
|
||||
# print(f"packet {packet}")
|
||||
print(f"byte1 0x{byte1:04x} byte2 0x{byte2:04x} byte3 0x{byte3:04x} packet 0x{packet:08x}")
|
||||
|
||||
|
||||
def test(proto=0):
|
||||
|
Loading…
Reference in New Issue
Block a user