-
Notifications
You must be signed in to change notification settings - Fork 0
/
StateMachine.c
97 lines (88 loc) · 2.79 KB
/
StateMachine.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <stdio.h>
#include "StateMachine.h"
#include "QueueManager.h"
#include "elev.h"
static int current_floor;
//kjøres ved sjekk av elev_get_stop_signal som returnerer 1
void stop_button_activated_ignore_orders() {
elev_set_stop_lamp(1);
elev_set_motor_direction(DIRN_STOP);
delete_Q();
if (elev_get_floor_sensor_signal()== -1) {
while (elev_get_stop_signal() == 1) {
continue;
}
}
else {
elev_set_door_open_lamp(1);
while (elev_get_stop_signal() == 1) {
continue;
}
}
elev_set_stop_lamp(0);
}
// kjører en if(i etg.){tell ned 3 sek} etter stop_button_activated_ignore orders
// hvor funksjonen tar inn et struct &timer og setter dør lampen av.
void set_current_floor(void) {
if (elev_get_floor_sensor_signal() != -1){
current_floor = elev_get_floor_sensor_signal();
}
}
int get_current_floor() {
return current_floor;
}
//en funksjon som skjekker at stp er aktivert
//sjekker om en knapp er trykket og legger til i kø og setter på lys, hvis en er trykket
void check_button_pressed_up() {
set_order_in_Q_up(TOP_FLOOR, 0);
if (elev_get_button_signal(BUTTON_CALL_UP, GROUND_FLOOR) == 1) {
set_order_in_Q_up(GROUND_FLOOR, 1);
elev_set_button_lamp(BUTTON_CALL_UP, GROUND_FLOOR, 1);
}
if (elev_get_button_signal(BUTTON_CALL_UP, FIRST) == 1) {
set_order_in_Q_up(FIRST, 1);
elev_set_button_lamp(BUTTON_CALL_UP, FIRST, 1);
}
if (elev_get_button_signal(BUTTON_CALL_UP, SECOND) == 1) {
set_order_in_Q_up(SECOND, 1);
elev_set_button_lamp(BUTTON_CALL_UP, SECOND, 1);
}
}
void check_button_pressed_down(){
set_order_in_Q_down(GROUND_FLOOR, 0);
if (elev_get_button_signal(BUTTON_CALL_DOWN, FIRST) == 1) {
set_order_in_Q_down(FIRST, 1);
elev_set_button_lamp(BUTTON_CALL_DOWN, FIRST, 1);
}
if (elev_get_button_signal(BUTTON_CALL_DOWN, SECOND) == 1) {
set_order_in_Q_down(SECOND, 1);
elev_set_button_lamp(BUTTON_CALL_DOWN, SECOND, 1);
}
if (elev_get_button_signal(BUTTON_CALL_DOWN, TOP_FLOOR) == 1) {
set_order_in_Q_down(TOP_FLOOR, 1);
elev_set_button_lamp(BUTTON_CALL_DOWN, TOP_FLOOR, 1);
}
}
void check_button_pressed_command(){
if (elev_get_button_signal(BUTTON_COMMAND, GROUND_FLOOR) == 1) {
set_order_in_Q_command(GROUND_FLOOR, 1);
elev_set_button_lamp(BUTTON_COMMAND, GROUND_FLOOR, 1);
}
if (elev_get_button_signal(BUTTON_COMMAND, FIRST) == 1) {
set_order_in_Q_command(FIRST, 1);
elev_set_button_lamp(BUTTON_COMMAND, FIRST, 1);
}
if (elev_get_button_signal(BUTTON_COMMAND, SECOND) == 1) {
set_order_in_Q_command(SECOND, 1);
elev_set_button_lamp(BUTTON_COMMAND, SECOND, 1);
}
if (elev_get_button_signal(BUTTON_COMMAND, TOP_FLOOR) == 1) {
set_order_in_Q_command(TOP_FLOOR, 1);
elev_set_button_lamp(BUTTON_COMMAND, TOP_FLOOR, 1);
}
}
void check_button_pressed() {
check_button_pressed_command();
check_button_pressed_down();
check_button_pressed_up();
}