1
0
mirror of https://github.com/kidoman/embd synced 2024-12-22 12:50:19 +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 package main
import ( import (
"flag"
"fmt" "fmt"
"os" "os"
"os/signal" "os/signal"
@ -12,6 +13,8 @@ import (
) )
func main() { func main() {
flag.Parse()
if err := embd.InitGPIO(); err != nil { if err := embd.InitGPIO(); err != nil {
panic(err) panic(err)
} }

View File

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

View File

@ -3,6 +3,7 @@
package main package main
import ( import (
"flag"
"fmt" "fmt"
"time" "time"
@ -11,6 +12,8 @@ import (
) )
func main() { func main() {
flag.Parse()
if err := embd.InitI2C(); err != nil { if err := embd.InitI2C(); err != nil {
panic(err) panic(err)
} }

View File

@ -3,6 +3,7 @@
package main package main
import ( import (
"flag"
"fmt" "fmt"
"time" "time"
@ -11,6 +12,8 @@ import (
) )
func main() { func main() {
flag.Parse()
if err := embd.InitI2C(); err != nil { if err := embd.InitI2C(); err != nil {
panic(err) panic(err)
} }

View File

@ -3,6 +3,7 @@
package main package main
import ( import (
"flag"
"fmt" "fmt"
"time" "time"
@ -11,6 +12,8 @@ import (
) )
func main() { func main() {
flag.Parse()
if err := embd.InitI2C(); err != nil { if err := embd.InitI2C(); err != nil {
panic(err) panic(err)
} }

View File

@ -3,12 +3,15 @@
package main package main
import ( import (
"flag"
"time" "time"
"github.com/kidoman/embd" "github.com/kidoman/embd"
) )
func main() { func main() {
flag.Parse()
if err := embd.InitGPIO(); err != nil { if err := embd.InitGPIO(); err != nil {
panic(err) panic(err)
} }

View File

@ -3,12 +3,15 @@
package main package main
import ( import (
"flag"
"time" "time"
"github.com/kidoman/embd" "github.com/kidoman/embd"
) )
func main() { func main() {
flag.Parse()
h, _, err := embd.DetectHost() h, _, err := embd.DetectHost()
if err != nil { if err != nil {
return return

View File

@ -3,12 +3,15 @@
package main package main
import ( import (
"flag"
"time" "time"
"github.com/kidoman/embd" "github.com/kidoman/embd"
) )
func main() { func main() {
flag.Parse()
if err := embd.InitGPIO(); err != nil { if err := embd.InitGPIO(); err != nil {
panic(err) panic(err)
} }

View File

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

View File

@ -3,6 +3,7 @@
package main package main
import ( import (
"flag"
"fmt" "fmt"
"os" "os"
"os/signal" "os/signal"
@ -13,6 +14,8 @@ import (
) )
func main() { func main() {
flag.Parse()
if err := embd.InitI2C(); err != nil { if err := embd.InitI2C(); err != nil {
panic(err) panic(err)
} }

View File

@ -5,6 +5,7 @@
package main package main
import ( import (
"flag"
"fmt" "fmt"
"os" "os"
"os/signal" "os/signal"
@ -14,6 +15,8 @@ import (
) )
func main() { func main() {
flag.Parse()
if err := embd.InitLED(); err != nil { if err := embd.InitLED(); err != nil {
panic(err) panic(err)
} }

View File

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

View File

@ -3,6 +3,7 @@
package main package main
import ( import (
"flag"
"fmt" "fmt"
"time" "time"
@ -11,6 +12,8 @@ import (
) )
func main() { func main() {
flag.Parse()
if err := embd.InitI2C(); err != nil { if err := embd.InitI2C(); err != nil {
panic(err) panic(err)
} }

View File

@ -3,6 +3,7 @@
package main package main
import ( import (
"flag"
"fmt" "fmt"
"math/rand" "math/rand"
"os" "os"
@ -13,6 +14,8 @@ import (
) )
func main() { func main() {
flag.Parse()
if err := embd.InitI2C(); err != nil { if err := embd.InitI2C(); err != nil {
panic(err) panic(err)
} }

View File

@ -3,6 +3,7 @@
package main package main
import ( import (
"flag"
"os" "os"
"os/signal" "os/signal"
"time" "time"
@ -12,6 +13,8 @@ import (
) )
func main() { func main() {
flag.Parse()
if err := embd.InitI2C(); err != nil { if err := embd.InitI2C(); err != nil {
panic(err) panic(err)
} }

View File

@ -5,12 +5,15 @@
package main package main
import ( import (
"flag"
"time" "time"
"github.com/kidoman/embd" "github.com/kidoman/embd"
) )
func main() { func main() {
flag.Parse()
if err := embd.InitGPIO(); err != nil { if err := embd.InitGPIO(); err != nil {
panic(err) panic(err)
} }

View File

@ -3,6 +3,7 @@
package main package main
import ( import (
"flag"
"os" "os"
"os/signal" "os/signal"
"time" "time"
@ -13,6 +14,8 @@ import (
) )
func main() { func main() {
flag.Parse()
if err := embd.InitI2C(); err != nil { if err := embd.InitI2C(); err != nil {
panic(err) panic(err)
} }

View File

@ -3,6 +3,8 @@
package main package main
import ( import (
"flag"
"fmt"
"os" "os"
"os/signal" "os/signal"
"time" "time"
@ -12,6 +14,8 @@ import (
) )
func main() { func main() {
flag.Parse()
embd.InitGPIO() embd.InitGPIO()
defer embd.CloseGPIO() defer embd.CloseGPIO()

View File

@ -3,6 +3,7 @@
package main package main
import ( import (
"flag"
"os" "os"
"os/signal" "os/signal"
"time" "time"
@ -12,6 +13,8 @@ import (
) )
func main() { func main() {
flag.Parse()
sb := servoblaster.New() sb := servoblaster.New()
defer sb.Close() defer sb.Close()

View File

@ -3,6 +3,7 @@
package main package main
import ( import (
"flag"
"fmt" "fmt"
"os" "os"
"os/signal" "os/signal"
@ -12,6 +13,8 @@ import (
) )
func main() { func main() {
flag.Parse()
if err := embd.InitI2C(); err != nil { if err := embd.InitI2C(); err != nil {
panic(err) panic(err)
} }

View File

@ -3,7 +3,10 @@
package main package main
import ( import (
"flag"
"fmt" "fmt"
"os"
"os/signal"
"time" "time"
"github.com/kidoman/embd" "github.com/kidoman/embd"
@ -11,16 +14,19 @@ import (
) )
func main() { func main() {
flag.Parse()
if err := embd.InitGPIO(); err != nil { if err := embd.InitGPIO(); err != nil {
panic(err) panic(err)
} }
defer embd.CloseGPIO() defer embd.CloseGPIO()
echoPin, err := embd.NewDigitalPin(10) echoPin, err := embd.NewDigitalPin("P9_21")
if err != nil { if err != nil {
panic(err) panic(err)
} }
triggerPin, err := embd.NewDigitalPin(9)
triggerPin, err := embd.NewDigitalPin("P9_22")
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -28,13 +34,21 @@ func main() {
rf := us020.New(echoPin, triggerPin, nil) rf := us020.New(echoPin, triggerPin, nil)
defer rf.Close() defer rf.Close()
for { quit := make(chan os.Signal, 1)
distance, err := rf.Distance() signal.Notify(quit, os.Interrupt, os.Kill)
if err != nil {
panic(err)
}
fmt.Printf("Distance is %v\n", distance)
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 package main
import ( import (
"flag"
"time" "time"
"github.com/golang/glog" "github.com/golang/glog"
@ -11,6 +12,8 @@ import (
) )
func main() { func main() {
flag.Parse()
if err := embd.InitGPIO(); err != nil { if err := embd.InitGPIO(); err != nil {
panic(err) panic(err)
} }