-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathelevator_io_device.c
72 lines (51 loc) · 1.76 KB
/
elevator_io_device.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
#include "elevator_io_device.h"
#include <assert.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <netdb.h>
#include <stdio.h>
#include "con_load.h"
#include "driver/elevator_hardware.h"
static void __attribute__((constructor)) elev_init(void){
elevator_hardware_init();
}
static int _wrap_requestButton(int f, Button b){
return elevator_hardware_get_button_signal(b, f);
}
static void _wrap_requestButtonLight(int f, Button b, int v){
elevator_hardware_set_button_lamp(b, f, v);
}
static void _wrap_motorDirection(Dirn d){
elevator_hardware_set_motor_direction(d);
}
ElevInputDevice elevio_getInputDevice(void){
return (ElevInputDevice){
.floorSensor = &elevator_hardware_get_floor_sensor_signal,
.requestButton = &_wrap_requestButton,
.stopButton = &elevator_hardware_get_stop_signal,
.obstruction = &elevator_hardware_get_obstruction_signal
};
}
ElevOutputDevice elevio_getOutputDevice(void){
return (ElevOutputDevice){
.floorIndicator = &elevator_hardware_set_floor_indicator,
.requestButtonLight = &_wrap_requestButtonLight,
.doorLight = &elevator_hardware_set_door_open_lamp,
.stopButtonLight = &elevator_hardware_set_stop_lamp,
.motorDirection = &_wrap_motorDirection
};
}
char* elevio_dirn_toString(Dirn d){
return
d == D_Up ? "D_Up" :
d == D_Down ? "D_Down" :
d == D_Stop ? "D_Stop" :
"D_UNDEFINED" ;
}
char* elevio_button_toString(Button b){
return
b == B_HallUp ? "B_HallUp" :
b == B_HallDown ? "B_HallDown" :
b == B_Cab ? "B_Cab" :
"B_UNDEFINED" ;
}