diff --git a/samples/analog.go b/samples/analog.go index 2348989..6b20b05 100644 --- a/samples/analog.go +++ b/samples/analog.go @@ -3,6 +3,7 @@ package main import ( + "flag" "fmt" "os" "os/signal" @@ -12,6 +13,8 @@ import ( ) func main() { + flag.Parse() + if err := embd.InitGPIO(); err != nil { panic(err) } diff --git a/samples/analogshort.go b/samples/analogshort.go index 78deb48..5ca3f91 100644 --- a/samples/analogshort.go +++ b/samples/analogshort.go @@ -3,12 +3,15 @@ package main import ( + "flag" "fmt" "github.com/kidoman/embd" ) func main() { + flag.Parse() + embd.InitGPIO() defer embd.CloseGPIO() diff --git a/samples/bh1750fvi.go b/samples/bh1750fvi.go index 95ee28c..35e208f 100644 --- a/samples/bh1750fvi.go +++ b/samples/bh1750fvi.go @@ -3,6 +3,7 @@ package main import ( + "flag" "fmt" "time" @@ -11,6 +12,8 @@ import ( ) func main() { + flag.Parse() + if err := embd.InitI2C(); err != nil { panic(err) } diff --git a/samples/bmp085.go b/samples/bmp085.go index 0f24197..f98608e 100644 --- a/samples/bmp085.go +++ b/samples/bmp085.go @@ -3,6 +3,7 @@ package main import ( + "flag" "fmt" "time" @@ -11,6 +12,8 @@ import ( ) func main() { + flag.Parse() + if err := embd.InitI2C(); err != nil { panic(err) } diff --git a/samples/bmp180.go b/samples/bmp180.go index e5b8535..8388b0d 100644 --- a/samples/bmp180.go +++ b/samples/bmp180.go @@ -3,6 +3,7 @@ package main import ( + "flag" "fmt" "time" @@ -11,6 +12,8 @@ import ( ) func main() { + flag.Parse() + if err := embd.InitI2C(); err != nil { panic(err) } diff --git a/samples/gpio.go b/samples/gpio.go index 4de86f1..5a9ad79 100644 --- a/samples/gpio.go +++ b/samples/gpio.go @@ -3,12 +3,15 @@ package main import ( + "flag" "time" "github.com/kidoman/embd" ) func main() { + flag.Parse() + if err := embd.InitGPIO(); err != nil { panic(err) } diff --git a/samples/gpiodetect.go b/samples/gpiodetect.go index e0c202e..1fac511 100644 --- a/samples/gpiodetect.go +++ b/samples/gpiodetect.go @@ -3,12 +3,15 @@ package main import ( + "flag" "time" "github.com/kidoman/embd" ) func main() { + flag.Parse() + h, _, err := embd.DetectHost() if err != nil { return diff --git a/samples/gpiodirect.go b/samples/gpiodirect.go index 0047b7e..b91d6b0 100644 --- a/samples/gpiodirect.go +++ b/samples/gpiodirect.go @@ -3,12 +3,15 @@ package main import ( + "flag" "time" "github.com/kidoman/embd" ) func main() { + flag.Parse() + if err := embd.InitGPIO(); err != nil { panic(err) } diff --git a/samples/gpioshort.go b/samples/gpioshort.go index f669cbe..56cb989 100644 --- a/samples/gpioshort.go +++ b/samples/gpioshort.go @@ -2,9 +2,15 @@ package main -import "github.com/kidoman/embd" +import ( + "flag" + + "github.com/kidoman/embd" +) func main() { + flag.Parse() + embd.InitGPIO() defer embd.CloseGPIO() diff --git a/samples/l3gd20.go b/samples/l3gd20.go index f479668..4d5ab47 100644 --- a/samples/l3gd20.go +++ b/samples/l3gd20.go @@ -3,6 +3,7 @@ package main import ( + "flag" "fmt" "os" "os/signal" @@ -13,6 +14,8 @@ import ( ) func main() { + flag.Parse() + if err := embd.InitI2C(); err != nil { panic(err) } diff --git a/samples/led.go b/samples/led.go index f3358cc..3acaa82 100644 --- a/samples/led.go +++ b/samples/led.go @@ -5,6 +5,7 @@ package main import ( + "flag" "fmt" "os" "os/signal" @@ -14,6 +15,8 @@ import ( ) func main() { + flag.Parse() + if err := embd.InitLED(); err != nil { panic(err) } diff --git a/samples/ledshort.go b/samples/ledshort.go index e3ee618..44b6097 100644 --- a/samples/ledshort.go +++ b/samples/ledshort.go @@ -5,12 +5,15 @@ package main import ( + "flag" "time" "github.com/kidoman/embd" ) func main() { + flag.Parse() + embd.InitLED() defer embd.CloseLED() diff --git a/samples/lsm303.go b/samples/lsm303.go index 393cc7c..2fdbbf3 100644 --- a/samples/lsm303.go +++ b/samples/lsm303.go @@ -3,6 +3,7 @@ package main import ( + "flag" "fmt" "time" @@ -11,6 +12,8 @@ import ( ) func main() { + flag.Parse() + if err := embd.InitI2C(); err != nil { panic(err) } diff --git a/samples/mcp4725.go b/samples/mcp4725.go index ab0e796..7e6425b 100644 --- a/samples/mcp4725.go +++ b/samples/mcp4725.go @@ -3,6 +3,7 @@ package main import ( + "flag" "fmt" "math/rand" "os" @@ -13,6 +14,8 @@ import ( ) func main() { + flag.Parse() + if err := embd.InitI2C(); err != nil { panic(err) } diff --git a/samples/pca9685.go b/samples/pca9685.go index e9dff48..ea90ea6 100644 --- a/samples/pca9685.go +++ b/samples/pca9685.go @@ -3,6 +3,7 @@ package main import ( + "flag" "os" "os/signal" "time" @@ -12,6 +13,8 @@ import ( ) func main() { + flag.Parse() + if err := embd.InitI2C(); err != nil { panic(err) } diff --git a/samples/pwm.go b/samples/pwm.go index e7f4406..85ff6d0 100644 --- a/samples/pwm.go +++ b/samples/pwm.go @@ -5,12 +5,15 @@ package main import ( + "flag" "time" "github.com/kidoman/embd" ) func main() { + flag.Parse() + if err := embd.InitGPIO(); err != nil { panic(err) } diff --git a/samples/servo.go b/samples/servo.go index 27b48a5..5077c10 100644 --- a/samples/servo.go +++ b/samples/servo.go @@ -3,6 +3,7 @@ package main import ( + "flag" "os" "os/signal" "time" @@ -13,6 +14,8 @@ import ( ) func main() { + flag.Parse() + if err := embd.InitI2C(); err != nil { panic(err) } diff --git a/samples/servobbb.go b/samples/servobbb.go index 13361a1..f9fe8cd 100644 --- a/samples/servobbb.go +++ b/samples/servobbb.go @@ -3,6 +3,8 @@ package main import ( + "flag" + "fmt" "os" "os/signal" "time" @@ -12,6 +14,8 @@ import ( ) func main() { + flag.Parse() + embd.InitGPIO() defer embd.CloseGPIO() diff --git a/samples/servoblaster.go b/samples/servoblaster.go index b752ebb..77a7b61 100644 --- a/samples/servoblaster.go +++ b/samples/servoblaster.go @@ -3,6 +3,7 @@ package main import ( + "flag" "os" "os/signal" "time" @@ -12,6 +13,8 @@ import ( ) func main() { + flag.Parse() + sb := servoblaster.New() defer sb.Close() diff --git a/samples/tmp006.go b/samples/tmp006.go index 38f2f15..3e73408 100644 --- a/samples/tmp006.go +++ b/samples/tmp006.go @@ -3,6 +3,7 @@ package main import ( + "flag" "fmt" "os" "os/signal" @@ -12,6 +13,8 @@ import ( ) func main() { + flag.Parse() + if err := embd.InitI2C(); err != nil { panic(err) } diff --git a/samples/us020.go b/samples/us020.go index 5884baf..078d8b0 100644 --- a/samples/us020.go +++ b/samples/us020.go @@ -3,7 +3,10 @@ package main import ( + "flag" "fmt" + "os" + "os/signal" "time" "github.com/kidoman/embd" @@ -11,16 +14,19 @@ import ( ) func main() { + flag.Parse() + if err := embd.InitGPIO(); err != nil { panic(err) } defer embd.CloseGPIO() - echoPin, err := embd.NewDigitalPin(10) + echoPin, err := embd.NewDigitalPin("P9_21") if err != nil { panic(err) } - triggerPin, err := embd.NewDigitalPin(9) + + triggerPin, err := embd.NewDigitalPin("P9_22") if err != nil { panic(err) } @@ -28,13 +34,21 @@ func main() { rf := us020.New(echoPin, triggerPin, nil) defer rf.Close() - for { - distance, err := rf.Distance() - if err != nil { - panic(err) - } - fmt.Printf("Distance is %v\n", distance) + quit := make(chan os.Signal, 1) + signal.Notify(quit, os.Interrupt, os.Kill) - time.Sleep(500 * time.Millisecond) + for { + select { + default: + distance, err := rf.Distance() + if err != nil { + panic(err) + } + fmt.Printf("Distance is %v\n", distance) + + time.Sleep(500 * time.Millisecond) + case <-quit: + return + } } } diff --git a/samples/watersensor.go b/samples/watersensor.go index 361ff8c..8e2eb8f 100644 --- a/samples/watersensor.go +++ b/samples/watersensor.go @@ -3,6 +3,7 @@ package main import ( + "flag" "time" "github.com/golang/glog" @@ -11,6 +12,8 @@ import ( ) func main() { + flag.Parse() + if err := embd.InitGPIO(); err != nil { panic(err) }