mirror of
https://github.com/kidoman/embd
synced 2025-07-03 11:57:38 +02:00
bring in the idea of a hardware abstraction layer
This commit is contained in:
parent
b4de382833
commit
b5e2d0acc7
35 changed files with 994 additions and 971 deletions
51
samples/gpiodetect.go
Normal file
51
samples/gpiodetect.go
Normal file
|
@ -0,0 +1,51 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/kidoman/embd"
|
||||
"github.com/kidoman/embd/host"
|
||||
)
|
||||
|
||||
func main() {
|
||||
h, _, err := host.Detect()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var pinNo interface{}
|
||||
|
||||
switch h {
|
||||
case host.BBB:
|
||||
pinNo = "P9_31"
|
||||
case host.RPi:
|
||||
pinNo = 10
|
||||
default:
|
||||
panic("host not supported (yet :P)")
|
||||
}
|
||||
|
||||
gpio, err := embd.NewGPIO()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer gpio.Close()
|
||||
|
||||
led, err := gpio.DigitalPin(pinNo)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer led.Close()
|
||||
|
||||
if err := led.SetDir(embd.Out); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := led.Write(embd.High); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
if err := led.SetDir(embd.In); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue