-
Notifications
You must be signed in to change notification settings - Fork 21
/
main.go
59 lines (46 loc) · 1.49 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
package main
import "Driver-go/elevio"
import "fmt"
func main(){
numFloors := 4
elevio.Init("localhost:15657", numFloors)
var d elevio.MotorDirection = elevio.MD_Up
//elevio.SetMotorDirection(d)
drv_buttons := make(chan elevio.ButtonEvent)
drv_floors := make(chan int)
drv_obstr := make(chan bool)
drv_stop := make(chan bool)
go elevio.PollButtons(drv_buttons)
go elevio.PollFloorSensor(drv_floors)
go elevio.PollObstructionSwitch(drv_obstr)
go elevio.PollStopButton(drv_stop)
for {
select {
case a := <- drv_buttons:
fmt.Printf("%+v\n", a)
elevio.SetButtonLamp(a.Button, a.Floor, true)
case a := <- drv_floors:
fmt.Printf("%+v\n", a)
if a == numFloors-1 {
d = elevio.MD_Down
} else if a == 0 {
d = elevio.MD_Up
}
elevio.SetMotorDirection(d)
case a := <- drv_obstr:
fmt.Printf("%+v\n", a)
if a {
elevio.SetMotorDirection(elevio.MD_Stop)
} else {
elevio.SetMotorDirection(d)
}
case a := <- drv_stop:
fmt.Printf("%+v\n", a)
for f := 0; f < numFloors; f++ {
for b := elevio.ButtonType(0); b < 3; b++ {
elevio.SetButtonLamp(b, f, false)
}
}
}
}
}