Skip to content

Commit

Permalink
Setting values inside limits
Browse files Browse the repository at this point in the history
  • Loading branch information
elC0mpa committed Dec 30, 2020
1 parent a132af8 commit b502fae
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/OLED_SSD1306_Chart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ bool OLED_SSD1306_Chart::updateChart(double firstValue, double secondValue)

_actual_x_coordinate += _x_inc;

if (firstValue < _y_min_values[0])
firstValue = _y_min_values[0];

if (firstValue > _y_max_values[0])
firstValue = _y_max_values[0];

if (_mode == SINGLE_PLOT_MODE)
{
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;
Expand All @@ -210,6 +216,11 @@ bool OLED_SSD1306_Chart::updateChart(double firstValue, double secondValue)

else
{
if (secondValue < _y_min_values[1])
secondValue = _y_min_values[1];

if (secondValue > _y_max_values[1])
secondValue = _y_max_values[1];
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;
Expand Down

0 comments on commit b502fae

Please sign in to comment.