auto_bus/src/bus.c
2022-05-24 11:43:19 +08:00

41 lines
944 B
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "bus.h"
#include "math.h"
bus_t *the_bus = NULL;
void RunBus(int direction)
{
if(direction == BUS_CLOCK_WISE)//顺时针
{
the_bus->distance++;
if(the_bus->distance == rails->next_node_distance)
{
the_bus->distance=0;//到达一个站点用重新置为0
}
}
else if(direction == BUS_COUNTER_CLOCK_WISE)
{
the_bus->distance--;
if(abs(the_bus->distance) ==rails->last_node_distance)
{
the_bus->distance=0;//到达一个站点又重新置为0
}
}
}
int GetBusPosition()
{
int a,b;
a=the_bus->rail_node_pos->id;//指向站点的指针以及这个指针对应的站台id
b=a*(rails->last_node_distance)+abs(the_bus->distance);
return b;
}
int JudgeOnStation()
{
if(abs(the_bus->distance) == rails->last_node_distance)
{
return BUS_TRUE;
}
else
{
return BUS_FAlSE;
}
}