]> cloudbase.mooo.com Git - irmp.git/blobdiff - irsnd.c
Version 1.7.0: stable release
[irmp.git] / irsnd.c
diff --git a/irsnd.c b/irsnd.c
index 6856da8b2de3aa0caeb034ea4806e4afce313f60..029d476d20e482b4c11d72c46c9c72356d775dbd 100644 (file)
--- a/irsnd.c
+++ b/irsnd.c
@@ -3,7 +3,7 @@
  *\r
  * Copyright (c) 2010 Frank Meyer - frank(at)fli4l.de\r
  *\r
- * $Id: irsnd.c,v 1.15 2010/06/02 13:18:03 fm Exp $\r
+ * $Id: irsnd.c,v 1.20 2010/06/15 15:47:21 fm Exp $\r
  *\r
  * This program is free software; you can redistribute it and/or modify\r
  * it under the terms of the GNU General Public License as published by\r
@@ -153,6 +153,20 @@ typedef unsigned short    uint16_t;
 #define IRSND_FREQ_56_KHZ                       (uint8_t) ((F_CPU / 56000 / 2) - 1)\r
 #define IRSND_FREQ_455_KHZ                      (uint8_t) ((F_CPU / 455000 / 2) - 1)\r
 \r
+#define FDC_START_BIT_PULSE_LEN                 (uint8_t)(F_INTERRUPTS * FDC_START_BIT_PULSE_TIME + 0.5)\r
+#define FDC_START_BIT_PAUSE_LEN                 (uint8_t)(F_INTERRUPTS * FDC_START_BIT_PAUSE_TIME + 0.5)\r
+#define FDC_PULSE_LEN                           (uint8_t)(F_INTERRUPTS * FDC_PULSE_TIME + 0.5)\r
+#define FDC_1_PAUSE_LEN                         (uint8_t)(F_INTERRUPTS * FDC_1_PAUSE_TIME + 0.5)\r
+#define FDC_0_PAUSE_LEN                         (uint8_t)(F_INTERRUPTS * FDC_0_PAUSE_TIME + 0.5)\r
+#define FDC_FRAME_REPEAT_PAUSE_LEN              (uint16_t)(F_INTERRUPTS * FDC_FRAME_REPEAT_PAUSE_TIME + 0.5)                // use uint16_t!\r
+\r
+#define RCCAR_START_BIT_PULSE_LEN               (uint8_t)(F_INTERRUPTS * RCCAR_START_BIT_PULSE_TIME + 0.5)\r
+#define RCCAR_START_BIT_PAUSE_LEN               (uint8_t)(F_INTERRUPTS * RCCAR_START_BIT_PAUSE_TIME + 0.5)\r
+#define RCCAR_PULSE_LEN                         (uint8_t)(F_INTERRUPTS * RCCAR_PULSE_TIME + 0.5)\r
+#define RCCAR_1_PAUSE_LEN                       (uint8_t)(F_INTERRUPTS * RCCAR_1_PAUSE_TIME + 0.5)\r
+#define RCCAR_0_PAUSE_LEN                       (uint8_t)(F_INTERRUPTS * RCCAR_0_PAUSE_TIME + 0.5)\r
+#define RCCAR_FRAME_REPEAT_PAUSE_LEN            (uint16_t)(F_INTERRUPTS * RCCAR_FRAME_REPEAT_PAUSE_TIME + 0.5)              // use uint16_t!\r
+\r
 static volatile uint8_t                         irsnd_busy;\r
 static volatile uint8_t                         irsnd_protocol;\r
 static volatile uint8_t                         irsnd_buffer[6];\r
@@ -269,7 +283,7 @@ bitsrevervse (uint16_t x, uint8_t len)
 \r
 \r
 uint8_t\r
-irsnd_send_data (IRMP_DATA * irmp_data_p)\r
+irsnd_send_data (IRMP_DATA * irmp_data_p, uint8_t do_wait)\r
 {\r
 #if IRSND_SUPPORT_RECS80_PROTOCOL == 1\r
     static uint8_t  toggle_bit_recs80;\r
@@ -283,9 +297,16 @@ irsnd_send_data (IRMP_DATA * irmp_data_p)
     uint16_t        address;\r
     uint16_t        command;\r
 \r
-    while (irsnd_busy)\r
+    if (do_wait)\r
+    {\r
+        while (irsnd_busy)\r
+        {\r
+            // do nothing;\r
+        }\r
+    }\r
+    else if (irsnd_busy)\r
     {\r
-        ;\r
+        return (FALSE);\r
     }\r
 \r
     irsnd_protocol  = irmp_data_p->protocol;\r
@@ -476,6 +497,34 @@ irsnd_send_data (IRMP_DATA * irmp_data_p)
             break;\r
         }\r
 #endif\r
+#if IRSND_SUPPORT_FDC_PROTOCOL == 1\r
+        case IRMP_FDC_PROTOCOL:\r
+        {\r
+            address = bitsrevervse (irmp_data_p->address, FDC_ADDRESS_LEN);\r
+            command = bitsrevervse (irmp_data_p->command, FDC_COMMAND_LEN);\r
+\r
+            irsnd_buffer[0] = (address & 0xFF);                                                                 // AAAAAAAA\r
+            irsnd_buffer[1] = 0;                                                                                // 00000000\r
+            irsnd_buffer[2] = 0;                                                                                // 0000RRRR\r
+            irsnd_buffer[3] = (command & 0xFF);                                                                 // CCCCCCCC\r
+            irsnd_buffer[4] = ~(command & 0xFF);                                                                // cccccccc\r
+            irsnd_busy      = TRUE;\r
+            break;\r
+        }\r
+#endif\r
+#if IRSND_SUPPORT_RCCAR_PROTOCOL == 1\r
+        case IRMP_RCCAR_PROTOCOL:\r
+        {\r
+            address = bitsrevervse (irmp_data_p->address, 2);                                                   //                            A0 A1\r
+            command = bitsrevervse (irmp_data_p->command, RCCAR_COMMAND_LEN - 2);                               // D0 D1 D2 D3 D4 D5 D6 D7 C0 C1 V\r
+\r
+            irsnd_buffer[0] = ((command & 0x06) << 5) | ((address & 0x0003) << 4) | ((command & 0x0780) >> 7);  //          C0 C1 A0 A1 D0 D1 D2 D3\r
+            irsnd_buffer[1] = ((command & 0x78) << 1) | ((command & 0x0001) << 3);                              //          D4 D5 D6 D7 V  0  0  0\r
+                                                                                                                \r
+            irsnd_busy      = TRUE;\r
+            break;\r
+        }\r
+#endif\r
         default:\r
         {\r
             break;\r
@@ -849,6 +898,42 @@ irsnd_ISR (void)
                         irsnd_set_freq (IRSND_FREQ_36_KHZ);\r
                         break;\r
                     }\r
+#endif\r
+#if IRSND_SUPPORT_FDC_PROTOCOL == 1\r
+                    case IRMP_FDC_PROTOCOL:\r
+                    {\r
+                        startbit_pulse_len          = FDC_START_BIT_PULSE_LEN;\r
+                        startbit_pause_len          = FDC_START_BIT_PAUSE_LEN;\r
+                        complete_data_len           = FDC_COMPLETE_DATA_LEN;\r
+                        pulse_1_len                 = FDC_PULSE_LEN;\r
+                        pause_1_len                 = FDC_1_PAUSE_LEN;\r
+                        pulse_0_len                 = FDC_PULSE_LEN;\r
+                        pause_0_len                 = FDC_0_PAUSE_LEN;\r
+                        has_stop_bit                = FDC_STOP_BIT;\r
+                        n_auto_repetitions          = 1;                                            // 1 frame\r
+                        auto_repetition_pause_len   = 0;\r
+                        repeat_frame_pause_len      = FDC_FRAME_REPEAT_PAUSE_LEN;\r
+                        irsnd_set_freq (IRSND_FREQ_38_KHZ);\r
+                        break;\r
+                    }\r
+#endif\r
+#if IRSND_SUPPORT_RCCAR_PROTOCOL == 1\r
+                    case IRMP_RCCAR_PROTOCOL:\r
+                    {\r
+                        startbit_pulse_len          = RCCAR_START_BIT_PULSE_LEN;\r
+                        startbit_pause_len          = RCCAR_START_BIT_PAUSE_LEN;\r
+                        complete_data_len           = RCCAR_COMPLETE_DATA_LEN;\r
+                        pulse_1_len                 = RCCAR_PULSE_LEN;\r
+                        pause_1_len                 = RCCAR_1_PAUSE_LEN;\r
+                        pulse_0_len                 = RCCAR_PULSE_LEN;\r
+                        pause_0_len                 = RCCAR_0_PAUSE_LEN;\r
+                        has_stop_bit                = RCCAR_STOP_BIT;\r
+                        n_auto_repetitions          = 1;                                            // 1 frame\r
+                        auto_repetition_pause_len   = 0;\r
+                        repeat_frame_pause_len      = RCCAR_FRAME_REPEAT_PAUSE_LEN;\r
+                        irsnd_set_freq (IRSND_FREQ_38_KHZ);\r
+                        break;\r
+                    }\r
 #endif\r
                     default:\r
                     {\r
@@ -893,11 +978,17 @@ irsnd_ISR (void)
 #if IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1\r
                 case IRMP_BANG_OLUFSEN_PROTOCOL:\r
 #endif\r
+#if IRSND_SUPPORT_FDC_PROTOCOL == 1\r
+                case IRMP_FDC_PROTOCOL:\r
+#endif\r
+#if IRSND_SUPPORT_RCCAR_PROTOCOL == 1\r
+                case IRMP_RCCAR_PROTOCOL:\r
+#endif\r
 \r
 \r
 #if IRSND_SUPPORT_SIRCS_PROTOCOL == 1  || IRSND_SUPPORT_NEC_PROTOCOL == 1 || IRSND_SUPPORT_SAMSUNG_PROTOCOL == 1 || IRSND_SUPPORT_MATSUSHITA_PROTOCOL == 1 || \\r
     IRSND_SUPPORT_RECS80_PROTOCOL == 1 || IRSND_SUPPORT_RECS80EXT_PROTOCOL == 1 || IRSND_SUPPORT_DENON_PROTOCOL == 1 || IRSND_SUPPORT_NUBERT_PROTOCOL == 1 || \\r
-    IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1\r
+    IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1 || IRSND_SUPPORT_FDC_PROTOCOL == 1 || IRSND_SUPPORT_RCCAR_PROTOCOL == 1\r
                 {\r
                     if (pulse_counter == 0)\r
                     {\r
@@ -1194,6 +1285,12 @@ irsnd_ISR (void)
         {\r
             if (repeat_counter < n_repeat_frames)\r
             {\r
+#if IRSND_SUPPORT_FDC_PROTOCOL == 1\r
+                if (irsnd_protocol == IRMP_FDC_PROTOCOL)\r
+                {\r
+                    irsnd_buffer[2] |= 0x0F;\r
+                }\r
+#endif\r
                 repeat_counter++;\r
                 irsnd_busy = TRUE;\r
             }\r
@@ -1262,7 +1359,7 @@ main (int argc, char ** argv)
 \r
         irsnd_init ();\r
 \r
-        (void) irsnd_send_data (&irmp_data);\r
+        (void) irsnd_send_data (&irmp_data, TRUE);\r
 \r
         while (irsnd_busy)\r
         {\r