Infrared remote test functions (11/26/2010)

Revision:
1:d1764facee30
Parent:
0:e526ff8f7602
--- a/Infrared.cpp	Fri Nov 26 18:43:44 2010 +0000
+++ b/Infrared.cpp	Sat Dec 04 22:47:38 2010 +0000
@@ -2,6 +2,8 @@
 #include "Infrared.h"
 #include "SDFileSystem.h"
  
+ Serial pc(USBTX, USBRX); // tx, rx
+ 
 Infrared::Infrared(PinName pin) : irLed(pin) {  // _pin(pin) means pass pin to the DigitalOut constructor
         irLed = 0;                                        // default the output to 0
 }   
@@ -14,7 +16,7 @@
     
     repeat = phead/(cycleOn+cycleOff);
     
-    repeat *= 0.78; // correction for overhead of loops
+    repeat *= 0.55; // correction for overhead of loops
     
     /* uses the length of the header pulse over the length of the on/off 
     modulation to give an integer representation of the number of cycles */
@@ -50,8 +52,8 @@
     /* uses the length of the header pulse over the length of the on/off 
     modulation to give an integer representation of the number of cycles */
 
-    repeat1 *= 0.78; // correction for overhead of loops    
-    repeat0 *= 0.78; // correction for overhead of loops
+    repeat1 *= 0.55; // correction for overhead of loops    
+    repeat0 *= 0.55; // correction for overhead of loops
     
     for(char i = 0; i < dataBits; i++)
     {
@@ -104,8 +106,8 @@
     repeat1 = pone/(cycleOn+cycleOff);
     repeat0 = pzero/(cycleOn+cycleOff);
 
-    repeat1 *= 0.78; // correction for overhead of loops
-    repeat0 *= 0.78; // correction for overhead of loops
+    repeat1 *= 0.55; // correction for overhead of loops
+    repeat0 *= 0.55; // correction for overhead of loops
     
     /* uses the length of the header pulse over the length of the on/off 
     modulation to give an integer representation of the number of cycles */  
@@ -160,7 +162,7 @@
     /* uses the length of the header pulse over the length of the on/off 
     modulation to give an integer representation of the number of cycles */
     
-    repeat *= 0.78; // correction factor for loop overheads
+    repeat *= 0.55; // correction factor for loop overheads
     
     for(int k = 0; k < repeat; k++)
     {
@@ -192,7 +194,7 @@
     
     pulse(ptrail);
     
-    wait(gap); 
+    wait(gap1); 
 
     return;
 }//sendCodeDVR
@@ -207,13 +209,13 @@
     strobeSpace();
     pulse(ptrail);
     
-    wait(gap);
+    wait(gap1);
     
     header(); 
     strobeSpace();
     pulse(ptrail); 
 
-    wait(gap);
+    wait(gap1);
 
     return;
 }//sendCodeGETV
@@ -222,34 +224,40 @@
 { 
 
     invertCode(inversionMask, command);
-
+    
+    gap1 = constLength(code);
+    gap2 = constLength(invCode);
+    
+    pc.printf("gap1: %f, gap2: %f\n", gap1, gap2);
+    
     data = code;
     
     strobeSpace();
     pulse(ptrail);
     
-    wait(gap);
+    
+    wait(gap1);
     
     data = invCode;
     
     strobeSpace();
     pulse(ptrail); 
     
-    wait(gap);
+    wait(gap2);
     
     data = code;
     
     strobeSpace();
     pulse(ptrail);
     
-    wait(gap);
+    wait(gap1);
     
     data = invCode;
     
     strobeSpace();
     pulse(ptrail); 
     
-    wait(gap);
+    wait(gap2);
 
     return;
 }//sendCodeSharpTV
@@ -272,12 +280,7 @@
     stoggle /= 1000000;
     ptrail /= 1000000;
     plead /= 1000000;
-    gap /= 1000000; 
-    
-    /*cycleOn = 100/dutycycle; 
-    irPeriod = 1/frequency;  
-    cycleOn = irPeriod/cycleOn;
-    cycleOff = cycleOn;*/
+    gap1 /= 1000000; 
     
     cycleOn = dutycycle/100;  // dutycycle is read in as a percentage value from 0 to 100
     cycleOff = 1-cycleOn;
@@ -319,3 +322,35 @@
     return;
 }// invertCode
 
+
+double Infrared::constLength(int sent)
+{
+    int mask; 
+    double gap = 0;
+    
+    for(char i = 0; i < dataBits; i++)
+    {
+        mask = 0x01<<i;
+        
+        if(sent & mask)
+        {
+            gap += pone;
+            gap += sone;        
+        }// if
+        
+        else
+        {
+            gap += pzero;
+            gap += szero;
+        }// else
+    }// for
+    
+    if(ptrail){
+        gap += ptrail;}
+    
+        pc.printf("\ngap: %f\n", gap);
+    
+    return(gap);
+    
+}// constLength
+