plotly interface based on ardunio sample code

Dependents:   Plotly_HelloWorld

Library for plotting a simple x/y scatter chart on the plot.ly website.

See plotly_HelloWorld for sample usage.

Revision:
7:9409a72ab6c0
Parent:
5:fc8eefeb301b
Parent:
6:e57d6e9313f4
Child:
8:d4f705ba2ea5
--- a/plotly.h	Mon Jul 28 10:56:42 2014 +0000
+++ b/plotly.h	Tue Jul 29 13:30:31 2014 +0000
@@ -5,7 +5,7 @@
 #include <TCPSocketConnection.h>
 
 // size of the large buffer used for constructing messages.
-#define k_bufferSize 400
+#define k_bufferSize 512
 
 
 /** Create a plot on plot.ly
@@ -31,12 +31,12 @@
     /**
     @param username Your plot.ly username
     @param api_key Your plot.ly API key
-    @param stream_token A plot.ly streaming token for your plot.ly account
+    @param stream_tokens An array of plot.ly streaming token for your plot.ly account
     @param filename The name of the file to save the chart as
+    @param nTraces The number of traces (MUST match the size of stream_tokens, can be omitted for a single line)
     */
-        plotly(char *username, char *api_key, char* stream_token, char *filename);
-        /**
-        */
+        plotly(const char *username, const char *api_key, const char ** stream_tokens, const char *filename, int nTraces = 1);
+
         ~plotly();
         
         /** Initalises the chart
@@ -52,19 +52,20 @@
         /**
         Adds a point to the chart. The chart MUST be initalised before calling this.
         Note, if the streaming network port is closed then this will attempt to open the port and re-establish the stream connection, this could block for a while.
-        
+        @param x The X value.
+        @param y The y value.
+        @param stream Which trace to add the point to counting from 0, can be omitted for charts with a single line. 
+        */
+        void plot(unsigned long x, int y, int stream = 0);
+
+        /**
+        Adds a point to the chart. The chart MUST be initalised before calling this.
+        Note, if the streaming network port is closed then this will attempt to open the port and re-establish the stream connection, this could block for a while.
+        @param stream Which trace to add the point to counting from 0, can be omitted for charts with a single line. 
         @param x The X value.
         @param y The y value.
         */
-        void plot(unsigned long x, int y);
-        /**
-        Adds a point to the chart. The chart MUST be initalised before calling this.
-        Note, if the streaming network port is closed then this will attempt to open the port and re-establish the stream connection, this could block for a while.
-        
-        @param x The X value.
-        @param y The y value.
-        */
-        void plot(unsigned long x, float y);
+        void plot(unsigned long x, float y, int stream = 0);
 
         /**
         Adds a point to the chart. The chart MUST be initalised before calling this.
@@ -72,19 +73,37 @@
         
         @param x The X value.
         @param y The y value.
+        @param stream Which trace to add the point to counting from 0, can be omitted for charts with a single line. 
         */
-        void plot(float x, float y);
+        void plot(float x, float y, int stream = 0);
+
 
         /**
-        Opens the streaming connection.
+        Opens all the streaming connections.
         
-        Normally you'd do this after a sucessful call to init() and before starting plotting in order to avoid a connection delays when you first call plot()
+        Normally you'd do this after a sucessful call to init() and before starting plotting in order to avoid a connection delays when you first call plot()        
+        */
+        void openStreams();
+        
+        /** close all the streaming connections
+        
+        Call to tidy up and free up system resources once there is no more data to send
         */
-        bool openStream();
+        void closeStreams();
+
         /**
-        closes the streaming connection
+        Opens a specific streaming connection. Normally you would use openStreams() however if you only want to update a single line on a multi-line chart then this can save time and memory.
+        
+        @param stream The line number (from 0) to open
         */
-        void closeStream();
+        bool openStream(int stream);
+        
+        /**
+        Close a specific streaming connection.
+        
+        @param stream The line number (from 0) to open
+        */
+        void closeStream(int stream);
 
         /**
          output message level
@@ -126,25 +145,27 @@
 
     private:
 
-        void reconnectStream();
+        void reconnectStream(int stream);
 
-        bool print_(int d);
-        bool print_(unsigned long d);
-        bool print_(float d);
-        bool print_(char *d);
-        bool printNetTerminator_();
- 
+        bool print_(int d,int stream = 0);
+        bool print_(unsigned long d,int stream = 0);
+        bool print_(float d,int stream = 0);
+        bool print_(char *d,int stream = 0) {return print_((const char *)d, stream);};
+        bool print_(const char *d,int stream = 0);
+        bool printHex_(uint16_t d,int stream = 0);
+        bool printNetTerminator_(int stream = 0);
+
+        bool sendFormatedText(char* data, int size,int stream = 0);
+
+        char buffer[k_bufferSize];
+
+        TCPSocketConnection **sockets;
         
-        bool sendFormatedText(char* data, int size);
-
-        char buffer[512];
-//        char rxBuffer[128];
-        TCPSocketConnection *socket;
-        
-        char *username_;
-        char *api_key_;
-        char *stream_token_;
-        char *filename_;
+        const char *username_;
+        const char *api_key_;
+        const char** stream_tokens_;
+        const char *filename_;
+        int nTraces_;
         
         bool initalised;