-
Notifications
You must be signed in to change notification settings - Fork 0
/
button.c
86 lines (68 loc) · 1.86 KB
/
button.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
#ifndef __INCLUDE_BUTTON_C__
#define __INCLUDE_BUTTON_C__
#include "button.h"
#include "state.h"
#include "elev.h"
#include "channels.h"
void floorLight(int floor)
{
if (floor != -1)
{
elev_set_floor_indicator(floor);
}
}
void clearButtons(int floor, state* current)
{
elev_set_button_lamp(BUTTON_COMMAND, floor, 0);
(current->buttons)[BUTTON_COMMAND][floor] = 0;
if (floor != 3)
{
elev_set_button_lamp(BUTTON_CALL_UP, floor, 0);
(current->buttons)[BUTTON_CALL_UP][floor] = 0;
}
if (floor != 0)
{
elev_set_button_lamp(BUTTON_CALL_DOWN, floor, 0);
(current->buttons)[BUTTON_CALL_DOWN][floor] = 0;
}
}
void buttonUpdate(state* current)
{
// go through all the floors
for (int f = 0; f < 4; ++f)
{
// check the buttons, don't check up if we're on floor 4 and down if we're on floor 1
// only check if it hasn't been checked before
// up button
if ((f != 3) && !(current->buttons[BUTTON_CALL_UP][f]))
{
current->buttons[BUTTON_CALL_UP][f] = elev_get_button_signal(BUTTON_CALL_UP, f);
// if the button has been pressed, set that button lamp
if (current->buttons[BUTTON_CALL_UP][f])
{
elev_set_button_lamp(BUTTON_CALL_UP, f, 1);
}
}
// down button
if ((f != 0) && !(current->buttons[BUTTON_CALL_DOWN][f]))
{
current->buttons[BUTTON_CALL_DOWN][f] = elev_get_button_signal(BUTTON_CALL_DOWN, f);
// if the button has been pressed, set that button lamp
if (current->buttons[BUTTON_CALL_DOWN][f])
{
elev_set_button_lamp(BUTTON_CALL_DOWN, f, 1);
}
}
// command button
if (!(current->buttons[BUTTON_COMMAND][f]))
{
current->buttons[BUTTON_COMMAND][f] = elev_get_button_signal(BUTTON_COMMAND, f);
// if the button has been pressed, set that button lamp
if (current->buttons[BUTTON_COMMAND][f])
{
elev_set_button_lamp(BUTTON_COMMAND, f, 1);
}
}
}
}
#endif // #ifndef __INCLUDE_BUTTON_C__