Subversion Repositories programming

Rev

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

Rev 330 Rev 331
Line 5... Line 5...
5
#include <cstdio>
5
#include <cstdio>
6
#include <iostream>
6
#include <iostream>
7
#include <unistd.h>
7
#include <unistd.h>
8
#include <assert.h>
8
#include <assert.h>
9
#include <vector>
9
#include <vector>
-
 
10
#include <string>
10
 
11
 
11
#include <boost/thread/thread.hpp>
12
#include <boost/thread/thread.hpp>
12
#include <boost/bind.hpp>
13
#include <boost/bind.hpp>
-
 
14
#include <boost/algorithm/string.hpp>
13
 
15
 
14
/* Custom #defines for just the elevator class */
16
#include "controller.h"
-
 
17
 
15
#define MOVE_UP     0
18
const int MOVE_UP   = 0;
16
#define MOVE_DOWN   1
19
const int MOVE_DOWN = 1;
17
#define IDLE        2
20
const int IDLE      = 2;
18
 
21
 
19
#define ELEVATOR_TIME_MOVE_AMOUNT   0.1
22
const float ELEVATOR_TIME_MOVE_AMOUNT = 0.1;
20
#define ELEVATOR_TIME_DELAY_USEC    500000
23
const int   ELEVATOR_TIME_DELAY_USEC  = 500000;
21
#define ELEVATOR_TIME_PAUSE_USEC    50000
24
const int   ELEVATOR_TIME_PAUSE_USEC  = 50000;
-
 
25
 
-
 
26
class Controller;
22
 
27
 
23
class Elevator
28
class Elevator
24
{
29
{
25
    public:
30
    public:
26
        Elevator (int num_floors);
31
        Elevator (int num_floors);
Line 30... Line 35...
30
        int floors_above_current ();
35
        int floors_above_current ();
31
        int floors_below_current ();
36
        int floors_below_current ();
32
        void push_button (int floor);
37
        void push_button (int floor);
33
        bool button_is_pushed (int floor);
38
        bool button_is_pushed (int floor);
34
 
39
 
-
 
40
        // User interaction
-
 
41
        void have_user_enter_buttons ();
-
 
42
 
35
        // Getters and Setters
43
        // Getters and Setters
36
        int get_direction ();
44
        int get_direction ();
37
        float get_current_floor ();
45
        float get_current_floor ();
-
 
46
        void set_controller (Controller *c);
38
 
47
 
39
        // Thread Functions
48
        // Thread Functions
40
        void thread_start ();
49
        void thread_start ();
41
        void thread_exit ();
50
        void thread_stop ();
42
        void thread_pause ();
51
        void thread_pause ();
43
        void thread_unpause ();
52
        void thread_unpause ();
44
 
53
 
45
    private:
54
    private:
46
        // Private Functions
55
        // Private Functions
Line 54... Line 63...
54
        static void thread_entry (const Elevator *me);
63
        static void thread_entry (const Elevator *me);
55
 
64
 
56
        // Private Variables
65
        // Private Variables
57
        int num_floors;
66
        int num_floors;
58
        float current_floor;
67
        float current_floor;
59
        std::vector<bool> stop_at_floors;
-
 
60
        int direction;
68
        int direction;
-
 
69
        std::vector<bool> stop_at_floors;
-
 
70
        Controller *controller;
61
 
71
 
62
        // Thread Variable
72
        // Thread Variable
63
        bool terminate;
73
        bool terminate;
64
        bool pause;
74
        bool pause;
65
 
75