def test_bad_header(self): pulses = [ 200000, 600, 600, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 600, 600, 600, 600, 600, ] with self.assertRaises(decoder.DecodeException): decoder.decode_sirc(pulses)
def test_short(self): pulses = [ 2400, 600, 600, ] with self.assertRaises(decoder.DecodeException): decoder.decode_sirc(pulses)
def test_ideal(self): pulses = [ 2400, 600, 600, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 600, 600, 600, 600, 600, ] self.assertEqual(decoder.decode_sirc(pulses), (18, 1))
def test_simple(self): pulses = [ 2442, 560, 623, 575, 1221, 577, 617, 582, 622, 577, 1219, 579, 625, 574, 620, 578, 1218, 580, 624, 575, 619, 581, 623, 575, 618, ] self.assertEqual(decoder.decode_sirc(pulses), (18, 1))
import board import pulseio import adafruit_irremote from pysirc import decoder pulsein = pulseio.PulseIn(board.D5, maxlen=120, idle_state=True) generic_decoder = adafruit_irremote.GenericDecode() while True: pulses = generic_decoder.read_pulses(pulsein) print("Heard", len(pulses), "Pulses:", pulses) try: code = decoder.decode_sirc(pulses) print("Decoded (SIRC):", code) except decoder.SIRCDecodeException as e: # failed to decode print("Failed to decode SIRC: ", e.args) try: code = decoder.decode_nec(pulses) print("Decoded (NEC):", code) except decoder.NECDecodeException as e: print("Failed to decode NEC: ", e.args) # We need to keep the generic_decoder last because it modifies the # pulses parameter. See # https://github.com/adafruit/Adafruit_CircuitPython_IRRemote/pull/38 # for details. try: