-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrobocape.go
53 lines (43 loc) · 908 Bytes
/
robocape.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
package robocape
/*
#cgo LDFLAGS: -lroboticscape
#include "roboticscape.h"
typedef void (*closure)(); // workaround see https://github.com/golang/go/issues/19835
*/
import "C"
import (
"fmt"
"time"
)
// Initialise initialise the robotcape
func Initialise() error {
return checkRes(C.rc_initialize())
}
// Cleanup release resources used by the robotcape
func Cleanup() error {
return checkRes(C.rc_cleanup())
}
// WaitForExit wait for exit
func WaitForExit() {
for {
if C.rc_get_state() == C.EXITING {
break
}
time.Sleep(100 * time.Millisecond)
}
}
// IsExiting check if the process should exit
func IsExiting() bool {
return C.rc_get_state() == C.EXITING
}
// Exit stop the process
func Exit() {
C.rc_set_state(C.EXITING)
}
// checkRes check for non zero return codes
func checkRes(res C.int) error {
if res != 0 {
return fmt.Errorf("Call failed res: %v", res)
}
return nil
}