Uses *spark d-fuser controller hardware as a USB-DMX interface. Developed for visualising Laurel Pardue’s augmented violin with lights.

Dependencies:   DMX mbed spk_oled_ssd1305

Revision:
1:f0cc153fe8d3
Parent:
0:59b1d685427c
Child:
2:24d9b7a3073c
--- a/main.cpp	Sat May 09 20:11:58 2015 +0000
+++ b/main.cpp	Wed May 13 18:35:06 2015 +0000
@@ -3,6 +3,8 @@
 #include "spk_oled_ssd1305.h"
 #include "spk_oled_gfx.h"
 
+// https://developer.mbed.org/forum/mbed/post/4526/
+// 110, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, 115200, 230400, 460800, 921600
 #define kUSB_BAUD 57600
 
 // MBED PINS
@@ -44,6 +46,7 @@
 // MISC Defines
 
 #define kStringBufferLength 30
+#define kUSBSerialBufferLength 256
 
 //// USB Serial
 
@@ -67,7 +70,8 @@
 DigitalIn button(kMBED_DIN_TAP_L);
 bool buttonLastState;
 
-string usbSerialString;
+char usbSerialBuffer[kUSBSerialBufferLength];
+int  usbSerialBufferPosition = 0;
 bool newData = false;
 
 //// LAUREL VIOLIN DATA
@@ -117,7 +121,7 @@
 //                               );
 //            if (scanCount == 25)
             scanCount = sscanf(
-                                usbSerialString.c_str(), 
+                                usbSerialBuffer, 
                                 "[S: %f, %f, %f, %f],[E: %f, %f, %d]",
                                 &S1, &S2, &S3, &S4, &EA, &EB, &EC
                                );
@@ -132,14 +136,15 @@
             }   
             
             // Clear to start again
-            usbSerialString.clear();
+            usbSerialBufferPosition = 0;
         }
-        else
+        else if (usbSerialBufferPosition < kUSBSerialBufferLength)
         {
             // Build string up
-            usbSerialString += receivedChar;
+            usbSerialBuffer[usbSerialBufferPosition++] = receivedChar;
+            usbSerialBuffer[usbSerialBufferPosition] = 0;
             
-            screen.textToBuffer(usbSerialString.c_str(),4);
+            screen.textToBuffer(usbSerialBuffer,4);
         }
     }
 }