2014-03-02 12:36:34 +05:30
|
|
|
// +build ignore
|
|
|
|
|
2014-01-02 06:50:57 +05:30
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2014-04-05 01:43:16 +05:30
|
|
|
"flag"
|
2014-03-31 18:46:04 +05:30
|
|
|
"fmt"
|
2014-01-07 22:11:41 +05:30
|
|
|
"os"
|
|
|
|
"os/signal"
|
2014-01-09 05:26:21 +05:30
|
|
|
"time"
|
2014-03-01 20:19:44 +05:30
|
|
|
|
2014-03-03 00:51:23 +05:30
|
|
|
"github.com/kidoman/embd"
|
2014-02-10 05:05:41 +05:30
|
|
|
"github.com/kidoman/embd/sensor/l3gd20"
|
2014-01-02 06:50:57 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2014-04-05 01:43:16 +05:30
|
|
|
flag.Parse()
|
|
|
|
|
2014-03-03 00:51:23 +05:30
|
|
|
if err := embd.InitI2C(); err != nil {
|
2014-02-27 04:24:53 +05:30
|
|
|
panic(err)
|
|
|
|
}
|
2014-03-03 00:51:23 +05:30
|
|
|
defer embd.CloseI2C()
|
2014-02-27 04:24:53 +05:30
|
|
|
|
2014-03-03 00:51:23 +05:30
|
|
|
bus := embd.NewI2CBus(1)
|
2014-02-08 03:52:06 +05:30
|
|
|
|
2014-01-02 06:50:57 +05:30
|
|
|
gyro := l3gd20.New(bus, l3gd20.R250DPS)
|
|
|
|
defer gyro.Close()
|
|
|
|
|
2014-01-07 22:11:41 +05:30
|
|
|
gyro.Start()
|
2014-01-02 06:50:57 +05:30
|
|
|
|
2014-01-07 22:11:41 +05:30
|
|
|
quit := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(quit, os.Interrupt, os.Kill)
|
2014-01-02 06:50:57 +05:30
|
|
|
|
2014-01-07 22:11:41 +05:30
|
|
|
orientations, err := gyro.Orientations()
|
|
|
|
if err != nil {
|
2014-03-31 18:46:04 +05:30
|
|
|
panic(err)
|
2014-01-07 22:11:41 +05:30
|
|
|
}
|
2014-01-02 06:50:57 +05:30
|
|
|
|
2014-01-09 05:26:21 +05:30
|
|
|
timer := time.Tick(250 * time.Millisecond)
|
|
|
|
|
2014-01-07 22:11:41 +05:30
|
|
|
for {
|
|
|
|
select {
|
2014-01-09 05:26:21 +05:30
|
|
|
case <-timer:
|
|
|
|
orientation := <-orientations
|
2014-03-31 18:46:04 +05:30
|
|
|
fmt.Printf("x: %v, y: %v, z: %v\n", orientation.X, orientation.Y, orientation.Z)
|
2014-01-07 22:11:41 +05:30
|
|
|
case <-quit:
|
|
|
|
return
|
|
|
|
}
|
2014-01-02 06:50:57 +05:30
|
|
|
}
|
|
|
|
}
|