forked from pettsol/heis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIOModule.c
More file actions
103 lines (85 loc) · 2.21 KB
/
Copy pathIOModule.c
File metadata and controls
103 lines (85 loc) · 2.21 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "IOModule.h"
void pollFloorsAndSetLights(int *currentFloor){
switch(elev_get_floor_sensor_signal()){
case -1:
break;
case 0:
*currentFloor = 0;
elev_set_floor_indicator(0);
previousDir = direction;
break;
case 1:
*currentFloor = 1;
elev_set_floor_indicator(1);
previousDir = direction;
break;
case 2:
*currentFloor = 2;
elev_set_floor_indicator(2);
previousDir = direction;
break;
case 3:
*currentFloor = 3;
elev_set_floor_indicator(3);
previousDir = direction;
break;
default:
printf("FLOOR SENSOR BROKEN\n");
}
};
void pollAndUpdateButtonsAndLights(){
for(int i = 0; i < BUTTON_TYPES; i++){
for(int j = 0; j < NUMBER_OF_FLOORS; j ++){
if (((i == 0) && (j == (NUMBER_OF_FLOORS - 1))) || ((i == 1) && (j == (0)))){
BUTTONS[j + i*NUMBER_OF_FLOORS] = 0; //NED I FØRSTE OG OPP I ØVERSTE ETASJE EKSISTERER IKKE;
}
else{
BUTTONS[j + i*NUMBER_OF_FLOORS] = (BUTTONS[j + i*NUMBER_OF_FLOORS] || elev_get_button_signal(i, j));
if(elev_get_stop_signal()){
elev_set_button_lamp(i, j, 0);
}
else{
elev_set_button_lamp(i, j, BUTTONS[j + i*NUMBER_OF_FLOORS]);
}
}
}
}
};
void setMotorDirection(int *currentFloor, struct order *currentOrder){
if(elev_get_floor_sensor_signal() != -1){
if(*currentFloor < currentOrder->floor){
elev_set_motor_direction(DIRN_UP);
direction = 0;
}
else if(*currentFloor > currentOrder->floor){
elev_set_motor_direction(DIRN_DOWN);
direction = 1;
}
}
else{
if(currentOrder->floor > *currentFloor){
elev_set_motor_direction(DIRN_UP);
direction = 0;
}
else if (currentOrder->floor < *currentFloor){
elev_set_motor_direction(DIRN_DOWN);
direction = 1;
}
else{
if (previousDir == 1){
elev_set_motor_direction(DIRN_UP);
direction = 0;
}
else{
elev_set_motor_direction(DIRN_DOWN);
direction = 1;
}
}
}
}
int getDirection(){
return direction;
}
void setDirection(int dir){
direction = dir;
}