LE KICKASS TEAM / Mbed 2 deprecated RTOS_Lights_Master

Dependencies:   mbed-rtos mbed

Revision:
5:8ae5aca33233
Parent:
4:b3c3bca604a6
Child:
6:012504bfe3e3
diff -r b3c3bca604a6 -r 8ae5aca33233 main.cpp
--- a/main.cpp	Sat Dec 12 01:21:09 2015 +0000
+++ b/main.cpp	Sat Dec 12 02:59:41 2015 +0000
@@ -58,8 +58,9 @@
 void testRGB(void);
 int testSlave(void);
 void checkSSEL_isr(void);
-void unpackRGB (int RGB);
+void unpackRGB (void);
 void packRGB (int R, int G, int B);
+void RGBconvert(void const *args);
 /*
 **************************
        Global Data
@@ -148,7 +149,7 @@
     RtosTimer refresh_timer(LEDPush, osTimerPeriodic, (void *)0);
     // 16.7Hz timer (60ms or ~1/2 of 30fps)
     refresh_timer.start(60);
-    RtosTimer update_timer(RGBpicker, osTimerPeriodic, (void *)0);
+    RtosTimer update_timer(RGBconvert, osTimerPeriodic, (void *)0);
     // 10Hz timer (100ms)
     update_timer.start(100);
     terminal.printf("done.");
@@ -300,9 +301,9 @@
 // called by the refresh timer every 60ms
 void LEDPush(void const *args)
 {
-    ld = 0; // active-low load
+    ld = 0; cs = 1;// active-low load, "open" lights, "lock" slave
     leds.write(LEDvals);
-    ld = 1; // "lock" lights
+    ld = 1; cs = 0;// "lock" lights, "open" slave
 }
 
 void RGBPush(void)
@@ -418,6 +419,13 @@
     }
 }
 
+void RGBconvert(void const *args){
+    cs = 0; ld = 1;
+    RGBtemp = leds.write(0);
+    unpackRGB();
+    cs = 1; ld = 0;
+    }
+
 // "chase" pattern to verify LED array
 void testLED(void)
 {
@@ -495,25 +503,33 @@
     return 0;
 }
 
-void unpackRGB (int RGB){
+void unpackRGB (){
+    int tempR, tempG, tempB;
     //Shift R from bits 23:16 to 7:0 and XOR with 0x00 to isolate data.
-    r = (float((RGB >> 16) ^ 0x00)/255.0);
+    terminal.printf("RGB: %h",RGBtemp);
+    newline();
+    newline();
+    tempR = (RGBtemp &0x00FF0000)>>16;
+    tempG = (RGBtemp &0x0000FF00)>>8;
+    tempB =  RGBtemp &0x000000FF;
+    r = (float(tempR))/255.0;
     //Shift G from bits 15:8 to 7:0 and XOR with 0x00 to isolate data.
-    g = (float((RGB >>  8) ^ 0x00)/255.0);
+    g = (float(tempG))/255.0;
     //XOR B ^ 0x00 to isolate data.
-    b = (float((RGB      ) ^ 0x00)/255.0);
-    printf("R: %f | G: %f | B: %f", r,g,b);
+    b = (float(tempB))/255.0;
+    printf("R: %f \n\r G: %f \n\r B: %f\n\r", r,g,b);
+    newline();
     RGBPush();
     }
     
 void packRGB (int R, int G, int B){
     RGB = 0;
     //Shift R from bits 23:16 to 7:0 and XOR with 0x00 to isolate data.
-    RGB = RGB|(int(r*255) << 16);
+    RGB = RGB|(int(r*255.0) << 16);
     //Shift G from bits 15:8 to 7:0 and XOR with 0x00 to isolate data.
-    RGB = RGB|(int(g*255) <<  8);
+    RGB = RGB|(int(g*255.0) <<  8);
     //XOR B ^ 0x00 to isolate data.
-    RGB = RGB|(int(b*255)      );
+    RGB = RGB|(int(b*255.0)      );
     //spi.reply(RGB);
     }