1
0
mirror of https://github.com/kidoman/embd synced 2024-12-23 05:10:05 +01:00
embd/samples/universalblinker.go

60 lines
833 B
Go
Raw Normal View History

2014-04-25 02:28:01 +05:30
// +build ignore
// Universal LED blinker, works OOTB on a RPi / BBB.
package main
import (
"flag"
"os"
"os/signal"
"time"
"github.com/kidoman/embd"
_ "github.com/kidoman/embd/host/all"
)
func main() {
flag.Parse()
panicIf(embd.InitLED())
defer embd.CloseLED()
led, err := embd.NewLED(ledToBlink())
panicIf(err)
defer led.Off()
quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt, os.Kill)
defer signal.Stop(quit)
for {
select {
case <-time.After(200 * time.Millisecond):
2014-04-25 02:28:01 +05:30
panicIf(led.Toggle())
case <-quit:
return
}
}
}
func ledToBlink() string {
host, _, err := embd.DetectHost()
panicIf(err)
switch host {
case embd.HostRPi:
return "LED0"
case embd.HostBBB:
return "USR3"
}
panic("Unsupported host")
}
func panicIf(err error) {
if err != nil {
panic(err)
}
}