IR remote control program test(IE. pre, pre-alpha)

Dependencies:   mbed SDFileSystem

Files at this revision

API Documentation at this revision

Comitter:
AndyHope
Date:
Sat Nov 20 16:31:39 2010 +0000
Commit message:
this is mostly for version control and is by no means finished

Changed in this revision

Infrared/FATFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
Infrared/Infrared.cpp Show annotated file Show diff for this revision Revisions of this file
Infrared/Infrared.h Show annotated file Show diff for this revision Revisions of this file
Infrared/SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 09b8098ea4e0 Infrared/FATFileSystem.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Infrared/FATFileSystem.lib	Sat Nov 20 16:31:39 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_unsupported/code/fatfilesystem/
\ No newline at end of file
diff -r 000000000000 -r 09b8098ea4e0 Infrared/Infrared.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Infrared/Infrared.cpp	Sat Nov 20 16:31:39 2010 +0000
@@ -0,0 +1,302 @@
+#include "mbed.h"
+#include "Infrared.h"
+#include "SDFileSystem.h"
+ 
+Infrared::Infrared(PinName pin) : irLed(pin) {  // _pin(pin) means pass pin to the DigitalOut constructor
+        irLed = 0;                                        // default the output to 0
+}   
+   
+    
+void Infrared::header(void)
+{
+
+    long float repeat;
+    
+    repeat = phead/(cycleOn+cycleOff);
+    
+    repeat *= 0.78; // 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 */
+    //pc.printf("%x\n", repeat);
+
+    for(int k = 0; k < repeat; k++)
+    {
+        irLed = 1;   
+        wait(cycleOn);
+        irLed = 0;   
+        wait(cycleOff);
+    } // for
+           
+    wait(shead);
+
+    return;
+} //header
+
+
+/* takes a data input of up to bytes, uses dynamic variables(timings ect),
+   calculates pulse lengths, encodes data for pulse modulation,
+   and shifts it out LSB first (sharp TV protocol, can be changed) */
+
+void Infrared::strobeSpace(void)
+{  // ir cycle time, ones, zeroes, and datastream
+
+    unsigned int temp;
+    long float repeat1, repeat0;
+    char k;
+    
+    repeat1 = pone/(cycleOn+cycleOff);
+    repeat0 = pzero/(cycleOn+cycleOff);
+    /* 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
+    
+    for(int i = 0; i < dataBits; i++)
+    {
+        temp = data<<i; // shift out lsb first 
+        
+        
+        if(temp & MSB)
+        {
+            for(k = 0; k < repeat1; k++)
+            {
+                irLed = 1;   
+                wait(cycleOn);
+                irLed = 0;   
+                wait(cycleOff);
+            }// for
+            
+            wait(sone);
+        }// if
+    
+        else
+        {    
+            for(k = 0; k < repeat0; k++)
+            {
+                irLed = 1;   
+                wait(cycleOn);
+                irLed = 0;   
+                wait(cycleOff);
+            }// for
+            
+            wait(szero);
+        }// else
+        
+    }// for
+    
+    return;
+}// strobeSpace
+
+
+/* takes a data input of up to bytes, uses dynamic variables(timings ect),
+   calculates pulse lengths, encodes data for RC6 (manchester) encoding,
+   and shifts it out MSB first (philips protocol, can be changed) */
+
+void Infrared::strobeRC6(void)
+{  // ir cycle time, ones, zeroes, and datastream
+
+    unsigned long int temp; 
+    long float repeat1, repeat0;
+    char k;
+    
+    repeat1 = pone/(cycleOn+cycleOff);
+    repeat0 = pzero/(cycleOn+cycleOff);
+
+    repeat1 *= 0.78; // correction for overhead of loops
+    repeat0 *= 0.78; // 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 */  
+      
+    for(int i = 0; i < dataBits; i++)
+    {
+        temp = data<<i; // shift out msb first 
+        
+        if(temp & MSB)
+        {
+            //pc.printf("1");
+            for(k = 0; k < repeat1; k++)
+            {
+                irLed = 1;   
+                wait(cycleOn);
+                irLed = 0;   
+                wait(cycleOff);
+            }// for
+        
+            wait(sone);
+        }// if
+    
+        else
+        {    
+            //pc.printf("0");
+            wait(szero);
+            
+            for(k = 0; k < repeat0; k++)
+            {
+                irLed = 1;   
+                wait(cycleOn);
+                irLed = 0;   
+                wait(cycleOff);
+            }// for
+            
+        }// else
+        
+    }// for
+    
+    return;
+}// strobeRC6
+
+
+/* calculates and transmits either a leading 
+ or trailing pulse, based on passed variables */
+
+void Infrared::pulse(void)
+{
+    long float repeat;
+    
+    repeat = pulseL/(cycleOn+cycleOff);
+    /* 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
+    
+    for(int k = 0; k < repeat; k++)
+    {
+        irLed = 1;   
+        wait(cycleOn);
+        irLed = 0;   
+        wait(cycleOff);
+    }// for
+    
+    return;
+}// pulse
+
+
+/* takes a command input and strobes the infrared LEDs */
+
+void Infrared::sendCodeDish(unsigned long int command) 
+{ 
+
+    data = command;
+    
+    header(); 
+    strobeSpace();
+    
+    header(); 
+    strobeSpace();
+    
+    header(); 
+    strobeSpace();
+    
+    pulse();
+    
+    wait(gap); 
+
+    return;
+}//sendCodeDVR
+
+
+void Infrared::sendCodeGETV(unsigned long int command) 
+{ 
+
+    data = command;
+    
+    header(); 
+    strobeSpace();
+    pulse();
+    
+    wait(gap);
+    
+    header(); 
+    strobeSpace();
+    pulse(); 
+
+    wait(gap);
+
+    return;
+}//sendCodeGETV
+
+void Infrared::sendCodeSharpTV(unsigned long int command) 
+{ 
+
+    invertCode(inversionMask, command);
+
+    data = code;
+    
+    strobeSpace();
+    pulse();
+    
+    wait(gap);
+    
+    data = invCode;
+    
+    strobeSpace();
+    pulse(); 
+    
+    wait(gap);
+
+    return;
+}//sendCodeSharpTV
+
+
+/* Takes the values for the remote timing in the LIRC remote files
+   (which are in us, Ex. phead =  450) and converts them down to the 
+   proper floating point value  */
+
+void Infrared::convertTiming()
+{
+
+    phead /= 1000000; // convert to u seconds
+    shead /= 1000000;
+    pone /= 1000000;
+    sone /= 1000000;
+    pzero /= 1000000;
+    szero /= 1000000;
+    ptoggle /= 1000000;
+    stoggle /= 1000000;
+    ptrail /= 1000000;
+    plead /= 1000000;
+    gap /= 1000000; 
+    
+    cycleOn = 100/dutycycle; 
+    cycleOff = 1-cycleOn;
+    irPeriod = 1/frequency;  
+    cycleOn = irPeriod/cycleOn;
+    cycleOff = irPeriod/cycleOff;
+    
+    return;
+}// convertTiming
+
+
+
+/* deciphers which mask is needed for sending 
+data out msb first with dynamic data lengths */
+
+void Infrared::maskBit(void) 
+{   
+    MSB = (0x01<<(dataBits-1)); 
+    /* uses the dataBits and uses it to shift a one
+     to the position of the MSB of the datastream */ 
+    
+    return;
+}// maskBit
+
+
+void Infrared::invertCode(int mask, int invertData)
+{
+
+    code = invertData;
+    invCode = invertData;
+    
+    for(int i = 0; i <= mask; i++)
+    {
+         
+        invCode ^= (0x01<<i);  
+        
+    }// for
+    
+    return;
+}// invertCode
+
diff -r 000000000000 -r 09b8098ea4e0 Infrared/Infrared.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Infrared/Infrared.h	Sat Nov 20 16:31:39 2010 +0000
@@ -0,0 +1,51 @@
+#ifndef MBED_IR_H
+#define MBED_IR_H
+
+#include "mbed.h"
+#include "SDFileSystem.h"
+
+class Infrared {
+public:
+
+    // these declared values will eventually be read off the SD micro card
+    
+    // format
+    int name, flags, eps, aeps;
+    
+    // Timing
+    double phead, shead, pone, sone; // values are time in us
+    double pzero, szero, ptoggle, stoggle, frequency;
+    double ptrail, plead, foot, gap, pulseL;
+    double irPeriod, cycleOn, cycleOff; 
+    
+    // data
+    int postdata, toggleMask, data, code, invCode, preData, command, dutycycle, inversionMask;
+    char preDataBits, dataBits, postDataBits, repeat;
+    unsigned long int MSB;
+    
+    // commands
+    int on, off, chup, chdn, volup, voldn;
+    int one, two, three, four, five, six;
+    int seven, eight, nine, zero;
+    int up, down, left, right, mute;
+    int enter, cancel, menu, info;
+    
+    // assigns specifier to output pin
+    Infrared(PinName pin);
+
+    void header(void);
+    void strobeSpace(void);
+    void strobeRC6(void);
+    void pulse(void);
+    void sendCodeDish(unsigned long int command);
+    void sendCodeGETV(unsigned long int command);
+    void sendCodeSharpTV(unsigned long int command);
+    void convertTiming();
+    void maskBit(void);
+    void invertCode(int mask, int invertData);
+  
+private:  
+    DigitalOut irLed;
+};
+
+#endif
diff -r 000000000000 -r 09b8098ea4e0 Infrared/SDFileSystem.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Infrared/SDFileSystem.lib	Sat Nov 20 16:31:39 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/SDFileSystem/#b1ddfc9a9b25
diff -r 000000000000 -r 09b8098ea4e0 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Nov 20 16:31:39 2010 +0000
@@ -0,0 +1,119 @@
+#include "mbed.h"
+#include "Infrared.h"
+
+Serial pc(USBTX, USBRX); // tx, rx
+
+DigitalIn ON (p19);
+DigitalIn SEL (p20);
+DigitalIn OneUP (p16);
+DigitalIn OneDN (p15);
+DigitalIn TwoUP (p18);
+DigitalIn TwoDN (p17);
+
+DigitalOut led1 (LED1);
+DigitalOut led2 (LED2);
+
+Infrared TV(p21);
+Infrared DVR(p21);
+
+int main() {
+
+    // these declared values will eventually be read off the SD micro card
+    TV.phead = 364; TV.shead = 6100; TV.pone = 364; TV.sone = 1739; // values are time in us
+    TV.pzero = 364; TV.szero = 690; TV.ptoggle = 0; TV.stoggle = 0;
+    TV.frequency = 38000; TV.ptrail = 364; TV.plead = 0; TV.foot = 0; 
+    TV.gap = 45310; TV.postdata = 0; TV.toggleMask = 0; TV.data = 0; 
+    TV.preData = 0; TV.command = 0; TV.dutycycle = 50; 
+    TV.preDataBits = 0; TV.dataBits = 15; TV.postDataBits = 0;
+    
+    TV.inversionMask = 8;
+
+    // commands
+    TV.on = 0x41A2; TV.chup = 0x4222; TV.chdn = 0x4122; TV.volup = 0x40A2; TV.voldn = 0x42A2;
+    TV.one = 0x4202; TV.two = 0x4102; TV.three = 0x4302; TV.four = 0x4082; TV.five = 0x4282; 
+    TV.six = 0x4182; TV.seven = 0x4382; TV.eight = 0x4042; TV.nine = 0x4242; TV.zero = 0x4142;
+    TV.mute = 0x43A2; 
+    
+    DVR.phead = 400; DVR.shead = 6100; DVR.pone = 400; DVR.sone = 1700; // values are time in us
+    DVR.pzero = 400; DVR.szero = 2800; DVR.ptoggle = 0; DVR.stoggle = 0;
+    DVR.frequency = 56000; DVR.ptrail = 400; DVR.plead = 0; DVR.foot = 0; 
+    DVR.gap = 6200; DVR.postdata = 0; DVR.toggleMask = 0; DVR.data = 0; 
+    DVR.preData = 0; DVR.command = 0; DVR.dutycycle = 50; 
+    DVR.preDataBits = 0; DVR.dataBits = 16; DVR.postDataBits = 0;
+    
+    // commands
+    DVR.on = 0x0800; DVR.up = 0x6800; DVR.down = 0x7800; DVR.left = 0x7000; DVR.right = 0x6000;
+    DVR.menu = 0x2C00; DVR.enter = 0x4000;
+
+    char deviceSel = 0;
+    
+    led1 = 1;
+    
+    TV.convertTiming();
+    TV.maskBit();
+    DVR.convertTiming();
+    DVR.maskBit();   
+    
+    while(1){
+    
+    
+    TV.sendCodeSharpTV(TV.on);
+    
+    wait(2);
+    
+    /*
+        if(SEL){
+            deviceSel = !deviceSel;
+            led1 = !led1;
+            led2 = !led2;
+            while(SEL);
+            wait(0.03);
+        }// if
+        
+        if(ON){
+            if(deviceSel){
+            DVR.sendCodeDish(DVR.on);
+            }// if
+            else{
+            TV.sendCodeSharpTV(TV.on);
+            }// else
+        }// if
+        
+        if(OneUP){
+            if(deviceSel){
+            DVR.sendCodeDish(DVR.menu);
+            }// if
+            else{
+            TV.sendCodeSharpTV(TV.chup);
+            }// else
+        }// if
+        
+        if(OneDN){
+            if(deviceSel){
+            DVR.sendCodeDish(DVR.enter);
+            }// if
+            else{
+            TV.sendCodeSharpTV(TV.chdn);
+            }// else
+        }
+        
+        if(TwoUP){
+            if(deviceSel){
+            DVR.sendCodeDish(DVR.up);
+            }// if
+            else{
+            TV.sendCodeSharpTV(TV.volup);
+            }// else
+        }// if
+        
+        if(TwoDN){
+            if(deviceSel){
+            DVR.sendCodeDish(DVR.down);
+            }// if
+            else{
+            TV.sendCodeSharpTV(TV.voldn);
+            }// else
+        }// if
+        */
+    }// while
+}// main
\ No newline at end of file
diff -r 000000000000 -r 09b8098ea4e0 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Nov 20 16:31:39 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/e2ac27c8e93e