Subversion Repositories programming

Rev

Rev 338 | Rev 340 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 338 Rev 339
Line 6... Line 6...
6
 * Copyright 2006, Ira W. Snyder (devel@irasnyder.com)
6
 * Copyright 2006, Ira W. Snyder (devel@irasnyder.com)
7
 ******************************************************************************/
7
 ******************************************************************************/
8
 
8
 
9
#include "elevator.h"
9
#include "elevator.h"
10
 
10
 
11
// FIXME
-
 
12
// FIXME
-
 
13
// FIXME
-
 
14
void debug_puts (const char* s)
-
 
15
{
-
 
16
#ifndef QUIET
-
 
17
    puts (s);
-
 
18
#endif
-
 
19
}
-
 
20
// FIXME
-
 
21
// FIXME
-
 
22
// FIXME
-
 
23
 
-
 
24
Elevator::Elevator (int num_floors) : num_floors(num_floors)
11
Elevator::Elevator (int num_floors) : num_floors(num_floors)
25
{
12
{
26
    int i;
13
    int i;
27
 
14
 
28
    this->terminate = false;
15
    this->terminate = false;
Line 164... Line 151...
164
            }
151
            }
165
 
152
 
166
            /* Decide to sit idle if we have no more floors to stop at */
153
            /* Decide to sit idle if we have no more floors to stop at */
167
            if (!has_floors_to_stop_at ())
154
            if (!has_floors_to_stop_at ())
168
            {
155
            {
-
 
156
#ifndef QUIET
169
                debug_puts ("decides to sit idle");
157
                puts ("decides to sit idle");
-
 
158
#endif
170
                direction = IDLE;
159
                direction = IDLE;
171
            }
160
            }
172
            /* Decide to switch directions if we have no more floors to stop
161
            /* Decide to switch directions if we have no more floors to stop
173
             * at in the current direction, but we have floors in the
162
             * at in the current direction, but we have floors in the
174
             * opposite direction to stop at. */
163
             * opposite direction to stop at. */
175
            else if (floors_below_current () && !floors_above_current ())
164
            else if (floors_below_current () && !floors_above_current ())
176
            {
165
            {
-
 
166
#ifndef QUIET
177
                debug_puts ("decides to switch direction to down");
167
                puts ("decides to switch direction to down");
-
 
168
#endif
178
                direction = MOVE_DOWN;
169
                direction = MOVE_DOWN;
179
            }
170
            }
180
            /* Since nothing else applies, we should keep moving in the
171
            /* Since nothing else applies, we should keep moving in the
181
             * current direction, up. */
172
             * current direction, up. */
182
            else
173
            else
183
            {
174
            {
184
                current_floor += ELEVATOR_TIME_MOVE_AMOUNT;
175
                current_floor += ELEVATOR_TIME_MOVE_AMOUNT;
185
                //debug_puts ("moving up");
-
 
186
 
176
 
187
                // TODO: Add a check here to make sure we don't go too high
177
                // Check to make sure we don't go too high
-
 
178
                assert (current_floor < (num_floors * 1.0));
188
 
179
 
189
            }
180
            }
190
 
181
 
191
            break;
182
            break;
192
 
183
 
Line 203... Line 194...
203
            }
194
            }
204
 
195
 
205
            /* Decide to sit idle if we have no more floors to stop at */
196
            /* Decide to sit idle if we have no more floors to stop at */
206
            if (!has_floors_to_stop_at ())
197
            if (!has_floors_to_stop_at ())
207
            {
198
            {
-
 
199
#ifndef QUIET
208
                debug_puts ("decides to sit idle");
200
                puts ("decides to sit idle");
-
 
201
#endif
209
                direction = IDLE;
202
                direction = IDLE;
210
            }
203
            }
211
            /* Decide to switch directions if we have no more floors to stop
204
            /* Decide to switch directions if we have no more floors to stop
212
             * at in the current direction, but we have floors in the
205
             * at in the current direction, but we have floors in the
213
             * opposite direction to stop at. */
206
             * opposite direction to stop at. */
214
            else if (floors_above_current () && !floors_below_current ())
207
            else if (floors_above_current () && !floors_below_current ())
215
            {
208
            {
-
 
209
#ifndef QUIET
216
                debug_puts ("decides to switch direction to up");
210
                puts ("decides to switch direction to up");
-
 
211
#endif
217
                direction = MOVE_UP;
212
                direction = MOVE_UP;
218
            }
213
            }
219
            /* Since nothing else applies, we should keep moving in the
214
            /* Since nothing else applies, we should keep moving in the
220
             * current direction, down. */
215
             * current direction, down. */
221
            else
216
            else
222
            {
217
            {
223
                current_floor -= ELEVATOR_TIME_MOVE_AMOUNT;
218
                current_floor -= ELEVATOR_TIME_MOVE_AMOUNT;
224
                //debug_puts ("moving down");
-
 
225
 
219
 
226
                // TODO: Add a check here to make sure we don't go too low
220
                // Check to make sure we don't go too low
-
 
221
                assert (current_floor > -0.1);
227
 
222
 
228
            }
223
            }
229
 
224
 
230
            break;
225
            break;
231
 
226
 
232
        default:
227
        default:
233
 
228
            
234
            debug_puts ("bad value of direction");
229
            assert (false); // bad value of direction
235
            break;
230
            break;
236
    }
231
    }
237
}
232
}
238
 
233
 
239
/**
234
/**
Line 351... Line 346...
351
    }
346
    }
352
 
347
 
353
    controller->unpause_all_elevators ();
348
    controller->unpause_all_elevators ();
354
}
349
}
355
 
350
 
356
 
-