-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfloors.c
83 lines (74 loc) · 2.32 KB
/
floors.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "floors.h"
void updateFloorStatus(floor *floors) {
for (int i = FLOOR_2; i <= FLOOR_4; i++) {
floors[i].downOrder = floors[i].downOrder || elev_get_button_signal(BUTTON_CALL_DOWN, i);
}
for (int i = FLOOR_1; i <= FLOOR_3; i++) {
floors[i].upOrder = floors[i].upOrder || elev_get_button_signal(BUTTON_CALL_UP, i);
}
for (int i = FLOOR_1; i <= FLOOR_4; i++) {
floors[i].innerOrder = floors[i].innerOrder || elev_get_button_signal(BUTTON_COMMAND, i);
}
}
bool updateCurrentFloor(floor_num *current) {
int get = elev_get_floor_sensor_signal();
if (get != -1) {
if (*current != get) {
*current = get;
return true;
}
return false;
}
return false;
}
void updateFloorLight(floor_num current) {
if (current != -1) {
elev_set_floor_indicator(current);
}
}
void updateLights(floor *floors) {
for (int i = FLOOR_2; i <= FLOOR_4; i++) {
elev_set_button_lamp(BUTTON_CALL_DOWN, i, (int) floors[i].downOrder);
}
for (int i = FLOOR_1; i <= FLOOR_3; i++) {
elev_set_button_lamp(BUTTON_CALL_UP, i, (int) floors[i].upOrder);
}
for (int i = FLOOR_1; i <= FLOOR_4; i++) {
elev_set_button_lamp(BUTTON_COMMAND, i, (int) floors[i].innerOrder);
}
}
bool getStopButton() {
bool active = elev_get_stop_signal();
elev_set_stop_lamp((int) active);
return active;
}
void setDoorOpen(bool status) {
elev_set_door_open_lamp((int) status);
}
bool hasOrdersInDir(floor_num current, floor *floors, elev_motor_direction_t dir) {
if ((current == FLOOR_1 && dir == DIRN_DOWN) || (current == FLOOR_4 && dir == DIRN_UP)) {
return false;
}
if (dir == DIRN_DOWN) {
for (int i = current-1; i >= FLOOR_1; i--) {
if (hasOrders(floors, i)) {
return true;
}
}
} else {
for (int i = current+1; i <= FLOOR_4; i++) {
if (hasOrders(floors, i)) {
return true;
}
}
}
return false;
}
bool hasOrders(floor *floors, int index) {
return floors[index].downOrder || floors[index].upOrder || floors[index].innerOrder;
}
void clearOrders(floor *floors, int index) {
floors[index].downOrder = false;
floors[index].upOrder = false;
floors[index].innerOrder = false;
}