Subversion Repositories programming

Rev

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

Rev 340 Rev 344
Line 20... Line 20...
20
 
20
 
21
    this->stop_at_floors.reserve (num_floors);
21
    this->stop_at_floors.reserve (num_floors);
22
 
22
 
23
    for (i=0; i<num_floors; i++)
23
    for (i=0; i<num_floors; i++)
24
        this->stop_at_floors.push_back(bool(false));
24
        this->stop_at_floors.push_back(bool(false));
25
 
-
 
26
    printf ("created elevator 0x%x-- numfloors=%d\n", this, this->num_floors);
-
 
27
}
25
}
28
 
26
 
29
Elevator::~Elevator ()
27
Elevator::~Elevator ()
30
{
28
{
31
    this->pause = false;
29
    this->pause = false;
Line 103... Line 101...
103
        }
101
        }
104
 
102
 
105
        pthis->run_elevator_logic ();
103
        pthis->run_elevator_logic ();
106
 
104
 
107
#ifndef QUIET
105
#ifndef QUIET
108
        std::cout << pthis << " Position: " << pthis->current_floor << std::endl;
106
        //std::cout << pthis << " Position: " << pthis->current_floor << std::endl;
109
#endif
107
#endif
110
        usleep (ELEVATOR_TIME_DELAY_USEC);
108
        usleep (ELEVATOR_TIME_DELAY_USEC);
111
    }
109
    }
112
}
110
}
113
 
111
 
Line 220... Line 218...
220
            
218
            
221
            assert (false); // bad value of direction
219
            assert (false); // bad value of direction
222
            break;
220
            break;
223
    }
221
    }
224
 
222
 
-
 
223
    Dispatch_Data data;
-
 
224
    data.type = DISPATCH_DATA_UPDATE_LABEL;
-
 
225
    data.elev = this;
-
 
226
    data.farg = current_floor;
-
 
227
 
225
    controller->update_elevator_position (this);
228
    controller->push_to_gui_queue (data);
-
 
229
 
-
 
230
    (*dispatcher)();
226
}
231
}
227
 
232
 
228
/**
233
/**
229
 * Call this to stop the thread from running.
234
 * Call this to stop the thread from running.
230
 */
235
 */
Line 313... Line 318...
313
void Elevator::set_controller (Controller *c)
318
void Elevator::set_controller (Controller *c)
314
{
319
{
315
    this->controller = c;
320
    this->controller = c;
316
}
321
}
317
 
322
 
318
void Elevator::have_user_enter_buttons ()
-
 
319
{
-
 
320
    controller->pause_all_elevators ();
-
 
321
    usleep (10000);
-
 
322
 
-
 
323
    std::string s;
-
 
324
 
-
 
325
    std::cout << "Enter floors to stop at for elevator (space seperated): ";
-
 
326
    getline (std::cin, s);
-
 
327
 
-
 
328
    typedef std::vector<std::string> split_vector_type;
-
 
329
    split_vector_type SplitVec;
-
 
330
    boost::split (SplitVec, s, boost::is_any_of(" "));
-
 
331
 
-
 
332
    int i, val;
-
 
333
    for (i=0; i<SplitVec.size(); i++)
-
 
334
    {
-
 
335
        val = atoi (SplitVec[i].c_str());
-
 
336
 
-
 
337
        // Ignore values that are outside of range
-
 
338
        if (val >= 0 && val < num_floors)
-
 
339
            this->push_button (val);
-
 
340
    }
-
 
341
 
-
 
342
    controller->unpause_all_elevators ();
-
 
343
}
-
 
344
 
-
 
345
void Elevator::stop_at_floor (int in_direction)
323
void Elevator::stop_at_floor (int in_direction)
346
{
324
{
347
    int the_floor = (int)(current_floor+0.5);
325
    int the_floor = (int)(current_floor+0.5);
348
 
326
 
349
#ifndef QUIET
327
#ifndef QUIET
Line 351... Line 329...
351
        printf ("stop at floor %d -- while going up\n", the_floor);
329
        printf ("stop at floor %d -- while going up\n", the_floor);
352
    else
330
    else
353
        printf ("stop at floor %d -- while going down\n", the_floor);
331
        printf ("stop at floor %d -- while going down\n", the_floor);
354
#endif
332
#endif
355
    stop_at_floors.at(the_floor) = false;
333
    stop_at_floors.at(the_floor) = false;
356
    //have_user_enter_buttons ();
-
 
357
 
334
 
-
 
335
    Dispatch_Data data;
-
 
336
    data.type = DISPATCH_DATA_STOP_AT_FLOOR;
-
 
337
    data.elev = this;
-
 
338
    data.iarg = the_floor;
-
 
339
 
358
    controller->stop_at_floor (this, the_floor);
340
    controller->push_to_gui_queue (data);
-
 
341
 
-
 
342
    (*dispatcher)();
-
 
343
}
-
 
344
 
-
 
345
void Elevator::set_dispatcher (Glib::Dispatcher *d)
-
 
346
{
-
 
347
    this->dispatcher = d;
359
}
348
}
360
 
349