EE445M RTOS
Taken at the University of Texas Spring 2015
graph_framebuffer.c File Reference
#include "graph_framebuffer.h"
#include "shape.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
Include dependency graph for graph_framebuffer.c:

Go to the source code of this file.

Functions

void FBDrawFullscreenGraph (framebuffer fb, graph *g)
 
void FBEraseFullscreenGraph (framebuffer fb, graph *g)
 
void FBEraseFullscreenGraphData (framebuffer fb, graph *g)
 
void FBDrawGraph (framebuffer fb, graph *g, point *top_left_corner, pixel_t width, pixel_t height)
 
void FBEraseGraph (framebuffer fb, graph *g, point *top_left_corner, pixel_t width, pixel_t height)
 
void FBEraseGraphData (framebuffer fb, graph *g, point *top_left_corner, pixel_t width, pixel_t height)
 
private void _FBDrawGraphBounds (framebuffer fb, graph *g, pixel_t x_range_padding, pixel_t y_range_padding, point *top_left_corner, pixel_t width, pixel_t height, shade_t shade)
 
private void _FBDrawGraphData (framebuffer fb, graph *g, point *top_left_corner, shade_t shade)
 
private void _FBDrawGraphTitle (framebuffer fb, graph *g)
 
private void _FBDrawGraphAxesTitles (framebuffer fb, graph *g)
 
private void _FBDrawGraphAxesScale (framebuffer fb, graph *g)
 
unsigned char max_uc (unsigned char one, unsigned char two)
 
pixel_t _FBPixelHeightOfString (char *str)
 
private pixel_t _FBPixelWidthOfString (char *str)
 
private pixel_t _FBPixelWidthOfLong (long l)
 
private pixel_t _FBPixelHeightOfLong (long l)
 

Function Documentation

private void _FBDrawGraphAxesScale ( framebuffer  fb,
graph g 
)

Definition at line 245 of file graph_framebuffer.c.

Referenced by FBDrawGraph(), and FBEraseGraph().

245  {
246 
247 }

Here is the caller graph for this function:

private void _FBDrawGraphAxesTitles ( framebuffer  fb,
graph g 
)

Definition at line 240 of file graph_framebuffer.c.

Referenced by FBDrawGraph(), and FBEraseGraph().

240  {
241 
242 }

Here is the caller graph for this function:

private void _FBDrawGraphBounds ( framebuffer  fb,
graph g,
pixel_t  x_range_padding,
pixel_t  y_range_padding,
point top_left_corner,
pixel_t  width,
pixel_t  height,
shade_t  shade 
)

Definition at line 159 of file graph_framebuffer.c.

References shape_create_point(), point::x, and point::y.

Referenced by FBDrawGraph(), and FBEraseGraph().

166  {
167  /* Draw X axis boundaries (aka vertical lines) */
168  FBDrawAnonLine(fb,
169  shape_create_point(top_left_corner->x + x_range_padding,
170  top_left_corner->y,
171  shade),
172  shape_create_point(top_left_corner->x + x_range_padding,
173  top_left_corner->y + (height - y_range_padding),
174  shade),
175  shade);
176  /* Draw Y axis boundaries (aka horizontal lines) */
177  FBDrawAnonLine(fb,
178  shape_create_point(top_left_corner->x + x_range_padding,
179  top_left_corner->y + height - y_range_padding,
180  shade),
181  shape_create_point(top_left_corner->x + x_range_padding + width,
182  top_left_corner->y + height - y_range_padding,
183  shade),
184  shade);
185 }
unsigned short y
Definition: shape.h:16
point * shape_create_point(ushort x, ushort y, shade_t shade)
Definition: shape.c:6
unsigned short x
Definition: shape.h:15

Here is the call graph for this function:

Here is the caller graph for this function:

private void _FBDrawGraphData ( framebuffer  fb,
graph g,
point top_left_corner,
shade_t  shade 
)

Definition at line 198 of file graph_framebuffer.c.

References graph::all_data_points_valid, graph::data, GL_BLANK_STEPS_PRECEEDING_STALE_DATA, graph::most_recent_data_point, pixel_t, shape_create_point(), when, graph::x_max, graph::x_min, graph::x_pixel_end, graph::x_pixel_start, graph::y_max, graph::y_min, graph::y_pixel_end, and graph::y_pixel_start.

Referenced by FBDrawGraph(), FBEraseGraph(), and FBEraseGraphData().

198  {
199 
200  long idx = 0;
201  /* Temporary variables reused in printfs */
202  pixel_t x1, x2, y1, y2;
203  /* Set this to true from lldb/gdb to see useful debugging information */
204  bool debug = true;
205 
206  for(idx=0;
207  (((g->all_data_points_valid == true) && (idx < g->x_index_max-1))) ||
208  (g->all_data_points_valid == false && (idx < (g->most_recent_data_point - 1)));
209  ++idx) {
210 
211  fprintf(stderr, "Printing index %ld\n", idx);
212 
213  if ((idx <= g->most_recent_data_point) &&
215  /* Draw nothing */
216  when (debug) {fprintf(stderr, "Not drawing this cycle [idx:%ld]\n", idx);}
217  } else {
218 
219  x1 = g->x_pixel_start + ((idx)*(g->x_pixel_end-g->x_pixel_start)/(g->x_max-g->x_min));
220  y1 = g->y_pixel_end - ((g->data[idx]+g->y_min)*(g->y_pixel_end-g->y_pixel_start)/(g->y_max-g->y_min));
221  x2 = g->x_pixel_start + ((idx+1)*(g->x_pixel_end-g->x_pixel_start)/(g->x_max-g->x_min));
222  y2 = g->y_pixel_end - ((g->data[idx+1]+g->y_min)*(g->y_pixel_end-g->y_pixel_start)/(g->y_max-g->y_min));
223 
224  FBDrawAnonLine(fb,
225  shape_create_point(x1, y1, shade),
226  shape_create_point(x2, y2, shade),
227  shade);
228 
229  when (debug) {fprintf(stderr, "Line from:\t(%u,\t%u) to (%u,\t%u)\n",x1,y1,x2,y2);}
230  }
231  }
232 }
pixel_t x_pixel_start
Definition: graphlib.h:71
pixel_t y_pixel_end
Definition: graphlib.h:72
#define when(cond)
Definition: defines.h:60
long most_recent_data_point
Definition: graphlib.h:66
pixel_t y_pixel_start
Definition: graphlib.h:72
#define pixel_t
Definition: defines.h:46
long * data
Definition: graphlib.h:41
long x_max
Definition: graphlib.h:37
#define GL_BLANK_STEPS_PRECEEDING_STALE_DATA
Definition: graphlib.h:14
point * shape_create_point(ushort x, ushort y, shade_t shade)
Definition: shape.c:6
long x_min
Definition: graphlib.h:37
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

Here is the call graph for this function:

Here is the caller graph for this function:

private void _FBDrawGraphTitle ( framebuffer  fb,
graph g 
)

Definition at line 235 of file graph_framebuffer.c.

Referenced by FBDrawGraph(), and FBEraseGraph().

235  {
236 
237 }

Here is the caller graph for this function:

private pixel_t _FBPixelHeightOfLong ( long  l)

Definition at line 293 of file graph_framebuffer.c.

293  {
294  // 2 pixels because we want one to pad the top and one on the bottom
295  return VALVANO_FONT_LINE_SPACING + VALVANO_FONT_HEIGHT;
296 }
pixel_t _FBPixelHeightOfString ( char *  str)

Definition at line 264 of file graph_framebuffer.c.

264  {
265  /* TODO: consider line wrapping */
266  return VALVANO_FONT_LINE_SPACING + VALVANO_FONT_HEIGHT;
267 }
private pixel_t _FBPixelWidthOfLong ( long  l)

Definition at line 283 of file graph_framebuffer.c.

283  {
284  // 2 pixels because we want one to pad the front and one on the back
285  return VALVANO_FONT_KERNING + (log(l) * VALVANO_FONT_WIDTH);
286 }
private pixel_t _FBPixelWidthOfString ( char *  str)

Definition at line 274 of file graph_framebuffer.c.

274  {
275  return VALVANO_FONT_KERNING + ((VALVANO_FONT_KERNING + VALVANO_FONT_WIDTH) * strlen(str));
276 }
void FBDrawFullscreenGraph ( framebuffer  fb,
graph g 
)

Definition at line 25 of file graph_framebuffer.c.

References FBDrawGraph(), OLED_HEIGHT, OLED_WIDTH, pixel_t, shade_t, and shape_create_point().

Referenced by main().

25  {
26  point* origin = shape_create_point((pixel_t) 0, (pixel_t) 0, (shade_t) 15);
27  FBDrawGraph(fb, g, origin, (pixel_t) OLED_WIDTH, (pixel_t) OLED_HEIGHT);
28  SHDestroyPoint(origin);
29 }
#define OLED_HEIGHT
Definition: defines.h:106
#define pixel_t
Definition: defines.h:46
#define OLED_WIDTH
Definition: defines.h:107
point * shape_create_point(ushort x, ushort y, shade_t shade)
Definition: shape.c:6
Representation of an ordered pair with a shade.
Definition: shape.h:13
#define shade_t
Definition: defines.h:41
void FBDrawGraph(framebuffer fb, graph *g, point *top_left_corner, pixel_t width, pixel_t height)

Here is the call graph for this function:

Here is the caller graph for this function:

void FBDrawGraph ( framebuffer  fb,
graph g,
point top_left_corner,
pixel_t  width,
pixel_t  height 
)

Definition at line 73 of file graph_framebuffer.c.

References _FBDrawGraphAxesScale(), _FBDrawGraphAxesTitles(), _FBDrawGraphBounds(), _FBDrawGraphData(), _FBDrawGraphTitle(), pixel_t, point::shade, point::x, graph::x_max, graph::x_min, graph::x_pixel_end, graph::x_pixel_start, point::y, graph::y_max, graph::y_min, graph::y_pixel_end, and graph::y_pixel_start.

Referenced by FBDrawFullscreenGraph().

74  {
75  /* Determine how many pixels to reserve for the scale numbers next
76  * to the axes */
77  pixel_t x_range_padding = max_pixel_width_of_long(g->y_min, g->y_max);
78  pixel_t y_range_padding = max_pixel_height_of_long(g->x_min, g->x_max);
79 
80  /* {x,y}_pixel_{start,end} information in /resources/2014-04-07 10.07.01.jpg */
81  g->x_pixel_start = top_left_corner->x + x_range_padding;
82  g->x_pixel_end = top_left_corner->x + width;
83  g->y_pixel_start = top_left_corner->y;
84  g->y_pixel_end = top_left_corner->y + height - 2 - y_range_padding;
85 
86  _FBDrawGraphBounds(fb, g, x_range_padding, y_range_padding, top_left_corner, width, height, top_left_corner->shade);
87  _FBDrawGraphData(fb, g, top_left_corner, top_left_corner->shade);
88  _FBDrawGraphTitle(fb, g);
90  _FBDrawGraphAxesScale(fb, g);
91 }
private void _FBDrawGraphAxesScale(framebuffer fb, graph *g)
unsigned short y
Definition: shape.h:16
pixel_t x_pixel_start
Definition: graphlib.h:71
pixel_t y_pixel_end
Definition: graphlib.h:72
pixel_t y_pixel_start
Definition: graphlib.h:72
#define pixel_t
Definition: defines.h:46
shade_t shade
Definition: shape.h:18
private void _FBDrawGraphBounds(framebuffer fb, graph *g, pixel_t x_range_padding, pixel_t y_range_padding, point *top_left_corner, pixel_t width, pixel_t height, shade_t shade)
long x_max
Definition: graphlib.h:37
private void _FBDrawGraphData(framebuffer fb, graph *g, point *top_left_corner, shade_t shade)
private void _FBDrawGraphTitle(framebuffer fb, graph *g)
private void _FBDrawGraphAxesTitles(framebuffer fb, graph *g)
long x_min
Definition: graphlib.h:37
long y_min
Definition: graphlib.h:38
long y_max
Definition: graphlib.h:38
pixel_t x_pixel_end
Definition: graphlib.h:71
unsigned short x
Definition: shape.h:15

Here is the call graph for this function:

Here is the caller graph for this function:

void FBEraseFullscreenGraph ( framebuffer  fb,
graph g 
)

Definition at line 38 of file graph_framebuffer.c.

References FB_COLOR_ERASE, FBEraseGraph(), OLED_HEIGHT, OLED_WIDTH, shade_t, shape_create_point(), x_pixel_t, and y_pixel_t.

Referenced by main().

38  {
41  SHDestroyPoint(origin);
42 }
#define OLED_HEIGHT
Definition: defines.h:106
#define OLED_WIDTH
Definition: defines.h:107
#define y_pixel_t
Definition: defines.h:48
void FBEraseGraph(framebuffer fb, graph *g, point *top_left_corner, pixel_t width, pixel_t height)
#define FB_COLOR_ERASE
Definition: defines.h:81
point * shape_create_point(ushort x, ushort y, shade_t shade)
Definition: shape.c:6
Representation of an ordered pair with a shade.
Definition: shape.h:13
#define shade_t
Definition: defines.h:41
#define x_pixel_t
Definition: defines.h:47

Here is the call graph for this function:

Here is the caller graph for this function:

void FBEraseFullscreenGraphData ( framebuffer  fb,
graph g 
)

Definition at line 51 of file graph_framebuffer.c.

References FB_COLOR_ERASE, FBEraseGraphData(), OLED_HEIGHT, OLED_WIDTH, shade_t, shape_create_point(), x_pixel_t, and y_pixel_t.

51  {
54  SHDestroyPoint(origin);
55 }
#define OLED_HEIGHT
Definition: defines.h:106
#define OLED_WIDTH
Definition: defines.h:107
#define y_pixel_t
Definition: defines.h:48
#define FB_COLOR_ERASE
Definition: defines.h:81
point * shape_create_point(ushort x, ushort y, shade_t shade)
Definition: shape.c:6
Representation of an ordered pair with a shade.
Definition: shape.h:13
#define shade_t
Definition: defines.h:41
void FBEraseGraphData(framebuffer fb, graph *g, point *top_left_corner, pixel_t width, pixel_t height)
#define x_pixel_t
Definition: defines.h:47

Here is the call graph for this function:

void FBEraseGraph ( framebuffer  fb,
graph g,
point top_left_corner,
pixel_t  width,
pixel_t  height 
)

Definition at line 103 of file graph_framebuffer.c.

References _FBDrawGraphAxesScale(), _FBDrawGraphAxesTitles(), _FBDrawGraphBounds(), _FBDrawGraphData(), _FBDrawGraphTitle(), FB_SHADE_ERASE, pixel_t, point::x, graph::x_max, graph::x_min, graph::x_pixel_end, graph::x_pixel_start, point::y, graph::y_max, graph::y_min, graph::y_pixel_end, and graph::y_pixel_start.

Referenced by FBEraseFullscreenGraph().

104  {
105  /* Determine how many pixels to reserve for the scale numbers next
106  * to the axes */
107  pixel_t x_range_padding = max_pixel_width_of_long(g->y_min, g->y_max);
108  pixel_t y_range_padding = max_pixel_height_of_long(g->x_min, g->x_max);
109 
110  /* {x,y}_pixel_{start,end} information in /resources/2014-04-07 10.07.01.jpg */
111  g->x_pixel_start = top_left_corner->x + x_range_padding;
112  g->x_pixel_end = top_left_corner->x + width;
113  g->y_pixel_start = top_left_corner->y;
114  g->y_pixel_end = top_left_corner->y + height - 2 - y_range_padding;
115 
116  _FBDrawGraphBounds(fb, g, x_range_padding, y_range_padding, top_left_corner, width, height, FB_SHADE_ERASE);
117  _FBDrawGraphData(fb, g, top_left_corner, FB_SHADE_ERASE);
118  _FBDrawGraphTitle(fb, g);
119  _FBDrawGraphAxesTitles(fb, g);
120  _FBDrawGraphAxesScale(fb, g);
121 }
private void _FBDrawGraphAxesScale(framebuffer fb, graph *g)
unsigned short y
Definition: shape.h:16
pixel_t x_pixel_start
Definition: graphlib.h:71
pixel_t y_pixel_end
Definition: graphlib.h:72
pixel_t y_pixel_start
Definition: graphlib.h:72
#define pixel_t
Definition: defines.h:46
private void _FBDrawGraphBounds(framebuffer fb, graph *g, pixel_t x_range_padding, pixel_t y_range_padding, point *top_left_corner, pixel_t width, pixel_t height, shade_t shade)
long x_max
Definition: graphlib.h:37
private void _FBDrawGraphData(framebuffer fb, graph *g, point *top_left_corner, shade_t shade)
private void _FBDrawGraphTitle(framebuffer fb, graph *g)
private void _FBDrawGraphAxesTitles(framebuffer fb, graph *g)
long x_min
Definition: graphlib.h:37
#define FB_SHADE_ERASE
Definition: defines.h:74
long y_min
Definition: graphlib.h:38
long y_max
Definition: graphlib.h:38
pixel_t x_pixel_end
Definition: graphlib.h:71
unsigned short x
Definition: shape.h:15

Here is the call graph for this function:

Here is the caller graph for this function:

void FBEraseGraphData ( framebuffer  fb,
graph g,
point top_left_corner,
pixel_t  width,
pixel_t  height 
)

Definition at line 133 of file graph_framebuffer.c.

References _FBDrawGraphData(), FB_SHADE_ERASE, pixel_t, point::x, graph::x_max, graph::x_min, graph::x_pixel_end, graph::x_pixel_start, point::y, graph::y_max, graph::y_min, graph::y_pixel_end, and graph::y_pixel_start.

Referenced by FBEraseFullscreenGraphData().

134  {
135  /* Determine how many pixels to reserve for the scale numbers next
136  * to the axes */
137  pixel_t x_range_padding = max_pixel_width_of_long(g->y_min, g->y_max);
138  pixel_t y_range_padding = max_pixel_height_of_long(g->x_min, g->x_max);
139 
140  /* {x,y}_pixel_{start,end} information in /resources/2014-04-07 10.07.01.jpg */
141  g->x_pixel_start = top_left_corner->x + x_range_padding;
142  g->x_pixel_end = top_left_corner->x + width;
143  g->y_pixel_start = top_left_corner->y;
144  g->y_pixel_end = top_left_corner->y + height - 2 - y_range_padding;
145 
146  _FBDrawGraphData(fb, g, top_left_corner, FB_SHADE_ERASE);
147 }
unsigned short y
Definition: shape.h:16
pixel_t x_pixel_start
Definition: graphlib.h:71
pixel_t y_pixel_end
Definition: graphlib.h:72
pixel_t y_pixel_start
Definition: graphlib.h:72
#define pixel_t
Definition: defines.h:46
long x_max
Definition: graphlib.h:37
private void _FBDrawGraphData(framebuffer fb, graph *g, point *top_left_corner, shade_t shade)
long x_min
Definition: graphlib.h:37
#define FB_SHADE_ERASE
Definition: defines.h:74
long y_min
Definition: graphlib.h:38
long y_max
Definition: graphlib.h:38
pixel_t x_pixel_end
Definition: graphlib.h:71
unsigned short x
Definition: shape.h:15

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned char max_uc ( unsigned char  one,
unsigned char  two 
)

Definition at line 255 of file graph_framebuffer.c.

255  {
256  if (one > two) {return one;} else return two;
257 }