Signed-off-by: Ira W. Snyder <devel@irasnyder.com>
+ if (stop.getDirection() == IDLE)
+ throw bad_direction();
+#if 0
/* If this is an "ALL" Stop, it supercedes all others */
if (stop.getDirection() == ALL)
{
/* If this is an "ALL" Stop, it supercedes all others */
if (stop.getDirection() == ALL)
{
stops_.push_back (stop);
return;
}
stops_.push_back (stop);
return;
}
/* Check if this stop already exists. If so, just leave */
for (it = stops_.begin(); it != stops_.end(); it++)
/* Check if this stop already exists. If so, just leave */
for (it = stops_.begin(); it != stops_.end(); it++)
+ std::cout << "Elevator: " << number_ << " stopping in direction=" << direction_ << std::endl;
+
+ /* Always unpress the in-elevator button for this stop, as well
+ * as clear the stop. This is like letting people off at a floor. */
+ gui_unpress_request_button (number_, (int)position_);
+ stops_.remove (Stop(position_, ALL));
+
+
/* If we are going to switch direction, clear all stops here,
* regardless of direction.
*
* Otherwise, just clear this stop */
if (direction_ == UP && stops_above == 0)
{
/* If we are going to switch direction, clear all stops here,
* regardless of direction.
*
* Otherwise, just clear this stop */
if (direction_ == UP && stops_above == 0)
{
- stops_.remove (Stop(position_, ALL));
- gui_unpress_request_button (number_, (int)position_);
+ stops_.remove (Stop(position_, UP));
+ stops_.remove (Stop(position_, DOWN));
gui_unpress_call_button ((int)position_, UP);
gui_unpress_call_button ((int)position_, DOWN);
}
else if (direction_ == DOWN && stops_below == 0)
{
gui_unpress_call_button ((int)position_, UP);
gui_unpress_call_button ((int)position_, DOWN);
}
else if (direction_ == DOWN && stops_below == 0)
{
- stops_.remove (Stop(position_, ALL));
- gui_unpress_request_button (number_, (int)position_);
+ stops_.remove (Stop(position_, UP));
+ stops_.remove (Stop(position_, DOWN));
gui_unpress_call_button ((int)position_, UP);
gui_unpress_call_button ((int)position_, DOWN);
}
else if (direction_ == IDLE)
{
gui_unpress_call_button ((int)position_, UP);
gui_unpress_call_button ((int)position_, DOWN);
}
else if (direction_ == IDLE)
{
- stops_.remove (Stop(position_, ALL));
- gui_unpress_request_button (number_, (int)position_);
+ stops_.remove (Stop(position_, UP));
+ stops_.remove (Stop(position_, DOWN));
gui_unpress_call_button ((int)position_, UP);
gui_unpress_call_button ((int)position_, DOWN);
}
gui_unpress_call_button ((int)position_, UP);
gui_unpress_call_button ((int)position_, DOWN);
}
{
stops_.remove (Stop(position_, direction_));
gui_unpress_call_button ((int)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
+bool Elevator::willStopAt (int floor, Direction direction) const
+{
+ Stop s (floor, direction);
+ StopList::const_iterator it;
+
+ for (it=stops_.begin(); it != stops_.end(); it++)
+ if (*it == s)
+ return true;
+
+ return false;
+}
+
/* vim: set ts=4 sts=4 sw=4 noexpandtab textwidth=112: */
/* vim: set ts=4 sts=4 sw=4 noexpandtab textwidth=112: */
#include "position.hpp"
#include "stop.hpp"
#include "position.hpp"
#include "stop.hpp"
+class bad_direction { };
+
typedef std::list<Stop> StopList;
enum State { STATE_IDLE, STATE_UP, STATE_DOWN, STATE_WAIT, STATE_OPEN_DOOR, STATE_CLOSE_DOOR };
typedef std::list<Stop> StopList;
enum State { STATE_IDLE, STATE_UP, STATE_DOWN, STATE_WAIT, STATE_OPEN_DOOR, STATE_CLOSE_DOOR };
void move ();
bool is_idle () const;
int getLoad () const;
void move ();
bool is_idle () const;
int getLoad () const;
+ bool willStopAt (int floor, Direction direction) const;
+bool ElevatorController::oneElevatorWillStillStopAt (int floor, Direction direction) const
+{
+ ElevatorList::const_iterator it;
+
+ for (it=elevators_.begin(); it!=elevators_.end(); it++)
+ if (it->willStopAt (floor, direction))
+ return true;
+
+ return false;
+}
+
/* vim: set ts=4 sts=4 sw=4 noet tw=112: */
/* vim: set ts=4 sts=4 sw=4 noet tw=112: */
void elevator_request (int elevator_number, int floor);
void move_elevators ();
void elevator_request (int elevator_number, int floor);
void move_elevators ();
+ /* true if at least one Elevator still stopping here */
+ bool oneElevatorWillStillStopAt (int floor, Direction direction) const;
+
private:
int number_of_floors_;
int number_of_elevators_;
private:
int number_of_floors_;
int number_of_elevators_;
{
CallButtonVector::iterator it;
{
CallButtonVector::iterator it;
+ /* If there is still an elevator coming, don't turn it off! */
+ if (ec_.oneElevatorWillStillStopAt (floor, direction))
+ return;
+
for (it=call_buttons_.begin(); it!=call_buttons_.end(); it++)
if ((*it)->getFloorNumber() == floor && (*it)->getDirection() == direction)
(*it)->set_active (false);
for (it=call_buttons_.begin(); it!=call_buttons_.end(); it++)
if ((*it)->getFloorNumber() == floor && (*it)->getDirection() == direction)
(*it)->set_active (false);
if (rhs.position_ != position_)
return false;
if (rhs.position_ != position_)
return false;
if (direction_ == ALL || rhs.direction_ == ALL)
return true;
if (direction_ == ALL || rhs.direction_ == ALL)
return true;
return (rhs.direction_ == direction_);
}
return (rhs.direction_ == direction_);
}
/* vim: set ts=4 sts=4 sw=4 noexpandtab textwidth=112: */
/* vim: set ts=4 sts=4 sw=4 noexpandtab textwidth=112: */