Blame |
Last modification |
View Log
| RSS feed
#include "include/auto.h"
#include <string.h>
#include <stdlib.h>
char retbuf
[22];
char chCTR
[22];
int man_rad
= RAD
;
int man_x
;
int man_y
;
int man_col
= rgb16
( 12,175, 16);
int black
= rgb16
( 0, 0, 0);
int white
= rgb16
(255,255,255);
int mycolour
= rgb16
(7, 0,250);
int col
;
int car_colour1
;
int crossed
= 0;
int accident
= 0;
int counter
= 0;
int casualty
= 0;
extern int red
;
extern int car_colour
;
extern int track_colour
;
extern sem_t grx_mutex
;
extern int track_direction
;
void moveup
();
void movedown
();
int check_accident
();
void display
();
int rand_color
()
{
return (rand()%16);
}
void actAccident
(){
if (check_accident
())
{
grx_disc
(man_x
,man_y
,man_rad
,mycolour
);
grx_disc
(450,45,20,red
);
task_delay
(20000);
casualty
++;
accident
= 0;
man_y
= HIGHWAY_Y_MAX
+man_rad
+40;
man_x
= 400;
grx_disc
(man_x
,man_y
,man_rad
,man_col
);
}
}
void movedown
()
{
if(man_y
< 485)
{
actAccident
();
sem_wait
(&grx_mutex
);
grx_disc
(man_x
,man_y
,man_rad
,track_colour
);
if (man_y
>=408) grx_disc
(man_x
,man_y
,man_rad
,black
);
if (man_y
<=92) grx_disc
(man_x
,man_y
,man_rad
,black
);
man_y
= man_y
+Y_INCREMENT
;
grx_disc
(man_x
,man_y
,man_rad
,man_col
);
sem_post
(&grx_mutex
);
if (man_y
< HIGHWAY_Y_MIN
)
crossed
= 1;
}
}
void moveup
()
{
if(man_y
>50)
{
actAccident
();
sem_wait
(&grx_mutex
);
grx_disc
(man_x
,man_y
,man_rad
,track_colour
);
if(man_y
>=408) grx_disc
(man_x
,man_y
,man_rad
,black
);
if(man_y
<=92) grx_disc
(man_x
,man_y
,man_rad
,black
);
if(man_y
<=394) grx_box
(392,400,408,416,black
);
man_y
= man_y
-Y_INCREMENT
;
grx_disc
(man_x
,man_y
,man_rad
,man_col
);
sem_post
(&grx_mutex
);
if (man_y
< HIGHWAY_Y_MIN
)
crossed
= 1;
}
}
int check_accident
()
{
// grx_disc(37,55,10,car_colour);
// car_colour= grx_getpixel(37,55);
col
= grx_getpixel
(man_x
,man_y
-man_rad
);
if((col
== car_colour
))
accident
= 1;
// car_colour1= grx_getpixel(37,55);
col
= grx_getpixel
(man_x
,man_y
+man_rad
);
if((col
== car_colour
))
accident
= 1;
return(accident
);
}
TASK man
(void *arg
)
{
man_x
= 400;
man_y
= HIGHWAY_Y_MAX
+man_rad
+40;
grx_disc
(man_x
,man_y
,man_rad
,man_col
);
// sem_post(&grx_mutex);
while (1)
{
display
();
actAccident
();
if (crossed
)
{
grx_disc
(man_x
,man_y
,man_rad
,track_colour
);
grx_box
(man_x
-man_rad
,man_y
-man_rad
,man_x
+man_rad
,man_y
,black
);
man_y
= HIGHWAY_Y_MAX
+man_rad
+40;
man_x
= 400; //SCREEN_WIDTH/2;
counter
++;
crossed
=0;
task_delay
(5000);
grx_disc
(man_x
,man_y
,man_rad
,man_col
);
}
task_endcycle
();
}
}
void create_man
()
{
HARD_TASK_MODEL man_m
;
PID man_pid
;
/* ------------ */
/* Task Calls */
/* ------------ */
hard_task_default_model
(man_m
);
hard_task_def_arg
(man_m
,NULL
);
hard_task_def_wcet
(man_m
, MAN_WCET
);
hard_task_def_mit
(man_m
, MAN_PERIOD
);
hard_task_def_usemath
(man_m
);
man_pid
= task_create
("man", man
,&man_m
, NULL
);
if(man_pid
== -1)
sys_end
();
task_activate
(man_pid
);
}
char *itoa(int n
)
{
sprintf(retbuf
,"%d",n
);
return retbuf
;
}
void display
()
{
sem_wait
(&grx_mutex
);
grx_text
("No of people successfully crossed the highway",100,8,red
,white
);
grx_text
("No of people met with the accident",500,8,red
,white
);
// chCTR[22] = itoa(counter);
grx_text
(itoa(counter
),210,20,red
,white
);
grx_text
(itoa(casualty
),520,20,red
,white
);
sem_post
(&grx_mutex
);
}