-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
72 lines (63 loc) · 1.25 KB
/
main.go
File metadata and controls
72 lines (63 loc) · 1.25 KB
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
package main
import (
"fmt"
"bytes"
"time"
"os"
"os/signal"
"os/exec"
"github.com/stianeikeland/go-rpio"
)
var (
LEDPin rpio.Pin = rpio.Pin(17)
PirPin int = 18
Timeout int = 30
)
func main() {
var name string
name="/usr/bin/omxplayer"
cmd := exec.Command(name, "-version")
fmt.Println("Starting player")
err := cmd.Run()
fmt.Println(" Process launched")
if err!=nil {
var buffer bytes.Buffer
buffer.WriteString("Could not start omxplayer: ")
buffer.WriteString(err.Error())
fmt.Println("Could not start omxplayer")
panic(buffer.String())
}
fmt.Println(" Player startet")
LedOn := false
Play := NewOMXPlayer()
pir := NewPIR(PirPin, Timeout)
if err := rpio.Open(); err != nil {
panic(err.Error())
}
LEDPin.Output()
quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt, os.Kill)
defer signal.Stop(quit)
for true {
if (pir.IsActive()) {
Play.Start()
} else {
Play.Stop()
}
select {
case <-time.After(200 * time.Millisecond):
if LedOn {
LEDPin.High()
LedOn = false
} else {
LEDPin.Low()
LedOn = true
}
case <-quit:
fmt.Println("Catch ctrl-c, exiting!")
Play.Close()
LEDPin.Low()
return
}
}
}