]> vault307.fbx.one Git - micorpython_ir.git/blobdiff - ir_tx/nec.py
Merge pull request #20 from cyrilchristin/samsumg-ir_tx-addr-patch
[micorpython_ir.git] / ir_tx / nec.py
index 8cf39e70ca79b462cf5d5438959627ef40e0d9b8..be9ee28ef7b898534ff3f5a0a0618f61df376827 100644 (file)
@@ -2,8 +2,9 @@
 # NEC protocol.
 
 # Author: Peter Hinch
 # NEC protocol.
 
 # Author: Peter Hinch
-# Copyright Peter Hinch 2020 Released under the MIT license
+# Copyright Peter Hinch 2020-2022 Released under the MIT license
 
 
+# With thanks to J.E. Tannenbaum for information re Samsung protocol
 from micropython import const
 from ir_tx import IR, STOP
 
 from micropython import const
 from ir_tx import IR, STOP
 
@@ -11,17 +12,25 @@ _TBURST = const(563)
 _T_ONE = const(1687)
 
 class NEC(IR):
 _T_ONE = const(1687)
 
 class NEC(IR):
+    valid = (0xffff, 0xff, 0)  # Max addr, data, toggle
+    samsung = False
 
 
-    def __init__(self, pin, freq=38000, verbose=False):  # NEC specifies 38KHz
-        super().__init__(pin, freq, 68, 50, verbose)
+    def __init__(self, pin, freq=38000, verbose=False):  # NEC specifies 38KHz also Samsung
+        super().__init__(pin, freq, 68, 33, verbose)  # Measured duty ratio 33%
 
     def _bit(self, b):
         self.append(_TBURST, _T_ONE if b else _TBURST)
 
     def tx(self, addr, data, _):  # Ignore toggle
 
     def _bit(self, b):
         self.append(_TBURST, _T_ONE if b else _TBURST)
 
     def tx(self, addr, data, _):  # Ignore toggle
-        self.append(9000, 4500)
+        if self.samsung:
+            self.append(4500, 4500)
+        else:
+            self.append(9000, 4500)
         if addr < 256:  # Short address: append complement
         if addr < 256:  # Short address: append complement
-            addr |= ((addr ^ 0xff) << 8)
+            if self.samsung:
+              addr |= addr << 8
+            else:
+              addr |= ((addr ^ 0xff) << 8)
         for _ in range(16):
             self._bit(addr & 1)
             addr >>= 1
         for _ in range(16):
             self._bit(addr & 1)
             addr >>= 1
@@ -33,6 +42,5 @@ class NEC(IR):
 
     def repeat(self):
         self.aptr = 0
 
     def repeat(self):
         self.aptr = 0
-        self.append(9000, 2250, _TBURST, STOP)
-        self.aptr = 0  # Reset pointer
-        self.cb(self._tim)  # Initiate physical transmission.
+        self.append(9000, 2250, _TBURST)
+        self.trigger()  # Initiate physical transmission.