-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (54 loc) · 1.3 KB
/
main.go
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
package main
import (
"ElevatorProject/ElevatorModules"
module "ElevatorProject/ElevatorModules"
io "ElevatorProject/elevio"
)
func main() {
numFloors := 4
io.Init("localhost:15657", numFloors)
drv_buttons := make(chan io.ButtonEvent)
drv_floors := make(chan int)
drv_obstr := make(chan bool)
drv_stop := make(chan bool)
go io.PollButtons(drv_buttons)
go io.PollFloorSensor(drv_floors)
go io.PollObstructionSwitch(drv_obstr)
go io.PollStopButton(drv_stop)
module.CheckForPrimary()
go module.CheckForDoorTimeout()
if io.GetFloor() == -1 {
module.Fsm_onInitBetweenFloors()
for {
if io.GetFloor() != -1 {
io.SetMotorDirection(io.MD_Stop)
break
}
}
}
module.InitLights()
go module.IAmAlive()
go module.RecieveTurnOnOffLight()
go ElevatorModules.RecieveOrderMatrix()
go module.Fsm_Obstructed()
go module.CheckMoveAvailability()
for {
select {
case a := <-drv_buttons:
if int(a.Button) == 2 {
if module.PingInternet() == 0 {
module.Fsm_OnRequestButtonPress(a.Floor, a.Button)
} else {
ElevatorModules.SendButtonPressUDP(a)
ElevatorModules.AddCabRequest(a.Floor, a.Button)
}
} else {
ElevatorModules.SendButtonPressUDP(a)
}
case a := <-drv_floors:
module.Fsm_OnFloorArrival(a)
case a := <-drv_obstr:
module.IsObstructed = a
}
}
}