Skip to content

Commit

Permalink
Changed vars name
Browse files Browse the repository at this point in the history
  • Loading branch information
elC0mpa committed Dec 29, 2020
1 parent f3b667c commit a132af8
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 113 deletions.
164 changes: 82 additions & 82 deletions src/OLED_SSD1306_Chart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ void OLED_SSD1306_Chart::drawChart()
{
double i, temp;
_dig = 0;
_ox[0] = _gx;
_ox[1] = _gx;
_oy[0] = _gy;
_oy[1] = _gy - _h / 2;
_x = _gx;
_xDrawingOffset = 0;

if (_yLabelsVisible)
_previous_x_coordinate[0] = _x_lower_left_coordinate;
_previous_x_coordinate[1] = _x_lower_left_coordinate;
_previous_y_coordinate[0] = _y_lower_left_coordinate;
_previous_y_coordinate[1] = _y_lower_left_coordinate - _chart_height / 2;
_actual_x_coordinate = _x_lower_left_coordinate;
_x_drawing_offset = 0;

if (_y_labels_visible)
{
if (_mode == SINGLE_PLOT_MODE)
{
Expand All @@ -26,26 +26,26 @@ void OLED_SSD1306_Chart::drawChart()
setTextSize(1);
setTextColor(WHITE);

getTextBounds(_yLabelHi[0], _gx + 5, _gy + 5 - _h, &x, &y, &w, &h);
_xDrawingOffset = w;
getTextBounds(_y_max_label[0], _x_lower_left_coordinate + 5, _y_lower_left_coordinate + 5 - _chart_height, &x, &y, &w, &h);
_x_drawing_offset = w;

// high label
setCursor(_gx, _gy - _h);
write(_yLabelHi[0]);
setCursor(_x_lower_left_coordinate, _y_lower_left_coordinate - _chart_height);
write(_y_max_label[0]);

getTextBounds(_yLabelLo[0], _gx + 5, _gy - 5, &x, &y, &w, &h);
getTextBounds(_y_min_label[0], _x_lower_left_coordinate + 5, _y_lower_left_coordinate - 5, &x, &y, &w, &h);

// low label
setCursor(_gx, _gy - (h / 2));
write(_yLabelLo[0]);
setCursor(_x_lower_left_coordinate, _y_lower_left_coordinate - (h / 2));
write(_y_min_label[0]);

if (w > _xDrawingOffset)
if (w > _x_drawing_offset)
{
_xDrawingOffset = w;
_x_drawing_offset = w;
}

// compensation for the y axis tick lines
_xDrawingOffset += 4;
_x_drawing_offset += 4;
}
else if (_mode == DOUBLE_PLOT_MODE)
{
Expand All @@ -55,74 +55,74 @@ void OLED_SSD1306_Chart::drawChart()
setTextSize(1);
setTextColor(WHITE);
//Chart 1
getTextBounds(_yLabelHi[1], _gx + 5, _gy + 5 - _h, &x, &y, &w, &h);
_xDrawingOffset = w;
getTextBounds(_y_max_label[1], _x_lower_left_coordinate + 5, _y_lower_left_coordinate + 5 - _chart_height, &x, &y, &w, &h);
_x_drawing_offset = w;

// high label
setCursor(_gx, _gy - _h);
write(_yLabelHi[1]);
setCursor(_x_lower_left_coordinate, _y_lower_left_coordinate - _chart_height);
write(_y_max_label[1]);

getTextBounds(_yLabelLo[1], _gx + 5, _gy - 5, &x, &y, &w, &h);
getTextBounds(_y_min_label[1], _x_lower_left_coordinate + 5, _y_lower_left_coordinate - 5, &x, &y, &w, &h);

// low label
setCursor(_gx, _gy - _h / 2 - (h / 2));
write(_yLabelLo[1]);
setCursor(_x_lower_left_coordinate, _y_lower_left_coordinate - _chart_height / 2 - (h / 2));
write(_y_min_label[1]);

if (w > _xDrawingOffset)
if (w > _x_drawing_offset)
{
_xDrawingOffset = w;
_x_drawing_offset = w;
}

//Chart 0
getTextBounds(_yLabelHi[0], _gx + 5, _gy + 5 - _h, &x, &y, &w, &h);
if (w > _xDrawingOffset)
getTextBounds(_y_max_label[0], _x_lower_left_coordinate + 5, _y_lower_left_coordinate + 5 - _chart_height, &x, &y, &w, &h);
if (w > _x_drawing_offset)
{
_xDrawingOffset = w;
_x_drawing_offset = w;
}

// high label
setCursor(_gx, _gy - _h / 2 + (h / 2));
write(_yLabelHi[0]);
setCursor(_x_lower_left_coordinate, _y_lower_left_coordinate - _chart_height / 2 + (h / 2));
write(_y_max_label[0]);

getTextBounds(_yLabelLo[0], _gx + 5, _gy - 5, &x, &y, &w, &h);
getTextBounds(_y_min_label[0], _x_lower_left_coordinate + 5, _y_lower_left_coordinate - 5, &x, &y, &w, &h);

// low label
setCursor(_gx, _gy - (h / 2));
write(_yLabelLo[0]);
setCursor(_x_lower_left_coordinate, _y_lower_left_coordinate - (h / 2));
write(_y_min_label[0]);

if (w > _xDrawingOffset)
if (w > _x_drawing_offset)
{
_xDrawingOffset = w;
_x_drawing_offset = w;
}

// compensation for the y axis tick lines
_xDrawingOffset += 4;
_x_drawing_offset += 4;
}
}

for (i = _gy; i <= _gy + _h; i += _yincdiv)
// draw y divisions
for (i = _y_lower_left_coordinate; i <= _y_lower_left_coordinate + _chart_height; i += _yinc_div)
{
temp = (i - _gy) * (_gy - _h - _gy) / (_h) + _gy;
if (i == _gy)
temp = (i - _y_lower_left_coordinate) * (_y_lower_left_coordinate - _chart_height - _y_lower_left_coordinate) / (_chart_height) + _y_lower_left_coordinate;
if (i == _y_lower_left_coordinate)
{
drawFastHLine(_gx - 3 + _xDrawingOffset, temp, _w + 3 - _xDrawingOffset, WHITE);
drawFastHLine(_x_lower_left_coordinate - 3 + _x_drawing_offset, temp, _chart_width + 3 - _x_drawing_offset, WHITE);
}
else
{
drawFastHLine(_gx - 3 + _xDrawingOffset, temp, 3, WHITE);
drawFastHLine(_x_lower_left_coordinate - 3 + _x_drawing_offset, temp, 3, WHITE);
}
}
// draw x scale
for (i = 0; i <= _w - _xDrawingOffset; i += _xincdiv)
// draw x divisions
for (i = 0; i <= _chart_width - _x_drawing_offset; i += _xinc_div)
{
temp = (i) + _gx + _xDrawingOffset;
temp = (i) + _x_lower_left_coordinate + _x_drawing_offset;
if (i == 0)
{
drawFastVLine(temp, _gy - _h, _h + 3, WHITE);
drawFastVLine(temp, _y_lower_left_coordinate - _chart_height, _chart_height + 3, WHITE);
}
else
{
drawFastVLine(temp, _gy, 3, WHITE);
drawFastVLine(temp, _y_lower_left_coordinate, 3, WHITE);
}
}
}
Expand All @@ -137,23 +137,23 @@ void OLED_SSD1306_Chart::setYLimits(double ylo, double yhi, uint8_t chart)
{
if (chart == 0 || chart == 1)
{
_ylo[chart] = ylo;
_yhi[chart] = yhi;
_y_min_values[chart] = ylo;
_y_max_values[chart] = yhi;
}
}

void OLED_SSD1306_Chart::setYLimitLabels(char *loLabel, char *hiLabel, uint8_t chart)
{
if (chart == 0 || chart == 1)
{
_yLabelLo[chart] = loLabel;
_yLabelHi[chart] = hiLabel;
_y_min_label[chart] = loLabel;
_y_max_label[chart] = hiLabel;
}
}

void OLED_SSD1306_Chart::setYLabelsVisible(bool yLabelsVisible)
{
_yLabelsVisible = yLabelsVisible;
_y_labels_visible = yLabelsVisible;
}

void OLED_SSD1306_Chart::setPointGeometry(char pointGeometry, uint8_t chart)
Expand All @@ -164,71 +164,71 @@ void OLED_SSD1306_Chart::setPointGeometry(char pointGeometry, uint8_t chart)

void OLED_SSD1306_Chart::setChartCoordinates(double x, double y)
{
_gx = x;
_gy = y;
_x_lower_left_coordinate = x;
_y_lower_left_coordinate = y;
}

void OLED_SSD1306_Chart::setChartWidthAndHeight(double w, double h)
{
_w = w;
_h = h;
_chart_width = w;
_chart_height = h;
}

void OLED_SSD1306_Chart::setAxisDivisionsInc(double xinc, double yinc)
{
_xincdiv = xinc;
_yincdiv = yinc;
_xinc_div = xinc;
_yinc_div = yinc;
}

void OLED_SSD1306_Chart::setXIncrement(double xinc)
{
_xinc = xinc;
_x_inc = xinc;
}

bool OLED_SSD1306_Chart::updateChart(double firstValue, double secondValue)
{
if (_x >= _gx + _w - _xDrawingOffset)
if (_actual_x_coordinate >= _x_lower_left_coordinate + _chart_width - _x_drawing_offset)
return false;

_x += _xinc;
_actual_x_coordinate += _x_inc;

if (_mode == SINGLE_PLOT_MODE)
{
double y = (firstValue - _ylo[0]) * (_gy - _h - _gy) / (_yhi[0] - _ylo[0]) + _gy;
drawLine(_ox[0] + _xDrawingOffset, _oy[0], _x + _xDrawingOffset, y, WHITE);
drawLine(_ox[0] + _xDrawingOffset, _oy[0] - 1, _x + _xDrawingOffset, y - 1, WHITE);
double y = (firstValue - _y_min_values[0]) * (_y_lower_left_coordinate - _chart_height - _y_lower_left_coordinate) / (_y_max_values[0] - _y_min_values[0]) + _y_lower_left_coordinate;
drawLine(_previous_x_coordinate[0] + _x_drawing_offset, _previous_y_coordinate[0], _actual_x_coordinate + _x_drawing_offset, y, WHITE);
drawLine(_previous_x_coordinate[0] + _x_drawing_offset, _previous_y_coordinate[0] - 1, _actual_x_coordinate + _x_drawing_offset, y - 1, WHITE);

_ox[0] = _x;
_oy[0] = y;
_previous_x_coordinate[0] = _actual_x_coordinate;
_previous_y_coordinate[0] = y;

if (_point_geometry[0] == POINT_GEOMETRY_CIRCLE)
fillCircle(_ox[0] + _xDrawingOffset, _oy[0], 2, WHITE);
fillCircle(_previous_x_coordinate[0] + _x_drawing_offset, _previous_y_coordinate[0], 2, WHITE);

display();
return true;
}

else
{
auto semiHeight = _h / 2;
double y = (firstValue - _ylo[0]) * (-semiHeight) / (_yhi[0] - _ylo[0]) + _gy;
double secondY = (secondValue - _ylo[1]) * (-semiHeight) / (_yhi[0] - _ylo[0]) + _gy - semiHeight;
auto semiHeight = _chart_height / 2;
double y = (firstValue - _y_min_values[0]) * (-semiHeight) / (_y_max_values[0] - _y_min_values[0]) + _y_lower_left_coordinate;
double secondY = (secondValue - _y_min_values[1]) * (-semiHeight) / (_y_max_values[0] - _y_min_values[0]) + _y_lower_left_coordinate - semiHeight;

drawLine(_ox[0] + _xDrawingOffset, _oy[0], _x + _xDrawingOffset, y, WHITE);
drawLine(_ox[0] + _xDrawingOffset, _oy[0] - 1, _x + _xDrawingOffset, y - 1, WHITE);
drawLine(_previous_x_coordinate[0] + _x_drawing_offset, _previous_y_coordinate[0], _actual_x_coordinate + _x_drawing_offset, y, WHITE);
drawLine(_previous_x_coordinate[0] + _x_drawing_offset, _previous_y_coordinate[0] - 1, _actual_x_coordinate + _x_drawing_offset, y - 1, WHITE);

drawLine(_ox[1] + _xDrawingOffset, _oy[1], _x + _xDrawingOffset, secondY, WHITE);
drawLine(_ox[1] + _xDrawingOffset, _oy[1] - 1, _x + _xDrawingOffset, secondY - 1, WHITE);
drawLine(_previous_x_coordinate[1] + _x_drawing_offset, _previous_y_coordinate[1], _actual_x_coordinate + _x_drawing_offset, secondY, WHITE);
drawLine(_previous_x_coordinate[1] + _x_drawing_offset, _previous_y_coordinate[1] - 1, _actual_x_coordinate + _x_drawing_offset, secondY - 1, WHITE);

_ox[0] = _x;
_oy[0] = y;
_ox[1] = _x;
_oy[1] = secondY;
_previous_x_coordinate[0] = _actual_x_coordinate;
_previous_y_coordinate[0] = y;
_previous_x_coordinate[1] = _actual_x_coordinate;
_previous_y_coordinate[1] = secondY;

if (_point_geometry[0] == POINT_GEOMETRY_CIRCLE)
fillCircle(_ox[0] + _xDrawingOffset, _oy[0], 2, WHITE);
fillCircle(_previous_x_coordinate[0] + _x_drawing_offset, _previous_y_coordinate[0], 2, WHITE);
if (_point_geometry[1] == POINT_GEOMETRY_CIRCLE)
fillCircle(_ox[1] + _xDrawingOffset, _oy[1], 2, WHITE);
fillCircle(_previous_x_coordinate[1] + _x_drawing_offset, _previous_y_coordinate[1], 2, WHITE);

display();
return true;
Expand Down
62 changes: 31 additions & 31 deletions src/OLED_SSD1306_Chart.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@
class OLED_SSD1306_Chart : public Adafruit_SSD1306
{
private:
double _ox[2], _oy[2]; //Previous point coordinates
double _gx, _gy; //Chart lower left coordinates
double _w, _h; //Chart width and height
double _ylo[2], _yhi[2]; //Y axis Min and max values
double _xinc; //X coordinate increment between values
double _x; //Actual point x coordinate
double _xincdiv, _yincdiv; //X and Y axis distance between division
double _previous_x_coordinate[2], _previous_y_coordinate[2]; //Previous point coordinates
double _x_lower_left_coordinate, _y_lower_left_coordinate; //Chart lower left coordinates
double _chart_width, _chart_height; //Chart width and height
double _y_min_values[2], _y_max_values[2]; //Y axis Min and max values
double _x_inc; //X coordinate increment between values
double _actual_x_coordinate; //Actual point x coordinate
double _xinc_div, _yinc_div; //X and Y axis distance between division
double _dig;
char _mode; //Plot mode: single or double
char _point_geometry[2]; //Point geometry
bool _yLabelsVisible; //Determines if the y labels should be shown
char *_yLabelLo[2]; //Labels of the lower y value
char *_yLabelHi[2]; //Labels of the higher y value
double _xDrawingOffset; //Used to draw the char after the labels are applied
bool _y_labels_visible; //Determines if the y labels should be shown
char *_y_min_label[2]; //Labels of the lower y value
char *_y_max_label[2]; //Labels of the higher y value
double _x_drawing_offset; //Used to draw the char after the labels are applied

public:
//Ctors
Expand All @@ -33,11 +33,11 @@ class OLED_SSD1306_Chart : public Adafruit_SSD1306
_mode = SINGLE_PLOT_MODE;
_point_geometry[0] = POINT_GEOMETRY_NONE;
_point_geometry[1] = POINT_GEOMETRY_NONE;
_yLabelsVisible = false;
_yLabelLo[0] = "";
_yLabelLo[1] = "";
_yLabelHi[0] = "";
_yLabelHi[1] = "";
_y_labels_visible = false;
_y_min_label[0] = "";
_y_min_label[1] = "";
_y_max_label[0] = "";
_y_max_label[1] = "";
}

OLED_SSD1306_Chart(uint8_t w, uint8_t h, TwoWire *twi, int8_t rst_pin = -1,
Expand All @@ -46,11 +46,11 @@ class OLED_SSD1306_Chart : public Adafruit_SSD1306
_mode = SINGLE_PLOT_MODE;
_point_geometry[0] = POINT_GEOMETRY_NONE;
_point_geometry[1] = POINT_GEOMETRY_NONE;
_yLabelsVisible = false;
_yLabelLo[0] = "";
_yLabelLo[1] = "";
_yLabelHi[0] = "";
_yLabelHi[1] = "";
_y_labels_visible = false;
_y_min_label[0] = "";
_y_min_label[1] = "";
_y_max_label[0] = "";
_y_max_label[1] = "";
}

OLED_SSD1306_Chart(uint8_t w, uint8_t h, int8_t mosi_pin, int8_t sclk_pin,
Expand All @@ -59,11 +59,11 @@ class OLED_SSD1306_Chart : public Adafruit_SSD1306
_mode = SINGLE_PLOT_MODE;
_point_geometry[0] = POINT_GEOMETRY_NONE;
_point_geometry[1] = POINT_GEOMETRY_NONE;
_yLabelsVisible = false;
_yLabelLo[0] = "";
_yLabelLo[1] = "";
_yLabelHi[0] = "";
_yLabelHi[1] = "";
_y_labels_visible = false;
_y_min_label[0] = "";
_y_min_label[1] = "";
_y_max_label[0] = "";
_y_max_label[1] = "";
}

OLED_SSD1306_Chart(uint8_t w, uint8_t h, SPIClass *spi,
Expand All @@ -72,11 +72,11 @@ class OLED_SSD1306_Chart : public Adafruit_SSD1306
_mode = SINGLE_PLOT_MODE;
_point_geometry[0] = POINT_GEOMETRY_NONE;
_point_geometry[1] = POINT_GEOMETRY_NONE;
_yLabelsVisible = false;
_yLabelLo[0] = "";
_yLabelLo[1] = "";
_yLabelHi[0] = "";
_yLabelHi[1] = "";
_y_labels_visible = false;
_y_min_label[0] = "";
_y_min_label[1] = "";
_y_max_label[0] = "";
_y_max_label[1] = "";
}

void setPlotMode(char mode);
Expand Down

0 comments on commit a132af8

Please sign in to comment.