X-Git-Url: https://irasnyder.com/gitweb/?a=blobdiff_plain;f=elevator.hpp;h=0a7348095416f1c6dfcda0b38d58c4eb9ddafc52;hb=f95be7131a6221491745f0a001f45589aa6acca3;hp=1b5c599ff58f78d997521302e1268fb0ec99f060;hpb=5c28697247e009e93b8b03bec8cdee88339d3226;p=cs356-p1-elevator.git diff --git a/elevator.hpp b/elevator.hpp index 1b5c599..0a73480 100644 --- a/elevator.hpp +++ b/elevator.hpp @@ -13,35 +13,57 @@ #include "position.hpp" #include "stop.hpp" -typedef enum { CLOSED, OPEN } DoorStatus; +class bad_direction { }; + typedef std::list StopList; +enum State { STATE_IDLE, STATE_UP, STATE_DOWN, STATE_WAIT, STATE_OPEN_DOOR, STATE_CLOSE_DOOR }; +enum Event { EVT_IDLE, EVT_UP, EVT_DOWN, EVT_WAIT, EVT_OPEN_DOOR, EVT_CLOSE_DOOR }; + class Elevator { public: - Elevator (); + Elevator (int elevator_number); + Elevator (int starting_floor, int elevator_number); void stop_at (Stop &stop); float distance_from (Position& pos) const; + float distance_from (Stop& s) const; void move (); bool is_idle () const; + int getLoad () const; + bool willStopAt (int floor, Direction direction) const; private: - /* Callbacks into the GUI */ - void open_door () const; - void close_door () const; - void update_position () const; + + /* State Machine: Helper Functions */ + Event find_next_event () const; + + /* State Machine: Transition Functions */ + void transition_move_up (); + void transition_move_down (); + void transition_move_idle (); + void transition_open_door (); + void transition_close_door (); + void transition_begin_wait (); + void transition_continue_wait (); /* Analyze the list of stops */ bool currently_at_stop () const; /* Elevator Status Variables */ - DoorStatus door_; Direction direction_; - Position current_position_; + Position position_; StopList stops_; - const float ELEVATOR_STEP; + /* State Machine */ + State state_; + int wait_; + + /* Elevator Number: Used to make calls into the GUI */ + int number_; + + static const float ELEVATOR_STEP = 0.1; };