Subversion Repositories programming

Rev

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

Rev 330 Rev 331
Line 4... Line 4...
4
// FIXME
4
// FIXME
5
// FIXME
5
// FIXME
6
// FIXME
6
// FIXME
7
void debug_puts (const char* s)
7
void debug_puts (const char* s)
8
{
8
{
9
#ifndef _NDEBUG
9
#ifndef NO_DEBUG_PUTS
10
    puts (s);
10
    puts (s);
11
#endif
11
#endif
12
}
12
}
13
// FIXME
13
// FIXME
14
// FIXME
14
// FIXME
Line 18... Line 18...
18
{
18
{
19
    this->terminate = false;
19
    this->terminate = false;
20
    this->pause = false;
20
    this->pause = false;
21
    this->direction = IDLE;
21
    this->direction = IDLE;
22
    this->current_floor = 1.0;
22
    this->current_floor = 1.0;
-
 
23
    this->controller = NULL;
23
 
24
 
24
    this->stop_at_floors = std::vector<bool> (num_floors+1, false);
25
    this->stop_at_floors = std::vector<bool> (num_floors+1, false);
25
}
26
}
26
 
27
 
27
Elevator::~Elevator ()
28
Elevator::~Elevator ()
Line 131... Line 132...
131
        case MOVE_UP:
132
        case MOVE_UP:
132
 
133
 
133
            /* Decide if we should stop at the floor we're at */
134
            /* Decide if we should stop at the floor we're at */
134
            if (should_stop_at_current_floor ())
135
            if (should_stop_at_current_floor ())
135
            {
136
            {
136
                debug_puts ("stop at a floor -- while going up");
137
                debug_puts ("stop at floor -- while going up");
137
                stop_at_floors[(int)(current_floor+0.5)] = false;
138
                stop_at_floors[(int)(current_floor+0.5)] = false;
-
 
139
                have_user_enter_buttons ();
138
            }
140
            }
139
 
141
 
140
            /* Decide to sit idle if we have no more floors to stop at */
142
            /* Decide to sit idle if we have no more floors to stop at */
141
            if (!has_floors_to_stop_at ())
143
            if (!has_floors_to_stop_at ())
142
            {
144
            {
Line 169... Line 171...
169
            /* Decide if we should stop at the floor we're at */
171
            /* Decide if we should stop at the floor we're at */
170
            if (should_stop_at_current_floor ())
172
            if (should_stop_at_current_floor ())
171
            {
173
            {
172
                debug_puts ("stop at floor -- while going down");
174
                debug_puts ("stop at floor -- while going down");
173
                stop_at_floors[(int)(current_floor)] = false;
175
                stop_at_floors[(int)(current_floor)] = false;
-
 
176
                have_user_enter_buttons ();
174
            }
177
            }
175
 
178
 
176
            /* Decide to sit idle if we have no more floors to stop at */
179
            /* Decide to sit idle if we have no more floors to stop at */
177
            if (!has_floors_to_stop_at ())
180
            if (!has_floors_to_stop_at ())
178
            {
181
            {
Line 208... Line 211...
208
}
211
}
209
 
212
 
210
/**
213
/**
211
 * Call this to stop the thread from running.
214
 * Call this to stop the thread from running.
212
 */
215
 */
213
void Elevator::thread_exit ()
216
void Elevator::thread_stop ()
214
{
217
{
215
    this->terminate = true;
218
    this->terminate = true;
216
}
219
}
217
 
220
 
218
/**
221
/**
Line 287... Line 290...
287
float Elevator::get_current_floor ()
290
float Elevator::get_current_floor ()
288
{
291
{
289
    return current_floor;
292
    return current_floor;
290
}
293
}
291
 
294
 
-
 
295
void Elevator::set_controller (Controller *c)
-
 
296
{
-
 
297
    this->controller = c;
-
 
298
}
-
 
299
 
-
 
300
void Elevator::have_user_enter_buttons ()
-
 
301
{
-
 
302
    controller->pause_all_elevators ();
-
 
303
    sleep (1);
-
 
304
 
-
 
305
    std::string s;
-
 
306
 
-
 
307
    std::cout << "Enter floors to stop at for elevator (space seperated): ";
-
 
308
    getline (std::cin, s);
-
 
309
    
-
 
310
    typedef std::vector<std::string> split_vector_type;
-
 
311
    split_vector_type SplitVec;
-
 
312
    boost::split (SplitVec, s, boost::is_any_of(" "));
-
 
313
 
-
 
314
    std::cout << "found " << SplitVec.size() << " strings" << std::endl;
-
 
315
 
-
 
316
    int i, val;
-
 
317
    for (i=0; i<SplitVec.size(); i++)
-
 
318
    {
-
 
319
        val = atoi (SplitVec[i].c_str());
-
 
320
 
-
 
321
        if (val > 0 && val <= num_floors)
-
 
322
            this->push_button (val);
-
 
323
    }
-
 
324
 
-
 
325
    controller->unpause_all_elevators ();
-
 
326
}
-
 
327