fix shot ir rx check

This commit is contained in:
Tomas Krejci 2024-05-28 23:41:54 +02:00
parent e655a75115
commit c7fb899083

View File

@ -4,13 +4,14 @@
from utime import ticks_us, ticks_diff
from olt_lib.ir_rx import IR_RX
# Bit reverse a 32 bit value
def rbit32(v):
v = (v & 0x0000ffff) << 16 | (v & 0xffff0000) >> 16
v = (v & 0x00ff00ff) << 8 | (v & 0xff00ff00) >> 8
v = (v & 0x0f0f0f0f) << 4 | (v & 0xf0f0f0f0) >> 4
v = (v & 0x33333333) << 2 | (v & 0xcccccccc) >> 2
return (v & 0x55555555) << 1 | (v & 0xaaaaaaaa) >> 1
v = (v & 0x0000FFFF) << 16 | (v & 0xFFFF0000) >> 16
v = (v & 0x00FF00FF) << 8 | (v & 0xFF00FF00) >> 8
v = (v & 0x0F0F0F0F) << 4 | (v & 0xF0F0F0F0) >> 4
v = (v & 0x33333333) << 2 | (v & 0xCCCCCCCC) >> 2
return (v & 0x55555555) << 1 | (v & 0xAAAAAAAA) >> 1
class SONY_ABC(IR_RX): # Abstract base class
@ -26,13 +27,13 @@ class SONY_ABC(IR_RX): # Abstract base class
def decode(self, _):
try:
nedges = self.edge # No. of edges detected
self.verbose and print('nedges', nedges)
self.verbose and print("nedges", nedges)
if nedges > 50:
raise RuntimeError(self.OVERRUN)
bits = (nedges - 2) // 2
if nedges not in (26, 32, 42, 50) or bits > self._bits:
if nedges not in (58, 30, 50) or bits > self._bits:
raise RuntimeError(self.BADBLOCK)
self.verbose and print('SIRC {}bit'.format(bits))
self.verbose and print("SIRC {}bit".format(bits))
width = ticks_diff(self._times[1], self._times[0])
if not 1800 < width < 3000: # 2.4ms leading mark for all valid data
raise RuntimeError(self.BADSTART)
@ -55,15 +56,15 @@ class SONY_ABC(IR_RX): # Abstract base class
val = rbit32(val)
val >>= 8
packet = val
byte3 = val & 0xff # 8 bit command
byte3 = val & 0xFF # 8 bit command
val >>= 8
byte2 = val & 0xff # 8 bit command
byte2 = val & 0xFF # 8 bit command
val >>= 8
byte1 = val & 0xff # 8 bit command
#if nedges < 42:
byte1 = val & 0xFF # 8 bit command
# if nedges < 42:
# addr = val & 0xff # 5 or 8 bit addr
# val = 0
#else:
# else:
# addr = val & 0x1f # 5 bit addr
# val >>= 5 # 8 bit extended
except RuntimeError as e:
@ -71,21 +72,25 @@ class SONY_ABC(IR_RX): # Abstract base class
byte1 = 0
byte2 = 0
byte3 = 0
#packet = 0
# packet = 0
self.do_callback(byte1, byte2, byte3, packet)
class SONY_12(SONY_ABC):
def __init__(self, pin, callback, *args):
super().__init__(pin, 12, callback, *args)
class SONY_15(SONY_ABC):
def __init__(self, pin, callback, *args):
super().__init__(pin, 15, callback, *args)
class SONY_20(SONY_ABC):
def __init__(self, pin, callback, *args):
super().__init__(pin, 20, callback, *args)
class LT_24(SONY_ABC):
def __init__(self, pin, callback, *args):
super().__init__(pin, 24, callback, *args)