]> vault307.fbx.one Git - micorpython_ir.git/blobdiff - ir_rx_test.py
Prior to package.
[micorpython_ir.git] / ir_rx_test.py
index 908d23f83cb229e29f2610bba9971a2ec417b0ac..a436082b411779f7f87c12693ac6bec533065ba1 100644 (file)
@@ -8,8 +8,9 @@
 
 from sys import platform
 import time
 
 from sys import platform
 import time
+import gc
 from machine import Pin, freq
 from machine import Pin, freq
-from arem import *
+from ir_rx import *
 
 ESP32 = platform == 'esp32' or platform == 'esp32_LoBo'
 
 
 ESP32 = platform == 'esp32' or platform == 'esp32_LoBo'
 
@@ -19,39 +20,49 @@ elif platform == 'esp8266':
     freq(160000000)
     p = Pin(13, Pin.IN)
 elif ESP32:
     freq(160000000)
     p = Pin(13, Pin.IN)
 elif ESP32:
-    p = Pin(23, Pin.IN)
-
-errors = {BADSTART : 'Invalid start pulse', BADBLOCK : 'Error: bad block',
-          BADREP : 'Error: repeat', OVERRUN : 'Error: overrun',
-          BADDATA : 'Error: invalid data', BADADDR : 'Error: invalid address'}
+    p = Pin(23, Pin.IN)  # was 27
 
 
+# User callback
 def cb(data, addr, ctrl):
 def cb(data, addr, ctrl):
-    if data == REPEAT:  # NEC protocol sends repeat codes.
+    if data < 0:  # NEC protocol sends repeat codes.
         print('Repeat code.')
         print('Repeat code.')
-    elif data >= 0:
-        print('Data {:03x} Addr {:03x} Ctrl {:01x}'.format(data, addr, ctrl))
     else:
     else:
-        print('{} Address: {}'.format(errors[data], hex(addr)))
+        print('Data {:03x} Addr {:03x} Ctrl {:01x}'.format(data, addr, ctrl))
 
 
+# Optionally print debug information
+def errf(data):
+    errors = {BADSTART : 'Invalid start pulse', BADBLOCK : 'Error: bad block',
+            BADREP : 'Error: repeat', OVERRUN : 'Error: overrun',
+            BADDATA : 'Error: invalid data', BADADDR : 'Error: invalid address'}
+    print(errors[data])
 
 s = '''Test for IR receiver. Run:
 
 s = '''Test for IR receiver. Run:
-ir_tx_test.test() for NEC protocol,
-ir_tx_test.test(5) for Philips RC-5 protocol,
-ir_tx_test.test(6) for RC6 mode 0.
+from ir_rx_test import test
+test() for NEC protocol,
+test(1) for Sony SIRC 12 bit,
+test(2) for Sony SIRC 15 bit,
+test(3) for Sony SIRC 20 bit,
+test(5) for Philips RC-5 protocol,
+test(6) for RC6 mode 0.
 
 
-Background processing means REPL prompt reappears.
-Hit ctrl-D to stop (soft reset).'''
+Hit ctrl-c to stop, then ctrl-d to soft reset.'''
 
 print(s)
 
 def test(proto=0):
     if proto == 0:
 
 print(s)
 
 def test(proto=0):
     if proto == 0:
-        ir = NEC_IR(p, cb, True, 0)  # Extended mode, dummy ctrl arg for callback
+        ir = NEC_IR(p, cb)  # Extended mode
+    elif proto < 4:
+        ir = SONY_IR(p, cb)
+        ir.bits = (12, 15, 20)[proto - 1]
+        #ir.verbose = True
     elif proto == 5:
         ir = RC5_IR(p, cb)
     elif proto == 6:
         ir = RC6_M0(p, cb)
     elif proto == 5:
         ir = RC5_IR(p, cb)
     elif proto == 6:
         ir = RC6_M0(p, cb)
+    ir.error_function(errf)  # Show debug information
     # A real application would do something here...
     # A real application would do something here...
-    #while True:
-        #time.sleep(5)
-        #print('running')
+    while True:
+        print('running')
+        time.sleep(5)
+        gc.collect()