EE445M RTOS
Taken at the University of Texas Spring 2015
graphlib.h
Go to the documentation of this file.
1 #ifndef __GRAPHLIB__
2 #define __GRAPHLIB__
3 
4 #include "libstd/defines.h"
5 
6 /*
7  TODO: finish implementing this behavior
8 
9  As it stands, this is supposed to be the number of pixels to leave
10  blank between new data and old. However, it is the number of steps to
11  leave blank, which does not correlate to pixels at all. Do the math
12  and implement the desired behavior.
13  */
14 #define GL_BLANK_STEPS_PRECEEDING_STALE_DATA 2
15 
16 /* A graph struct
17 
18  This graph manages nearly all aspects of graph-life internally.
19  All it expects from a user is proper configuration (see
20  GLCreateGraph) and for values to be pushed (see GLPushDataPoint)
21  onto the graph. When there is no more room on the right to display
22  information, the graph object will wrap the current index back to
23  the left side of the graph and overwrite the oldest existing data.
24 
25  Limitations:
26  - Y axis can currently only be left-justified
27  - Window cannot be adjusted yet after creation
28  */
29 typedef struct graph {
30  /* Strings labeling important graph areas */
31  char* x_title;
32  char* y_title;
33  char* title;
34 
35  /* Bounds of visible data -- this version of graphlib does not
36  * support dynamic ranges */
37  long x_min, x_max;
38  long y_min, y_max;
39 
40  /* Honeypot -- all the gold (information) goes in here */
41  long* data;
42 
43  /* Current position within- and size of- data */
44  unsigned long x_index;
45  unsigned long x_index_max;
46 
47  /* Below variables concern the state of fresh information in the
48  * graph. Since all data points start at 0, which could be valid,
49  * we need another way to differentiate valid data from invalid
50  * data. */
51 
52  /* This signifies that the data has filled up once and x_index has
53  * wrapped back to zero. Implications: only display all points
54  * when this is true. */
56 
57  /* This field indicates the most recent data point (index) in our
58  * array of data. This is useful in conjunction with the above
59  * member variable. If all_data_points_valid is not set, graph up
60  * to most_recent_data_point. If all_data_points_valid is set,
61  * then the data points have 'wrapped around' the screen much like
62  * an old-school o-scope. In this case, draw up to
63  * most_recent_data_point, draw a break for
64  * GL_BLANK_STEPS_PRECEEDING_STALE_DATA steps, and then graph the
65  * older data. */
67 
68  /* Below variables used for developer sanity during graphing
69  * routines. These fields WILL change with every new graph
70  * size. Don't use them, they are for internal use only. */
73 } graph;
74 
75 /* The joys of programming for embedded systems. */
76 char* strdup(const char *str);
77 
78 /*** Memory management of graph objects ***/
79 /* Method to create an instance of a graph. */
80 graph* GLCreateGraph(long x_min, long x_max, long y_min, long y_max, long x_steps);
81 /* Corresponding method to destroy a graph instance. */
83 
84 /* Set the title of graph and return the head of its new char*. */
85 char* GLSetTitle(graph* graph, char* title);
86 
87 /* Set the titles of the x and y axes. */
88 void GLLabelAxes(graph* graph, char* x_axis, char* y_axis);
89 
90 /* Push a data point onto the end of the graph. The graph will
91  * automatically wrap around when there is no more room in the
92  * internal buffer. */
93 void GLPushDataPoint(graph* graph, long y_val);
94 
95 /* Find a value that, when graphed, will not be visible on the graph
96  * due to the current range of the graph's window. Note that resizing
97  * the window may result in 'visible' OffScreenValues. */
99 
100 #endif // __GRAPHLIB__
pixel_t x_pixel_start
Definition: graphlib.h:71
char * y_title
Definition: graphlib.h:32
pixel_t y_pixel_end
Definition: graphlib.h:72
long most_recent_data_point
Definition: graphlib.h:66
char * GLSetTitle(graph *graph, char *title)
Definition: graphlib.c:42
pixel_t y_pixel_start
Definition: graphlib.h:72
#define pixel_t
Definition: defines.h:46
struct graph graph
void GLPushDataPoint(graph *graph, long y_val)
Definition: graphlib.c:56
long * data
Definition: graphlib.h:41
long x_max
Definition: graphlib.h:37
unsigned long x_index_max
Definition: graphlib.h:45
char * x_title
Definition: graphlib.h:31
Definition: graphlib.h:29
graph * GLCreateGraph(long x_min, long x_max, long y_min, long y_max, long x_steps)
Definition: graphlib.c:25
void GLDestroyGraph(graph *graph)
Definition: graphlib.c:83
long GLOffScreenValue(graph *graph)
Definition: graphlib.c:71
unsigned long x_index
Definition: graphlib.h:44
void GLLabelAxes(graph *graph, char *x_axis, char *y_axis)
Definition: graphlib.c:48
long x_min
Definition: graphlib.h:37
char * strdup(const char *str)
Definition: graphlib.c:15
char * title
Definition: graphlib.h:33
long y_min
Definition: graphlib.h:38
long y_max
Definition: graphlib.h:38
pixel_t x_pixel_end
Definition: graphlib.h:71
bool all_data_points_valid
Definition: graphlib.h:55