Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1664 | pj | 1 | #include "include/auto.h" |
2 | #include <string.h> |
||
3 | #include <stdlib.h> |
||
4 | |||
5 | char retbuf[22]; |
||
6 | char chCTR[22]; |
||
7 | int man_rad = RAD; |
||
8 | int man_x ; |
||
9 | int man_y ; |
||
10 | int man_col = rgb16( 12,175, 16); |
||
11 | int black = rgb16( 0, 0, 0); |
||
12 | int white = rgb16(255,255,255); |
||
13 | int mycolour = rgb16(7, 0,250); |
||
14 | int col; |
||
15 | int car_colour1; |
||
16 | int crossed = 0; |
||
17 | int accident = 0; |
||
18 | int counter = 0; |
||
19 | int casualty = 0; |
||
20 | |||
21 | |||
22 | |||
23 | extern int red; |
||
24 | extern int car_colour; |
||
25 | extern int track_colour; |
||
26 | |||
27 | extern sem_t grx_mutex; |
||
28 | extern int track_direction; |
||
29 | |||
30 | void moveup(); |
||
31 | void movedown(); |
||
32 | int check_accident(); |
||
33 | void display(); |
||
34 | |||
35 | |||
36 | int rand_color() |
||
37 | { |
||
38 | return (rand()%16); |
||
39 | } |
||
40 | |||
41 | void actAccident(){ |
||
42 | if (check_accident()) |
||
43 | { |
||
44 | grx_disc(man_x,man_y,man_rad,mycolour); |
||
45 | grx_disc(450,45,20,red); |
||
46 | task_delay(20000); |
||
47 | casualty++; |
||
48 | accident = 0; |
||
49 | man_y = HIGHWAY_Y_MAX+man_rad+40; |
||
50 | man_x = 400; |
||
51 | grx_disc(man_x,man_y,man_rad,man_col); |
||
52 | } |
||
53 | |||
54 | } |
||
55 | |||
56 | void movedown() |
||
57 | { |
||
58 | if(man_y < 485) |
||
59 | { |
||
60 | actAccident(); |
||
61 | sem_wait(&grx_mutex); |
||
62 | grx_disc(man_x,man_y,man_rad,track_colour); |
||
63 | if (man_y>=408) grx_disc(man_x,man_y,man_rad,black); |
||
64 | if (man_y<=92) grx_disc(man_x,man_y,man_rad,black); |
||
65 | man_y = man_y+Y_INCREMENT; |
||
66 | grx_disc(man_x,man_y,man_rad,man_col); |
||
67 | sem_post(&grx_mutex); |
||
68 | |||
69 | if (man_y < HIGHWAY_Y_MIN) |
||
70 | crossed = 1; |
||
71 | |||
72 | } |
||
73 | } |
||
74 | |||
75 | void moveup() |
||
76 | { |
||
77 | if(man_y>50) |
||
78 | { |
||
79 | actAccident(); |
||
80 | sem_wait(&grx_mutex); |
||
81 | grx_disc(man_x,man_y,man_rad,track_colour); |
||
82 | if(man_y >=408) grx_disc(man_x,man_y,man_rad,black); |
||
83 | if(man_y <=92) grx_disc(man_x,man_y,man_rad,black); |
||
84 | if(man_y <=394) grx_box(392,400,408,416,black); |
||
85 | man_y = man_y-Y_INCREMENT; |
||
86 | grx_disc(man_x,man_y,man_rad,man_col); |
||
87 | sem_post(&grx_mutex); |
||
88 | |||
89 | if (man_y < HIGHWAY_Y_MIN) |
||
90 | crossed = 1; |
||
91 | |||
92 | } |
||
93 | } |
||
94 | |||
95 | int check_accident() |
||
96 | { |
||
97 | |||
98 | // grx_disc(37,55,10,car_colour); |
||
99 | // car_colour= grx_getpixel(37,55); |
||
100 | col = grx_getpixel(man_x,man_y-man_rad); |
||
101 | if((col == car_colour)) |
||
102 | accident = 1; |
||
103 | // car_colour1= grx_getpixel(37,55); |
||
104 | col = grx_getpixel(man_x,man_y+man_rad); |
||
105 | if((col == car_colour)) |
||
106 | accident = 1; |
||
107 | |||
108 | return(accident); |
||
109 | } |
||
110 | |||
111 | |||
112 | TASK man(void *arg) |
||
113 | { |
||
114 | man_x = 400; |
||
115 | man_y = HIGHWAY_Y_MAX+man_rad+40; |
||
116 | grx_disc(man_x,man_y,man_rad,man_col); |
||
117 | // sem_post(&grx_mutex); |
||
118 | |||
119 | while (1) |
||
120 | { |
||
121 | display(); |
||
122 | |||
123 | actAccident(); |
||
124 | if (crossed) |
||
125 | { |
||
126 | grx_disc(man_x,man_y,man_rad,track_colour); |
||
127 | grx_box(man_x-man_rad,man_y-man_rad,man_x+man_rad,man_y,black); |
||
128 | man_y = HIGHWAY_Y_MAX+man_rad+40; |
||
129 | man_x = 400; //SCREEN_WIDTH/2; |
||
130 | counter++; |
||
131 | crossed=0; |
||
132 | task_delay(5000); |
||
133 | grx_disc(man_x,man_y,man_rad,man_col); |
||
134 | } |
||
135 | task_endcycle(); |
||
136 | } |
||
137 | } |
||
138 | |||
139 | |||
140 | void create_man() |
||
141 | { |
||
142 | |||
143 | HARD_TASK_MODEL man_m; |
||
144 | PID man_pid; |
||
145 | |||
146 | /* ------------ */ |
||
147 | /* Task Calls */ |
||
148 | /* ------------ */ |
||
149 | |||
150 | hard_task_default_model(man_m); |
||
151 | |||
152 | hard_task_def_arg(man_m,NULL); |
||
153 | hard_task_def_wcet(man_m, MAN_WCET); |
||
154 | hard_task_def_mit(man_m, MAN_PERIOD); |
||
155 | hard_task_def_usemath(man_m); |
||
156 | man_pid = task_create("man", man,&man_m, NULL); |
||
157 | if(man_pid == -1) |
||
158 | sys_end(); |
||
159 | |||
160 | task_activate(man_pid); |
||
161 | |||
162 | } |
||
163 | |||
164 | char *itoa(int n) |
||
165 | { |
||
166 | sprintf(retbuf,"%d",n); |
||
167 | return retbuf; |
||
168 | } |
||
169 | |||
170 | |||
171 | void display() |
||
172 | { |
||
173 | |||
174 | sem_wait(&grx_mutex); |
||
175 | grx_text("No of people successfully crossed the highway",100,8,red,white); |
||
176 | grx_text("No of people met with the accident",500,8,red,white); |
||
177 | // chCTR[22] = itoa(counter); |
||
178 | grx_text(itoa(counter),210,20,red,white); |
||
179 | grx_text(itoa(casualty),520,20,red,white); |
||
180 | sem_post(&grx_mutex); |
||
181 | |||
182 | } |