Use the GUI
authorIra W. Snyder <devel@irasnyder.com>
Sun, 7 Oct 2007 06:18:02 +0000 (23:18 -0700)
committerIra W. Snyder <devel@irasnyder.com>
Sun, 7 Oct 2007 06:18:02 +0000 (23:18 -0700)
Signed-off-by: Ira W. Snyder <devel@irasnyder.com>
elevator.cpp
main.cpp
main.hpp
position.cpp
position.hpp

index 4a5eb37..b8cdb50 100644 (file)
@@ -1,4 +1,5 @@
 #include "elevator.hpp"
 #include "elevator.hpp"
+#include "main.hpp"
 
 Elevator::Elevator (int elevator_number)
        : state_(STATE_IDLE)
 
 Elevator::Elevator (int elevator_number)
        : state_(STATE_IDLE)
@@ -61,6 +62,14 @@ bool Elevator::currently_at_stop () const
                if (*it == current)
                        return true;
 
                if (*it == current)
                        return true;
 
+       /* Check if we are IDLE. If so, only the position needs to match */
+       if (direction_ == IDLE)
+       {
+               for (it = stops_.begin (); it != stops_.end (); it++)
+                       if (it->getPosition() == position_)
+                               return true;
+       }
+
        /* No match */
        return false;
 }
        /* No match */
        return false;
 }
@@ -117,6 +126,7 @@ void Elevator::transition_move_up ()
        position_ += ELEVATOR_STEP;
 
        // TODO: Call into the GUI to update the position
        position_ += ELEVATOR_STEP;
 
        // TODO: Call into the GUI to update the position
+       gui_update_position_label (number_, (float)position_);
        std::cout << "Updating the GUI with our position: " << position_ << std::endl;
 }
 
        std::cout << "Updating the GUI with our position: " << position_ << std::endl;
 }
 
@@ -126,6 +136,7 @@ void Elevator::transition_move_down ()
        position_ -= ELEVATOR_STEP;
 
        // TODO: Call into the GUI to update the position
        position_ -= ELEVATOR_STEP;
 
        // TODO: Call into the GUI to update the position
+       gui_update_position_label (number_, (float)position_);
        std::cout << "Updating the GUI with our position: " << position_ << std::endl;
 }
 
        std::cout << "Updating the GUI with our position: " << position_ << std::endl;
 }
 
@@ -158,19 +169,41 @@ void Elevator::transition_open_door ()
         *
         * Otherwise, just clear this stop */
        if      (direction_ == UP && stops_above == 0)
         *
         * Otherwise, just clear this stop */
        if      (direction_ == UP && stops_above == 0)
+       {
                stops_.remove (Stop(position_, ALL));
                stops_.remove (Stop(position_, ALL));
+               gui_unpress_request_button (number_, (int)position_);
+               gui_unpress_call_button ((int)position_, UP);
+               gui_unpress_call_button ((int)position_, DOWN);
+       }
        else if (direction_ == DOWN && stops_below == 0)
        else if (direction_ == DOWN && stops_below == 0)
+       {
+               stops_.remove (Stop(position_, ALL));
+               gui_unpress_request_button (number_, (int)position_);
+               gui_unpress_call_button ((int)position_, UP);
+               gui_unpress_call_button ((int)position_, DOWN);
+       }
+       else if (direction_ == IDLE)
+       {
                stops_.remove (Stop(position_, ALL));
                stops_.remove (Stop(position_, ALL));
+               gui_unpress_request_button (number_, (int)position_);
+               gui_unpress_call_button ((int)position_, UP);
+               gui_unpress_call_button ((int)position_, DOWN);
+       }
        else
        else
+       {
                stops_.remove (Stop(position_, direction_));
                stops_.remove (Stop(position_, direction_));
+               gui_unpress_call_button ((int)position_, direction_);
+       }
 
        // TODO: Call into the GUI to open the door
 
        // TODO: Call into the GUI to open the door
+       gui_open_door (number_, (int)position_);
        std::cout << "Opening Door" << std::endl;
 }
 
 void Elevator::transition_close_door ()
 {
        // TODO: Call into the GUI to close the door
        std::cout << "Opening Door" << std::endl;
 }
 
 void Elevator::transition_close_door ()
 {
        // TODO: Call into the GUI to close the door
+       gui_close_door (number_, (int)position_);
        std::cout << "Closing Door" << std::endl;
 }
 
        std::cout << "Closing Door" << std::endl;
 }
 
index 9b2d2e0..f49b107 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -1,6 +1,7 @@
 #include "main.hpp"
 #include "main.hpp"
+#include "elevatorgui.hpp"
 
 
-ElevatorGUI *thegui = NULL;
+static ElevatorGUI *thegui = NULL;
 
 int main (int argc, char *argv[])
 {
 
 int main (int argc, char *argv[])
 {
@@ -62,4 +63,30 @@ int main (int argc, char *argv[])
        return 0;
 }
 
        return 0;
 }
 
+
+void gui_update_position_label (int elevator, float new_position)
+{
+       thegui->gui_update_position_label (elevator, new_position);
+}
+
+void gui_unpress_call_button (int floor, Direction direction)
+{
+       thegui->gui_unpress_call_button (floor, direction);
+}
+
+void gui_unpress_request_button (int elevator, int floor)
+{
+       thegui->gui_unpress_request_button (elevator, floor);
+}
+
+void gui_open_door (int elevator, int floor)
+{
+       thegui->gui_open_door (elevator, floor);
+}
+
+void gui_close_door (int elevator, int floor)
+{
+       thegui->gui_close_door (elevator, floor);
+}
+
 /* vim: set ts=4 sts=4 sw=4 noet tw=112: */
 /* vim: set ts=4 sts=4 sw=4 noet tw=112: */
index 570ca17..124c63e 100644 (file)
--- a/main.hpp
+++ b/main.hpp
@@ -1,11 +1,17 @@
 #ifndef MAIN_HPP
 #define MAIN_HPP
 
 #ifndef MAIN_HPP
 #define MAIN_HPP
 
-#include "elevatorgui.hpp"
+#include "direction.hpp"
+
 #include <iostream>
 #include <gtkmm/main.h>
 
 #include <iostream>
 #include <gtkmm/main.h>
 
-extern ElevatorGUI *thegui;
+void gui_update_position_label (int elevator, float new_position);
+void gui_unpress_call_button (int floor, Direction direction);
+void gui_unpress_request_button (int elevator, int floor);
+void gui_open_door (int elevator, int floor);
+void gui_close_door (int elevator, int floor);
+
 
 #endif /* MAIN_HPP */
 
 
 #endif /* MAIN_HPP */
 
index e0da0f4..1d4a293 100644 (file)
@@ -114,6 +114,11 @@ Position::operator float() const
        return temp;
 }
 
        return temp;
 }
 
+Position::operator int() const
+{
+       return major_;
+}
+
 std::ostream& operator<< (std::ostream& os, const Position& rhs)
 {
        os << "Position(" << rhs.major_ << "." << rhs.minor_ << ")";
 std::ostream& operator<< (std::ostream& os, const Position& rhs)
 {
        os << "Position(" << rhs.major_ << "." << rhs.minor_ << ")";
index 0585b69..029966d 100644 (file)
@@ -26,6 +26,7 @@ class Position
                bool operator> (const Position& rhs) const;
                Position operator- (const Position& rhs) const;
                operator float() const;
                bool operator> (const Position& rhs) const;
                Position operator- (const Position& rhs) const;
                operator float() const;
+               operator int() const;
 
 
        private:
 
 
        private: