X-Git-Url: https://irasnyder.com/gitweb/?a=blobdiff_plain;f=elevator.hpp;h=a5b550060d9c193e7bd9270674e899292cfc7006;hb=2172ce055533d5865d58538ee00bf609e59b0f99;hp=6f8b5a31b42a86d6aa07f6130af4d2292190b247;hpb=28c9908e524bd7bd51e4141e21046e2a60b83bd0;p=cs356-p1-elevator.git diff --git a/elevator.hpp b/elevator.hpp index 6f8b5a3..a5b5500 100644 --- a/elevator.hpp +++ b/elevator.hpp @@ -13,36 +13,53 @@ #include "position.hpp" #include "stop.hpp" -typedef enum { CLOSED, OPEN } DoorStatus; 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 starting_floor); + 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; 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; };