Skip to content

IR Unit error when initializing receiver callback. #79

@vincebusam

Description

@vincebusam

When adding a callback for IRUnit, the following error occurs:

Traceback (most recent call last):
  File "<stdin>", line 115, in <module>
  File "<stdin>", line 60, in setup
  File "unit/ir.py", line 24, in rx_cb
  File "driver/ir/nec.py", line 116, in __init__
  File "driver/ir/nec.py", line 67, in __init__
  File "driver/ir/receiver.py", line 47, in __init__
ValueError: invalid Timer number

This is due to

self.tim = Timer(-1) # Sofware timer

-1 is no longer a valid argument to Timer(). The caller must now pass in a valid timer.

Here is a basic UIKit2/micropython example

import os, sys, io
import M5
from M5 import *
from unit import IRUnit

ir_0 = None

data = None
addr = None

def ir_0_rx_event(_data, _addr, _ctrl):
  global ir_0, data, addr
  data = _data
  addr = _addr
  print('Got IR')
  print(f'0x{addr:00X}')
  print(f'0x{data:00X}')

def setup():
  global ir_0, data, addr

  M5.begin()
  Widgets.fillScreen(0x000000)

  ir_0 = IRUnit((1, 2))
  ir_0.rx_cb(ir_0_rx_event)

def loop():
  global ir_0, data, addr
  M5.update()

if __name__ == '__main__':
  try:
    setup()
    while True:
      loop()
  except (Exception, KeyboardInterrupt) as e:
    try:
      from utility import print_error_msg
      print_error_msg(e)
    except ImportError:
      print("please update to latest firmware")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions