-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
84 lines (75 loc) · 1.82 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
_ "embed"
"github.com/Nescient/gpio-timer/derbynet"
"github.com/Nescient/gpio-timer/gpio"
"log"
"os"
"runtime/debug"
// "sync"
"time"
)
//go:generate sh -c "printf %s $(git rev-parse HEAD) > .commit_id"
//go:embed .commit_id
var gitrev string
func main() {
whoAmI := os.Args[0]
if info, ok := debug.ReadBuildInfo(); ok {
for _, setting := range info.Settings {
if setting.Key == "vcs.revision" {
whoAmI += setting.Value
} else if setting.Key == "vcs.time" {
whoAmI += setting.Value
} else if setting.Key == "vcs.modified" {
whoAmI += "-DIRTY"
}
}
}
log.Println(whoAmI)
log.Println(gitrev)
var client derbynet.DerbyNet
client.Initialize()
log.Println("Getting cookie...")
client.GetCookie()
log.Println("Saying hello...")
client.Hello()
log.Println("Indentifying...")
client.Identified(gitrev)
// timer heartbeats
log.Println("Establishing heartbeats...")
isQuitting := false
go func() {
for !isQuitting {
client.Heartbeat()
time.Sleep(time.Second * 10)
}
client.Terminate()
}()
// main race loop
log.Println("Starting main race loop...")
for isQuitting == false {
log.Println("Waiting for heat...")
if client.WaitForHeat() {
start, err := gpio.ArmStart()
if err != nil {
log.Fatal(err)
}
log.Println("Waiting for start gate...")
gpio.WaitForStart(start)
client.Started()
lanes, err := gpio.ArmLanes()
if err != nil {
log.Fatal(err)
}
log.Println("Waiting for lanes...")
gpio.WaitForLanes(lanes)
laneTimes := gpio.GetTimes(start, lanes)
client.Finished(laneTimes[0], laneTimes[1], laneTimes[2], laneTimes[3])
log.Printf("Times %f %f %f %f\n", laneTimes[0], laneTimes[1], laneTimes[2], laneTimes[3])
}
}
isQuitting = true
log.Println("Terminating...")
client.Terminate()
time.Sleep(time.Second * 2)
}