:)

Dependencies:   MbedJSONValue DebounceIn TextLCD USBDevice mbed WebSocketClient cc3000_hostdriver_mbedsocket Adafruit_LEDBackpack_2

Revision:
12:c4b046975527
Parent:
8:725d938b301b
Child:
13:209da1dcb6e1
--- a/main.cpp	Mon Dec 01 18:27:08 2014 +0000
+++ b/main.cpp	Tue Dec 02 23:55:01 2014 +0000
@@ -6,7 +6,6 @@
 #include "DebounceIn.h"
 #include "cc3000.h"
 #include "Websocket.h"
-#include "MbedJSONValue.h"
 
 //Debug
 Serial pc(USBTX, USBRX); // tx, rx
@@ -64,7 +63,44 @@
                          "SSID", "PASSWORD", WPA2, false);
 Websocket ws("ws://sockets.mbed.org/ws/toastboard/rw");
 
-MbedJSONValue demo;
+// json encoding
+std::string s;
+std::string t;
+std::back_insert_iterator<std::string> json_str = std::back_inserter(t);
+char row[1] = ""; // holder for row tokens
+char rowvoltage[4] = ""; // holder for voltage values
+
+void jsoncopy(const std::string& s, std::back_insert_iterator<std::string> oi) {
+    std::copy(s.begin(), s.end(), oi);
+}
+
+void add_to_json(const std::string& s, std::back_insert_iterator<std::string> oi) {
+    // this chunk of code lifted from the MbedJSONValue library
+    for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) {
+        switch (*i) {
+#define MAP(val, sym) case val: jsoncopy(sym, oi); break
+                MAP('"', "\\\"");
+                MAP('\\', "\\\\");
+                MAP('/', "\\/");
+                MAP('\b', "\\b");
+                MAP('\f', "\\f");
+                MAP('\n', "\\n");
+                MAP('\r', "\\r");
+                MAP('\t', "\\t");
+#undef MAP
+            default:
+                if ((unsigned char)*i < 0x20 || *i == 0x7f) {
+                    char buf[7];
+                    sprintf(buf, "\\u%04x", *i & 0xff);
+                    copy(buf, buf + 6, oi);
+                } else {
+                    *oi++ = *i;
+                }
+                break;
+        }
+    }
+}
+
 
 int main()
 {
@@ -229,18 +265,30 @@
                } } //END OF ROWSCAN FOR LOOP
                 
                 //STUFF INTO JSON FORMAT
+                add_to_json("{\"vddval\":",json_str);
+                sprintf(rowvoltage,"%.f",vddval);
+                add_to_json(rowvoltage,json_str);
+                add_to_json(", \"selected\":",json_str);
+                selected = rowselect;
+                if (colselect == 1){
+                    selected = selected+24;
+                }
+                sprintf(rowvoltage,"%d",selected);
+                add_to_json(", \"rows\": [",json_str);
+                
                 char str[1];
                 for (int i= 0; i < 48; i++) {
-                sprintf(str, "%d", i);
-                demo[str] = clientdata[i];
+                    if (i != 0) {
+                        add_to_json(",",json_str);
                     }
-                demo["vdd"] = vddval;
-                demo["rowval"] = rowval;
-                selected = rowselect;
-                    if (colselect == 1){
-                      selected = selected+24;
-                      }
-                demo["selected"] = selected;
+                    add_to_json("{\"",json_str);
+                    sprintf(str, "%d", i);
+                    add_to_json(str,json_str);
+                    add_to_json("\":",json_str);
+                    sprintf(rowvoltage,"%.f",clientdata[i]);
+                    add_to_json(rowvoltage,json_str);
+                    add_to_json("}",json_str);
+                }
                 
                 
                 moved = 0;