예제 #1
0
int main(int argc, char **argv) {
    init();

    move_elevator(1, 4);               /* Floor 1 -> Floor 4. */
    move_elevator(4, 2);               /* Floor 4 -> Floor 2. */
    move_elevator(2, 3);               /* Floor 2 -> Floor 3. */
    move_elevator(3, 1);               /* Floor 3 -> Floor 1. */

    return 0;
}
예제 #2
0
파일: chandan.a.cpp 프로젝트: conghd/Misc
void run_test(void)
{
	int personTargetFloor;
	for(int currentFloor=0;currentFloor<FLOOR;currentFloor++){//Hardcode FLORR->100.
		move_elevator(currentFloor);
		personTargetFloor=get_floor();
		//Proceed only if person belongs to other floor..
		if(personTargetFloor!=currentFloor){
			//Load him to elevator..
			load_elevator();
			//Iterate till no person moved to elevator..
			while(personTargetFloor!=-1){
				move_elevator(personTargetFloor);
				personTargetFloor=get_floor();
				exchange_elevator();
			}
		}

	}
}
예제 #3
0
void run_elevator()
{
	//once started this keeps looping accepting passengers
	int testc = 3;
	while(testc!=0)
	{	
		unloadpassenger();
		consumepassenger();
		sleep(1);
		print_status();
		setdestination();
		move_elevator();
		//for moving
		sleep(2);
		testc--;
	}
}
void move_elevControl(elevControl_t * ctr){
    count_t ec;
        for (ec=0; ec < (ctr->numElev); ec++)
            move_elevator(&(ctr->elevators[ec]));
}//move_elevControl
예제 #5
0
int main (void)
{
	enum states state;
	state = idle; //initial state is in idle

	DDRA  = 0xF0;		// P.A[7:4] OUT P.A[3:0] IN
	PORTA = 0xFF;		// P.A[3:0] Pullup P.A[7:4] set HIGH
	DDRB  = 0xFF;		// P.B for 7seg
	PORTB = 0xFF;		//
	DDRC  = 0xFF;		// Port C for debugging purposes
	PORTC = 0x00;
	timer_init();		// initialize timer
	sei();				// enable global interrupts

	current_floor=1;
	while(1)
	{
		display_7led(current_floor);
		switch (state)
		{

		case idle:
		{
//			display_7led(1);//debug
			up_amount = 0;
			floor_selection_pointer = 0;
			delay_time=0;
//			call_flag=0;
//			sel_flag = 0;
			floor_clear();
			read_keypad(0);
			if(call_flag==1)
			{
				state=move_x;
			}
			if (sel_flag==1)
			{
				if(current_floor!=4)
					dir_flag=1; //move up before going down if not on 4th floor
				else
					dir_flag=0; //move down if on 4th floor
				state=delay_select;
			}
			break;
		}

		case move_x:
		{
//			display_7led(2);//debug

			if(call_flag==1)	// if a call operation, move then go to idle
			{
				move_elevator(call_floor_distance);	// move to called floor
				call_floor_distance = 0;
//				call_flag=0; 			// reset call flag
				state=open;
			}
			else
			{
				move_elevator(call_floor_distance);
				floor_amount_moved++;
				state=open;
				call_floor_distance = 0;
			}
			break;
		}
		case open:
		{
//			display_7led(3);//debug

			move_door(1);		// open the door
			state=delay_close;
			break;
		}
		case delay_close:
		{
//			display_7led(4);//debug

			delay_flag = 1;		//begin counting delay_time
			if(delay_time == 2)	// wait 3 sec before closing door
			{
				state = closing;	// close door;
				delay_flag = 0;		// turn off delay flag
				delay_time = 0;		// reset delay_time
			}
			break;
		}
		case delay_select:	//
		{
//			display_7led(5);//debug
//			move_door(1);//debug
//			sel_flag=0;			// turn off select flag
//			read_keypad(1);
			delay_flag = 1;		// begin counting delay_time
//			if (sel_flag ==1)
//			{
//				delay_time = 0;	// reset delay_time if button is pressed
//				sel_flag=0;
//			}
			if (delay_time >= 2)	// after grace period, move next state
			{
				state=adj_distance;	// begin to adj distances
				delay_flag = 0;
				delay_time =0;
			}

			break;
		}
		case closing:
		{
//			display_7led(6);//debug

			move_door(0); 		// close the door
			if((call_flag==1)||(floor_amount_moved>=floor_amount_selected))
			{
				call_flag=0;
				floor_clear();
				floor_selection_pointer=0;
				state = idle;
			}
			else if (floor_amount_moved<floor_amount_selected)
			{
				up_amount--;
				if (up_amount<=0)
					dir_flag=0;	// start moving down after done going up
				state = adj_distance;
			}
			break;
		}
		case adj_distance:
		{
//			move_door(1);//debug
//			display_7led(7);//debug

			floor_adj();		// adjust the distances in array
			state = move_x;		// move to next floor
			break;
		}
		default:
			;
		} //end of switch

//		_delay_ms(250);
//		display_7led(9);
//		_delay_ms(250);


	} //end of while


}