1
0
mirror of https://github.com/kidoman/embd synced 2024-12-22 04:40:04 +01:00

samples: enable flag parsing

this will allow people to use glog options (like -v=3) to increase
verbosity of the log output
This commit is contained in:
Kunal Powar 2014-04-05 01:43:16 +05:30
parent 10992981e3
commit 779096e668
22 changed files with 91 additions and 10 deletions

View File

@ -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)
}

View File

@ -3,12 +3,15 @@
package main
import (
"flag"
"fmt"
"github.com/kidoman/embd"
)
func main() {
flag.Parse()
embd.InitGPIO()
defer embd.CloseGPIO()

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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

View File

@ -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)
}

View File

@ -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()

View File

@ -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)
}

View File

@ -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)
}

View File

@ -5,12 +5,15 @@
package main
import (
"flag"
"time"
"github.com/kidoman/embd"
)
func main() {
flag.Parse()
embd.InitLED()
defer embd.CloseLED()

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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()

View File

@ -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()

View File

@ -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)
}

View File

@ -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
}
}
}

View File

@ -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)
}