Subversion Repositories programming

Rev

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

Rev 328 Rev 329
Line 97... Line 97...
97
            usleep (ELEVATOR_TIME_PAUSE_USEC);
97
            usleep (ELEVATOR_TIME_PAUSE_USEC);
98
        }
98
        }
99
 
99
 
100
        pthis->run_elevator_logic ();
100
        pthis->run_elevator_logic ();
101
 
101
 
102
        std::cout << "Current Elevator Position: " << pthis->current_floor << std::endl;
102
        std::cout << pthis << " Position: " << pthis->current_floor << std::endl;
103
        usleep (ELEVATOR_TIME_DELAY_USEC);
103
        usleep (ELEVATOR_TIME_DELAY_USEC);
104
    }
104
    }
105
}
105
}
106
 
106
 
-
 
107
void Elevator::thread_start ()
-
 
108
{
-
 
109
    boost::thread t1 (boost::bind (this->thread_entry, this));
-
 
110
}
-
 
111
 
107
void Elevator::run_elevator_logic ()
112
void Elevator::run_elevator_logic ()
108
{
113
{
109
    int i;
114
    int i;
110
 
115
 
111
    /* Decide what to do */
116
    /* Decide what to do */
Line 226... Line 231...
226
    this->pause = false;
231
    this->pause = false;
227
}
232
}
228
 
233
 
229
bool Elevator::near_a_floor ()
234
bool Elevator::near_a_floor ()
230
{
235
{
231
    const float range = ELEVATOR_TIME_MOVE_AMOUNT / 4.0;
236
    const float range = ELEVATOR_TIME_MOVE_AMOUNT / 2.0;
232
 
237
 
233
    /* This seems somewhat counter-intuitive, but it's really not.
238
    /* This seems somewhat counter-intuitive, but it's really not.
234
     * If we are near a floor, then one of the two of these will fail.
239
     * If we are near a floor, then one of the two of these will fail.
235
     *
240
     *
236
     * Example:
241
     * Example:
Line 270... Line 275...
270
 
275
 
271
bool Elevator::should_stop_at_current_floor ()
276
bool Elevator::should_stop_at_current_floor ()
272
{
277
{
273
    int i;
278
    int i;
274
 
279
 
275
    for (i=1; i<= num_floors; i++)
280
    for (i=1; i<=num_floors; i++)
276
        if (near_floor (i) && stop_at_floors[i] == true)
281
        if (near_floor (i) && stop_at_floors[i] == true)
277
            return true;
282
            return true;
278
 
283
 
279
    return false;
284
    return false;
280
}
285
}