EE445M RTOS
Taken at the University of Texas Spring 2015
clock.h File Reference
#include "libmath/geometry/shape.h"
#include "timekit.h"
Include dependency graph for clock.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  clockhand
 
struct  clockface
 

Macros

#define CH_HOURS   1
 
#define CH_MINUTES   2
 
#define CH_SECONDS   3
 
#define CH_MS   4
 
#define CH_MAX_HOURS   12
 
#define CH_MAX_MINUTES   60
 
#define CH_MAX_SECONDS   60
 
#define CH_MAX_MS   1000
 
#define CH_MAX_DEGREES   360
 
#define CH_ANGLE_OFFSET   90.0
 
#define PI_PI   3.142159
 

Typedefs

typedef struct clockhand clockhand
 
typedef struct clockface clockface
 

Functions

clockhandCHCreateClockHand (point *center, ushort radius, uchar type)
 
void CHCalculateAngle (clockhand *ch, clocktime *tm)
 
shapeCHToShape (clockhand *ch)
 
void CHDestroyClockHand (clockhand *ch)
 
void CHDestroyClockHandShape (clockhand *ch)
 
clockfaceCFCreateClockFace (ushort numHands, clockhand **chs, clocktime *th)
 
void CFDestroyClockFace (clockface *cf)
 
void CFUpdateTime (clockface *cf)
 
shape ** CFToShapes (clockface *cf)
 
void CFDestroyShapes (clockface *cf)
 

Macro Definition Documentation

#define CH_ANGLE_OFFSET   90.0

Definition at line 27 of file clock.h.

Referenced by CHToShape().

#define CH_HOURS   1

Definition at line 16 of file clock.h.

Referenced by CHCalculateAngle(), and demonstrateClock().

#define CH_MAX_DEGREES   360

Definition at line 26 of file clock.h.

#define CH_MAX_HOURS   12

Definition at line 21 of file clock.h.

#define CH_MAX_MINUTES   60

Definition at line 22 of file clock.h.

#define CH_MAX_MS   1000

Definition at line 24 of file clock.h.

#define CH_MAX_SECONDS   60

Definition at line 23 of file clock.h.

#define CH_MINUTES   2

Definition at line 17 of file clock.h.

Referenced by CHCalculateAngle(), and demonstrateClock().

#define CH_MS   4

Definition at line 19 of file clock.h.

Referenced by CHCalculateAngle(), and demonstrateClock().

#define CH_SECONDS   3

Definition at line 18 of file clock.h.

Referenced by CHCalculateAngle(), and demonstrateClock().

#define PI_PI   3.142159

Definition at line 29 of file clock.h.

Referenced by CHToShape().

Typedef Documentation

typedef struct clockface clockface
typedef struct clockhand clockhand

Function Documentation

clockface* CFCreateClockFace ( ushort  numHands,
clockhand **  chs,
clocktime th 
)

Definition at line 91 of file clock.c.

References clockface::hands, clockface::numHands, and clockface::timehandle.

Referenced by demonstrateClock().

91  {
92 
93  ushort i;
94  clockface* cf = (clockface*) calloc(1, sizeof(clockface));
95 
96  /* Moved to CFToShapes */
97  /* cf->shapeBuffer = (shape**)malloc(numHands * sizeof(shape*)); */
98  cf->numHands = numHands;
99 
100  /* Shallow copy of clockhands */
101  cf->hands = (clockhand**) calloc(numHands, sizeof(clockhand*));
102  for(i=0; i < numHands; ++i) {
103  cf->hands[i] = chs[i];
104  }
105 
106  /* Don't deep copy timehandle, we need it for the interrupt */
107  cf->timehandle = th;
108 
109  return cf;
110 }
unsigned short ushort
Definition: defines.h:35
clocktime * timehandle
Definition: clock.h:61
clockhand ** hands
Definition: clock.h:54
ushort numHands
Definition: clock.h:55

Here is the caller graph for this function:

void CFDestroyClockFace ( clockface cf)

Definition at line 112 of file clock.c.

References clockface::hands.

Referenced by demonstrateClock().

112  {
113  free(cf->hands);
114  free(cf);
115 }
clockhand ** hands
Definition: clock.h:54

Here is the caller graph for this function:

void CFDestroyShapes ( clockface cf)

Definition at line 146 of file clock.c.

References CHDestroyClockHandShape(), clockface::hands, clockface::numHands, and clockface::shapeBuffer.

Referenced by demonstrateClock().

146  {
147  ushort i;
148  for(i=0; i<cf->numHands; ++i) {
149  /* free(cf->shapeBuffer[i]); */
151  }
152  free(cf->shapeBuffer);
153 }
unsigned short ushort
Definition: defines.h:35
void CHDestroyClockHandShape(clockhand *ch)
Definition: clock.c:80
shape ** shapeBuffer
Definition: clock.h:65
clockhand ** hands
Definition: clock.h:54
ushort numHands
Definition: clock.h:55

Here is the call graph for this function:

Here is the caller graph for this function:

shape** CFToShapes ( clockface cf)

Definition at line 135 of file clock.c.

References CHToShape(), clockface::hands, clockface::numHands, and clockface::shapeBuffer.

Referenced by demonstrateClock().

135  {
136  ushort i;
137 
138  cf->shapeBuffer = (shape**)malloc(cf->numHands * sizeof(shape*));
139 
140  for(i=0; i<cf->numHands; ++i) {
141  cf->shapeBuffer[i] = CHToShape(cf->hands[i]);
142  }
143  return cf->shapeBuffer;
144 }
shape * CHToShape(clockhand *ch)
Definition: clock.c:15
Representation of a shape.
Definition: shape.h:26
unsigned short ushort
Definition: defines.h:35
shape ** shapeBuffer
Definition: clock.h:65
clockhand ** hands
Definition: clock.h:54
ushort numHands
Definition: clock.h:55

Here is the call graph for this function:

Here is the caller graph for this function:

void CFUpdateTime ( clockface cf)

Definition at line 128 of file clock.c.

References CHCalculateAngle(), clockface::hands, clockface::numHands, and clockface::timehandle.

Referenced by demonstrateClock().

128  {
129  ushort i;
130  for(i=0; i<cf->numHands; ++i) {
131  CHCalculateAngle(cf->hands[i], cf->timehandle);
132  }
133 }
unsigned short ushort
Definition: defines.h:35
void CHCalculateAngle(clockhand *ch, clocktime *tm)
Definition: clock.c:46
clocktime * timehandle
Definition: clock.h:61
clockhand ** hands
Definition: clock.h:54
ushort numHands
Definition: clock.h:55

Here is the call graph for this function:

Here is the caller graph for this function:

void CHCalculateAngle ( clockhand ch,
clocktime tm 
)

Definition at line 46 of file clock.c.

References clockhand::angle, CH_HOURS, CH_MINUTES, CH_MS, CH_SECONDS, clocktime::hours, clocktime::minutes, clocktime::ms, clocktime::seconds, and clockhand::type.

Referenced by CFUpdateTime().

46  {
47  ushort tmpHours;
48 
49  switch(ch->type) {
50  case CH_HOURS:
51  tmpHours = tm->hours;
52  while(tmpHours > 12) {
53  tmpHours -= 12;
54  }
55  ch->angle = (short)(30*tmpHours + (tm->minutes)/2.0);
56  break;
57  case CH_MINUTES:
58  ch->angle = (short)(6.0*tm->minutes + tm->seconds/10.0);
59  break;
60  case CH_SECONDS:
61  ch->angle = 6*tm->seconds + 3.0/500*tm->ms;
62  break;
63  case CH_MS:
64  ch->angle = (short)((9/25.0)*(tm->ms));
65  break;
66  }
67 
68  /* printf("--- ANGLE FOR %i: %i --- %i\n", ch->type, ch->angle, CH_SECONDS); */
69 }
short seconds
Definition: timekit.h:24
#define CH_SECONDS
Definition: clock.h:18
unsigned short ushort
Definition: defines.h:35
uchar type
Definition: clock.h:39
#define CH_MINUTES
Definition: clock.h:17
#define CH_MS
Definition: clock.h:19
ushort angle
Definition: clock.h:45
short minutes
Definition: timekit.h:23
short hours
Definition: timekit.h:22
#define CH_HOURS
Definition: clock.h:16
short ms
Definition: timekit.h:25

Here is the caller graph for this function:

clockhand* CHCreateClockHand ( point center,
ushort  radius,
uchar  type 
)

Definition at line 32 of file clock.c.

References clockhand::angle, clockhand::center, clockhand::pointOnCircumference, clockhand::radius, shape_duplicate_point(), and clockhand::type.

Referenced by demonstrateClock().

32  {
33  clockhand* ch = (clockhand*) calloc(1, sizeof(clockhand));
34 
35  ch->radius = radius;
36  ch->center = shape_duplicate_point(center);
37  ch->type = type;
38 
39  ch->angle = 0;
40 
42 
43  return ch;
44 }
ushort radius
Definition: clock.h:35
point * shape_duplicate_point(point *p)
Definition: shape.h:77
uchar type
Definition: clock.h:39
point * center
Definition: clock.h:37
point * pointOnCircumference
Definition: clock.h:46
ushort angle
Definition: clock.h:45

Here is the call graph for this function:

Here is the caller graph for this function:

void CHDestroyClockHand ( clockhand ch)

Definition at line 71 of file clock.c.

References clockhand::center, and clockhand::pointOnCircumference.

Referenced by demonstrateClock().

71  {
72 
73  /* SHDestroyShape(ch->shapeBuffer); */
74  /* free(ch->shapeBuffer); */
75  free(ch->pointOnCircumference);
76  free(ch->center);
77  free(ch);
78 }
point * center
Definition: clock.h:37
point * pointOnCircumference
Definition: clock.h:46

Here is the caller graph for this function:

void CHDestroyClockHandShape ( clockhand ch)

Definition at line 80 of file clock.c.

References shape::points, and clockhand::shapeBuffer.

Referenced by CFDestroyShapes().

80  {
81 
82  /* point* p; */
83  /* p = SHCreatePoint(p->x, p->y, p->shade); */
84  /* SHDestroyShape(ch->shapeBuffer); */
85  /* ch->center = p; */
86 
87  free(ch->shapeBuffer->points);
88  free(ch->shapeBuffer);
89 }
shape * shapeBuffer
Definition: clock.h:43
point ** points
Definition: shape.h:29

Here is the caller graph for this function:

shape* CHToShape ( clockhand ch)

Definition at line 15 of file clock.c.

References clockhand::angle, clockhand::center, CH_ANGLE_OFFSET, PI_PI, clockhand::pointOnCircumference, clockhand::radius, shape_create(), clockhand::shapeBuffer, point::x, and point::y.

Referenced by CFToShapes().

15  {
16  float x, y;
17 
18  x = cosf((ch->angle - CH_ANGLE_OFFSET) * PI_PI / 180) * ch->radius;
19  y = sinf((ch->angle - CH_ANGLE_OFFSET) * PI_PI / 180) * ch->radius;
20 
21  /* avoid underflow (subtracting too much from an unsigned number) */
22  if(-x > ch->center->x) {x = -ch->center->x;}
23  if(-y > ch->center->y) {y = -ch->center->y;}
24 
25  ch->pointOnCircumference->x = ch->center->x+x;
26  ch->pointOnCircumference->y = ch->center->y+y;
27 
29  return ch->shapeBuffer;
30 }
unsigned short y
Definition: shape.h:16
shape * shape_create(ushort num_points,...)
Definition: shape.c:31
ushort radius
Definition: clock.h:35
#define PI_PI
Definition: clock.h:29
shape * shapeBuffer
Definition: clock.h:43
#define CH_ANGLE_OFFSET
Definition: clock.h:27
point * center
Definition: clock.h:37
point * pointOnCircumference
Definition: clock.h:46
ushort angle
Definition: clock.h:45
unsigned short x
Definition: shape.h:15

Here is the call graph for this function:

Here is the caller graph for this function: