Rotorhead / Mbed 2 deprecated MainMitFreq

Dependencies:   mbed

Revision:
4:7ce2cdd04dd8
Parent:
3:c9341431a333
Child:
5:4a44eb020490
diff -r c9341431a333 -r 7ce2cdd04dd8 TestRadar.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TestRadar.cpp	Fri Jun 27 00:08:45 2014 +0000
@@ -0,0 +1,326 @@
+#include "mbed.h"
+
+SPI spiR(p11, p12, p13);  // mosi, miso, sclk
+DigitalOut lpR(p10);
+DigitalOut bpR(p14);
+
+SPI spiL(p5, p6, p7);
+DigitalOut lpL(p8);
+DigitalOut bpL(p9);
+
+void latch()
+{
+    lpR = 1;
+    lpL = 1;
+    lpR = 1;
+    lpL = 1;
+    lpR = 1;
+    lpL = 1;
+    lpR = 0;
+    lpL = 0;
+}
+
+
+
+//FREQ CONTROL CONFIG
+
+Ticker tick;
+InterruptIn in(p22);
+Timer t1;
+Timer t2;
+
+//INTERRUPT FEEDBACK LED
+ 
+DigitalOut led(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+DigitalOut led4(LED4);
+
+//RUNTIME VARS
+
+float t_period = 0;                   // This is the period between interrupts in microseconds
+float t_freq = 0;
+int last = -1;
+float curt = 0;
+int f = 0;
+
+//DUMMY FUNCTION AS THERE IS NO HEADER FILE
+
+void flip();
+void flip()
+{
+    t_period = t1.read_us();                // Get time since last interrupt
+    t_freq = (1/(float)t_period)*1000000;   // Convert period (in us) to frequency (Hz)
+    t1.reset();                             // Reset timer and wait for next interrupt
+    t2.reset();
+    led = !led;
+    f++;
+}
+
+
+
+short radaroff[24]= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+short radaron[24]= {0xFFF,0xFFF,0xFFF,0xFFF,0xFFF,0xFFF,0xFFF,0xFFF,0xFFF,0xFFF,0xFFF,0xFFF,0xFFF,0xFFF,0xFFF,0xFFF,0xFFF,
+                    0xFFF,0xFFF,0xFFF,0xFFF,0xFFF,0xFFF,0xFFF
+                   };
+short radardot[24]= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0xFFF,0,0,0,0,0,0,0,0};
+
+int lookupport(int j)
+{
+    int led, p;
+
+    if(j%2 == 1)            //Alle ungeradezahligen Ports
+        //werden vom rechten Controller angesteuert
+        //entsprechend wird "R" als "Side" zugewiesen
+    {
+
+        p = j/2;          //Durch Division /2 bekommen wir eine "normierte Reihe" also (0,1 ,2 ... 12)
+
+        if (p%2 == 0)          //nochmal %2 da Ports sich abwechseln (0, 23, 1, 22... siehe Tabelle)
+            led = 23 - (p/2);  //also von "p" ausgegangen, beginnen gerade Zahlen von hinten an (Ports 23, 22, 21... 12)
+        else
+            led = (p/2);   // ungerade Zahlen beginnen von vorne an (Port 0, 1, 2... 11)
+    }
+
+    else
+
+    {
+        p = (j-1)/2;
+
+        if (p%2 == 0)
+            led = 23 - (p/2);
+        else
+            led = (p/2);
+    }
+    return led;
+
+}
+
+//returns 1 if right Port, else 0
+int lookupLR(int j)
+{
+    return j % 2;
+}
+
+//Hier kommt die Funktion
+
+
+int main()
+{
+
+    lpR = 0;
+    lpL = 0;
+    spiR.format(12, 0);
+    spiR.frequency(30 * 1000 * 1000);
+    spiL.format(12, 0);
+    spiL.frequency(30 * 1000 * 1000);
+    bpR=1;
+    bpL = 1;
+/*
+    for (int v = 0; v<5; ++v)   {
+
+        for(int i=47; i>=0; i--) {
+            bpR=1;
+            bpL = 1;
+            for(int j = 0; j<sizeof(outp[0])/sizeof(outp[0][0]); j++) {
+                if (lookupLR(j)) {
+                    actualrowR[lookupport(j)] = outp[i][j];
+                } else {
+                    actualrowL[lookupport(j)] = outp[i][j];
+                }
+            }
+            for (int k =0; k<sizeof(actualrowR)/sizeof(actualrowR[0]); ++k) {
+                spiR.write(actualrowR[k]);
+            }
+            for (int k =0; k<sizeof(actualrowL)/sizeof(actualrowL[0]); ++k) {
+                spiL.write(actualrowL[k]);
+            }
+            latch();
+            bpR=0;
+            bpL = 0;
+            wait(0.08);
+        }
+        for(int i=0; i<sizeof(outp)/sizeof(outp[0]); i++) {
+            bpR=1;
+            bpL = 1;
+            for(int j = 0; j<sizeof(outp[0])/sizeof(outp[0][0]); j++) {
+                if (lookupLR(j)) {
+                    actualrowR[lookupport(j)] = outp[i][j];
+                } else {
+                    actualrowL[lookupport(j)] = outp[i][j];
+                }
+            }
+            for (int k =0; k<sizeof(actualrowR)/sizeof(actualrowR[0]); ++k) {
+                spiR.write(actualrowR[k]);
+            }
+            for (int k =0; k<sizeof(actualrowL)/sizeof(actualrowL[0]); ++k) {
+                spiL.write(actualrowL[k]);
+            }
+            latch();
+            bpR=0;
+            bpL = 0;
+            wait(0.08);
+        }
+
+    }
+*/
+    //****************************//
+    //CAKE FUNCTION - YUM YUM
+    //****************************//
+
+/*
+    {
+        in.mode(PullDown);              // Set the pin to Pull Down mode.
+        in.rise(&flip);                 // Set up the interrupt for rising edge
+        t1.start();                     // start the timer
+        t2.start();
+
+        for(; f<500;) {                  //as a placeholder until we find a way to navigate between programmes
+
+            if(t_period == 0) {
+                continue;
+            }
+            curt = t2.read_us();
+            if (curt < t_period * 0.135
+                    || (t_period/4 < curt && curt < (t_period*0.135)*3 )
+                    || (t_period/2 < curt && curt < (t_period/0.135)*5 )
+                    || ((t_period/4)*3 < curt && curt < (t_period/0.135)*7 )
+               ) {
+                if (last != 0) {
+                    //cake empty
+
+                    bpL=1;
+                    bpR=1;
+                    for (int j = 0; j<48; j++) {
+                        spiR.write(0x000);
+                        spiL.write(0x000);
+                    }
+                    //for(int j=0; j<sizeof(cakeempty)/sizeof(cakeempty[0]); j++) {
+                    //  spiR.write(cakeempty[j]);
+                    //spiL.write(cakeempty[j]);
+                    //}
+                    latch();
+                    bpL=0;
+                    bpR=0;
+                    last = 0;
+                }
+            } else {
+                if (last != 1) {
+
+                    //cake full
+                    bpL=1;
+                    bpR=1;
+
+                    for (int j = 0; j<48; j++) {
+                        spiR.write(0xFFF);
+                        spiL.write(0xFFF);
+                    }
+
+                    //for(int j=0; j<sizeof(cakefull)/sizeof(cakefull[0]); j++) {
+                    //  spiR.write(cakefull[j]);
+                    //spiL.write(cakefull[j]);
+                    //}
+                    latch();
+                    bpL=0;
+                    bpR=0;
+                    last = 1;
+                }
+            }
+
+        }
+*/
+
+        /*********************************/
+        //    RADAR FUNCTION FUCK YEAH   //
+        /**********************************/
+{
+        in.mode(PullDown);              // Set the pin to Pull Down mode.
+        in.rise(&flip);                 // Set up the interrupt for rising edge
+        t1.start();                     // start the timer
+        t2.start();
+        int m=0;
+        float a;
+        a=t_period*0.01667;
+        for(m=0; m<500;m++) {                  //as a placeholder until we find a way to navigate between programmes
+
+            if(t_period == 0) {
+                continue;
+            }
+            curt = t2.read_us();            //esta es la aguja
+            if (curt < t_period *0.25 + m*a)
+            {
+                if (last != 0) {
+                    //cake empty
+
+                    bpL=1;
+                    bpR=1;
+                    for (int j = 0; j<48; j++) {
+                        spiR.write(0x000);
+                        spiL.write(0x000);
+                    }
+                    latch();
+                    bpL=0;
+                    bpR=0;
+                    last = 0;
+                }
+            } else {
+                if (last != 1) {
+
+                    //cake full
+                    bpL=1;
+                    bpR=1;
+
+                    for (int j = 0; j<48; j++) {
+                        spiR.write(0xFFF);
+                        spiL.write(0x000);
+                    }
+
+                    latch();
+                    bpL=0;
+                    bpR=0;
+                    last = 1;
+                }
+            }
+            
+            
+            
+            
+            curt = t2.read_us();        //maes di aqui va el puntillo en teoria
+            if (curt == t_period)
+            {
+                if (last != 0) {
+                    //cake empty
+
+                    bpL=1;
+                    bpR=1;
+                    for (int j = 0; j<48; j++) {
+                        spiR.write(0x000);
+                        spiL.write(0x000);
+                    }
+                    latch();
+                    bpL=0;
+                    bpR=0;
+                    last = 0;
+                }
+            } else {
+                if (last != 1) {
+
+                    //cake full
+                    bpL=1;
+                    bpR=1;
+
+                    for (int j = 0; j<48; j++) {
+                        spiR.write(radardot[j]);
+                        spiL.write(0x000);
+                    }
+
+                    latch();
+                    bpL=0;
+                    bpR=0;
+                    last = 1;
+                }
+            }
+        }
+ 
+    
+ }   }
\ No newline at end of file