projects
/
cs356-p1-elevator.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
GUI-ize the Floor and Elevator entry
[cs356-p1-elevator.git]
/
elevator.cpp
diff --git
a/elevator.cpp
b/elevator.cpp
index
4a5eb37
..
cbf9775
100644
(file)
--- a/
elevator.cpp
+++ b/
elevator.cpp
@@
-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_, direction_);
std::cout << "Updating the GUI with our position: " << position_ << std::endl;
}
std::cout << "Updating the GUI with our position: " << position_ << std::endl;
}
@@
-126,12
+136,15
@@
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_, direction_);
std::cout << "Updating the GUI with our position: " << position_ << std::endl;
}
void Elevator::transition_move_idle ()
{
direction_ = IDLE;
std::cout << "Updating the GUI with our position: " << position_ << std::endl;
}
void Elevator::transition_move_idle ()
{
direction_ = IDLE;
+ // TODO: Call into the GUI to update the position
+ gui_update_position_label (number_, (float)position_, direction_);
// do not change position while IDLE
}
// do not change position while IDLE
}
@@
-158,19
+171,42
@@
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_);
+ gui_unpress_request_button (number_, (int)position_);
+ }
// 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;
}
@@
-483,6
+519,9
@@
void Elevator::move ()
bool Elevator::is_idle () const
{
bool Elevator::is_idle () const
{
+ if (stops_.size() != 0)
+ return false;
+
return direction_ == IDLE;
}
return direction_ == IDLE;
}