diff --git a/plotter/Plotter.cpp b/plotter/Plotter.cpp index ab7d27f..5eb508c 100644 --- a/plotter/Plotter.cpp +++ b/plotter/Plotter.cpp @@ -56,7 +56,7 @@ Plotter::~Plotter() delete temp; } -void Plotter::AddGraphHelper( String title, VariableWrapper * wrappers, int sz, bool xvy, int pointsDisplayed ) +void Plotter::AddGraphHelper( const char * title, VariableWrapper * wrappers, int sz, bool xvy, int pointsDisplayed ) { Graph * temp = new Graph( title, wrappers, sz, xvy, pointsDisplayed ); if ( head ) @@ -105,46 +105,46 @@ bool Plotter::Remove( int index ) } } -bool Plotter::SetColor( int index, String colorA ) +bool Plotter::SetColor( int index, const char * colorA ) { - String colors[] = { colorA }; + const char * colors[] = { colorA }; return SetColorHelper( index, 1, colors ); } -bool Plotter::SetColor( int index, String colorA, String colorB ) +bool Plotter::SetColor( int index, const char * colorA, const char * colorB ) { - String colors[] = { colorA, colorB }; + const char * colors[] = { colorA, colorB }; return SetColorHelper( index, 2, colors ); } -bool Plotter::SetColor( int index, String colorA, String colorB, String colorC ) +bool Plotter::SetColor( int index, const char * colorA, const char * colorB, const char * colorC ) { - String colors[] = { colorA, colorB, colorC }; + const char * colors[] = { colorA, colorB, colorC }; return SetColorHelper( index, 3, colors ); } -bool Plotter::SetColor( int index, String colorA, String colorB, String colorC, - String colorD ) +bool Plotter::SetColor( int index, const char * colorA, const char * colorB, const char * colorC, + const char * colorD ) { - String colors[] = { colorA, colorB, colorC, colorD }; + const char * colors[] = { colorA, colorB, colorC, colorD }; return SetColorHelper( index, 4, colors ); } -bool Plotter::SetColor( int index, String colorA, String colorB, String colorC, - String colorD, String colorE ) +bool Plotter::SetColor( int index, const char * colorA, const char * colorB, const char * colorC, + const char * colorD, const char * colorE ) { - String colors[] = { colorA, colorB, colorC, colorD, colorE }; + const char * colors[] = { colorA, colorB, colorC, colorD, colorE }; return SetColorHelper( index, 5, colors ); } -bool Plotter::SetColor( int index, String colorA, String colorB, String colorC, - String colorD, String colorE, String colorF ) +bool Plotter::SetColor( int index, const char * colorA, const char * colorB, const char * colorC, + const char * colorD, const char * colorE, const char * colorF ) { - String colors[] = { colorA, colorB, colorC, colorD, colorE, colorF }; + const char * colors[] = { colorA, colorB, colorC, colorD, colorE, colorF }; return SetColorHelper( index, 6, colors ); } -bool Plotter::SetColorHelper( int index, int sz, String * colors ) +bool Plotter::SetColorHelper( int index, int sz, const char * * colors ) { if ( numGraphs == 0 || index < 0 || numGraphs <= index ) { @@ -167,15 +167,15 @@ void Plotter::Plot() { bool config = counter == 0; - Serial.print( "{\"" + TIME_KEY + "\":" ); Serial.print( millis() ); + Serial.print( "{\"" ); Serial.print( TIME_KEY ); Serial.print( "\":" ); Serial.print( millis() ); if ( config ) { - Serial.print( ",\"" + NUM_GRAPH_KEY + "\":" ); Serial.print( numGraphs ); - Serial.print( ",\"" + LAST_UPDATED_KEY + "\":" ); Serial.print( lastUpdated ); + Serial.print( ",\"" ); Serial.print( NUM_GRAPH_KEY ); Serial.print( "\":" ); Serial.print( numGraphs ); + Serial.print( ",\"" ); Serial.print( LAST_UPDATED_KEY ); Serial.print( "\":" ); Serial.print( lastUpdated ); } - Serial.print( ",\"" + GRAPHS_KEY + "\":[" ); + Serial.print( ",\"" ); Serial.print( GRAPHS_KEY ); Serial.print( "\":[" ); Graph * temp = head; while ( temp ) @@ -198,7 +198,7 @@ void Plotter::Plot() // Graph -Plotter::Graph::Graph( String title, VariableWrapper * wrappers, int size, bool xvy, int pointsDisplayed ) : +Plotter::Graph::Graph( const char * title, VariableWrapper * wrappers, int size, bool xvy, int pointsDisplayed ) : next( NULL ), xvy( xvy ), size( size ), @@ -215,26 +215,26 @@ Plotter::Graph::~Graph() void Plotter::Graph::Plot( bool config ) { Serial.print( "{" ); - + if ( config ) { - Serial.print( "\"" + TITLE_KEY + "\":" ); Serial.print( "\"" + title + "\"" ); - Serial.print( ",\"" + XVY_KEY + "\":" ); Serial.print( xvy ); - Serial.print( ",\"" + POINTS_DISPLAYED_KEY + "\":" ); Serial.print( pointsDisplayed ); - Serial.print( ",\"" + SIZE_KEY + "\":" ); Serial.print( size ); - Serial.print( ",\"" + LABELS_KEY + "\":[" ); + Serial.print( "\"" ); Serial.print( TITLE_KEY ); Serial.print( "\":" ); Serial.print( "\"" ); Serial.print( title ); Serial.print( "\"" ); + Serial.print( ",\"" ); Serial.print( XVY_KEY ); Serial.print( "\":" ); Serial.print( xvy ); + Serial.print( ",\"" ); Serial.print( POINTS_DISPLAYED_KEY ); Serial.print( "\":" ); Serial.print( pointsDisplayed ); + Serial.print( ",\"" ); Serial.print( SIZE_KEY ); Serial.print( "\":" ); Serial.print( size ); + Serial.print( ",\"" ); Serial.print( LABELS_KEY ); Serial.print( "\":[" ); for ( int i = 0; i < size; i++ ) { - Serial.print( "\"" + wrappers[i].GetLabel() + "\"" ); + Serial.print( "\"" ); Serial.print( wrappers[i].GetLabel() ); Serial.print( "\"" ); if ( i + 1 < size ) { Serial.print( "," ); } } - Serial.print( "],\"" + COLORS_KEY + "\":[" ); + Serial.print( "],\"" ); Serial.print( COLORS_KEY ); Serial.print( "\":[" ); for ( int i = 0; i < size; i++ ) { - Serial.print( "\"" + wrappers[i].GetColor() + "\"" ); + Serial.print( "\"" ); Serial.print( wrappers[i].GetColor() ); Serial.print( "\"" ); if ( i + 1 < size ) { Serial.print( "," ); @@ -243,8 +243,8 @@ void Plotter::Graph::Plot( bool config ) Serial.print( "]," ); } - Serial.print( "\"" + DATA_KEY + "\":[" ); - for (int i = 0; i < size; i++) + Serial.print( "\"" ); Serial.print( DATA_KEY ); Serial.print( "\":[" ); + for ( int i = 0; i < size; i++ ) { Serial.print( wrappers[i].GetValue(), 8 ); if ( i + 1 < size ) @@ -256,7 +256,7 @@ void Plotter::Graph::Plot( bool config ) Serial.print( "]}" ); } -bool Plotter::Graph::SetColor( int sz, String * colors ) +bool Plotter::Graph::SetColor( int sz, const char * * colors ) { if ( sz != size && !xvy ) { @@ -284,14 +284,14 @@ Plotter::VariableWrapper::VariableWrapper() : deref( NULL ) {} -Plotter::VariableWrapper::VariableWrapper( String label, void * ref, double ( * deref )( void * ), String color ) : +Plotter::VariableWrapper::VariableWrapper( const char * label, void * ref, double ( * deref )( void * ), const char * color ) : label( label ), color( color ), ref( ref ), deref( deref ) {} -String Plotter::VariableWrapper::GetLabel() +const char * Plotter::VariableWrapper::GetLabel() { return label; } @@ -301,12 +301,12 @@ double Plotter::VariableWrapper::GetValue() return deref( ref ); } -String Plotter::VariableWrapper::GetColor() +const char * Plotter::VariableWrapper::GetColor() { return color; } -void Plotter::VariableWrapper::SetColor( String col ) +void Plotter::VariableWrapper::SetColor( const char * col ) { color = col; } diff --git a/plotter/Plotter.h b/plotter/Plotter.h index 319eee6..c9f2601 100644 --- a/plotter/Plotter.h +++ b/plotter/Plotter.h @@ -41,16 +41,16 @@ class Plotter Add a 1-variable graph vs. time Args: - - title: String with title of graph + - title: const char * with title of graph - pointsDisplayed: number of points to be shown at a given time. Used to control time-scaling - - labelA: String with label of the plotted variable + - labelA: const char * with label of the plotted variable - refA: reference to global variable that will be updated throughout program Similar methods for multi-variable graphing vs. time are declared below and follow the same format */ template - void AddTimeGraph( String title, int pointsDisplayed, - String labelA, A & refA ) + void AddTimeGraph( const char * title, int pointsDisplayed, + const char * labelA, A & refA ) { VariableWrapper * wrappers = new VariableWrapper[1]; wrappers[0] = VariableWrapper( labelA, static_cast( &refA ), &Dereference, "green" ); @@ -61,16 +61,16 @@ class Plotter Add an X vs. Y graph Args: - - title: String with title of graph + - title: const char * with title of graph - pointsDisplayed: number of points to be shown at a given time. Determines duration of data persistance - - labelX: String with label of variable to be plotted along X-axis + - labelX: const char * with label of variable to be plotted along X-axis - refX: reference to global X-variable that will be updated throughout program - - labelY: String with label of variable to be plotted along Y-axis + - labelY: const char * with label of variable to be plotted along Y-axis - refY: reference to global Y-variable that will be updated throughout program */ template - void AddXYGraph( String title, int pointsDisplayed, - String labelX, X & refX, String labelY, Y & refY ) + void AddXYGraph( const char * title, int pointsDisplayed, + const char * labelX, X & refX, const char * labelY, Y & refY ) { VariableWrapper * wrappers = new VariableWrapper[2]; wrappers[0] = VariableWrapper( labelX, static_cast( &refX ), &Dereference, "green" ); @@ -107,12 +107,12 @@ class Plotter Returns: - true, if successful */ - bool SetColor( int index, String colorA ); + bool SetColor( int index, const char * colorA ); // Add a 2-variable graph vs. time template - void AddTimeGraph( String title, int pointsDisplayed, - String labelA, A & refA, String labelB, B & refB ) + void AddTimeGraph( const char * title, int pointsDisplayed, + const char * labelA, A & refA, const char * labelB, B & refB ) { VariableWrapper * wrappers = new VariableWrapper[2]; wrappers[0] = VariableWrapper( labelA, static_cast( &refA ), &Dereference, "green" ); @@ -122,8 +122,8 @@ class Plotter // Add a 3-variable graph vs. time template - void AddTimeGraph( String title, int pointsDisplayed, - String labelA, A & refA, String labelB, B & refB, String labelC, C & refC ) + void AddTimeGraph( const char * title, int pointsDisplayed, + const char * labelA, A & refA, const char * labelB, B & refB, const char * labelC, C & refC ) { VariableWrapper * wrappers = new VariableWrapper[3]; wrappers[0] = VariableWrapper( labelA, static_cast( &refA ), &Dereference, "green" ); @@ -134,12 +134,12 @@ class Plotter // Add a 4-variable graph vs. time template - void AddTimeGraph( String title, int pointsDisplayed, - String labelA, A & refA, String labelB, B & refB, String labelC, C & refC, - String labelD, D & refD ) + void AddTimeGraph( const char * title, int pointsDisplayed, + const char * labelA, A & refA, const char * labelB, B & refB, const char * labelC, C & refC, + const char * labelD, D & refD ) { VariableWrapper * wrappers = new VariableWrapper[4]; - wrappers[0] = VariableWrapper( labelA, static_cast( &refA ), &Dereference, "green"); + wrappers[0] = VariableWrapper( labelA, static_cast( &refA ), &Dereference, "green" ); wrappers[1] = VariableWrapper( labelB, static_cast( &refB ), &Dereference, "orange" ); wrappers[2] = VariableWrapper( labelC, static_cast( &refC ), &Dereference, "cyan" ); wrappers[3] = VariableWrapper( labelD, static_cast( &refD ), &Dereference, "yellow" ); @@ -148,9 +148,9 @@ class Plotter // Add a 5-variable graph vs. time template - void AddTimeGraph( String title, int pointsDisplayed, - String labelA, A & refA, String labelB, B & refB, String labelC, C & refC, - String labelD, D & refD, String labelE, E & refE ) + void AddTimeGraph( const char * title, int pointsDisplayed, + const char * labelA, A & refA, const char * labelB, B & refB, const char * labelC, C & refC, + const char * labelD, D & refD, const char * labelE, E & refE ) { VariableWrapper * wrappers = new VariableWrapper[5]; wrappers[0] = VariableWrapper( labelA, static_cast( &refA ), &Dereference, "green" ); @@ -163,9 +163,9 @@ class Plotter // Add a 6-variable graph vs. time template - void AddTimeGraph( String title, int pointsDisplayed, - String labelA, A & refA, String labelB, B & refB, String labelC, C & refC, - String labelD, D & refD, String labelE, E & refE, String labelF, F & refF ) + void AddTimeGraph( const char * title, int pointsDisplayed, + const char * labelA, A & refA, const char * labelB, B & refB, const char * labelC, C & refC, + const char * labelD, D & refD, const char * labelE, E & refE, const char * labelF, F & refF ) { VariableWrapper * wrappers = new VariableWrapper[6]; wrappers[0] = VariableWrapper( labelA, static_cast( &refA ), &Dereference, "green" ); @@ -178,14 +178,14 @@ class Plotter } // Set Colors for multivariable graphs - bool SetColor( int index, String colorA, String colorB ); - bool SetColor( int index, String colorA, String colorB, String colorC ); - bool SetColor( int index, String colorA, String colroB, String colorC, - String colorD ); - bool SetColor( int index, String colorA, String colroB, String colorC, - String colorD, String colorE ); - bool SetColor( int index, String colorA, String colroB, String colorC, - String colorD, String colorE, String colorF ); + bool SetColor( int index, const char * colorA, const char * colorB ); + bool SetColor( int index, const char * colorA, const char * colorB, const char * colorC ); + bool SetColor( int index, const char * colorA, const char * colorB, const char * colorC, + const char * colorD ); + bool SetColor( int index, const char * colorA, const char * colorB, const char * colorC, + const char * colorD, const char * colorE ); + bool SetColor( int index, const char * colorA, const char * colorB, const char * colorC, + const char * colorD, const char * colorE, const char * colorF ); // Destructor for Plotter class ~Plotter(); @@ -197,17 +197,17 @@ class Plotter { public: VariableWrapper(); - VariableWrapper( String label, void * ref, double ( * deref )( void * ), String color ); + VariableWrapper( const char * label, void * ref, double ( * deref )( void * ), const char * color ); - String GetLabel(); + const char * GetLabel(); double GetValue(); - String GetColor(); - void SetColor( String col ); + const char * GetColor(); + void SetColor( const char * col ); private: // Data - String label; - String color; + const char * label; + const char * color; void * ref; double ( * deref )( void * ); @@ -219,10 +219,10 @@ class Plotter class Graph { public: - Graph(String title, VariableWrapper * wrappers, int size, bool xvy, int pointsDisplayed); + Graph( const char * title, VariableWrapper * wrappers, int size, bool xvy, int pointsDisplayed ); ~Graph(); void Plot( bool config ); - bool SetColor( int sz, String * colors ); + bool SetColor( int sz, const char * * colors ); // Data Graph * next; @@ -231,20 +231,20 @@ class Plotter bool xvy; int size; int pointsDisplayed; - String title; + const char * title; VariableWrapper * wrappers; }; //-- Graph private: // Helpers - void AddGraphHelper( String title, VariableWrapper * wrappers, int sz, bool xvy, int pointsDisplayed ); - bool SetColorHelper( int index, int sz, String * colors ); + void AddGraphHelper( const char * title, VariableWrapper * wrappers, int sz, bool xvy, int pointsDisplayed ); + bool SetColorHelper( int index, int sz, const char * * colors ); template static double Dereference( void * ref ) { - return static_cast( (* static_cast( ref ) ) ); + return static_cast( ( * static_cast( ref ) ) ); } @@ -261,17 +261,17 @@ class Plotter static const int CONFIG_INTERVAL = 50; // Transmission Keys -static const String OUTER_KEY = "#"; -static const String TIME_KEY = "t"; -static const String NUM_GRAPH_KEY = "ng"; -static const String LAST_UPDATED_KEY = "lu"; -static const String GRAPHS_KEY = "g"; -static const String TITLE_KEY = "t"; -static const String XVY_KEY = "xvy"; -static const String POINTS_DISPLAYED_KEY = "pd"; -static const String SIZE_KEY = "sz"; -static const String LABELS_KEY = "l"; -static const String COLORS_KEY = "c"; -static const String DATA_KEY = "d"; +static const char * OUTER_KEY = "#"; +static const char * TIME_KEY = "t"; +static const char * NUM_GRAPH_KEY = "ng"; +static const char * LAST_UPDATED_KEY = "lu"; +static const char * GRAPHS_KEY = "g"; +static const char * TITLE_KEY = "t"; +static const char * XVY_KEY = "xvy"; +static const char * POINTS_DISPLAYED_KEY = "pd"; +static const char * SIZE_KEY = "sz"; +static const char * LABELS_KEY = "l"; +static const char * COLORS_KEY = "c"; +static const char * DATA_KEY = "d"; #endif