Subversion Repositories programming

Rev

Rev 348 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 348 Rev 350
Line 100... Line 100...
100
            usleep (ELEVATOR_TIME_PAUSE_USEC);
100
            usleep (ELEVATOR_TIME_PAUSE_USEC);
101
        }
101
        }
102
 
102
 
103
        pthis->run_elevator_logic ();
103
        pthis->run_elevator_logic ();
104
 
104
 
105
#ifndef QUIET
-
 
106
        //std::cout << pthis << " Position: " << pthis->current_floor << std::endl;
-
 
107
#endif
-
 
108
        usleep (ELEVATOR_TIME_DELAY_USEC);
105
        usleep (ELEVATOR_TIME_DELAY_USEC);
109
    }
106
    }
110
}
107
}
111
 
108
 
112
void Elevator::thread_start ()
109
void Elevator::thread_start ()
Line 125... Line 122...
125
 
122
 
126
            /* Move towards the direction that has more floors to stop at.
123
            /* Move towards the direction that has more floors to stop at.
127
             * Prefer DOWN if there is a tie. */
124
             * Prefer DOWN if there is a tie. */
128
            if (has_floors_to_stop_at ())
125
            if (has_floors_to_stop_at ())
129
            {
126
            {
130
                direction = (floors_above_current () > floors_below_current ()) ? MOVE_UP : MOVE_DOWN;
127
                if (floors_above_current () > floors_below_current ())
131
 
-
 
-
 
128
                    direction = MOVE_UP;
-
 
129
                else
-
 
130
                    direction = MOVE_DOWN;
132
#ifndef QUIET
131
#ifndef QUIET
-
 
132
                if (direction == MOVE_UP)
-
 
133
                    std::cout << "changed direction to up" << std::endl;
-
 
134
                else
133
                printf ("changed direction to: %s\n", (direction == MOVE_UP) ? "MOVE_UP" : "MOVE_DOWN");
135
                    std::cout << "changed direction to down" << std::endl;
134
#endif
136
#endif
135
            }
137
            }
136
 
138
 
137
            break;
139
            break;
138
 
140
 
139
        case MOVE_UP:
141
        case MOVE_UP:
140
 
142
 
141
            /* Decide if we should stop at the floor we're at */
143
            /* Decide if we should stop at the floor we're at */
142
            if (should_stop_at_current_floor ())
144
            if (should_stop_at_current_floor ())
143
            {
-
 
144
                stop_at_floor (MOVE_UP);
145
                stop_at_floor (MOVE_UP);
145
            }
-
 
146
 
146
 
147
            /* Decide to sit idle if we have no more floors to stop at */
147
            /* Decide to sit idle if we have no more floors to stop at */
148
            if (!has_floors_to_stop_at ())
148
            if (!has_floors_to_stop_at ())
149
            {
149
            {
150
#ifndef QUIET
150
#ifndef QUIET
Line 177... Line 177...
177
 
177
 
178
        case MOVE_DOWN:
178
        case MOVE_DOWN:
179
 
179
 
180
            /* Decide if we should stop at the floor we're at */
180
            /* Decide if we should stop at the floor we're at */
181
            if (should_stop_at_current_floor ())
181
            if (should_stop_at_current_floor ())
182
            {
-
 
183
                stop_at_floor (MOVE_DOWN);
182
                stop_at_floor (MOVE_DOWN);
184
            }
-
 
185
 
183
 
186
            /* Decide to sit idle if we have no more floors to stop at */
184
            /* Decide to sit idle if we have no more floors to stop at */
187
            if (!has_floors_to_stop_at ())
185
            if (!has_floors_to_stop_at ())
188
            {
186
            {
189
#ifndef QUIET
187
#ifndef QUIET