Shellminator V3.0.1
Simple Terminal
Loading...
Searching...
No Matches
ShellminatorPlot Class Reference

This class can create a simple plotter object. More...

#include <Shellminator-PlotModule.hpp>

Inheritance diagram for ShellminatorPlot:
Collaboration diagram for ShellminatorPlot:

Public Member Functions

 ShellminatorPlot ()
 Empty constructor. More...
 
 ShellminatorPlot (float *data_p, int dataSize_p, const char *name_p, int color_p=Shellminator::GREEN)
 Constructor for user calculated float array. More...
 
void init (Shellminator *parent_p, Stream *channel_p) override
 Init function. More...
 
void draw (bool noClear=false) override
 Draw function. More...
 
void update (int width_p, int height_p) override
 Update function. More...
 
void forceRedraw () override
 
void setColor (Shellminator::textColor_t color_p)
 Set the color of the plot. More...
 
void setName (const char *name_p)
 Set the name of the plot. More...
 
- Public Member Functions inherited from ShellminatorScreen
virtual void draw (bool noClear=false)
 Draw function. More...
 
virtual void init (Shellminator *parent_p, Stream *channel_p)
 Init function. More...
 
virtual void setOrigin (int x, int y)
 Origin of the top left corner. More...
 
virtual void update (int width_p, int height_p)
 Update function. More...
 
virtual void forceRedraw ()
 
int left ()
 Return the coordinate of the left column next to the object. More...
 
int right ()
 Return the coordinate of the right column next to the object. More...
 
int up ()
 Return the coordinate of the upper row next to the object. More...
 
int down ()
 Return the coordinate of the lower row next to the object. More...
 
ShellminatorgetParent ()
 
void attachEndFunction (void(*end_func_p)(Shellminator *))
 
void removeEndFunction ()
 

Private Member Functions

virtual void drawScale ()
 Draw the scale for the plot. More...
 
virtual void drawPlot ()
 Draw the plot data. More...
 
float lerp (float v0, float v1, float t)
 Linear interpolation. More...
 
float mapFloat (float x, float inStart, float inStop, float outStart, float outStop)
 Floating point implementation of the map function. More...
 

Private Attributes

float * data = NULL
 Pointer to the data array. More...
 
int dataSize = 0
 Size of the data array in elements. More...
 
bool redraw = true
 
unsigned long plotTimerStart
 
int plotRedrawPeriod
 
const char * name = NULL
 Plot name. More...
 
int color = Shellminator::GREEN
 Color code for the plot. More...
 
char valueTextBuffer [15]
 This buffer holds a generated string that us used to print numbers to the scale. More...
 
int valueTextSizeMax = 0
 This variable holds the size of the largest element generated in the valueTextBuffer. More...
 
int resultTextSize = 0
 This variable holds the size of the last elements text. More...
 
float min
 Holds the minimum value in the data array. More...
 
float max
 Holds the maximum value in the data array. More...
 

Static Private Attributes

static const char clearCell [2] = " "
 
static const char dotCell [5] = "\u2022"
 

Additional Inherited Members

- Public Attributes inherited from ShellminatorScreen
int row = 1
 It is used by the grid layout. More...
 
int column = 1
 It is used by the grid layout. More...
 
int columnSpan = 1
 It is used by the grid layout. More...
 
int rowSpan = 1
 It is used by the grid layout. More...
 
ShellminatorScreennextElement = NULL
 It is used by the grid layout. More...
 
void(*)(Shellminator *) getEndFunction ()
 
- Protected Attributes inherited from ShellminatorScreen
Shellminatorparent = NULL
 Pointer to the caller terminal object. More...
 
Stream * channel = NULL
 
int width = 1
 Actual width of the object. More...
 
int height = 1
 Actual height of the object. More...
 
int originX = 1
 X coordinate of the origin. More...
 
int originY = 1
 Y coordinate of the origin. More...
 
void(* end_func )(Shellminator *) = NULL
 

Detailed Description

This class can create a simple plotter object.

With this class, you can easily create a plotter object, which is capable of real time plotting. It can be attached to the main terminal with the beginScreen function.

Definition at line 63 of file Shellminator-PlotModule.hpp.

Constructor & Destructor Documentation

◆ ShellminatorPlot() [1/2]

ShellminatorPlot::ShellminatorPlot ( )

Empty constructor.

Definition at line 44 of file Shellminator-PlotModule.cpp.

◆ ShellminatorPlot() [2/2]

ShellminatorPlot::ShellminatorPlot ( float *  data_p,
int  dataSize_p,
const char *  name_p,
int  color_p = Shellminator::GREEN 
)

Constructor for user calculated float array.

With this constructor you can create a plotter object which is using a user created dataset.

Parameters
data_pPointer to a float array, which contains the data points to be printed.
dataSize_pThe size of the float array in elements( NOT IN BYTES! ).
name_pThe name of the plot.
color_pOptionally, you can specify the color of the plot. Available colors: *Shellminator::RED *Shellminator::GREEN *Shellminator::WHITE

Definition at line 36 of file Shellminator-PlotModule.cpp.

Member Function Documentation

◆ draw()

void ShellminatorPlot::draw ( bool  noClear = false)
overridevirtual

Draw function.

This function is called by the caller terminal if redraw is requested. If you need to draw your screen, the requestRedraw function must be called on the parent terminal object. The reason for this is to save some CPU time and do not waste it to draw something unnecessarily.

Reimplemented from ShellminatorScreen.

Definition at line 89 of file Shellminator-PlotModule.cpp.

Here is the call graph for this function:

◆ drawPlot()

void ShellminatorPlot::drawPlot ( )
privatevirtual

Draw the plot data.

This function renders the data points from the data array. It can be overriden to create different kinds of plots.

Definition at line 326 of file Shellminator-PlotModule.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ drawScale()

void ShellminatorPlot::drawScale ( )
privatevirtual

Draw the scale for the plot.

The scale is on the left side with this implementation. It can be overriden to create different kinds of plots.

Definition at line 202 of file Shellminator-PlotModule.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ forceRedraw()

void ShellminatorPlot::forceRedraw ( )
overridevirtual

Reimplemented from ShellminatorScreen.

Definition at line 415 of file Shellminator-PlotModule.cpp.

◆ init()

void ShellminatorPlot::init ( Shellminator parent_p,
Stream *  channel_p 
)
overridevirtual

Init function.

This function is called by the host terminal, when the plot object gets registered to it. You can put all the initialisation section here.

Parameters
parent_pPointer to the caller terminal object.
channel_pThis is a pointer to a Stream object, which can be used to print the output data.
Note
Please use the channel_p object instead of parent -> channel method. This object can be a regular channel or a buffer accelerated one. The logic behind the buffering and flushing is handled by the caller terminal.

Reimplemented from ShellminatorScreen.

Definition at line 51 of file Shellminator-PlotModule.cpp.

◆ lerp()

float ShellminatorPlot::lerp ( float  v0,
float  v1,
float  t 
)
private

Linear interpolation.

Original source

Parameters
v0First corner value.
v1Second corner value.
tControl value between 0.0 and 1.0.

Definition at line 315 of file Shellminator-PlotModule.cpp.

Here is the caller graph for this function:

◆ mapFloat()

float ShellminatorPlot::mapFloat ( float  x,
float  inStart,
float  inStop,
float  outStart,
float  outStop 
)
private

Floating point implementation of the map function.

Definition at line 319 of file Shellminator-PlotModule.cpp.

Here is the caller graph for this function:

◆ setColor()

void ShellminatorPlot::setColor ( Shellminator::textColor_t  color_p)

Set the color of the plot.

With this function, you can set the color of the plot.

Parameters
color_pSpecify a color from Shellminator::textColor_t enumeration.

Definition at line 411 of file Shellminator-PlotModule.cpp.

◆ setName()

void ShellminatorPlot::setName ( const char *  name_p)

Set the name of the plot.

Parameters
name_pThe name of the plot.

Definition at line 419 of file Shellminator-PlotModule.cpp.

◆ update()

void ShellminatorPlot::update ( int  width_p,
int  height_p 
)
overridevirtual

Update function.

The update function must be used to process events and not to draw the objects. It is called much frequently than, the draw function. All the event handling should be done in the update function, including key and mouse detection along with various events.

Parameters
width_pThe width of the screen area in characters.
height_pThe height of the screen area in characters.

Reimplemented from ShellminatorScreen.

Definition at line 57 of file Shellminator-PlotModule.cpp.

Member Data Documentation

◆ clearCell

const char ShellminatorPlot::clearCell = " "
staticprivate

Definition at line 178 of file Shellminator-PlotModule.hpp.

◆ color

int ShellminatorPlot::color = Shellminator::GREEN
private

Color code for the plot.

Definition at line 146 of file Shellminator-PlotModule.hpp.

◆ data

float* ShellminatorPlot::data = NULL
private

Pointer to the data array.

Definition at line 132 of file Shellminator-PlotModule.hpp.

◆ dataSize

int ShellminatorPlot::dataSize = 0
private

Size of the data array in elements.

Definition at line 135 of file Shellminator-PlotModule.hpp.

◆ dotCell

const char ShellminatorPlot::dotCell = "\u2022"
staticprivate

Definition at line 179 of file Shellminator-PlotModule.hpp.

◆ max

float ShellminatorPlot::max
private

Holds the maximum value in the data array.

Definition at line 176 of file Shellminator-PlotModule.hpp.

◆ min

float ShellminatorPlot::min
private

Holds the minimum value in the data array.

Definition at line 173 of file Shellminator-PlotModule.hpp.

◆ name

const char* ShellminatorPlot::name = NULL
private

Plot name.

Definition at line 143 of file Shellminator-PlotModule.hpp.

◆ plotRedrawPeriod

int ShellminatorPlot::plotRedrawPeriod
private

Definition at line 140 of file Shellminator-PlotModule.hpp.

◆ plotTimerStart

unsigned long ShellminatorPlot::plotTimerStart
private

Definition at line 139 of file Shellminator-PlotModule.hpp.

◆ redraw

bool ShellminatorPlot::redraw = true
private

Definition at line 137 of file Shellminator-PlotModule.hpp.

◆ resultTextSize

int ShellminatorPlot::resultTextSize = 0
private

This variable holds the size of the last elements text.

Definition at line 170 of file Shellminator-PlotModule.hpp.

◆ valueTextBuffer

char ShellminatorPlot::valueTextBuffer[15]
private

This buffer holds a generated string that us used to print numbers to the scale.

Definition at line 162 of file Shellminator-PlotModule.hpp.

◆ valueTextSizeMax

int ShellminatorPlot::valueTextSizeMax = 0
private

This variable holds the size of the largest element generated in the valueTextBuffer.

Definition at line 166 of file Shellminator-PlotModule.hpp.