up rx lib

This commit is contained in:
Tomas Krejci 2024-05-16 19:30:29 +02:00
parent 9bc670b2b9
commit a2d591e2a0
2 changed files with 15 additions and 56 deletions

View File

@ -7,6 +7,15 @@
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
class SONY_ABC(IR_RX): # Abstract base class
def __init__(self, pin, bits, callback, *args):
# 24 bit block has 50 edges and lasts <= 39ms nominal. Add 4ms to time
@ -46,22 +55,14 @@ class SONY_ABC(IR_RX): # Abstract base class
val |= bit
bit <<= 1
x += 2
#ba = int.to_bytes(val)
#ba = bytearray(val)
#ba.reverse()
#bytes = b'\xAA\x00\x00\x00'
#val = int.from_bytes(ba, byteorder='little', signed=False)
#print(integer)
val = rbit32(val)
val >>= 8
packet = val
byte1 = val & 0xff # 8 bit command
byte3 = val & 0xff # 8 bit command
val >>= 8
byte2 = val & 0xff # 8 bit command
val >>= 8
byte3 = val & 0xff # 8 bit command
byte1 = val & 0xff # 8 bit command
#if nedges < 42:
# addr = val & 0xff # 5 or 8 bit addr
# val = 0

View File

@ -26,54 +26,12 @@ elif platform == "esp32" or platform == "esp32_LoBo":
elif platform == "rp2":
p = Pin(16, Pin.IN)
def reverse(s):
str = ""
for i in s:
str = i + str
return str
# 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
# User callback
def cb(byte1, byte2, byte3, packet):
# print("TEST")
# print(f"packet {packet}")
print(f"byte1 0x{byte1:02x} byte2 0x{byte2:02x} byte3 0x{byte3:02x} packet 0x{packet:08x}")
#packet.reverse()
#print(packet)
#reversed
#print(f" XXX {ustruct.unpack(">I", packet)[0]}")
#print(data)
#ba = int.to_bits(packet, 1, 'big')
#ba[0].reverse()
test = bin(packet)
print(test)
test2 = reverse(test)
print(test2)
#test.__reversed__()
test3 = rbit32(packet)
print(f"{test3:08x}")
#print(test)
# print(f"test: {(int.to_bytes(packet, 4, 'big'))}")
#ba = ba.reversed()
#print(ba)
#ba = int.to_bytes(packet, 4, 'little')
#print(f"packet {ba:08x}")
#ba = bytearray(val)
#ba.reverse()
#bytes = b'\xAA\x00\x00\x00'
#packet = int.from_bytes(ba, byteorder='little', signed=False)
#print(integer)
#print(f"packet {packet:08x}")
print(f"byte1 0x{byte1:02x} byte2 0x{byte2:02x} byte3 0x{byte3:02x} packet 0x{packet:06x}")
def test(proto=0):
classes = (LT_24, SONY_12, SONY_15, SONY_20)
ir = classes[proto](p, cb) # Instantiate receiver