Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 38 additions & 38 deletions plotter/Plotter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -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 )
{
Expand All @@ -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 )
Expand All @@ -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 ),
Expand All @@ -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( "," );
Expand All @@ -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 )
Expand All @@ -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 )
{
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Loading