From 355fc4ee7491df48b01d7e555ce27c210428386e Mon Sep 17 00:00:00 2001 From: aquazx20 Date: Thu, 4 May 2023 09:36:35 -0600 Subject: [PATCH] Cartesian chart modified to support x axis modifications according to the value of a variable, so now the number of samples can be modified. --- resources/Graph.h | 10 ++++++---- resources/Screen.h | 8 ++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/resources/Graph.h b/resources/Graph.h index b36b623..e055f39 100644 --- a/resources/Graph.h +++ b/resources/Graph.h @@ -17,7 +17,8 @@ class Graph{ //ContentType (1) double xmaximum; //For: Horizontal Bar Cartesian double yStepSize; //For: Vertical Bar Cartesian double xStepSize; //For: Horizontal Bar Cartesian - int digit; //For: Vertical Bar Horizontal Bar Cartesian + int digit; //For: Vertical Bar Horizontal Bar Cartesian + int * maximum; double x; double yrange; double xrange; @@ -34,7 +35,7 @@ class Graph{ //ContentType (1) //This method configures the graph created, defines its parameters according the type of graph selected. void configure(String title, char graphType, double xpos, double ypos, double width, double height, - double yminimum, double ymaximum, double xminimum, double xmaximum, double yStepSize, double xStepSize, int digit){ + double yminimum, double ymaximum, double xminimum, double xmaximum, double yStepSize, double xStepSize, int digit, void *maximum){ this->title = title; this->graphType = graphType; this->yminimum = yminimum; @@ -49,6 +50,7 @@ class Graph{ //ContentType (1) this->digit = digit; this->xpos = xpos; this->ypos = ypos; + this->maximum = (int *) maximum; switch(graphType){ case 'a': this->yrange = ymaximum - yminimum; @@ -62,7 +64,6 @@ class Graph{ //ContentType (1) case 'c': this->yrange = ymaximum - yminimum; - this->xrange = xmaximum - xminimum; break; } } @@ -149,6 +150,7 @@ class Graph{ //ContentType (1) if (this->redraw == true) { this->redraw = false; + this->xrange = *this->maximum - xminimum; display.clearDisplay(); display.fillRect(0, 0, 127 , 16, SSD1306_WHITE); display.setTextColor(SSD1306_BLACK, SSD1306_WHITE); @@ -174,7 +176,7 @@ class Graph{ //ContentType (1) display.println(i, this->digit); } // draw x scale - for (i = this->xminimum; i <= this->xmaximum; i += this->xStepSize) { + for (i = this->xminimum; i <= *this->maximum; i += this->xStepSize) { // compute the transform display.setTextSize(1); display.setTextColor(SSD1306_WHITE, SSD1306_BLACK); diff --git a/resources/Screen.h b/resources/Screen.h index 15f86b7..28bbe32 100644 --- a/resources/Screen.h +++ b/resources/Screen.h @@ -55,19 +55,19 @@ class Screen{ void createVGraph(String title, double xpos, double ypos, double width, double height, double yminimum, double ymaximum, double yStepSize, int digit){ //this method calls the configure() of graph for a vertical graph - this->graph[counterG].configure(title, 'a', xpos, ypos, width, height, yminimum, ymaximum, 0, 0, yStepSize, 0, digit); + this->graph[counterG].configure(title, 'a', xpos, ypos, width, height, yminimum, ymaximum, 0, 0, yStepSize, 0, digit, 0); this->counterG++; } void createHGraph(String title, double xpos, double ypos, double width, double height, double xminimum, double xmaximum, double xStepSize, int digit){ //this method calls the configure() of graph for a horizontal graph - this->graph[counterG].configure(title, 'b', xpos, ypos, width, height, 0, 0, xminimum, xmaximum, 0, xStepSize, digit); + this->graph[counterG].configure(title, 'b', xpos, ypos, width, height, 0, 0, xminimum, xmaximum, 0, xStepSize, digit, 0); counterG++; } void createCGraph(String title, double xpos, double ypos, double width, double height, - double yminimum, double ymaximum, double xminimum, double xmaximum, double yStepSize, double xStepSize, int digit){ //this method calls the configure() of graph for a cartesian chart - this->graph[counterG].configure(title, 'c', xpos, ypos, width, height, yminimum, ymaximum, xminimum, xmaximum, yStepSize, xStepSize, digit); + double yminimum, double ymaximum, double xminimum, double yStepSize, double xStepSize, int digit, void * maximum){ //this method calls the configure() of graph for a cartesian chart + this->graph[counterG].configure(title, 'c', xpos, ypos, width, height, yminimum, ymaximum, xminimum, 0, yStepSize, xStepSize, digit, maximum); counterG++; }