EE445M RTOS
Taken at the University of Texas Spring 2015
console-fb.c File Reference
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include "shape.h"
#include "clock.h"
#include "framebuffer.h"
#include "graphics2d.h"
#include "timekit.h"
Include dependency graph for console-fb.c:

Go to the source code of this file.

Functions

int usleep (int usec)
 
void mockCheckout (void)
 
void demonstrateVoidPointerMenus (void)
 
void demonstrateClockMenu (void)
 
void demonstrateClock (void)
 
void demonstrateDrawString (void)
 
void demonstrateDrawShapes (void)
 
void printFramebuffer (unsigned char *fb)
 
void pseudointerrupt (clocktime *tm)
 
int main (void)
 

Function Documentation

void demonstrateClock ( void  )

Definition at line 154 of file console-fb.c.

References CFCreateClockFace(), CFDestroyClockFace(), CFDestroyShapes(), CFToShapes(), CFUpdateTime(), CH_HOURS, CH_MINUTES, CH_MS, CH_SECONDS, CHCreateClockHand(), CHDestroyClockHand(), FB_COLOR_MUCH, G2ConvertFBToRITFormat(), OLED_HEIGHT, OLED_WIDTH, printFramebuffer(), pseudointerrupt(), TK_PRINT_MODE_HOURS_MINUTES_SECONDS_MS, TKCreateTimeHandle(), TKDestroy(), TKIncrementHours(), TKIncrementMinutes(), and usleep().

Referenced by main().

154  {
155 
156 
157  point* pt_center = SHCreatePoint(OLED_WIDTH/2, OLED_HEIGHT/2, 15);
158  point* pt_offset_ms = SHCreatePoint(OLED_WIDTH/2, 3*OLED_HEIGHT/4, 15);
159  circle* circle_cir = SHCreateCircle(46, pt_center);
160  circle* circle_ms = SHCreateCircle(12, pt_offset_ms);
161 
163 
164  clockhand* ch_hour = CHCreateClockHand(pt_center, 25, CH_HOURS); // px
165  clockhand* ch_min = CHCreateClockHand(pt_center, 32, CH_MINUTES); // px
166  clockhand* ch_sec = CHCreateClockHand(pt_center, 36, CH_SECONDS); // px
167  clockhand* ch_ms = CHCreateClockHand(pt_offset_ms, 10, CH_MS); // px
168 
169  ushort numhands = 4;
170  clockhand** hands_arr = (clockhand**)malloc(numhands*sizeof(clockhand*));
171  hands_arr[0] = ch_hour;
172  hands_arr[1] = ch_min;
173  hands_arr[2] = ch_sec;
174  hands_arr[3] = ch_ms;
175  clockface* cf = CFCreateClockFace(numhands, hands_arr, tm);
176 
177  shape** shapeptr;
178 
179  TKIncrementHours(tm, 10);
180  TKIncrementMinutes(tm, 40);
181 
182  framebuffer fb = FBInit();
183 
184  /* Begin clock face layout */
185  point* twelve_corner = SHCreatePoint(58, 4, FB_COLOR_MUCH);
186  point* six_corner = SHCreatePoint(62, 86, FB_COLOR_MUCH);
187  point* three_corner = SHCreatePoint(21, 45, FB_COLOR_MUCH);
188  point* nine_corner = SHCreatePoint(103, 45, FB_COLOR_MUCH);
189  FBDrawCircle(fb, circle_cir);
190  FBDrawString(fb, twelve_corner, "12");
191  FBDrawString(fb, six_corner, "6");
192  FBDrawString(fb, three_corner, "3");
193  FBDrawString(fb, nine_corner, "9");
194  free(twelve_corner);
195  free(six_corner);
196  free(three_corner);
197  free(nine_corner);
198  /* End clock face layout */
199 
200  while(1) {
201  /* printf("----- %s -----\n", TKToString(tm)); */
202  pseudointerrupt(tm);
203  CFUpdateTime(cf);
204  shapeptr = CFToShapes(cf);
205  FBDrawCircle(fb, circle_ms);
206  FBDrawShapeArr(fb, numhands, shapeptr);
208  FBEraseShapeArr(fb, numhands, shapeptr);
209  CFDestroyShapes(cf);
210  usleep(500000); // .5 second
211  }
212 
213  /* cleanup */
214  /* CFDestroyClockFace(cf); */
215  free(circle_cir);
216  free(circle_ms);
217  free(pt_offset_ms);
218  free(pt_center);
219  TKDestroy(tm);
220 
221  CHDestroyClockHand(ch_hour);
222  CHDestroyClockHand(ch_min);
223  CHDestroyClockHand(ch_sec);
224  CHDestroyClockHand(ch_ms);
225  CFDestroyClockFace(cf);
226  free(hands_arr);
227 
228  /* free(fb); */
229  FBDestroy(fb);
230 }
unsigned char * G2ConvertFBToRITFormat(framebuffer fb)
Definition: graphics2d.c:23
int usleep(int usec)
#define OLED_HEIGHT
Definition: defines.h:106
void TKIncrementHours(clocktime *tm, short hours)
Definition: timekit.c:55
Representation of a circle.
Definition: shape.h:37
Representation of a shape.
Definition: shape.h:26
void TKDestroy(clocktime *tm)
Definition: timekit.c:24
void CFDestroyClockFace(clockface *cf)
Definition: clock.c:112
#define CH_SECONDS
Definition: clock.h:18
#define OLED_WIDTH
Definition: defines.h:107
unsigned short ushort
Definition: defines.h:35
char ** framebuffer
Definition: framebuffer.h:12
void printFramebuffer(unsigned char *fb)
Definition: console-fb.c:282
void CFUpdateTime(clockface *cf)
Definition: clock.c:128
shape ** CFToShapes(clockface *cf)
Definition: clock.c:135
clockhand * CHCreateClockHand(point *center, ushort radius, uchar type)
Definition: clock.c:32
#define FB_COLOR_MUCH
Definition: defines.h:85
void CHDestroyClockHand(clockhand *ch)
Definition: clock.c:71
#define CH_MINUTES
Definition: clock.h:17
#define CH_MS
Definition: clock.h:19
void CFDestroyShapes(clockface *cf)
Definition: clock.c:146
Representation of an ordered pair with a shade.
Definition: shape.h:13
clockface * CFCreateClockFace(ushort numHands, clockhand **chs, clocktime *th)
Definition: clock.c:91
void pseudointerrupt(clocktime *tm)
Definition: console-fb.c:232
#define CH_HOURS
Definition: clock.h:16
void TKIncrementMinutes(clocktime *tm, short minutes)
Definition: timekit.c:69
#define TK_PRINT_MODE_HOURS_MINUTES_SECONDS_MS
Definition: timekit.h:8
clocktime * TKCreateTimeHandle(char mode)
Definition: timekit.c:14

Here is the call graph for this function:

Here is the caller graph for this function:

void demonstrateClockMenu ( void  )
void demonstrateDrawShapes ( void  )

Definition at line 237 of file console-fb.c.

References G2ConvertFBToRITFormat(), printFramebuffer(), and point::shade.

237  {
238  point* p0 = SHCreatePoint(10, 10, 15);
239  point* p1 = SHCreatePoint(10, 20, 15);
240  point* p2 = SHCreatePoint(30, 30, 15);
241  shape* tri = SHCreateTriangle(p0, p1, p2);
242 
243  point* p2_0 = SHCreatePoint(50, 50, 11);
244  shape* square = SHCreateQuad(p2_0, 10, 10);
245 
246  point* round_center =SHCreatePoint(70, 35, 7);
247  /* circle* circle = SHCreateCircle(15, round_center); */
248 
249  shape** shapeArr = (shape**)malloc(2*sizeof(shape*));
250  shapeArr[0] = tri; shapeArr[1] = square;
251 
252  framebuffer fb = FBInit();
253 
254  FBDrawLine(fb, SHCreatePoint(0, 0, 15), SHCreatePoint(0, 10, 15), 15);
255 
256  /* FBDrawShape(fb, tri); */
257  /* FBDrawShape(fb, square); */
258  /* FBDrawMultipleShapes(fb, 2, square, tri); */
259  FBDrawShapeArr(fb, 2, shapeArr);
260  free(shapeArr);
261 
262  FBDrawEllipseFill(fb, round_center, 30, 5, round_center->shade);
264  FBDestroy(fb);
265 }
unsigned char * G2ConvertFBToRITFormat(framebuffer fb)
Definition: graphics2d.c:23
Representation of a shape.
Definition: shape.h:26
shade_t shade
Definition: shape.h:18
char ** framebuffer
Definition: framebuffer.h:12
void printFramebuffer(unsigned char *fb)
Definition: console-fb.c:282
Representation of an ordered pair with a shade.
Definition: shape.h:13

Here is the call graph for this function:

void demonstrateDrawString ( void  )

Definition at line 267 of file console-fb.c.

References G2ConvertFBToRITFormat(), and printFramebuffer().

267  {
268  framebuffer fb = FBInit();
269  point* pt = SHCreatePoint(20, 35, 15);
270 
271  FBDrawString(fb, pt, "A B C D E F G");
273 
274  FBDestroy(fb);
275  free(pt);
276 }
unsigned char * G2ConvertFBToRITFormat(framebuffer fb)
Definition: graphics2d.c:23
char ** framebuffer
Definition: framebuffer.h:12
void printFramebuffer(unsigned char *fb)
Definition: console-fb.c:282
Representation of an ordered pair with a shade.
Definition: shape.h:13

Here is the call graph for this function:

void demonstrateVoidPointerMenus ( void  )
int main ( void  )

Definition at line 37 of file console-fb.c.

References demonstrateClock().

37  {
38  /* mockCheckout(); */
39  /* demonstrateVoidPointerMenus(); */
40  /* demonstrateClockMenu(); */
41  /* demonstrateMenu(); */
43  /* demonstrateDrawString(); */
44  /* demonstrateDrawShapes(); */
45 }
void demonstrateClock(void)
Definition: console-fb.c:154

Here is the call graph for this function:

void mockCheckout ( void  )

Definition at line 47 of file console-fb.c.

47  {
48 
49 }
void printFramebuffer ( unsigned char *  fb)

Definition at line 282 of file console-fb.c.

References OLED_HEIGHT, OLED_WIDTH, RIT_FB_WIDTH, SHADE_0, SHADE_1, SHADE_2, and SHADE_3.

Referenced by demonstrateClock(), demonstrateDrawShapes(), and demonstrateDrawString().

282  {
283  unsigned char i, j, a, b;
284 
285  for(j=0; j<OLED_HEIGHT; ++j) {
286  for(i=0; i<OLED_WIDTH; i+=2) {
287  a = (fb[(i/2)+j*RIT_FB_WIDTH] >> 4);
288  b = (fb[(i/2)+j*RIT_FB_WIDTH] & 0x0F);
289 
290  switch(a/4) {
291  case 0: a=SHADE_0; break;
292  case 1: a=SHADE_1; break;
293  case 2: a=SHADE_2; break;
294  case 3: a=SHADE_3; break;
295  }
296 
297  switch(b/4) {
298  case 0: b=SHADE_0; break;
299  case 1: b=SHADE_1; break;
300  case 2: b=SHADE_2; break;
301  case 3: b=SHADE_3; break;
302  }
303 
304  printf("%c%c", a, b);
305  }
306  printf("\n");
307  }
308 }
#define OLED_HEIGHT
Definition: defines.h:106
#define RIT_FB_WIDTH
Definition: defines.h:110
#define SHADE_3
Definition: defines.h:92
#define OLED_WIDTH
Definition: defines.h:107
#define SHADE_2
Definition: defines.h:91
#define SHADE_0
Definition: defines.h:89
#define SHADE_1
Definition: defines.h:90

Here is the caller graph for this function:

void pseudointerrupt ( clocktime tm)

Definition at line 232 of file console-fb.c.

References TKIncrementMS().

Referenced by demonstrateClock().

232  {
233  TKIncrementMS(tm,100);
234  /* TKIncrementHours(tm,1); */
235 }
void TKIncrementMS(clocktime *tm, short ms)
Definition: timekit.c:109

Here is the call graph for this function:

Here is the caller graph for this function:

int usleep ( int  usec)

Referenced by demonstrateClock().

Here is the caller graph for this function: