]> cloudbase.mooo.com Git - irmp.git/blobdiff - irmp.c
Version 2.3.10: improved ORTEK detection, added ROOMBA protocol
[irmp.git] / irmp.c
diff --git a/irmp.c b/irmp.c
index 7d40b629a5bb5617ad67fb6c907908da92f38fcf..3f313de0487916c2ab77ccddee9b6b09f7ca301e 100644 (file)
--- a/irmp.c
+++ b/irmp.c
@@ -3,7 +3,7 @@
  *\r
  * Copyright (c) 2009-2013 Frank Meyer - frank(at)fli4l.de\r
  *\r
- * $Id: irmp.c,v 1.140 2013/03/19 15:11:55 fm Exp $\r
+ * $Id: irmp.c,v 1.141 2013/04/09 11:55:39 fm Exp $\r
  *\r
  * ATMEGA88 @ 8 MHz\r
  *\r
 #define ORTEK_START_BIT_PULSE_LEN_MAX           ((uint8_t)(F_INTERRUPTS * ORTEK_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)\r
 #define ORTEK_START_BIT_PAUSE_LEN_MIN           ((uint8_t)(F_INTERRUPTS * ORTEK_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)\r
 #define ORTEK_START_BIT_PAUSE_LEN_MAX           ((uint8_t)(F_INTERRUPTS * ORTEK_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)\r
-#define ORTEK_BIT_PULSE_LEN_MIN                 ((uint8_t)(F_INTERRUPTS * ORTEK_BIT_TIME * MIN_TOLERANCE_30 + 0.5) - 1)\r
-#define ORTEK_BIT_PULSE_LEN_MAX                 ((uint8_t)(F_INTERRUPTS * ORTEK_BIT_TIME * MAX_TOLERANCE_30 + 0.5) + 1)\r
-#define ORTEK_BIT_PAUSE_LEN_MIN                 ((uint8_t)(F_INTERRUPTS * ORTEK_BIT_TIME * MIN_TOLERANCE_30 + 0.5) - 1)\r
-#define ORTEK_BIT_PAUSE_LEN_MAX                 ((uint8_t)(F_INTERRUPTS * ORTEK_BIT_TIME * MAX_TOLERANCE_30 + 0.5) + 1)\r
+#define ORTEK_BIT_PULSE_LEN_MIN                 ((uint8_t)(F_INTERRUPTS * ORTEK_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1)\r
+#define ORTEK_BIT_PULSE_LEN_MAX                 ((uint8_t)(F_INTERRUPTS * ORTEK_BIT_TIME * MAX_TOLERANCE_10 + 0.5) + 1)\r
+#define ORTEK_BIT_PAUSE_LEN_MIN                 ((uint8_t)(F_INTERRUPTS * ORTEK_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1)\r
+#define ORTEK_BIT_PAUSE_LEN_MAX                 ((uint8_t)(F_INTERRUPTS * ORTEK_BIT_TIME * MAX_TOLERANCE_10 + 0.5) + 1)\r
 \r
 #define TELEFUNKEN_START_BIT_PULSE_LEN_MIN      ((uint8_t)(F_INTERRUPTS * TELEFUNKEN_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)\r
 #define TELEFUNKEN_START_BIT_PULSE_LEN_MAX      ((uint8_t)(F_INTERRUPTS * TELEFUNKEN_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)\r
 // autodetect TELEFUNKEN repetition frame within 50 msec:\r
 // #define TELEFUNKEN_FRAME_REPEAT_PAUSE_LEN_MAX   (uint16_t)(F_INTERRUPTS * TELEFUNKEN_FRAME_REPEAT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5)\r
 \r
+#define ROOMBA_START_BIT_PULSE_LEN_MIN          ((uint8_t)(F_INTERRUPTS * ROOMBA_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)\r
+#define ROOMBA_START_BIT_PULSE_LEN_MAX          ((uint8_t)(F_INTERRUPTS * ROOMBA_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)\r
+#define ROOMBA_START_BIT_PAUSE_LEN_MIN          ((uint8_t)(F_INTERRUPTS * ROOMBA_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)\r
+#define ROOMBA_START_BIT_PAUSE_LEN_MAX          ((uint8_t)(F_INTERRUPTS * ROOMBA_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)\r
+#define ROOMBA_1_PAUSE_LEN                      ((uint8_t)(F_INTERRUPTS * ROOMBA_1_PAUSE_TIME))\r
+#define ROOMBA_1_PULSE_LEN_MIN                  ((uint8_t)(F_INTERRUPTS * ROOMBA_1_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)\r
+#define ROOMBA_1_PULSE_LEN_MAX                  ((uint8_t)(F_INTERRUPTS * ROOMBA_1_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)\r
+#define ROOMBA_1_PAUSE_LEN_MIN                  ((uint8_t)(F_INTERRUPTS * ROOMBA_1_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)\r
+#define ROOMBA_1_PAUSE_LEN_MAX                  ((uint8_t)(F_INTERRUPTS * ROOMBA_1_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)\r
+#define ROOMBA_0_PAUSE_LEN                      ((uint8_t)(F_INTERRUPTS * ROOMBA_0_PAUSE_TIME))\r
+#define ROOMBA_0_PULSE_LEN_MIN                  ((uint8_t)(F_INTERRUPTS * ROOMBA_0_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)\r
+#define ROOMBA_0_PULSE_LEN_MAX                  ((uint8_t)(F_INTERRUPTS * ROOMBA_0_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)\r
+#define ROOMBA_0_PAUSE_LEN_MIN                  ((uint8_t)(F_INTERRUPTS * ROOMBA_0_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)\r
+#define ROOMBA_0_PAUSE_LEN_MAX                  ((uint8_t)(F_INTERRUPTS * ROOMBA_0_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)\r
+\r
 #define AUTO_FRAME_REPETITION_LEN               (uint16_t)(F_INTERRUPTS * AUTO_FRAME_REPETITION_TIME + 0.5)       // use uint16_t!\r
 \r
 #ifdef ANALYZE\r
@@ -428,6 +443,9 @@ static int                                      verbose;
 static void                                     (*irmp_callback_ptr) (uint8_t);\r
 #endif // IRMP_USE_CALLBACK == 1\r
 \r
+#define PARITY_CHECK_OK                         1\r
+#define PARITY_CHECK_FAILED                     0\r
+\r
 /*---------------------------------------------------------------------------------------------------------------------------------------------------\r
  *  Protocol names\r
  *---------------------------------------------------------------------------------------------------------------------------------------------------\r
@@ -470,8 +488,10 @@ irmp_protocol_names[IRMP_N_PROTOCOLS + 1] =
     "BOSE",\r
     "A1TVBOX",\r
     "ORTEK",\r
-    "TELEFUNKEN"\r
+    "TELEFUNKEN",\r
+    "ROOMBA"\r
 };\r
+\r
 #endif\r
 \r
 /*---------------------------------------------------------------------------------------------------------------------------------------------------\r
@@ -1455,6 +1475,31 @@ static const PROGMEM IRMP_PARAMETER ortek_param =
 \r
 #endif\r
 \r
+#if IRMP_SUPPORT_ROOMBA_PROTOCOL == 1\r
+\r
+static const PROGMEM IRMP_PARAMETER roomba_param =\r
+{\r
+    IRMP_ROOMBA_PROTOCOL,                                               // protocol:        ir protocol\r
+    ROOMBA_1_PULSE_LEN_MIN,                                             // pulse_1_len_min: minimum length of pulse with bit value 1\r
+    ROOMBA_1_PULSE_LEN_MAX,                                             // pulse_1_len_max: maximum length of pulse with bit value 1\r
+    ROOMBA_1_PAUSE_LEN_MIN,                                             // pause_1_len_min: minimum length of pause with bit value 1\r
+    ROOMBA_1_PAUSE_LEN_MAX,                                             // pause_1_len_max: maximum length of pause with bit value 1\r
+    ROOMBA_0_PULSE_LEN_MIN,                                             // pulse_0_len_min: minimum length of pulse with bit value 0\r
+    ROOMBA_0_PULSE_LEN_MAX,                                             // pulse_0_len_max: maximum length of pulse with bit value 0\r
+    ROOMBA_0_PAUSE_LEN_MIN,                                             // pause_0_len_min: minimum length of pause with bit value 0\r
+    ROOMBA_0_PAUSE_LEN_MAX,                                             // pause_0_len_max: maximum length of pause with bit value 0\r
+    ROOMBA_ADDRESS_OFFSET,                                              // address_offset:  address offset\r
+    ROOMBA_ADDRESS_OFFSET + ROOMBA_ADDRESS_LEN,                         // address_end:     end of address\r
+    ROOMBA_COMMAND_OFFSET,                                              // command_offset:  command offset\r
+    ROOMBA_COMMAND_OFFSET + ROOMBA_COMMAND_LEN,                         // command_end:     end of command\r
+    ROOMBA_COMPLETE_DATA_LEN,                                           // complete_len:    complete length of frame\r
+    ROOMBA_STOP_BIT,                                                    // stop_bit:        flag: frame has stop bit\r
+    ROOMBA_LSB,                                                         // lsb_first:       flag: LSB first\r
+    ROOMBA_FLAGS                                                        // flags:           some flags\r
+};\r
+\r
+#endif\r
+\r
 static uint8_t                              irmp_bit;                   // current bit position\r
 static IRMP_PARAMETER                       irmp_param;\r
 \r
@@ -1729,6 +1774,10 @@ static uint8_t  xor_check[6];
 static uint8_t  genre2;                                                                 // save genre2 bits here, later copied to MSB in flags\r
 #endif\r
 \r
+#if IRMP_SUPPORT_ORTEK_PROTOCOL == 1\r
+static uint8_t  parity;                                                                 // number of '1' of the first 14 bits, check if even.\r
+#endif\r
+\r
 /*---------------------------------------------------------------------------------------------------------------------------------------------------\r
  *  store bit\r
  *  @details  store bit in temp address or temp command\r
@@ -1741,6 +1790,44 @@ static uint8_t  genre2;
 static void\r
 irmp_store_bit (uint8_t value)\r
 {\r
+#if IRMP_SUPPORT_ORTEK_PROTOCOL == 1\r
+    if (irmp_param.protocol == IRMP_ORTEK_PROTOCOL)\r
+    {\r
+        if (irmp_bit < 14)\r
+        {\r
+            if (value)\r
+            {\r
+                parity++;\r
+            }\r
+        }\r
+        else if (irmp_bit == 14)\r
+        {\r
+            if (value)                                                                                      // value == 1: even parity\r
+            {\r
+                if (parity & 0x01)\r
+                {\r
+                    parity = PARITY_CHECK_FAILED;\r
+                }\r
+                else\r
+                {\r
+                    parity = PARITY_CHECK_OK;\r
+                }\r
+            }\r
+            else\r
+            {\r
+                if (parity & 0x01)                                                                          // value == 0: odd parity\r
+                {\r
+                    parity = PARITY_CHECK_OK;\r
+                }\r
+                else\r
+                {\r
+                    parity = PARITY_CHECK_FAILED;\r
+                }\r
+            }\r
+        }\r
+    }\r
+#endif\r
+\r
 #if IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL == 1\r
     if (irmp_bit == 0 && irmp_param.protocol == IRMP_GRUNDIG_PROTOCOL)\r
     {\r
@@ -2105,6 +2192,18 @@ irmp_ISR (void)
                     else\r
 #endif // IRMP_SUPPORT_TELEFUNKEN_PROTOCOL == 1\r
 \r
+#if IRMP_SUPPORT_ROOMBA_PROTOCOL == 1\r
+                    if (irmp_pulse_time >= ROOMBA_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= ROOMBA_START_BIT_PULSE_LEN_MAX &&\r
+                        irmp_pause_time >= ROOMBA_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= ROOMBA_START_BIT_PAUSE_LEN_MAX)\r
+                    {\r
+                        ANALYZE_PRINTF ("protocol = ROOMBA, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",\r
+                                        ROOMBA_START_BIT_PULSE_LEN_MIN, ROOMBA_START_BIT_PULSE_LEN_MAX,\r
+                                        ROOMBA_START_BIT_PAUSE_LEN_MIN, ROOMBA_START_BIT_PAUSE_LEN_MAX);\r
+                        irmp_param_p = (IRMP_PARAMETER *) &roomba_param;\r
+                    }\r
+                    else\r
+#endif // IRMP_SUPPORT_ROOMBA_PROTOCOL == 1\r
+\r
 #if IRMP_SUPPORT_NIKON_PROTOCOL == 1\r
                     if (irmp_pulse_time >= NIKON_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= NIKON_START_BIT_PULSE_LEN_MAX &&\r
                         irmp_pause_time >= NIKON_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NIKON_START_BIT_PAUSE_LEN_MAX)\r
@@ -2442,8 +2541,9 @@ irmp_ISR (void)
                                         ORTEK_START_BIT_PULSE_LEN_MIN, ORTEK_START_BIT_PULSE_LEN_MAX,\r
                                         ORTEK_START_BIT_PAUSE_LEN_MIN, ORTEK_START_BIT_PAUSE_LEN_MAX);\r
                         irmp_param_p = (IRMP_PARAMETER *) &ortek_param;\r
-                        last_pause = 0;\r
-                        last_value = 1;\r
+                        last_pause  = 0;\r
+                        last_value  = 1;\r
+                        parity      = 0;\r
                     }\r
                     else\r
 #endif // IRMP_SUPPORT_A1TVBOX_PROTOCOL == 1\r
@@ -2737,6 +2837,23 @@ irmp_ISR (void)
                         }\r
                         else\r
 #endif\r
+#if IRMP_SUPPORT_ROOMBA_PROTOCOL == 1\r
+                        if (irmp_param.protocol == IRMP_ROOMBA_PROTOCOL &&                          // Roomba has no stop bit\r
+                            irmp_bit >= ROOMBA_COMPLETE_DATA_LEN - 1)                               // it's the last datab bit...\r
+                        {                                                                           // break and close this frame\r
+                            if (irmp_pulse_time >= ROOMBA_1_PULSE_LEN_MIN && irmp_pulse_time <= ROOMBA_1_PULSE_LEN_MAX)\r
+                            {\r
+                                irmp_pause_time = ROOMBA_1_PAUSE_LEN;\r
+                            }\r
+                            else if (irmp_pulse_time >= ROOMBA_0_PULSE_LEN_MIN && irmp_pulse_time <= ROOMBA_0_PULSE_LEN_MAX)\r
+                            {\r
+                                irmp_pause_time = ROOMBA_0_PAUSE_LEN;\r
+                            }\r
+\r
+                            got_light = TRUE;                                                       // this is a lie, but helps (generates stop bit)\r
+                        }\r
+                        else\r
+#endif\r
 #if IRMP_SUPPORT_MANCHESTER == 1\r
                         if ((irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER) &&\r
                             irmp_pause_time >= 2 * irmp_param.pause_1_len_max && irmp_bit >= irmp_param.complete_len - 2 && !irmp_param.stop_bit)\r
@@ -3292,6 +3409,17 @@ irmp_ISR (void)
                 else\r
 #endif\r
 \r
+#if IRMP_SUPPORT_ORTEK_PROTOCOL == 1\r
+                // if ORTEK protocol and the code will be repeated within 50 ms, we will ignore 2nd repetition frame\r
+                if (irmp_param.protocol == IRMP_ORTEK_PROTOCOL && repetition_frame_number == 1)\r
+                {\r
+                    ANALYZE_PRINTF ("code skipped: ORTEK auto repetition frame #%d, counter = %d, auto repetition len = %d\n",\r
+                                    repetition_frame_number + 1, key_repetition_len, AUTO_FRAME_REPETITION_LEN);\r
+                    key_repetition_len = 0;\r
+                }\r
+                else\r
+#endif\r
+\r
 #if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1\r
                 // if KASEIKYO protocol and the code will be repeated within 50 ms, we will ignore 2nd repetition frame\r
                 if (irmp_param.protocol == IRMP_KASEIKYO_PROTOCOL && repetition_frame_number == 1)\r
@@ -3427,6 +3555,24 @@ irmp_ISR (void)
                         }\r
 #endif // IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1\r
 \r
+#if IRMP_SUPPORT_ORTEK_PROTOCOL == 1\r
+                        if (irmp_param.protocol == IRMP_ORTEK_PROTOCOL)\r
+                        {\r
+                            if (parity == PARITY_CHECK_FAILED)\r
+                            {\r
+                                ANALYZE_PRINTF ("error 6: parity check failed\n");\r
+                                irmp_ir_detected = FALSE;\r
+                            }\r
+\r
+                            if ((irmp_tmp_address & 0x03) == 0x02)\r
+                            {\r
+                                ANALYZE_PRINTF ("code skipped: ORTEK end of transmission frame (key release)\n");\r
+                                irmp_ir_detected = FALSE;\r
+                            }\r
+                            irmp_tmp_address >>= 2;\r
+                        }\r
+#endif // IRMP_SUPPORT_ORTEK_PROTOCOL == 1\r
+\r
 #if IRMP_SUPPORT_RC6_PROTOCOL == 1\r
                         if (irmp_param.protocol == IRMP_RC6_PROTOCOL && irmp_param.complete_len == RC6_COMPLETE_DATA_LEN_LONG)     // RC6 mode = 6?\r
                         {\r